Skip to content

Properly use thin space after math text operator #17890

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 6 commits into from
Jul 16, 2020
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
26 changes: 19 additions & 7 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pyparsing import (
Combine, Empty, FollowedBy, Forward, Group, Literal, oneOf, OneOrMore,
Optional, ParseBaseException, ParseFatalException, ParserElement,
QuotedString, Regex, StringEnd, Suppress, ZeroOrMore)
ParseResults, QuotedString, Regex, StringEnd, Suppress, ZeroOrMore)

from matplotlib import cbook, colors as mcolors, rcParams
from matplotlib.afm import AFM
Expand Down Expand Up @@ -2873,25 +2873,37 @@ def accent(self, s, loc, toks):
])

def function(self, s, loc, toks):
self.push_state()
state = self.get_state()
state.font = 'rm'
hlist = Hlist([Char(c, state) for c in toks[0]])
self.pop_state()
hlist = self.operatorname(s, loc, toks)
hlist.function_name = toks[0]
return hlist

def operatorname(self, s, loc, toks):
self.push_state()
state = self.get_state()
state.font = 'rm'
hlist_list = []
# Change the font of Chars, but leave Kerns alone
for c in toks[0]:
if isinstance(c, Char):
c.font = 'rm'
c._update_metrics()
hlist_list.append(c)
elif isinstance(c, str):
hlist_list.append(Char(c, state))
else:
hlist_list.append(c)
next_char_loc = loc + len(toks[0]) + 1
if isinstance(toks[0], ParseResults):
next_char_loc += len('operatorname{}')
next_char = next((c for c in s[next_char_loc:] if c != ' '), '')
delimiters = self._left_delim | self._ambi_delim | self._right_delim
delimiters |= {'^', '_'}
if (next_char not in delimiters and
toks[0] not in self._overunder_functions):
# Add thin space except when followed by parenthesis, bracket, etc.
hlist_list += [self._make_space(self._space_widths[r'\,'])]
self.pop_state()
return Hlist(toks[0])
return Hlist(hlist_list)

def start_group(self, s, loc, toks):
self.push_state()
Expand Down
Binary file not shown.
Binary file not shown.
202 changes: 0 additions & 202 deletions lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_66.svg

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading