Skip to content

Commit

Permalink
Merge pull request matplotlib#836 from mdboom/mathtext-prime
Browse files Browse the repository at this point in the history
mathtext-prime
  • Loading branch information
mdboom committed Apr 17, 2012
2 parents c063a9f + aa7e33d commit 9a8b35e
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 158 deletions.
4 changes: 3 additions & 1 deletion lib/matplotlib/_mathtext_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
r'\Psi' : ('cmr10', 15),
r'\Omega' : ('cmr10', 12),

r'\prime' : ('cmsy10', 73),

# these are mathml names, I think. I'm just using them for the
# tex methods noted
r'\circumflexaccent' : ('cmr10', 124), # for \hat
Expand Down Expand Up @@ -245,7 +247,7 @@
r'\spadesuit' : ('cmsy10', 7),
r'?' : ('cmr10', 50),
r'!' : ('cmr10', 29),
r'&' : ('cmr10', 109)
r'&' : ('cmr10', 109)
}

latex_to_cmex = {
Expand Down
48 changes: 36 additions & 12 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,13 +2179,15 @@ def __init__(self):
).setParseAction(self.customspace).setName('customspace')

unicode_range = u"\U00000080-\U0001ffff"
symbol =(Regex(UR"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" % unicode_range)
symbol =(Regex(UR"([a-zA-Z0-9 +\-*/<>=:,.;!\?&@()\[\]|%s])|(\\[%%${}\[\]_|])" % unicode_range)
| (Combine(
bslash
+ oneOf(tex2uni.keys())
) + FollowedBy(Regex("[^a-zA-Z]")))
).setParseAction(self.symbol).leaveWhitespace()

apostrophe = Regex(r"'+")

c_over_c =(Suppress(bslash)
+ oneOf(self._char_over_chars.keys())
).setParseAction(self.char_over_chars)
Expand Down Expand Up @@ -2296,8 +2298,10 @@ def __init__(self):
subsuperop
- placeable
)
+ Optional(apostrophe)
)
| placeable
| (placeable + Optional(apostrophe))
| apostrophe
)

autoDelim <<(Suppress(Literal(r"\left"))
Expand Down Expand Up @@ -2464,8 +2468,6 @@ def customspace(self, s, loc, toks):
def symbol(self, s, loc, toks):
# print "symbol", toks
c = toks[0]
if c == "'":
c = '\prime'
try:
char = Char(c, self.get_state())
except ValueError:
Expand Down Expand Up @@ -2625,23 +2627,39 @@ def subsuperscript(self, s, loc, toks):
sub = None
super = None

if len(toks[0]) == 1:
return toks[0].asList()
elif len(toks[0]) == 2:
op, next = toks[0]
# Pick all of the apostrophe's out
napostrophes = 0
new_toks = []
for tok in toks[0]:
if isinstance(tok, str) and tok not in ('^', '_'):
napostrophes += len(tok)
else:
new_toks.append(tok)
toks = new_toks

if len(toks) == 0:
assert napostrophes
nucleus = Hbox(0.0)
elif len(toks) == 1:
if not napostrophes:
return toks[0] # .asList()
else:
nucleus = toks[0]
elif len(toks) == 2:
op, next = toks
nucleus = Hbox(0.0)
if op == '_':
sub = next
else:
super = next
elif len(toks[0]) == 3:
nucleus, op, next = toks[0]
elif len(toks) == 3:
nucleus, op, next = toks
if op == '_':
sub = next
else:
super = next
elif len(toks[0]) == 5:
nucleus, op1, next1, op2, next2 = toks[0]
elif len(toks) == 5:
nucleus, op1, next1, op2, next2 = toks
if op1 == op2:
if op1 == '_':
raise ParseFatalException("Double subscript")
Expand All @@ -2664,6 +2682,12 @@ def subsuperscript(self, s, loc, toks):
xHeight = state.font_output.get_xheight(
state.font, state.fontsize, state.dpi)

if napostrophes:
if super is None:
super = Hlist([])
for i in range(napostrophes):
super.children.extend(self.symbol(s, loc, ['\prime']))

# Handle over/under symbols, such as sum or integral
if self.is_overunder(nucleus):
vlist = []
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.
169 changes: 85 additions & 84 deletions lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_37.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading

0 comments on commit 9a8b35e

Please sign in to comment.