I'm using matplotlib to generate pgf files.
Based on those, I use standalone tex files which only include necessary settings and the afore-built pgfs.
In this scenario, I'm getting errors when using custom tex-macros for descriptions in my plot files.
Here an example pgf generator:
import matplotlib as mpl
mpl.use("pgf")
mpl.rcParams.update({
"pgf.texsystem": "pdflatex",
"pgf.preamble": [
#r"\newcommand{\foo}{foo}",
r"\usepackage{import}",
r'\subimport{./}{foo.tex}'
]
})
import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
plt.xlabel(r'\foo{}')
plt.savefig('foo.pgf')
that can be used in a dir with the following foo.tex file:
\newcommand{\foo}{foo}
Running this results in the following error:
ValueError: Error processing '\foo{}'
LaTeX Output:
! Undefined control sequence.
<argument> ....000000}{12.000000}\selectfont \foo
{}
<*> ...ze{10.000000}{12.000000}\selectfont \foo{}}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
Please note, that this is an error generated by matplotlib and not of compiling my standalone files.
Also note, that the error goes away when the \foo macro is provided as part of the pgf.preamble
(the line commented out) instead.
I checked the pgf produced by this variant and indeed it uses \foo{}.
I'm having trouble narrowing the problem further down. Here my concrete questions:
- Why does
matplotlibinvokepdflatexat all? I'm generatingpgfoutput and thuspdflatexshould not be necessary. (For the reference: Istraced the script above and indeed know thatpdflatexis being called.) - Is there a way of preserving the temporary file that
matplotlibtries to compile? The error referencestexput.logby (of course) that file doesn't exist afterwards. - Why can't I use a macro in a label which is provided in another tex file?