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 6d83289

Browse filesBrowse files
committed
Fix use of psfrags in ps backend + usetex.
Looks like psfrags interacts badly with `\newgeometry`, so we need to use `\geometry` instead in the custom preamble to set the paper size. In turn this means that `\usepackage{geometry}` needs to move to before the custom preamble into `TexManager._get_preamble()`, and thus we can't pass the dvips option to it anymore, but fortunately dvips is documented as the default driver anyways (section 5.6 of `geometry` docs). Also, in order to keep everything under 79 characters wide, change `{72in,72in}` to just `72in` (which is synonymous per section 4.3.3 of `geometry` docs). Also insert some extra newlines in the generated tex file for ease of debugging.
1 parent ad76c83 commit 6d83289
Copy full SHA for 6d83289

File tree

Expand file treeCollapse file tree

2 files changed

+14
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-11
lines changed

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,18 +1098,20 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
10981098
with mpl.rc_context({
10991099
"text.latex.preamble":
11001100
mpl.rcParams["text.latex.preamble"] +
1101-
r"\usepackage{psfrag,color}"
1102-
r"\usepackage[dvips]{graphicx}"
1103-
r"\PassOptionsToPackage{dvips}{geometry}"}):
1101+
r"\usepackage{psfrag,color}""\n"
1102+
r"\usepackage[dvips]{graphicx}""\n"
1103+
r"\geometry{papersize={%(width)sin,%(height)sin},"
1104+
r"body={%(width)sin,%(height)sin},margin=0in}"
1105+
% {"width": paper_width, "height": paper_height}
1106+
}):
11041107
dvifile = TexManager().make_dvi(
1105-
r"\newgeometry{papersize={%(width)sin,%(height)sin},"
1106-
r"body={%(width)sin,%(height)sin}, margin={0in,0in}}""\n"
1107-
r"\begin{figure}"
1108-
r"\centering\leavevmode%(psfrags)s"
1109-
r"\includegraphics*[angle=%(angle)s]{%(epsfile)s}"
1108+
"\n"
1109+
r"\begin{figure}""\n"
1110+
r" \centering\leavevmode""\n"
1111+
r" %(psfrags)s""\n"
1112+
r" \includegraphics*[angle=%(angle)s]{%(epsfile)s}""\n"
11101113
r"\end{figure}"
11111114
% {
1112-
"width": paper_width, "height": paper_height,
11131115
"psfrags": "\n".join(psfrags),
11141116
"angle": 90 if orientation == 'landscape' else 0,
11151117
"epsfile": pathlib.Path(tmpfile).resolve().as_posix(),

‎lib/matplotlib/texmanager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/texmanager.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ def _get_preamble(self):
186186
self._font_preamble,
187187
r"\usepackage[utf8]{inputenc}",
188188
r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}",
189+
# Needs to come early so that the custom preamble can change the
190+
# geometry, e.g. in convert_psfrags.
191+
r"\usepackage[papersize=72in,body=70in,margin=1in]{geometry}",
189192
self.get_custom_preamble(),
190193
])
191194

@@ -204,7 +207,6 @@ def make_tex(self, tex, fontsize):
204207
Path(texfile).write_text(
205208
r"""
206209
%s
207-
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
208210
\pagestyle{empty}
209211
\begin{document}
210212
\fontsize{%f}{%f}%s
@@ -239,7 +241,6 @@ def make_tex_preview(self, tex, fontsize):
239241
r"""
240242
%s
241243
\usepackage[active,showbox,tightpage]{preview}
242-
\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry}
243244
244245
%% we override the default showbox as it is treated as an error and makes
245246
%% the exit status not zero

0 commit comments

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