Skip to content

Commit 32afcf5

Browse files
authored
Merge pull request matplotlib#20446 from anntzer/psp
Make used tex packages consistent between ps and other backends.
2 parents 31cc4e7 + 18c8cfb commit 32afcf5

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
11171117
with mpl.rc_context({
11181118
"text.latex.preamble":
11191119
mpl.rcParams["text.latex.preamble"] +
1120-
r"\usepackage{psfrag,color}""\n"
1121-
r"\usepackage[dvips]{graphicx}""\n"
1120+
# Only load these packages if they have not already been loaded, in
1121+
# order not to clash with custom packages.
1122+
r"\makeatletter"
1123+
r"\@ifpackageloaded{color}{}{\usepackage{color}}"
1124+
r"\@ifpackageloaded{graphicx}{}{\usepackage{graphicx}}"
1125+
r"\@ifpackageloaded{psfrag}{}{\usepackage{psfrag}}"
1126+
r"\makeatother"
11221127
r"\geometry{papersize={%(width)sin,%(height)sin},margin=0in}"
11231128
% {"width": paper_width, "height": paper_height}
11241129
}):

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@
319319
# statements.
320320
# Note that it has to be put on a single line, which may
321321
# become quite long.
322-
# The following packages are always loaded with usetex, so
323-
# beware of package collisions: color, geometry, graphicx,
324-
# type1cm, textcomp.
325-
# Adobe Postscript (PSSNFS) font packages may also be
322+
# The following packages are always loaded with usetex,
323+
# so beware of package collisions:
324+
# geometry, inputenc, type1cm.
325+
# PostScript (PSNFSS) font packages may also be
326326
# loaded, depending on your font settings.
327327

328328
## The following settings allow you to select the fonts in math mode.

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ def test_partial_usetex(caplog):
155155
for record in caplog.records)
156156

157157

158+
@needs_usetex
159+
def test_usetex_preamble(caplog):
160+
mpl.rcParams.update({
161+
"text.usetex": True,
162+
# Check that these don't conflict with the packages loaded by default.
163+
"text.latex.preamble": r"\usepackage{color,graphicx,textcomp}",
164+
})
165+
plt.figtext(.5, .5, "foo")
166+
plt.savefig(io.BytesIO(), format="ps")
167+
168+
158169
@image_comparison(["useafm.eps"])
159170
def test_useafm():
160171
mpl.rcParams["ps.useafm"] = True

0 commit comments

Comments
 (0)