Skip to content

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 14, 2022

hyphen-to-unicode-minus replacement now occurs at the parsing stage, and
thus does not need to be done again in get_unicode_index (otherwise,
text hyphens also get incorrectly substituted.

Strictly speaking, one would need either to fully deprecate
get_unicode_index and replace it by a private helper (for which math
is always False), or introduce a deprecation period during which users
must pass the math kwarg (any value other than False results in a
warning) and then another one that deprecates that kwarg; which is quite
long; hopefully the change is in a private-enough part of the library
that we can just do it as is.

Also do some more changes to the mathtext-svg-text-only-tests that I
missed when the feature first went in: only test svg (that's the
point of it...) and only test two fonts: a "standard" truetype font --
the default dejavusans -- and the "cm" font, which has a very specific
encoding (see the BakomaFonts class).

Closes #23268, sorry about that :)

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

@anntzer anntzer added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: text/mathtext labels Jun 14, 2022
@anntzer anntzer added this to the v3.6.0 milestone Jun 14, 2022
hyphen-to-unicode-minus replacement now occurs at the parsing stage, and
thus does not need to be done again in get_unicode_index (otherwise,
text hyphens also get incorrectly substituted.

Strictly speaking, one would need either to fully deprecate
get_unicode_index and replace it by a private helper (for which `math`
is always False), or introduce a deprecation period during which users
*must* pass the `math` kwarg (any value other than False results in a
warning) and then another one that deprecates that kwarg; which is quite
long; hopefully the change is in a private-enough part of the library
that we can just do it as is.

Also do some more changes to the mathtext-svg-text-only-tests that I
missed when the feature first went in: only test svg (that's the
point of it...) and only test two fonts: a "standard" truetype font --
the default dejavusans -- and the "cm" font, which has a very specific
encoding (see the BakomaFonts class).
@@ -119,6 +119,7 @@
# 'svgastext' tests switch svg output to embed text as text (rather than as
# paths).
svgastext_math_tests = [
r'$-$-',
Copy link
Member

Choose a reason for hiding this comment

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

Excellent test case!

@oscargus
Copy link
Member

What about creating a helper function in mathtext.py that has math=True by default?

@anntzer
Copy link
Contributor Author

anntzer commented Jun 14, 2022

If we are really bothered with the change here I would rather just make get_unicode_index fully private rather than keep reexporting it to a public module, but that seems a bit of a pity (in my view, the main useful third-party use of get_unicode_index is to map \commandnames to unicode indices, not to perform the hyphen-to-minus substitution).

@oscargus
Copy link
Member

not to perform the hyphen-to-minus substitution

I agree. Was more thinking of the "breaking" change without deprecation. But then I have no idea how much of a problem that is.

@jklymak jklymak merged commit 40dea5a into matplotlib:main Jun 22, 2022
@anntzer anntzer deleted the m branch June 22, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: text/mathtext
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: hyphen renders different length depending on presence of MathText
3 participants