Skip to content

Commit 1bf0be7

Browse files
committed
Refactor _DOCUMENTCLASS variable to inline pgf.documentclass access
1 parent e8f44bc commit 1bf0be7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
_log = logging.getLogger(__name__)
3030

3131

32-
_DOCUMENTCLASS = (
33-
rf"\documentclass{{{mpl.rcParams.get('pgf.documentclass', 'article')}}}"
34-
)
35-
36-
3732
# Note: When formatting floating point values, it is important to use the
3833
# %f/{:f} format rather than %s/{} to avoid triggering scientific notation,
3934
# which is not recognized by TeX.
@@ -207,7 +202,7 @@ class LatexManager:
207202
@staticmethod
208203
def _build_latex_header():
209204
latex_header = [
210-
_DOCUMENTCLASS,
205+
rf"\documentclass{{{mpl.rcParams.get('pgf.documentclass', 'article')}}}",
211206
# Include TeX program name as a comment for cache invalidation.
212207
# TeX does not allow this to be the first line.
213208
rf"% !TeX program = {mpl.rcParams['pgf.texsystem']}",
@@ -833,10 +828,11 @@ def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs):
833828
# print figure to pgf and compile it with latex
834829
with TemporaryDirectory() as tmpdir:
835830
tmppath = pathlib.Path(tmpdir)
831+
docclass = mpl.rcParams.get("pgf.documentclass", "article")
836832
self.print_pgf(tmppath / "figure.pgf", **kwargs)
837833
(tmppath / "figure.tex").write_text(
838834
"\n".join([
839-
_DOCUMENTCLASS,
835+
rf"\documentclass{{{docclass}}}"
840836
r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
841837
r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
842838
% (w, h),
@@ -933,7 +929,7 @@ def _write_header(self, width_inches, height_inches):
933929
pdfinfo = ','.join(
934930
_metadata_to_str(k, v) for k, v in self._info_dict.items())
935931
latex_header = "\n".join([
936-
_DOCUMENTCLASS,
932+
rf"\documentclass{{{mpl.rcParams.get('pgf.documentclass', 'article')}}}",
937933
r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
938934
r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
939935
% (width_inches, height_inches),

0 commit comments

Comments
 (0)