Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4513b61

Browse files
author
Ronald Hartley-Davies
committed
Fix handling of latex combined subscript and superscript
1 parent a468e31 commit 4513b61

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/matplotlib/mathtext.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,21 +2881,18 @@ def subsuper(self, s, loc, toks):
28812881
return toks[0] # .asList()
28822882
else:
28832883
nucleus = toks[0]
2884-
elif len(toks) == 2:
2885-
op, next = toks
2886-
nucleus = Hbox(0.0)
2887-
if op == '_':
2888-
sub = next
2889-
else:
2890-
super = next
2891-
elif len(toks) == 3:
2892-
nucleus, op, next = toks
2884+
elif len(toks) in (2, 3):
2885+
# single subscript or superscript
2886+
nucleus = toks[0] if len(toks) == 3 else Hbox(0.0)
2887+
op, next = toks[-2:]
28932888
if op == '_':
28942889
sub = next
28952890
else:
28962891
super = next
2897-
elif len(toks) == 5:
2898-
nucleus, op1, next1, op2, next2 = toks
2892+
elif len(toks) in (4, 5):
2893+
# subscript and superscript
2894+
nucleus = toks[0] if len(toks) == 5 else Hbox(0.0)
2895+
op1, next1, op2, next2 = toks[-4:]
28992896
if op1 == op2:
29002897
if op1 == '_':
29012898
raise ParseFatalException("Double subscript")

lib/matplotlib/tests/test_mathtext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
r'$6-2$; $-2$; $ -2$; ${-2}$; ${ -2}$; $20^{+3}_{-2}$',
107107
r'$\overline{\omega}^x \frac{1}{2}_0^x$', # github issue #5444
108108
r'$,$ $.$ $1{,}234{, }567{ , }890$ and $1,234,567,890$', # github issue 5799
109+
r'$\left(X\right)_{a}^{b}$', # github issue 7615
109110
]
110111

111112
digits = "0123456789"

0 commit comments

Comments
 (0)