8000 Merge pull request #26563 from meeseeksmachine/auto-backport-of-pr-26… · matplotlib/matplotlib@6ab8dbb · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ab8dbb

Browse files
authored
Merge pull request #26563 from meeseeksmachine/auto-backport-of-pr-26519-on-v3.8.x
Backport PR #26519 on branch v3.8.x (Fix mathtext mismatched braces)
2 parents aeb4eb1 + 1c1018f commit 6ab8dbb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,7 @@ def csnames(group, names):
19361936
p.function = csnames("name", self._function_names)
19371937

19381938
p.group = p.start_group + ZeroOrMore(p.token)("group") + p.end_group
1939+
p.unclosed_group = (p.start_group + ZeroOrMore(p.token)("group") + StringEnd())
19391940

19401941
p.frac = cmd(r"\frac", p.required_group("num") + p.required_group("den"))
19411942
p.dfrac = cmd(r"\dfrac", p.required_group("num") + p.required_group("den"))
@@ -1984,6 +1985,7 @@ def csnames(group, names):
19841985
p.token <<= (
19851986
p.simple
19861987
| p.auto_delim
1988+
| p.unclosed_group
19871989
| p.unknown_symbol # Must be last
19881990
)
19891991

@@ -2072,7 +2074,7 @@ def main(self, s, loc, toks):
20722074
return [Hlist(toks)]
20732075

20742076
def math_string(self, s, loc, toks):
2075-
return self._math_expression.parseString(toks[0][1:-1])
2077+
return self._math_expression.parseString(toks[0][1:-1], parseAll=True)
20762078

20772079
def math(self, s, loc, toks):
20782080
hlist = Hlist(toks)
@@ -2294,6 +2296,9 @@ def end_group(self, s, loc, toks):
22942296
self.pop_state()
22952297
return []
22962298

2299+
def unclosed_group(self, s, loc, toks):
2300+
raise ParseFatalException(s, len(s), "Expected '}'")
2301+
22972302
def font(self, s, loc, toks):
22982303
self.get_state().font = toks["font"]
22992304
return []

lib/matplotlib/tests/test_mathtext.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def test_fontinfo():
320320
(r'$a^2^2$', r'Double superscript'),
321321
(r'$a_2_2$', r'Double subscript'),
322322
(r'$a^2_a^2$', r'Double superscript'),
323+
(r'$a = {b$', r"Expected '}'"),
323324
],
324325
ids=[
325326
'hspace without value',
@@ -347,7 +348,8 @@ def test_fontinfo():
347348
'unknown symbol',
348349
'double superscript',
349350
'double subscript',
350-
'super on sub without braces'
351+
'super on sub without braces',
352+
'unclosed group',
351353
]
352354
)
353355
def test_mathtext_exceptions(math, msg):

0 commit comments

Comments
 (0)
0