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

apply unary minus spacing directly after equals sign #28186

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

OdileVidrine
Copy link

@OdileVidrine OdileVidrine commented May 8, 2024

PR summary

Fixes a visual inconsistency where mathtext does not modify the spacing around a unary minus sign after an equals sign like it does for a unary minus sign after a closing parenthesis. Closes #28180.

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@anntzer
Copy link
Contributor

anntzer commented May 8, 2024

The fix looks plausible (although there's also the case of a leading minus at the beginning of a equation, perhaps?). Did you check the TeXbook for reference?

@@ -2285,7 +2285,7 @@ def symbol(self, s: str, loc: int,
if (self._in_subscript_or_superscript or (
c in self._binary_operators and (
len(s[:loc].split()) == 0 or prev_char == '{' or
prev_char in self._left_delims))):
prev_char in self._left_delims or prev_char == '='))):
Copy link
Contributor

Choose a reason for hiding this comment

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

It should not just be =, but all relational operators.

Copy link
Author

Choose a reason for hiding this comment

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

good idea, I will change that

@OdileVidrine OdileVidrine marked this pull request as ready for review May 9, 2024 18:04
Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

There's a comment above the if that could be updated.

Comment on lines 2287 to 2289
len(s[:loc].split()) == 0 or prev_char == '{' or
prev_char in self._left_delims))):
prev_char in self._left_delims or
prev_char in self._relation_symbols))):
Copy link
Member

Choose a reason for hiding this comment

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

These could be compressed:

Suggested change
len(s[:loc].split()) == 0 or prev_char == '{' or
prev_char in self._left_delims))):
prev_char in self._left_delims or
prev_char in self._relation_symbols))):
len(s[:loc].split()) == 0 or
prev_char in {'{', *self._left_delims, *self._relation_symbols}))):

Copy link
Author

Choose a reason for hiding this comment

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

I made the change you suggested and tested it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

[Bug]: mathtext should distinguish between unary and binary minus
4 participants