Skip to content

Commit 46ac87e

Browse files
committed
PGF: Fix inconsistent options for \documentclass
This could cause a mismatch between lengths when measuring vs. producing output for things that depend on the font size setting at the beginning of the document, e.g. unicode-math. Use \documentclass{article} without options here, which defaults to a font size of 10pt (same as the matplotlib rc default for font.size).
1 parent 199c31f commit 46ac87e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
_log = logging.getLogger(__name__)
2929

3030

31+
DOCUMENTCLASS = r"\documentclass{article}"
32+
3133
# Note: When formatting floating point values, it is important to use the
3234
# %f/{:f} format rather than %s/{} to avoid triggering scientific notation,
3335
# which is not recognized by TeX.
@@ -185,7 +187,7 @@ class LatexManager:
185187
@staticmethod
186188
def _build_latex_header():
187189
latex_header = [
188-
r"\documentclass{article}",
190+
DOCUMENTCLASS,
189191
# Include TeX program name as a comment for cache invalidation.
190192
# TeX does not allow this to be the first line.
191193
rf"% !TeX program = {mpl.rcParams['pgf.texsystem']}",
@@ -814,7 +816,7 @@ def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs):
814816
self.print_pgf(tmppath / "figure.pgf", **kwargs)
815817
(tmppath / "figure.tex").write_text(
816818
"\n".join([
817-
r"\documentclass[12pt]{article}",
819+
DOCUMENTCLASS,
818820
r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
819821
r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
820822
% (w, h),
@@ -924,7 +926,7 @@ def _write_header(self, width_inches, height_inches):
924926
pdfinfo = ','.join(
925927
_metadata_to_str(k, v) for k, v in self._info_dict.items())
926928
latex_header = "\n".join([
927-
r"\documentclass[12pt]{article}",
929+
DOCUMENTCLASS,
928930
r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo,
929931
r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
930932
% (width_inches, height_inches),

0 commit comments

Comments
 (0)