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

Appearance settings

Commit 63d96d2

Browse filesBrowse files
authored
Merge pull request #14567 from anntzer/texminus
Fix unicode_minus + usetex.
2 parents f0290cc + a973b75 commit 63d96d2
Copy full SHA for 63d96d2

File tree

Expand file treeCollapse file tree

3 files changed

+22
-22
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-22
lines changed

‎lib/matplotlib/dviread.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dviread.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def _parse_enc(path):
989989
with open(path, encoding="ascii") as file:
990990
no_comments = "\n".join(line.split("%")[0].rstrip() for line in file)
991991
array = re.search(r"(?s)\[(.*)\]", no_comments).group(1)
992-
lines = [line for line in array.split("\n") if line]
992+
lines = [line for line in array.split() if line]
993993
if all(line.startswith("/") for line in lines):
994994
return [line[1:] for line in lines]
995995
else:

‎lib/matplotlib/tests/test_usetex.py

Copy file name to clipboard
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
import warnings
2-
31
import pytest
42

5-
import matplotlib
6-
from matplotlib.testing.decorators import image_comparison
3+
import matplotlib as mpl
4+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
75
import matplotlib.pyplot as plt
86
from matplotlib.ticker import EngFormatter
97

108

11-
with warnings.catch_warnings():
12-
warnings.simplefilter('ignore')
13-
needs_usetex = pytest.mark.skipif(
14-
not matplotlib.checkdep_usetex(True),
15-
reason='Missing TeX of Ghostscript or dvipng')
9+
@pytest.fixture(autouse=True) # All tests in this module use usetex.
10+
def usetex():
11+
if not mpl.checkdep_usetex(True):
12+
pytest.skip('Missing TeX of Ghostscript or dvipng')
13+
mpl.rcParams['text.usetex'] = True
1614

1715

18-
@needs_usetex
1916
@image_comparison(baseline_images=['test_usetex'],
2017
extensions=['pdf', 'png'],
2118
tol=0.3)
2219
def test_usetex():
23-
matplotlib.rcParams['text.usetex'] = True
2420
fig = plt.figure()
2521
ax = fig.add_subplot(111)
2622
ax.text(0.1, 0.2,
@@ -32,3 +28,9 @@ def test_usetex():
3228
fontsize=24)
3329
ax.set_xticks([])
3430
ax.set_yticks([])
31+
32+
33+
@check_figures_equal()
34+
def test_unicode_minus(fig_test, fig_ref):
35+
fig_test.text(.5, .5, "$-$")
36+
fig_ref.text(.5, .5, "\N{MINUS SIGN}")

‎lib/matplotlib/texmanager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/texmanager.py
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,10 @@ def make_tex(self, tex, fontsize):
206206
r'{\rmfamily %s}')
207207
tex = fontcmd % tex
208208

209-
if rcParams['text.latex.unicode']:
210-
unicode_preamble = r"""
211-
\usepackage[utf8]{inputenc}"""
212-
else:
213-
unicode_preamble = ''
209+
unicode_preamble = "\n".join([
210+
r"\usepackage[utf8]{inputenc}",
211+
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
212+
]) if rcParams["text.latex.unicode"] else ""
214213

215214
s = r"""
216215
\documentclass{article}
@@ -257,11 +256,10 @@ def make_tex_preview(self, tex, fontsize):
257256
r'{\rmfamily %s}')
258257
tex = fontcmd % tex
259258

260-
if rcParams['text.latex.unicode']:
261-
unicode_preamble = r"""
262-
\usepackage[utf8]{inputenc}"""
263-
else:
264-
unicode_preamble = ''
259+
unicode_preamble = "\n".join([
260+
r"\usepackage[utf8]{inputenc}",
261+
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
262+
]) if rcParams["text.latex.unicode"] else ""
265263

266264
# newbox, setbox, immediate, etc. are used to find the box
267265
# extent of the rendered text.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.