Skip to content

Commit 706684f

Browse files
committed
Improved coverage of mathtext and removed unused code
1 parent bf3c651 commit 706684f

File tree

3 files changed

+15
-51
lines changed

3 files changed

+15
-51
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,6 @@ def __init__(self):
19541954
p.auto_delim = Forward()
19551955
p.binom = Forward()
19561956
p.bslash = Forward()
1957-
p.c_over_c = Forward()
19581957
p.customspace = Forward()
19591958
p.end_group = Forward()
19601959
p.float_literal = Forward()
@@ -2031,11 +2030,6 @@ def __init__(self):
20312030

20322031
p.apostrophe <<= Regex("'+")
20332032

2034-
p.c_over_c <<= (
2035-
Suppress(p.bslash)
2036-
+ oneOf(list(self._char_over_chars))
2037-
)
2038-
20392033
p.accent <<= Group(
20402034
Suppress(p.bslash)
20412035
+ oneOf([*self._accent_map, *self._wide_accents])
@@ -2138,7 +2132,6 @@ def __init__(self):
21382132
| p.accent # Must be before symbol as all accents are symbols
21392133
| p.symbol # Must be third to catch all named symbols and single
21402134
# chars not in a group
2141-
| p.c_over_c
21422135
| p.function
21432136
| p.group
21442137
| p.frac
@@ -2375,50 +2368,6 @@ def unknown_symbol(self, s, loc, toks):
23752368
c, = toks
23762369
raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)
23772370

2378-
_char_over_chars = {
2379-
# The first 2 entries in the tuple are (font, char, sizescale) for
2380-
# the two symbols under and over. The third element is the space
2381-
# (in multiples of underline height)
2382-
r'AA': (('it', 'A', 1.0), (None, '\\circ', 0.5), 0.0),
2383-
}
2384-
2385-
def c_over_c(self, s, loc, toks):
2386-
sym, = toks
2387-
state = self.get_state()
2388-
thickness = state.font_output.get_underline_thickness(
2389-
state.font, state.fontsize, state.dpi)
2390-
2391-
under_desc, over_desc, space = \
2392-
self._char_over_chars.get(sym, (None, None, 0.0))
2393-
if under_desc is None:
2394-
raise ParseFatalException("Error parsing symbol")
2395-
2396-
over_state = state.copy()
2397-
if over_desc[0] is not None:
2398-
over_state.font = over_desc[0]
2399-
over_state.fontsize *= over_desc[2]
2400-
over = Accent(over_desc[1], over_state)
2401-
2402-
under_state = state.copy()
2403-
if under_desc[0] is not None:
2404-
under_state.font = under_desc[0]
2405-
under_state.fontsize *= under_desc[2]
2406-
under = Char(under_desc[1], under_state)
2407-
2408-
width = max(over.width, under.width)
2409-
2410-
over_centered = HCentered([over])
2411-
over_centered.hpack(width, 'exactly')
2412-
2413-
under_centered = HCentered([under])
2414-
under_centered.hpack(width, 'exactly')
2415-
2416-
return Vlist([
2417-
over_centered,
2418-
Vbox(0., thickness * space),
2419-
under_centered
2420-
])
2421-
24222371
_accent_map = {
24232372
r'hat': r'\circumflexaccent',
24242373
r'breve': r'\combiningbreve',

lib/matplotlib/_mathtext_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@
11161116
'cwopencirclearrow' : 8635,
11171117
'geqq' : 8807,
11181118
'rightleftarrows' : 8644,
1119+
'aa' : 229,
11191120
'ac' : 8766,
11201121
'ae' : 230,
11211122
'int' : 8747,

lib/matplotlib/tests/test_mathtext.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ def test_fontinfo():
257257
(r'$\dfrac{}{}$', r'Expected \dfrac{num}{den}'),
258258
(r'$\overset$', r'Expected \overset{body}{annotation}'),
259259
(r'$\underset$', r'Expected \underset{body}{annotation}'),
260+
(r'$\foo$', r'Unknown symbol: \foo'),
261+
(r'$a^2^2$', r'Double superscript'),
262+
(r'$a_2_2$', r'Double subscript'),
263+
(r'$a^2_a^2$', r'Subscript/superscript sequence is too long.'\
264+
r' Use braces { } to remove ambiguity.'),
260265
],
261266
ids=[
262267
'hspace without value',
@@ -279,6 +284,10 @@ def test_fontinfo():
279284
'dfrac with empty parameters',
280285
'overset without parameters',
281286
'underset without parameters',
287+
'unknown symbol',
288+
'double superscript',
289+
'double subscript',
290+
'super on sub without braces'
282291
]
283292
)
284293
def test_mathtext_exceptions(math, msg):
@@ -288,6 +297,11 @@ def test_mathtext_exceptions(math, msg):
288297
parser.parse(math)
289298

290299

300+
def test_get_unicode_index_exception():
301+
with pytest.raises(ValueError):
302+
_mathtext.get_unicode_index(r'\foo')
303+
304+
291305
def test_single_minus_sign():
292306
plt.figure(figsize=(0.3, 0.3))
293307
plt.text(0.5, 0.5, '$-$')

0 commit comments

Comments
 (0)