Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support\text inmathtext#22173

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
greglucas merged 1 commit intomatplotlib:mainfromoscargus:textinmathtext
Mar 31, 2023
Merged

Conversation

oscargus
Copy link
Member

@oscargusoscargus commentedJan 9, 2022
edited
Loading

PR Summary

Closes#18520

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

gives
image

However, the kerning is still from math, see

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

image
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.

image

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 (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

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

@oscargus
Copy link
MemberAuthor

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

@QuLogicQuLogic changed the titlemathtext now supports\textSupport\text inmathtextJan 11, 2022
@oscargusoscargus mentioned this pull requestJan 12, 2022
6 tasks
@@ -2294,6 +2301,18 @@ def non_math(self, s, loc, toks):
self.get_state().font = mpl.rcParams['mathtext.default']
return [hlist]

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

Choose a reason for hiding this comment

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

This won't work with something liker"$\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
MemberAuthor

Choose a reason for hiding this comment

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

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

@anntzer
Copy link
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.)

@oscargus
Copy link
MemberAuthor

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

@anntzer
Copy link
Contributor

anntzer commentedMar 28, 2023
edited
Loading

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

@greglucasgreglucas merged commit83afb15 intomatplotlib:mainMar 31, 2023
@oscargusoscargus deleted the textinmathtext branchApril 1, 2023 08:41
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@anntzeranntzeranntzer approved these changes

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.8.0
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
@oscargus@anntzer@greglucas@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp