diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 958ad6204210..a20abe56f621 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -1098,18 +1098,20 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble, with mpl.rc_context({ "text.latex.preamble": mpl.rcParams["text.latex.preamble"] + - r"\usepackage{psfrag,color}" - r"\usepackage[dvips]{graphicx}" - r"\PassOptionsToPackage{dvips}{geometry}"}): + r"\usepackage{psfrag,color}""\n" + r"\usepackage[dvips]{graphicx}""\n" + r"\geometry{papersize={%(width)sin,%(height)sin}," + r"body={%(width)sin,%(height)sin},margin=0in}" + % {"width": paper_width, "height": paper_height} + }): dvifile = TexManager().make_dvi( - r"\newgeometry{papersize={%(width)sin,%(height)sin}," - r"body={%(width)sin,%(height)sin}, margin={0in,0in}}""\n" - r"\begin{figure}" - r"\centering\leavevmode%(psfrags)s" - r"\includegraphics*[angle=%(angle)s]{%(epsfile)s}" + "\n" + r"\begin{figure}""\n" + r" \centering\leavevmode""\n" + r" %(psfrags)s""\n" + r" \includegraphics*[angle=%(angle)s]{%(epsfile)s}""\n" r"\end{figure}" % { - "width": paper_width, "height": paper_height, "psfrags": "\n".join(psfrags), "angle": 90 if orientation == 'landscape' else 0, "epsfile": pathlib.Path(tmpfile).resolve().as_posix(), diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index f954254adc9e..e274a7f7e662 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -186,6 +186,9 @@ def _get_preamble(self): self._font_preamble, r"\usepackage[utf8]{inputenc}", r"\DeclareUnicodeCharacter{2212}{\ensuremath{-}}", + # Needs to come early so that the custom preamble can change the + # geometry, e.g. in convert_psfrags. + r"\usepackage[papersize=72in,body=70in,margin=1in]{geometry}", self.get_custom_preamble(), ]) @@ -204,7 +207,6 @@ def make_tex(self, tex, fontsize): Path(texfile).write_text( r""" %s -\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry} \pagestyle{empty} \begin{document} \fontsize{%f}{%f}%s @@ -239,7 +241,6 @@ def make_tex_preview(self, tex, fontsize): r""" %s \usepackage[active,showbox,tightpage]{preview} -\usepackage[papersize={72in,72in},body={70in,70in},margin={1in,1in}]{geometry} %% we override the default showbox as it is treated as an error and makes %% the exit status not zero