From 0454e4339af816180a79c35e42631edc3fb2cc9c Mon Sep 17 00:00:00 2001 From: Philipp Arras Date: Wed, 28 Oct 2020 10:03:13 +0100 Subject: [PATCH 1/3] Cleanup --- lib/matplotlib/backends/backend_pgf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index a36dda160c06..21eccf805cc2 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -10,7 +10,6 @@ import re import shutil import subprocess -import sys from tempfile import TemporaryDirectory import weakref From cd930576f6e7ff73f5fc0651b4d3fbcc93b713e0 Mon Sep 17 00:00:00 2001 From: Philipp Arras Date: Thu, 29 Oct 2020 23:00:35 +0100 Subject: [PATCH 2/3] Support minus signs for pgf backend in combination with pdflatex Add test and fix for issue #18826 --- lib/matplotlib/backends/backend_pgf.py | 6 ++---- lib/matplotlib/tests/test_backend_pgf.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 21eccf805cc2..a55c931387a8 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -100,6 +100,7 @@ def common_texification(text): # Sometimes, matplotlib adds the unknown command \mathdefault. # Not using \mathnormal instead since this looks odd for the latex cm font. text = _replace_mathdefault(text) + text = text.replace("\N{MINUS SIGN}", r"\ensuremath{-}") # split text into normaltext and inline math parts parts = re_mathsep.split(text) for i, s in enumerate(parts): @@ -791,10 +792,7 @@ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None): %% Make sure the required packages are loaded in your preamble %% \\usepackage{pgf} %% -%% and, on pdftex -%% \\usepackage[utf8]{inputenc}\\DeclareUnicodeCharacter{2212}{-} -%% -%% or, on luatex and xetex +%% and on luatex and xetex %% \\usepackage{unicode-math} %% %% Figures using additional raster images can only be included by \\input if diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index e089ab4f9c33..736ce760105b 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -12,8 +12,10 @@ import matplotlib as mpl import matplotlib.pyplot as plt from matplotlib.testing.compare import compare_images, ImageComparisonFailure -from matplotlib.testing.decorators import image_comparison, _image_directories from matplotlib.backends.backend_pgf import PdfPages, common_texification +from matplotlib.testing.decorators import (_image_directories, + check_figures_equal, + image_comparison) baseline_dir, result_dir = _image_directories(lambda: 'dummy func') @@ -338,3 +340,12 @@ def test_unknown_font(caplog): plt.savefig(BytesIO(), format="pgf") assert "Ignoring unknown font: this-font-does-not-exist" in [ r.getMessage() for r in caplog.records] + + +@check_figures_equal(extensions=["pdf"]) +@pytest.mark.parametrize("texsystem", ("pdflatex", "xelatex", "lualatex")) +@pytest.mark.backend("pgf") +def test_minus_signs_with_tex(fig_test, fig_ref, texsystem): + mpl.rcParams["pgf.texsystem"] = texsystem + fig_test.text(.5, .5, "$-1$") + fig_ref.text(.5, .5, "$\N{MINUS SIGN}1$") From 7ff6ded93a4b983c11ecf5bf3094241dd3cc776b Mon Sep 17 00:00:00 2001 From: Philipp Arras Date: Mon, 2 Nov 2020 09:12:55 +0100 Subject: [PATCH 3/3] Skip test if LaTeX is not available --- lib/matplotlib/tests/test_backend_pgf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index 736ce760105b..e71b6291e4c6 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -346,6 +346,8 @@ def test_unknown_font(caplog): @pytest.mark.parametrize("texsystem", ("pdflatex", "xelatex", "lualatex")) @pytest.mark.backend("pgf") def test_minus_signs_with_tex(fig_test, fig_ref, texsystem): + if not check_for(texsystem): + pytest.skip(texsystem + ' + pgf is required') mpl.rcParams["pgf.texsystem"] = texsystem fig_test.text(.5, .5, "$-1$") fig_ref.text(.5, .5, "$\N{MINUS SIGN}1$")