8000 FIX: mathtext accents by tacaswell · Pull Request #4887 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
< 8000 svg style="box-sizing: content-box; color: var(--color-icon-primary);" width="32" height="32" viewBox="0 0 16 16" fill="none" aria-hidden="true" data-view-component="true" class="anim-rotate"> Loading
Diff view
Diff view
Next Next commit
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')
  • Loading branch information
tacaswell committed Aug 29, 2015
commit e2ce13b5c17ddf63eb288c4652bf01f87f025b1f
17 changes: 14 additions & 3 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
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 @@ -2505,6 +2509,8 @@ def symbol(self, s, loc, toks):
do_kern = False)]
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
0