You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Spaced symbols should not be spaced when in limits etc #26174
As seen, LaTeX does not add a space around the arrows (or =/+-sign) when in subscripts, but mathtext does.
Note that there is no space around \to but in mathtext,around \rightarrow in mathtext, while for LaTeX they look exactly the same. (This is because \to is not listed in _mathtext.Parser._arrow_symbols, but it should be.)
All the equations get parsed through the def symbol: function, so in mathtext we have the following code to add spacing around the operators. Currently, we have a check for binary operators to neglect spacing at the start.
(Side point re: the original report: the fair comparison with latex would use $$...$$ in latex as we're effectively always in displaymath mode in mathtext, but even there the spacing gets suppressed.)
The same issue happens in sub- and superscripts as well. I checked the code a bit and maybe the easiest way is to remove any space from sub- and superscripts (and over/under)?
(Re: side point: I was too lazy to sort that out, but have updated the example, at least if you wait 30 seconds after this comment.)
Or maybe one can use self._in_subscript_or_superscript to determine if spaces should be added? (Have not studied the code enough to realize if that may work.)
I guess blindly removing spaces may also remove those added by e.g. \quad...
The self._in_subscript_or_superscript check does work for the over-under cases!
I think the self._in_subscript_or_superscript flag determines if we need to add spacing to the nucleus, and it is not checking if the equation is a subscript or superscript, so for the string like r'$A^{a \times b}_{c \Uparrow d}$ in the example the flag's value is False
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
devRD commentedon Jun 23, 2023
All the equations get parsed through the
def symbol:function, so in mathtext we have the following code to add spacing around the operators. Currently, we have a check for binary operators to neglect spacing at the start.matplotlib/lib/matplotlib/_mathtext.py
Lines 2128 to 2131 in 623da30
For this issue, we could add a check for limits so that the symbols are not spaced by mathtext?
anntzer commentedon Jun 23, 2023
(Side point re: the original report: the fair comparison with latex would use
$$...$$in latex as we're effectively always in displaymath mode in mathtext, but even there the spacing gets suppressed.)oscargus commentedon Jun 23, 2023
The same issue happens in sub- and superscripts as well. I checked the code a bit and maybe the easiest way is to remove any space from sub- and superscripts (and over/under)?
(Re: side point: I was too lazy to sort that out, but have updated the example, at least if you wait 30 seconds after this comment.)
oscargus commentedon Jun 23, 2023
Or maybe one can use
self._in_subscript_or_superscriptto determine if spaces should be added? (Have not studied the code enough to realize if that may work.)I guess blindly removing spaces may also remove those added by e.g.
\quad...oscargus commentedon Jun 24, 2023
@devRD, I fixed it in #26173 as it turned out to be straightforward (do not add space if
self._in_subscript_or_superscript).oscargus commentedon Jun 24, 2023
Well, actually not fully. It works for the overunder case, but not for sub- and superscripts...
devRD commentedon Jun 24, 2023
The
self._in_subscript_or_superscriptcheck does work for the over-under cases!I think the
self._in_subscript_or_superscriptflag determines if we need to add spacing to the nucleus, and it is not checking if the equation is a subscript or superscript, so for the string liker'$A^{a \times b}_{c \Uparrow d}$in the example the flag's value isFalseoscargus commentedon Jun 24, 2023
Agreed. I've tried to insert a separate flag in
subsuper, but that didn't work...github-actions commentedon Sep 14, 2026
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!