Skip to content

mathtext: Fix bugs in conversion of apostrophes to primes #5880

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 2 commits into from
Jan 25, 2016
Merged
Show file tree
Hide file tree
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.
Loading
Diff view
Diff view
Next Next commit
Fix apostrophes as primes
Fixes #5864
  • Loading branch information
zblz committed Jan 19, 2016
commit ffe069dfb9ca36a65acf4096fa1c0ada6d4e4da5
8 changes: 7 additions & 1 deletion lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2852,12 +2852,15 @@ def subsuper(self, s, loc, toks):
sub = None
super = None

# Pick all of the apostrophe's out
# Pick all of the apostrophes out, including first apostrophes that have
# been parsed as characters
napostrophes = 0
new_toks = []
for tok in toks[0]:
if isinstance(tok, six.string_types) and tok not in ('^', '_'):
napostrophes += len(tok)
elif isinstance(tok, Char) and tok.c == "'":
napostrophes += 1
else:
new_toks.append(tok)
toks = new_toks
Expand Down Expand Up @@ -2912,6 +2915,9 @@ def subsuper(self, s, loc, toks):
super = Hlist([])
for i in range(napostrophes):
super.children.extend(self.symbol(s, loc, ['\prime']))
# kern() and hpack() needed to get the metrics right after extending
super.kern()
super.hpack()

# Handle over/under symbols, such as sum or integral
if self.is_overunder(nucleus):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
r"$\gamma = \frac{x=\frac{6}{8}}{y} \delta$",
r'$\limsup_{x\to\infty}$',
r'$\oint^\infty_0$',
r"$f'$",
r"$f'\quad f'''(x)\quad ''/\mathrm{yr}$",
r'$\frac{x_2888}{y}$',
r"$\sqrt[3]{\frac{X_2}{Y}}=5$",
r"$\sqrt[5]{\prod^\frac{x}{2\pi^2}_\infty}$",
Expand Down