Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 02f9429

Browse filesBrowse files
authored
Merge pull request #26519 from devRD/mt-brace
Fix mathtext mismatched braces
2 parents 0b5940f + 3dc3457 commit 02f9429
Copy full SHA for 02f9429

File tree

2 files changed

+9
-2
lines changed
Filter options

2 files changed

+9
-2
lines changed

‎lib/matplotlib/_mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_mathtext.py
+6-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_mathtext.py
+3-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.