Skip to content

Commit 18c8cfb

Browse files
committed
Make used tex packages consistent between ps and other backends.
... by wrapping ps-specific packages in `\@ifpackageloaded`, which makes their use transparent to the end user (if they already loaded it themselves, we don't do anything). So don't mention them anymore in the matplotlibrc docs either. Also, graphicx doesn't need the dvips option (the graphicx docs explicitly state "normally you should... allow it to be defaulted automatically". (The pgf backend is a completely different beast and has its own custom preamble anyways.)
1 parent 295f9c0 commit 18c8cfb

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
@@ -1112,8 +1112,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
11121112
with mpl.rc_context({
11131113
"text.latex.preamble":
11141114
mpl.rcParams["text.latex.preamble"] +
1115-
r"\usepackage{psfrag,color}""\n"
1116-
r"\usepackage[dvips]{graphicx}""\n"
1115+
# Only load these packages if they have not already been loaded, in
1116+
# order not to clash with custom packages.
1117+
r"\makeatletter"
1118+
r"\@ifpackageloaded{color}{}{\usepackage{color}}"
1119+
r"\@ifpackageloaded{graphicx}{}{\usepackage{graphicx}}"
1120+
r"\@ifpackageloaded{psfrag}{}{\usepackage{psfrag}}"
1121+
r"\makeatother"
11171122
r"\geometry{papersize={%(width)sin,%(height)sin},margin=0in}"
11181123
% {"width": paper_width, "height": paper_height}
11191124
}):

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)