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

Backport PR #26519 on branch v3.8.x (Fix mathtext mismatched braces) #26563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion 7 lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,7 @@ def csnames(group, names):
p.function = csnames("name", self._function_names)

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

p.frac = cmd(r"\frac", p.required_group("num") + p.required_group("den"))
p.dfrac = cmd(r"\dfrac", p.required_group("num") + p.required_group("den"))
Expand Down Expand Up @@ -1984,6 +1985,7 @@ def csnames(group, names):
p.token <<= (
p.simple
| p.auto_delim
| p.unclosed_group
| p.unknown_symbol # Must be last
)

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

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

def math(self, s, loc, toks):
hlist = Hlist(toks)
Expand Down Expand Up @@ -2294,6 +2296,9 @@ def end_group(self, s, loc, toks):
self.pop_state()
return []

def unclosed_group(self, s, loc, toks):
raise ParseFatalException(s, len(s), "Expected '}'")

def font(self, s, loc, toks):
self.get_state().font = toks["font"]
return []
Expand Down
4 changes: 3 additions & 1 deletion 4 lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def test_fontinfo():
(r'$a^2^2$', r'Double superscript'),
(r'$a_2_2$', r'Double subscript'),
(r'$a^2_a^2$', r'Double superscript'),
(r'$a = {b$', r"Expected '}'"),
],
ids=[
'hspace without value',
Expand Down Expand Up @@ -347,7 +348,8 @@ def test_fontinfo():
'unknown symbol',
'double superscript',
'double subscript',
'super on sub without braces'
'super on sub without braces',
'unclosed group',
]
)
def test_mathtext_exceptions(math, msg):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.