@@ -2179,13 +2179,15 @@ def __init__(self):
2179
2179
).setParseAction (self .customspace ).setName ('customspace' )
2180
2180
2181
2181
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 )
2183
2183
| (Combine (
2184
2184
bslash
2185
2185
+ oneOf (tex2uni .keys ())
2186
2186
) + FollowedBy (Regex ("[^a-zA-Z]" )))
2187
2187
).setParseAction (self .symbol ).leaveWhitespace ()
2188
2188
2189
+ apostrophe = Regex (r"'+" )
2190
+
2189
2191
c_over_c = (Suppress (bslash )
2190
2192
+ oneOf (self ._char_over_chars .keys ())
2191
2193
).setParseAction (self .char_over_chars )
@@ -2296,8 +2298,10 @@ def __init__(self):
2296
2298
subsuperop
2297
2299
- placeable
2298
2300
)
2301
+ + Optional (apostrophe )
2299
2302
)
2300
- | placeable
2303
+ | (placeable + Optional (apostrophe ))
2304
+ | apostrophe
2301
2305
)
2302
2306
2303
2307
autoDelim << (Suppress (Literal (r"\left" ))
@@ -2464,8 +2468,6 @@ def customspace(self, s, loc, toks):
2464
2468
def symbol (self , s , loc , toks ):
2465
2469
# print "symbol", toks
2466
2470
c = toks [0 ]
2467
- if c == "'" :
2468
- c = '\prime'
2469
2471
try :
2470
2472
char = Char (c , self .get_state ())
2471
2473
except ValueError :
@@ -2625,23 +2627,39 @@ def subsuperscript(self, s, loc, toks):
2625
2627
sub = None
2626
2628
super = None
2627
2629
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
2632
2650
nucleus = Hbox (0.0 )
2633
2651
if op == '_' :
2634
2652
sub = next
2635
2653
else :
2636
2654
super = next
2637
- elif len (toks [ 0 ] ) == 3 :
2638
- nucleus , op , next = toks [ 0 ]
2655
+ elif len (toks ) == 3 :
2656
+ nucleus , op , next = toks
2639
2657
if op == '_' :
2640
2658
sub = next
2641
2659
else :
2642
2660
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
2645
2663
if op1 == op2 :
2646
2664
if op1 == '_' :
2647
2665
raise ParseFatalException ("Double subscript" )
@@ -2664,6 +2682,12 @@ def subsuperscript(self, s, loc, toks):
2664
2682
xHeight = state .font_output .get_xheight (
2665
2683
state .font , state .fontsize , state .dpi )
2666
2684
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
+
2667
2691
# Handle over/under symbols, such as sum or integral
2668
2692
if self .is_overunder (nucleus ):
2669
2693
vlist = []
0 commit comments