@@ -61,21 +61,21 @@ def HasBalancedTags(s):
6161
6262def ReplaceMath (cache , data ):
6363 old = data
64+ data = re .sub ('[\\ \\ ]\\ [([0-9]|-)' , '\\ \\ DOUBLESLASH\\ [\\ 1' , data ) # Messed up by Bikeshed
6465 data = data .replace ('\\ \\ ' , '\\ DOUBLESLASH' )
6566 data = data .replace ('\\ (' , '' )
6667 data = data .replace ('\\ )' , '' )
6768 data = data .replace ('\\ [' , '' )
6869 data = data .replace ('\\ ]' , '' )
6970 data = data .replace ('\\ DOUBLESLASH' , '\\ \\ ' )
70- data = data .replace ('’' , '\\ text{’}' )
71- data = data .replace ('‘' , '\\ text{‘}' )
72- data = data .replace ('\\ hfill' , '' )
71+ data = data .replace ('\u2019 ' , '\' ' ) # "Right Single Quotation Mark" messed up by Bikeshed
72+ data = data .replace ('\\ hfill' , ' ' )
7373 data = data .replace ('\\ mbox' , '\\ text' )
7474 data = data .replace ('\\ begin{split}' , '\\ begin{aligned}' )
7575 data = data .replace ('\\ end{split}' , '\\ end{aligned}' )
76- data = data .replace ('&' , '&' )
77- data = data .replace ('<' , '<' )
78- data = data .replace ('>' , '>' )
76+ data = data .replace ('&' , '&' ) # Messed up by Bikeshed
77+ data = data .replace ('<' , '<' ) # Messed up by Bikeshed
78+ data = data .replace ('>' , '>' ) # Messed up by Bikeshed
7979 data = data .replace ('{array}[t]' , '{array}' )
8080 data = data .replace ('{array}[b]' , '{array}' )
8181 data = data .replace ('@{~}' , '' )
@@ -108,12 +108,17 @@ def ReplaceMath(cache, data):
108108 data = data [:start ] + v .replace ('#1' , data [start + len (k ):end ]) + data [end :]
109109 p = subprocess .Popen (
110110 ['node' , os .path .join (SCRIPT_DIR , 'katex/cli.js' ), '--display-mode' , '--trust' ],
111- stdin = subprocess .PIPE , stdout = subprocess .PIPE , text = True )
112- ret = p .communicate (input = data )[0 ]
113- if p .returncode != 0 :
111+ stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
112+ ret , err = p .communicate (input = data )
113+ if p .returncode != 0 or err != "" :
114+ if err != "" :
115+ sys .stderr .write ('\n \n ' + err + '\n ' )
114116 sys .stderr .write ('BEFORE:\n ' + old + '\n ' )
115117 sys .stderr .write ('AFTER:\n ' + data + '\n ' )
116- raise Exception ()
118+ if p .returncode != 0 :
119+ raise Exception ()
120+ else :
121+ sys .stderr .write ('RESULT:\n ' + ret + '\n ' )
117122 ret = ret .strip ()
118123 ret = ret [ret .find ('<span class="katex-html"' ):]
119124 ret = '<span class="katex-display"><span class="katex">' + ret
@@ -207,7 +212,7 @@ def ExtractMath(match):
207212 # Pull out math fragments.
208213 data = re .sub (
209214 'class="([^"]*)math([^"]*)"[^>]*>'
210- '((?:[ ]*<span[^>]*>[^<]*</span>)*)([^<]*)<' ,
215+ '((?:[ \n ]*<span[^>]*>[^<]*</span>)*)([^<]*)<' ,
211216 ExtractMath , data )
212217
213218 sys .stderr .write ('Processing %d fragments.\n ' % len (fixups ))
@@ -223,7 +228,8 @@ def Worker():
223228 fixed = ('class="' + cls_before + ' ' + cls_after + '">' +
224229 spans + ReplaceMath (cache , mth ) + '<' )
225230 done_fixups .append ((start , end , fixed ))
226- except Exception :
231+ except Exception as inst :
232+ sys .stderr .write ('\n Exception: ' + inst .__str__ () + '\n ' )
227233 success = False
228234
229235 q .task_done ()
0 commit comments