Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6b9969

Browse files
committed
FIX: mathtext accents
This is a follow up to #4588 The change in ae91e9f fixed the symbols that started with accent names, but broke all of the other accents. This fixes both by special casing the 8 named symbols that start with an accent as a prefix. ex '\doteq' should be parsed as a single symbol, not as as two symbols (e, q) with a dot over the e ('\dot{e}q')
1 parent d265a6e commit c6b9969

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/matplotlib/mathtext.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,7 @@ def __init__(self):
21562156
p.simple = Forward()
21572157
p.simple_group = Forward()
21582158
p.single_symbol = Forward()
2159+
p.snowflake = Forward()
21592160
p.space = Forward()
21602161
p.sqrt = Forward()
21612162
p.stackrel = Forward()
@@ -2189,6 +2190,7 @@ def __init__(self):
21892190
unicode_range = "\U00000080-\U0001ffff"
21902191
p.single_symbol <<= Regex(r"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" %
21912192
unicode_range)
2193+
p.snowflake <<= Suppress(p.bslash) + oneOf(self._snowflake)
21922194
p.symbol_name <<= (Combine(p.bslash + oneOf(list(six.iterkeys(tex2uni)))) +
21932195
FollowedBy(Regex("[^A-Za-z]").leaveWhitespace() | StringEnd()))
21942196
p.symbol <<= (p.single_symbol | p.symbol_name).leaveWhitespace()
@@ -2263,8 +2265,10 @@ def __init__(self):
22632265
| Error("Expected \operatorname{value}"))
22642266
)
22652267

2266-
p.placeable <<= ( p.symbol # Must be first
2267-
| p.accent # Must be second
2268+
p.placeable <<= ( p.snowflake # this needs to be before accent so named symbols
2269+
# that are prefixed with an accent name work
2270+
| p.accent # Must be before symbol as all accents are symbols
2271+
| p.symbol # Must be third to catch all named symbols and single chars not in a group
22682272
| p.c_over_c
22692273
| p.function
22702274
| p.group
@@ -2471,6 +2475,8 @@ def symbol(self, s, loc, toks):
24712475
do_kern = False)]
24722476
return [char]
24732477

2478+
snowflake = symbol
2479+
24742480
def unknown_symbol(self, s, loc, toks):
24752481
# print "symbol", toks
24762482
c = toks[0]
@@ -2526,9 +2532,9 @@ def c_over_c(self, s, loc, toks):
25262532
r'bar' : r'\combiningoverline',
25272533
r'grave' : r'\combininggraveaccent',
25282534
r'acute' : r'\combiningacuteaccent',
2529-
r'ddot' : r'\combiningdiaeresis',
25302535
r'tilde' : r'\combiningtilde',
25312536
r'dot' : r'\combiningdotabove',
2537+
r'ddot' : r'\combiningdiaeresis',
25322538
r'vec' : r'\combiningrightarrowabove',
25332539
r'"' : r'\combiningdiaeresis',
25342540
r"`" : r'\combininggraveaccent',
@@ -2543,6 +2549,11 @@ def c_over_c(self, s, loc, toks):
25432549

25442550
_wide_accents = set(r"widehat widetilde widebar".split())
25452551

2552+
# make a lambda and call it to get the namespace right
2553+
_snowflake = (lambda am: [p for p in tex2uni if
2554+
any(p.startswith(a) and a != p for a in am)]
2555+
) (set(_accent_map))
2556+
25462557
def accent(self, s, loc, toks):
25472558
assert(len(toks)==1)
25482559
state = self.get_state()

0 commit comments

Comments
 (0)