Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove *math* parameter of various mathtext internal APIs. #22507

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

Merged
merged 1 commit into from
Jun 11, 2022

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 19, 2022

The math parameter is passed through many layers of the call stack
but is ultimately only used for a single purpose: deciding whether to
replace the ASCII hyphen by a (longer) unicode minus. Instead of doing
that, just do the substitution at the parsing stage. In particular,
this fixes problematic unicode minus support with the "cm" fontset.

This patch also reverts a significant part of 52003e4, as LogFormatters
no longer need to pass unicode minuses in mathtext -- everything gets
converted by mathtext. Likewise, this change also invalidates the
test_log_scales baseline image (old, buggy wrt. unicode minus); replace
it by a test that the drawn ticks are as expected (which was the intent
in 90c1aa3).

Closes #21687.

PR Summary

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

  • 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).
  • 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
Copy link
Member

How does this affect the possibility to support \text?

@anntzer
Copy link
Contributor Author

anntzer commented Feb 19, 2022

I think it's OK? Your implementation at #22173 should not be affected too much by this, as long as it doesn't perform the same dash-to-unicodeminus replacement as is now done by symbol().

@oscargus
Copy link
Member

oscargus commented Feb 19, 2022

OK! Just was a bit worried that the long dash was already in the string, so that $\text{foo-bar}$ (with hyphen) ended up as $\text{foo−bar}$ (with minus instead of hyphen), so that it had to be reverted in case of \text.

Not sure I will finish #22173 (especially since I read that you have one), but we'll see.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 19, 2022

I don't have an implementation of \text? I think #22173 is probably the closest there is.

Replacment to unicode minus occurs within symbol, which text doesn't hit, I think?

@oscargus
Copy link
Member

OK! Just have some memory of reading that you had a branch hanging around (but I may be wrong and either I didn't read it or it was someone else).

Ahh, I see now. Primarily read the description, which caused my doubt.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 19, 2022

I think I gave it a try at some point, but am not sure it's really ready either, so let's try to get yours in.

Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Not fully sure why the image tests are removed, but the general change seems to make sense.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 20, 2022

The old image had a non-unicode minus (due to #21687); this patch changes the image. But we try to avoid adding new (or modified) baseline images if possible (due to repo size concerns); here the test was really to check what are the ticks so now I just do that instead.

@jklymak
Copy link
Member

jklymak commented Jun 2, 2022

Not sure if all the failures are related....

@jklymak jklymak marked this pull request as draft June 2, 2022 14:21
@anntzer anntzer marked this pull request as ready for review June 10, 2022 16:23
@anntzer
Copy link
Contributor Author

anntzer commented Jun 10, 2022

Should be good to go now.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

May self-merge after addressing the formatting suggestion.

The *math* parameter is passed through many layers of the call stack
but is ultimately only used for a single purpose: deciding whether to
replace the ASCII hyphen by a (longer) unicode minus.  Instead of doing
that, just do the substitution at the parsing stage.  In particular,
this fixes problematic unicode minus support with the "cm" fontset.

This patch also reverts a significant part of 52003e4, as LogFormatters
no longer need to pass unicode minuses in mathtext -- everything gets
converted by mathtext.  Likewise, this change also invalidates the
test_log_scales baseline image (old, buggy wrt. unicode minus); replace
it by a test that the drawn ticks are as expected (which was the intent
in 90c1aa3).
@timhoffm timhoffm merged commit d0bef3b into matplotlib:main Jun 11, 2022
@anntzer anntzer deleted the mathtextunmath branch June 11, 2022 13:06
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.

[Bug]: math_fontfamily="cm" prevents replacement of minus by unicode minus in \mathdefault
4 participants