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

Matplotlib cannot parse TeX with \text command #18520

Closed
sindzicat opened this issue Sep 18, 2020 · 6 comments · Fixed by #22173
Closed

Matplotlib cannot parse TeX with \text command #18520

sindzicat opened this issue Sep 18, 2020 · 6 comments · Fixed by #22173

Comments

@sindzicat
Copy link

Hello!

Minimal example:

import matplotlib as plt
fig, ax = plt.subplots()
ax.text(0, 0, r'$s_\text{ind}$')

Result:

ValueError: 
s_\text{ind}
    ^
Expected {accentprefixed | accent | symbol | c_over_c | function | group | frac | dfrac | stackrel | binom | genfrac | sqrt | overline | operatorname}, found 'e'  (at char 4), (line:1, col:5)

As far as I remember, r means raw string, so \t mustn't interpreter as tab. I tried \\t and other ways to avoid this problem but I didn't find any workaround for this case yet... So it seems to me I found a bug.

I use Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)],
Matplotlib version is 3.3.1. I tried my code in JupyterLab ver. 2.2.7 on Windows 10.
Matplotlib backend is module://ipykernel.pylab.backend_inline.

Best regards,
Sindzicat.

@anntzer
Copy link
Contributor

anntzer commented Sep 18, 2020

\text is not supported, but I agree that it should be, especially because I think it can just be mapped to \mathdefault; in fact \mathdefault/\mathregular (which are synonyms, and which both only exist in Matplotlib and not in TeX or any(?) package that I know of) could be (soft-)deprecated in favor of \text (which is from the pretty standard amsmath).

@sindzicat
Copy link
Author

Sorry, I didn't expect, that there are some TeX commands, that aren't supported in Matplotlib yet. Is there any list of (un)suppoted TeX commands in Matplotlib?

@anntzer
Copy link
Contributor

anntzer commented Sep 18, 2020

See #14766.

@sindzicat
Copy link
Author

@anntzer, many thanks!

@tueda
Copy link

tueda commented Oct 23, 2021

It will be nice if the \text command can be recognized in Matplotlib. As a first step, \text can be mapped to \mathdefault, but the amsmath \text command keeps spaces in the given text while \mathdefault does not.

@oscargus
Copy link
Contributor

oscargus commented Jan 9, 2022

Another issue here (which is maybe more a theoretical issue maybe) is that \text is supposed to use the text font, not the math font. However, I guess it is most commonly used to obtain upright text in math, rather than using the actual text font in equations. At least in the matplotlib context it seems like a fair approximation.

(One should really need \mathup or something similar to have a family independent, upright font in math mode.)

@QuLogic QuLogic added this to the v3.8.0 milestone Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants