Skip to content

Commit deb8d04

Browse files
committed
Fix handling of nonmath hyphens in mathtext.
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).
1 parent 0371cf9 commit deb8d04

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The *math* parameter of ``mathtext.get_unicode_index`` is deprecated and defaults to False
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
In math mode, ASCII hyphens (U+002D) are now replaced by unicode minus signs
5+
(U+2212) at the parsing stage.

doc/api/next_api_changes/deprecations/22507-AL.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/matplotlib/_mathtext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
@_api.delete_parameter("3.6", "math")
37-
def get_unicode_index(symbol, math=True): # Publicly exported.
37+
def get_unicode_index(symbol, math=False): # Publicly exported.
3838
r"""
3939
Return the integer index (from the Unicode table) of *symbol*.
4040
@@ -43,8 +43,8 @@ def get_unicode_index(symbol, math=True): # Publicly exported.
4343
symbol : str
4444
A single (Unicode) character, a TeX command (e.g. r'\pi') or a Type1
4545
symbol name (e.g. 'phi').
46-
math : bool, default: True
47-
If False, always treat as a single Unicode character.
46+
math : bool, default: False
47+
If True (deprecated), replace ASCII hyphen-minus by Unicode minus.
4848
"""
4949
# From UTF #25: U+2212 minus sign is the preferred
5050
# representation of the unary and binary minus sign rather than
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Loading

lib/matplotlib/tests/test_mathtext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
# 'svgastext' tests switch svg output to embed text as text (rather than as
120120
# paths).
121121
svgastext_math_tests = [
122+
r'$-$-',
122123
]
123124
# 'lightweight' tests test only a single fontset (dejavusans, which is the
124125
# default) and only png outputs, in order to minimize the size of baseline
@@ -206,11 +207,10 @@ def test_mathtext_rendering(baseline_images, fontset, index, text):
206207

207208
@pytest.mark.parametrize('index, text', enumerate(svgastext_math_tests),
208209
ids=range(len(svgastext_math_tests)))
209-
@pytest.mark.parametrize(
210-
'fontset', ['cm', 'stix', 'stixsans', 'dejavusans', 'dejavuserif'])
210+
@pytest.mark.parametrize('fontset', ['cm', 'dejavusans'])
211211
@pytest.mark.parametrize('baseline_images', ['mathtext0'], indirect=True)
212212
@image_comparison(
213-
baseline_images=None,
213+
baseline_images=None, extensions=['svg'],
214214
savefig_kwarg={'metadata': { # Minimize image size.
215215
'Creator': None, 'Date': None, 'Format': None, 'Type': None}})
216216
def test_mathtext_rendering_svgastext(baseline_images, fontset, index, text):

0 commit comments

Comments
 (0)