@@ -2179,13 +2179,15 @@ def __init__(self):
21792179 ).setParseAction (self .customspace ).setName ('customspace' )
21802180
21812181 unicode_range = u"\U00000080 -\U0001ffff "
2182- symbol = (Regex (UR"([a-zA-Z0-9 +\-*/<>=:,.;!\?&' @()\[\]|%s])|(\\[%%${}\[\]_|])" % unicode_range )
2182+ symbol = (Regex (UR"([a-zA-Z0-9 +\-*/<>=:,.;!\?&@()\[\]|%s])|(\\[%%${}\[\]_|])" % unicode_range )
21832183 | (Combine (
21842184 bslash
21852185 + oneOf (tex2uni .keys ())
21862186 ) + FollowedBy (Regex ("[^a-zA-Z]" )))
21872187 ).setParseAction (self .symbol ).leaveWhitespace ()
21882188
2189+ apostrophe = Regex (r"'+" )
2190+
21892191 c_over_c = (Suppress (bslash )
21902192 + oneOf (self ._char_over_chars .keys ())
21912193 ).setParseAction (self .char_over_chars )
@@ -2296,8 +2298,10 @@ def __init__(self):
22962298 subsuperop
22972299 - placeable
22982300 )
2301+ + Optional (apostrophe )
22992302 )
2300- | placeable
2303+ | (placeable + Optional (apostrophe ))
2304+ | apostrophe
23012305 )
23022306
23032307 autoDelim << (Suppress (Literal (r"\left" ))
@@ -2464,8 +2468,6 @@ def customspace(self, s, loc, toks):
24642468 def symbol (self , s , loc , toks ):
24652469 # print "symbol", toks
24662470 c = toks [0 ]
2467- if c == "'" :
2468- c = '\prime'
24692471 try :
24702472 char = Char (c , self .get_state ())
24712473 except ValueError :
@@ -2625,23 +2627,39 @@ def subsuperscript(self, s, loc, toks):
26252627 sub = None
26262628 super = None
26272629
2628- if len (toks [0 ]) == 1 :
2629- return toks [0 ].asList ()
2630- elif len (toks [0 ]) == 2 :
2631- op , next = toks [0 ]
2630+ # Pick all of the apostrophe's out
2631+ napostrophes = 0
2632+ new_toks = []
2633+ for tok in toks [0 ]:
2634+ if isinstance (tok , str ) and tok not in ('^' , '_' ):
2635+ napostrophes += len (tok )
2636+ else :
2637+ new_toks .append (tok )
2638+ toks = new_toks
2639+
2640+ if len (toks ) == 0 :
2641+ assert napostrophes
2642+ nucleus = Hbox (0.0 )
2643+ elif len (toks ) == 1 :
2644+ if not napostrophes :
2645+ return toks [0 ] # .asList()
2646+ else :
2647+ nucleus = toks [0 ]
2648+ elif len (toks ) == 2 :
2649+ op , next = toks
26322650 nucleus = Hbox (0.0 )
26332651 if op == '_' :
26342652 sub = next
26352653 else :
26362654 super = next
2637- elif len (toks [ 0 ] ) == 3 :
2638- nucleus , op , next = toks [ 0 ]
2655+ elif len (toks ) == 3 :
2656+ nucleus , op , next = toks
26392657 if op == '_' :
26402658 sub = next
26412659 else :
26422660 super = next
2643- elif len (toks [ 0 ] ) == 5 :
2644- nucleus , op1 , next1 , op2 , next2 = toks [ 0 ]
2661+ elif len (toks ) == 5 :
2662+ nucleus , op1 , next1 , op2 , next2 = toks
26452663 if op1 == op2 :
26462664 if op1 == '_' :
26472665 raise ParseFatalException ("Double subscript" )
@@ -2664,6 +2682,12 @@ def subsuperscript(self, s, loc, toks):
26642682 xHeight = state .font_output .get_xheight (
26652683 state .font , state .fontsize , state .dpi )
26662684
2685+ if napostrophes :
2686+ if super is None :
2687+ super = Hlist ([])
2688+ for i in range (napostrophes ):
2689+ super .children .extend (self .symbol (s , loc , ['\prime' ]))
2690+
26672691 # Handle over/under symbols, such as sum or integral
26682692 if self .is_overunder (nucleus ):
26692693 vlist = []
0 commit comments