FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support `\text` in `mathtext` by oscargus · Pull Request #22173 · matplotlib/matplotlib · GitHub

Repository navigation

Support \text in mathtext - #22173

Merged
greglucas merged 1 commit into
matplotlib:mainfrom
oscargus:textinmathtext
Mar 31, 2023
Merged

greglucas merged 1 commit into
matplotlib:mainfrom
oscargus:textinmathtext

Conversation

oscargus commented Jan 9, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

PR Summary

Closes #18520

import matplotlib.pyplot as plt
plt.text(0.1, 0.5, r"where $a = \sin(\phi) \text{ such that } \phi = \frac{x}{y}$")
plt.draw()

gives

However, the kerning is still from math, see

import matplotlib.pyplot as plt
plt.text(0.1, 0.5, r"where $a = \sin(\phi) \text{ where } \phi = \frac{x}{y}$")
plt.draw()


where the spacing between the e and the r in where differs.

However, it is not the case for e.g. r"where $\text{where}$" so not really clear to me why and where this happens.

Again, a bit doubtful (see #22171) if I can generate correct test images, so tests must be added.

It is not really clear how things will work with special symbols etc. Right now \{, \} and \$ can be dealt with, but one can probably break it if one tries (as for LaTeX itself).

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

oscargus commented Jan 9, 2022

Copy link
Copy Markdown
Member Author

And as I was a bit doubtful myself, it works with sub- and superscripts as well:

QuLogic changed the title mathtext now supports \text Support \text in mathtext Jan 11, 2022
oscargus mentioned this pull request Jan 12, 2022
6 tasks
Comment thread lib/matplotlib/_mathtext.py Outdated
return [hlist]

def text(self, s, loc, toks):
self.pop_state()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This won't work with something like r"$\mathbf{\text{hello, world!}}$" (popping out of the mathbf puts you in italic mode, and setting back to italic at exit isn't correct either; instead I think you just need to push a new state for the \text.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ahh, OK! I'll look into the state things. Almost looked a bit too easy to solve it...

anntzer commented Jan 13, 2022

Copy link
Copy Markdown
Contributor

I can't repro the kerning issue? Usually you can try blowing up text size (e.g. fontsize=42) to make it easier to check them; otherwise it may just be pixellation.

One major comment, but otherwise the approach looks good to me. (Just needs a test as well.)

Copy link
Copy Markdown
Member Author

This is updated (although I only pushed, not commented), if you have time @anntzer ...

Comment thread lib/matplotlib/_mathtext.py Outdated

anntzer commented Mar 28, 2023 •
edited
Loading

Copy link
Copy Markdown
Contributor

Just one minor point left, I think.
Also, is the kerning issue you mentioned originally fixed?

Comment thread lib/matplotlib/tests/test_mathtext.py Outdated
greglucas merged commit 83afb15 into matplotlib:main Mar 31, 2023
oscargus deleted the textinmathtext branch April 1, 2023 08:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Doc]: How to show an ASCII hyphen in math text without using TeX? Matplotlib cannot parse TeX with \text command

4 participants


Back | FazBrowse Home | New Git URL