Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 703c086

Browse files
committed
Fix spacing in r"$\max f$".
Previously, in a mathtext string like `r"$\sin x$"`, a thin space would (correctly) be added between "sin" and "x", but that space would be missing in expressions like `r"$\max f$"`. The difference arose because of the slightly different handling of subscripts and superscripts after the `\sin` and `\max` operators: `\sin^n` puts the superscript as a normal exponent, but `\max_x` puts the subscript centered below the operator name ("overunder symbol). The previous code for inserting the thin space did not handle the "overunder" case; fix that. The new behavior is tested by the change in test_operator_space, as well as by mathtext1_dejavusans_06. The change in mathtext_foo_29 arises because the extra thin space now inserted after `\limsup` slightly shifts the centering of the whole string. Ideally that thin space should be suppressed if there's no token after the operator, but that's not something currently implemented either for e.g. `\sin` (compare e.g. the right-alignments in `text(.5, .9, r"$\sin$", ha="right"); text(.5, .8, r"$\mathrm{sin}$", ha="right"); axvline(.5)` where the extra thin space after `\sin` is visible), so this patch just makes things more consistent.
1 parent efc43d1 commit 703c086

13 files changed

Lines changed: 1257 additions & 1157 deletions

lib/matplotlib/_mathtext.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,8 +2377,7 @@ def operatorname(self, s: str, loc: int, toks: ParseResults) -> T.Any:
23772377
next_char_loc += len('operatorname{}')
23782378
next_char = next((c for c in s[next_char_loc:] if c != ' '), '')
23792379
delimiters = self._delims | {'^', '_'}
2380-
if (next_char not in delimiters and
2381-
name not in self._overunder_functions):
2380+
if next_char not in delimiters:
23822381
# Add thin space except when followed by parenthesis, bracket, etc.
23832382
hlist_list += [self._make_space(self._space_widths[r'\,'])]
23842383
self.pop_state()
@@ -2498,7 +2497,12 @@ def subsuper(self, s: str, loc: int, toks: ParseResults) -> T.Any:
24982497
shift = hlist.height + vgap + nucleus.depth
24992498
vlt = Vlist(vlist)
25002499
vlt.shift_amount = shift
2501-
result = Hlist([vlt])
2500+
result = Hlist([
2501+
vlt,
2502+
*([self._make_space(self._space_widths[r'\,'])]
2503+
if self._in_subscript_or_superscript else []),
2504+
])
2505+
self._in_subscript_or_superscript = False
25022506
return [result]
25032507

25042508
# We remove kerning on the last character for consistency (otherwise
-739 Bytes
Loading
Binary file not shown.

0 commit comments

Comments
 (0)