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

Skip to content

Commit da01cf8

Browse files
committed
Fix bug with space between operator and sub / superscripts.
Also add tests for it. A thin space should not be inserted in math text between the operator and subscript / superscript.
1 parent 8fd1c62 commit da01cf8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/matplotlib/mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,10 +2894,10 @@ def operatorname(self, s, loc, toks):
28942894
hlist_list.append(c)
28952895
next_char_loc = loc + len(toks[0]) + 1
28962896
if isinstance(toks[0], ParseResults):
2897-
next_char_loc += 14 # Skip `operatorname{}`
2897+
next_char_loc += len('operatorname{}')
28982898
next_char = next((c for c in s[next_char_loc:] if c != ' '), '')
28992899
delimiters = self._left_delim | self._ambi_delim | self._right_delim
2900-
delimiters |= set(r"^_".split())
2900+
delimiters |= {'^', '_'}
29012901
if (next_char not in delimiters and
29022902
toks[0] not in self._overunder_functions):
29032903
# Add thin space except when followed by parenthesis, bracket, etc.

lib/matplotlib/tests/test_mathtext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,17 @@ def test_operator_space(fig_test, fig_ref):
297297
fig_test.text(0.1, 0.4, r"$\arcsin|6|$")
298298
fig_test.text(0.1, 0.5, r"$\operatorname{op} 6$") # GitHub issue #553
299299
fig_test.text(0.1, 0.6, r"$\operatorname{op}[6]$")
300+
fig_test.text(0.1, 0.7, r"$\cos^2$")
301+
fig_test.text(0.1, 0.8, r"$\log_2$")
302+
300303
fig_ref.text(0.1, 0.1, r"$\mathrm{log\,}6$")
301304
fig_ref.text(0.1, 0.2, r"$\mathrm{log}(6)$")
302305
fig_ref.text(0.1, 0.3, r"$\mathrm{arcsin\,}6$")
303306
fig_ref.text(0.1, 0.4, r"$\mathrm{arcsin}|6|$")
304307
fig_ref.text(0.1, 0.5, r"$\mathrm{op\,}6$")
305308
fig_ref.text(0.1, 0.6, r"$\mathrm{op}[6]$")
309+
fig_ref.text(0.1, 0.7, r"$\mathrm{cos}^2$")
310+
fig_ref.text(0.1, 0.8, r"$\mathrm{log}_2$")
306311

307312

308313
def test_mathtext_fallback_valid():

0 commit comments

Comments
 (0)