Skip to content

FIX: mathtext accents #4887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,8 +2107,8 @@ class Parser(object):
\\subseteq \\supseteq \\cong \\Join
\\sqsubset \\sqsupset \\neq \\smile
\\sqsubseteq \\sqsupseteq \\doteq \\frown
\\in \\ni \\propto
\\vdash \\dashv \\dots'''.split())
\\in \\ni \\propto \\vdash
\\dashv \\dots \\dotplus \\doteqdot'''.split())

_arrow_symbols = set('''
\\leftarrow \\longleftarrow \\uparrow
Expand Down Expand Up @@ -2190,6 +2190,7 @@ def __init__(self):
p.simple = Forward()
p.simple_group = Forward()
p.single_symbol = Forward()
p.snowflake = Forward()
p.space = Forward()
p.sqrt = Forward()
p.stackrel = Forward()
Expand Down Expand Up @@ -2223,6 +2224,7 @@ def __init__(self):
unicode_range = "\U00000080-\U0001ffff"
p.single_symbol <<= Regex(r"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" %
unicode_range)
p.snowflake <<= Suppress(p.bslash) + oneOf(self._snowflake)
p.symbol_name <<= (Combine(p.bslash + oneOf(list(six.iterkeys(tex2uni)))) +
FollowedBy(Regex("[^A-Za-z]").leaveWhitespace() | StringEnd()))
p.symbol <<= (p.single_symbol | p.symbol_name).leaveWhitespace()
Expand Down Expand Up @@ -2297,8 +2299,10 @@ def __init__(self):
| Error("Expected \operatorname{value}"))
)

p.placeable <<= ( p.symbol # Must be first
| p.accent # Must be second
p.placeable <<= ( p.snowflake # this needs to be before accent so named symbols
# that are prefixed with an accent name work
| p.accent # Must be before symbol as all accents are symbols
| p.symbol # Must be third to catch all named symbols and single chars not in a group
| p.c_over_c
| p.function
| p.group
Expand Down Expand Up @@ -2498,13 +2502,15 @@ def symbol(self, s, loc, toks):
return [Hlist( [self._make_space(0.2),
char,
self._make_space(0.2)] ,
do_kern = False)]
do_kern = True)]
elif c in self._punctuation_symbols:
return [Hlist( [char,
self._make_space(0.2)] ,
do_kern = False)]
do_kern = True)]
return [char]

snowflake = symbol

def unknown_symbol(self, s, loc, toks):
# print "symbol", toks
c = toks[0]
Expand Down Expand Up @@ -2560,9 +2566,9 @@ def c_over_c(self, s, loc, toks):
r'bar' : r'\combiningoverline',
r'grave' : r'\combininggraveaccent',
r'acute' : r'\combiningacuteaccent',
r'ddot' : r'\combiningdiaeresis',
r'tilde' : r'\combiningtilde',
r'dot' : r'\combiningdotabove',
r'ddot' : r'\combiningdiaeresis',
r'vec' : r'\combiningrightarrowabove',
r'"' : r'\combiningdiaeresis',
r"`" : r'\combininggraveaccent',
Expand All @@ -2577,6 +2583,11 @@ def c_over_c(self, s, loc, toks):

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

# make a lambda and call it to get the namespace right
_snowflake = (lambda am: [p for p in tex2uni if
any(p.startswith(a) and a != p for a in am)]
) (set(_accent_map))

def accent(self, s, loc, toks):
assert(len(toks)==1)
state = self.get_state()
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading