Skip to content

Commit f83daa7

Browse files
committed
Only check _metrics of subsuper nucleus if available
Fixes #5444
1 parent d6354b8 commit f83daa7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/matplotlib/mathtext.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2859,10 +2859,12 @@ def subsuper(self, s, loc, toks):
28592859
new_children = nucleus.children
28602860
if len(new_children):
28612861
# remove last kern
2862-
if isinstance(new_children[-1],Kern):
2862+
if (isinstance(new_children[-1],Kern) and
2863+
hasattr(new_children[-2], '_metrics')):
28632864
new_children = new_children[:-1]
28642865
last_char = new_children[-1]
2865-
last_char.width = last_char._metrics.advance
2866+
if hasattr(last_char, '_metrics'):
2867+
last_char.width = last_char._metrics.advance
28662868
# create new Hlist without kerning
28672869
nucleus = Hlist(new_children, do_kern=False)
28682870
else:

lib/matplotlib/tests/test_mathtext.py

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
r'testing$^{123}$',
105105
' '.join('$\\' + p + '$' for p in sorted(mathtext.Parser._snowflake)),
106106
r'$6-2$; $-2$; $ -2$; ${-2}$; ${ -2}$; $20^{+3}_{-2}$',
107+
r'$\overline{\omega}^x \frac{1}{2}_0^x$', # github issue #5444
107108
]
108109

109110
digits = "0123456789"

0 commit comments

Comments
 (0)