@@ -2190,6 +2190,7 @@ def __init__(self):
21902190 p .simple = Forward ()
21912191 p .simple_group = Forward ()
21922192 p .single_symbol = Forward ()
2193+ p .snowflake = Forward ()
21932194 p .space = Forward ()
21942195 p .sqrt = Forward ()
21952196 p .stackrel = Forward ()
@@ -2223,6 +2224,7 @@ def __init__(self):
22232224 unicode_range = "\U00000080 -\U0001ffff "
22242225 p .single_symbol <<= Regex (r"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" %
22252226 unicode_range )
2227+ p .snowflake <<= Suppress (p .bslash ) + oneOf (self ._snowflake )
22262228 p .symbol_name <<= (Combine (p .bslash + oneOf (list (six .iterkeys (tex2uni )))) +
22272229 FollowedBy (Regex ("[^A-Za-z]" ).leaveWhitespace () | StringEnd ()))
22282230 p .symbol <<= (p .single_symbol | p .symbol_name ).leaveWhitespace ()
@@ -2297,8 +2299,10 @@ def __init__(self):
22972299 | Error ("Expected \operatorname{value}" ))
22982300 )
22992301
2300- p .placeable <<= ( p .symbol # Must be first
2301- | p .accent # Must be second
2302+ p .placeable <<= ( p .snowflake # this needs to be before accent so named symbols
2303+ # that are prefixed with an accent name work
2304+ | p .accent # Must be before symbol as all accents are symbols
2305+ | p .symbol # Must be third to catch all named symbols and single chars not in a group
23022306 | p .c_over_c
23032307 | p .function
23042308 | p .group
@@ -2505,6 +2509,8 @@ def symbol(self, s, loc, toks):
25052509 do_kern = False )]
25062510 return [char ]
25072511
2512+ snowflake = symbol
2513+
25082514 def unknown_symbol (self , s , loc , toks ):
25092515 # print "symbol", toks
25102516 c = toks [0 ]
@@ -2560,9 +2566,9 @@ def c_over_c(self, s, loc, toks):
25602566 r'bar' : r'\combiningoverline' ,
25612567 r'grave' : r'\combininggraveaccent' ,
25622568 r'acute' : r'\combiningacuteaccent' ,
2563- r'ddot' : r'\combiningdiaeresis' ,
25642569 r'tilde' : r'\combiningtilde' ,
25652570 r'dot' : r'\combiningdotabove' ,
2571+ r'ddot' : r'\combiningdiaeresis' ,
25662572 r'vec' : r'\combiningrightarrowabove' ,
25672573 r'"' : r'\combiningdiaeresis' ,
25682574 r"`" : r'\combininggraveaccent' ,
@@ -2577,6 +2583,11 @@ def c_over_c(self, s, loc, toks):
25772583
25782584 _wide_accents = set (r"widehat widetilde widebar" .split ())
25792585
2586+ # make a lambda and call it to get the namespace right
2587+ _snowflake = (lambda am : [p for p in tex2uni if
2588+ any (p .startswith (a ) and a != p for a in am )]
2589+ ) (set (_accent_map ))
2590+
25802591 def accent (self , s , loc , toks ):
25812592 assert (len (toks )== 1 )
25822593 state = self .get_state ()
0 commit comments