Skip to content
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
21 changes: 16 additions & 5 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@ class Parser(object):
corners.
"""
_binary_operators = set('''
+ *
+ * -
\\pm \\sqcap \\rhd
\\mp \\sqcup \\unlhd
\\times \\vee \\unrhd
Expand Down Expand Up @@ -2499,10 +2499,21 @@ def symbol(self, s, loc, toks):
raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)

if c in self._spaced_symbols:
return [Hlist( [self._make_space(0.2),
char,
self._make_space(0.2)] ,
do_kern = True)]
# iterate until we find previous character, needed for cases
# such as ${ -2}$, $ -2$, or $ -2$.
for i in six.moves.xrange(1, loc + 1):
prev_char = s[loc-i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more pythonic to use six.xrange for this loop: i.e.:

for i in six.xrange(1, loc + 1):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, I wasn't very happy with that loop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will need a break then:

for i in six.moves.xrange(1, loc + 1):
    prev_char = s[loc-i]
    if prev_char != ' ':
        break

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's better.

if prev_char != ' ':
break
# Binary operators at start of string should not be spaced
if (c in self._binary_operators and
(len(s[:loc].split()) == 0 or prev_char == '{')):
return [char]
else:
return [Hlist( [self._make_space(0.2),
char,
self._make_space(0.2)] ,
do_kern = True)]
elif c in self._punctuation_symbols:
return [Hlist( [char,
self._make_space(0.2)] ,
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading