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

[Bug]: mathtext should distinguish between unary and binary minus #28180

Open
anntzer opened this issue May 7, 2024 · 4 comments · May be fixed by #28186
Open

[Bug]: mathtext should distinguish between unary and binary minus #28180

anntzer opened this issue May 7, 2024 · 4 comments · May be fixed by #28186
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! topic: text/mathtext

Comments

@anntzer
Copy link
Contributor

anntzer commented May 7, 2024

Bug summary

TeX inserts a (thin?) space after a binary minus, but not before a unary minus. Typographically, I believe this does look nicer.
mathtext does not distinguish the two cases and always puts in a thin space. It would be nice if it followed tex's behavior.

Code for reproduction

from pylab import *
figtext(.2, .6, "$a=-b-c$")
figtext(.2, .5, "$a=-b-c$", usetex=True)

Actual outcome

Figure_1
Compare the spacing before the "b" and the "c": they are different with usetex, but not with mathtext.

Expected outcome

Remove the space in mathtext before the unary minus.

Additional information

Probably involves reading the TeXbook to figure out what is TeX's logic for distinguishing unary and binary minus.
Tagging as good first issue solely because there should be no API design at all, but medium (-hard) difficulty because that'll require both reading the TeXbook and learning about mathtext's implementation. However I would guess there's no "strong" technical blockers either.

Operating system

any

Matplotlib Version

3.10.0.dev137+g9387431ab6

Matplotlib Backend

qtagg

Python version

3.12

Jupyter version

no

Installation

git checkout

@anntzer anntzer added Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! topic: text/mathtext labels May 7, 2024
Copy link

github-actions bot commented May 7, 2024

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the
Matplotlib internals. To get started, please see our contributing
guide
.

We do not assign issues. Check the Development section in the sidebar for linked pull
requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please
collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication
channels
.

@OdileVidrine
Copy link

I did some preliminary research and it seems TeX actually does not distinguish between the unary and binary minus symbol. Maybe I was reading an outdated version of the TeXbook, but I cannot find any mention of unary operators. I will keep looking to find out what logic TeX is using to change the spacing for unary operators.

@anntzer
Copy link
Contributor Author

anntzer commented May 8, 2024

Another example where I think the difference is clear:
Figure_1

@OdileVidrine
Copy link

I have found the issue, the code contains logic to do different spacing for unary minus if the unary minus happens directly after a parenthesis or if the minus is the first character in the equation, but the code does not contain logic to create a unary minus after an equals sign. It is an easy fix, but I am still working on setting up a testing environment to verify my fix.

@OdileVidrine OdileVidrine linked a pull request May 8, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! topic: text/mathtext
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants