Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mathtext: Add - to spaced symbols, and do not space symbols at start of string #5020

Merged
merged 3 commits into from Sep 8, 2015

Conversation

zblz
Copy link
Member

@zblz zblz commented Sep 3, 2015

PR related to changes in symbol spacing made in #4872. This PR does two things:

  • Add - to set of _binary_operators that are then considered in _spaced_symbols, so that - is spaced equivalently to +: $1-2$ should be spaced exactly as $1+2$.
  • Following LaTeX: Remove the spacing when any binary operator (including - and +) is at the start of the string or of a unit delimited by { }. This makes things like $+2$ or $21^{+2}_{-3}$ more natural, as the + or - are not really a binary operator anymore but part of the number.

A test has been added to check for spacing in the second item, so that $-2$; $ -2$; ${-2}$; ${ -2}$ all render equally, but with different spacing than $6-2$.

attn @mdboom, @tacaswell (also sorry for not catching this in #4872!)

prev_char = s[loc-i]
while prev_char == ' ' and i <= loc:
i += 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.

@zblz
Copy link
Member Author

zblz commented Sep 8, 2015

@mdboom: Anything else that should be changed in this PR?

@mdboom
Copy link
Member

mdboom commented Sep 8, 2015

No, this looks fine to me.

mdboom added a commit that referenced this pull request Sep 8, 2015
mathtext: Add `-` to spaced symbols, and do not space symbols at start of string
@mdboom mdboom merged commit e01241c into matplotlib:master Sep 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants