Skip to content

Commit e01241c

Browse files
committed
Merge pull request #5020 from zblz/fix-asy-unc
mathtext: Add `-` to spaced symbols, and do not space symbols at start of string
2 parents a4eb0c6 + acf73c2 commit e01241c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3755
-3077
lines changed

lib/matplotlib/mathtext.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ class Parser(object):
20832083
corners.
20842084
"""
20852085
_binary_operators = set('''
2086-
+ *
2086+
+ * -
20872087
\\pm \\sqcap \\rhd
20882088
\\mp \\sqcup \\unlhd
20892089
\\times \\vee \\unrhd
@@ -2499,10 +2499,21 @@ def symbol(self, s, loc, toks):
24992499
raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)
25002500

25012501
if c in self._spaced_symbols:
2502-
return [Hlist( [self._make_space(0.2),
2503-
char,
2504-
self._make_space(0.2)] ,
2505-
do_kern = True)]
2502+
# iterate until we find previous character, needed for cases
2503+
# such as ${ -2}$, $ -2$, or $ -2$.
2504+
for i in six.moves.xrange(1, loc + 1):
2505+
prev_char = s[loc-i]
2506+
if prev_char != ' ':
2507+
break
2508+
# Binary operators at start of string should not be spaced
2509+
if (c in self._binary_operators and
2510+
(len(s[:loc].split()) == 0 or prev_char == '{')):
2511+
return [char]
2512+
else:
2513+
return [Hlist( [self._make_space(0.2),
2514+
char,
2515+
self._make_space(0.2)] ,
2516+
do_kern = True)]
25062517
elif c in self._punctuation_symbols:
25072518
return [Hlist( [char,
25082519
self._make_space(0.2)] ,
Binary file not shown.

0 commit comments

Comments
 (0)