FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix spacing after mathtext operators with sub/superscripts by timhoffm · Pull Request #23243 · matplotlib/matplotlib · GitHub

Repository navigation

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

Filter by extension

Filter by extension .pdf  (5) .png  (5) .py  (2) .svg  (5) All 4 file types selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 20 additions & 1 deletion lib/matplotlib/_mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,9 @@ def __init__(self):
self._expression = p.main
self._math_expression = p.math

# To add space to nucleus operators after sub/superscripts
self._in_subscript_or_superscript = False

def parse(self, s, fonts_object, fontsize, dpi):
"""
Parse expression *s* using the given *fonts_object* for
Expand All @@ -1965,6 +1968,8 @@ def parse(self, s, fonts_object, fontsize, dpi):
" " * (err.column - 1) + "^",
str(err)])) from err
self._state_stack = None
self._in_subscript_or_superscript = False
# prevent operator spacing from leaking into a new expression
self._em_width_cache = {}
self._expression.resetCache()
return result[0]
Expand Down Expand Up @@ -2164,6 +2169,13 @@ def operatorname(self, s, loc, toks):
# Add thin space except when followed by parenthesis, bracket, etc.
hlist_list += [self._make_space(self._space_widths[r'\,'])]
self.pop_state()
# if followed by a super/subscript, set flag to true
# This flag tells subsuper to add space after this operator
if next_char in {'^', '_'}:
self._in_subscript_or_superscript = True
else:
self._in_subscript_or_superscript = False

return Hlist(hlist_list)

def start_group(self, s, loc, toks):
Expand Down Expand Up @@ -2394,8 +2406,15 @@ def subsuper(self, s, loc, toks):

if not self.is_dropsub(last_char):
x.width += constants.script_space * xHeight
result = Hlist([nucleus, x])

# Do we need to add a space after the nucleus?
# To find out, check the flag set by operatorname
spaced_nucleus = [nucleus, x]
if self._in_subscript_or_superscript:
spaced_nucleus += [self._make_space(self._space_widths[r'\,'])]
self._in_subscript_or_superscript = False

result = Hlist(spaced_nucleus)
return [result]

def _genfrac(self, ldelim, rdelim, rule, style, num, den):
Expand Down
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Loading

Back | FazBrowse Home | New Git URL