Skip to content

Commit 8e01118

Browse files
tacaswellmeeseeksmachine
authored andcommitted
Backport PR matplotlib#32066: Fix crash on prime after single-character superscript
1 parent e15b81d commit 8e01118

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/matplotlib/_mathtext.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,6 +2607,10 @@ def subsuper(self, s: str, loc: int, toks: ParseResults) -> T.Any:
26072607
if napostrophes:
26082608
if super is None:
26092609
super = Hlist([])
2610+
elif not isinstance(super, Hlist):
2611+
# A single-char superscript is a bare Char; wrap it so the
2612+
# prime glyphs can be appended.
2613+
super = Hlist([super])
26102614
for i in range(napostrophes):
26112615
super.children.extend(self.symbol(s, loc, {"sym": "\\prime"}))
26122616
# kern() and hpack() needed to get the metrics right after

lib/matplotlib/tests/test_mathtext.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,13 @@ def test_mathtext_operators():
569569
fig.draw_without_rendering()
570570

571571

572+
@pytest.mark.parametrize("expr", [r"$x^2'$", r"$x^a'$", r"$x^2''$", r"$x^\alpha'$"])
573+
def test_mathtext_single_char_super_with_prime(expr):
574+
# Regression test for a crash: prime after a single-char superscript.
575+
parser = mathtext.MathTextParser('agg')
576+
parser.parse(expr)
577+
578+
572579
@check_figures_equal()
573580
def test_boldsymbol(fig_test, fig_ref):
574581
fig_test.text(0.1, 0.2, r"$\boldsymbol{\mathrm{abc0123\alpha}}$")

0 commit comments

Comments
 (0)