29
29
_log = logging .getLogger (__name__ )
30
30
31
31
32
- _DOCUMENTCLASS = (
33
- rf"\documentclass{{{ mpl .rcParams .get ('pgf.documentclass' , 'article' )} }}"
34
- )
35
-
36
-
37
32
# Note: When formatting floating point values, it is important to use the
38
33
# %f/{:f} format rather than %s/{} to avoid triggering scientific notation,
39
34
# which is not recognized by TeX.
@@ -207,7 +202,7 @@ class LatexManager:
207
202
@staticmethod
208
203
def _build_latex_header ():
209
204
latex_header = [
210
- _DOCUMENTCLASS ,
205
+ rf"\documentclass{{ { mpl . rcParams . get ( 'pgf.documentclass' , 'article' ) } }}" ,
211
206
# Include TeX program name as a comment for cache invalidation.
212
207
# TeX does not allow this to be the first line.
213
208
rf"% !TeX program = { mpl .rcParams ['pgf.texsystem' ]} " ,
@@ -833,10 +828,11 @@ def print_pdf(self, fname_or_fh, *, metadata=None, **kwargs):
833
828
# print figure to pgf and compile it with latex
834
829
with TemporaryDirectory () as tmpdir :
835
830
tmppath = pathlib .Path (tmpdir )
831
+ docclass = mpl .rcParams .get ("pgf.documentclass" , "article" )
836
832
self .print_pgf (tmppath / "figure.pgf" , ** kwargs )
837
833
(tmppath / "figure.tex" ).write_text (
838
834
"\n " .join ([
839
- _DOCUMENTCLASS ,
835
+ rf"\documentclass{{ { docclass } }}"
840
836
r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo ,
841
837
r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
842
838
% (w , h ),
@@ -933,7 +929,7 @@ def _write_header(self, width_inches, height_inches):
933
929
pdfinfo = ',' .join (
934
930
_metadata_to_str (k , v ) for k , v in self ._info_dict .items ())
935
931
latex_header = "\n " .join ([
936
- _DOCUMENTCLASS ,
932
+ rf"\documentclass{{ { mpl . rcParams . get ( 'pgf.documentclass' , 'article' ) } }}" ,
937
933
r"\usepackage[pdfinfo={%s}]{hyperref}" % pdfinfo ,
938
934
r"\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}"
939
935
% (width_inches , height_inches ),
0 commit comments