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

Skip to content

Commit cd93057

Browse files
author
Philipp Arras
committed
Support minus signs for pgf backend in combination with pdflatex
Add test and fix for issue #18826
1 parent 0454e43 commit cd93057

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

lib/matplotlib/backends/backend_pgf.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def common_texification(text):
100100
# Sometimes, matplotlib adds the unknown command \mathdefault.
101101
# Not using \mathnormal instead since this looks odd for the latex cm font.
102102
text = _replace_mathdefault(text)
103+
text = text.replace("\N{MINUS SIGN}", r"\ensuremath{-}")
103104
# split text into normaltext and inline math parts
104105
parts = re_mathsep.split(text)
105106
for i, s in enumerate(parts):
@@ -791,10 +792,7 @@ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None):
791792
%% Make sure the required packages are loaded in your preamble
792793
%% \\usepackage{pgf}
793794
%%
794-
%% and, on pdftex
795-
%% \\usepackage[utf8]{inputenc}\\DeclareUnicodeCharacter{2212}{-}
796-
%%
797-
%% or, on luatex and xetex
795+
%% and on luatex and xetex
798796
%% \\usepackage{unicode-math}
799797
%%
800798
%% Figures using additional raster images can only be included by \\input if

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import matplotlib as mpl
1313
import matplotlib.pyplot as plt
1414
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
15-
from matplotlib.testing.decorators import image_comparison, _image_directories
1615
from matplotlib.backends.backend_pgf import PdfPages, common_texification
16+
from matplotlib.testing.decorators import (_image_directories,
17+
check_figures_equal,
18+
image_comparison)
1719

1820
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
1921

@@ -338,3 +340,12 @@ def test_unknown_font(caplog):
338340
plt.savefig(BytesIO(), format="pgf")
339341
assert "Ignoring unknown font: this-font-does-not-exist" in [
340342
r.getMessage() for r in caplog.records]
343+
344+
345+
@check_figures_equal(extensions=["pdf"])
346+
@pytest.mark.parametrize("texsystem", ("pdflatex", "xelatex", "lualatex"))
347+
@pytest.mark.backend("pgf")
348+
def test_minus_signs_with_tex(fig_test, fig_ref, texsystem):
349+
mpl.rcParams["pgf.texsystem"] = texsystem
350+
fig_test.text(.5, .5, "$-1$")
351+
fig_ref.text(.5, .5, "$\N{MINUS SIGN}1$")

0 commit comments

Comments
 (0)