Matplotlib doesn't seem to find files in the current working directory when running latex. Does anyone know where it looks for files?
The background is: I have a huge preamble that I \input
into latex before processing (lots of macros, various usepackages, etc.). In a stand-alone paper, I do \input{BigFatHeader.tex}
. So when I use matplotlib, I try to just input this file in the preamble. The python code to do this is
matplotlib.rcParams['text.latex.preamble'].append(r'\input{BigFatHeader.tex}')
And I can verify that that file is in the cwd -- I see it when I ls
, or I can do os.path.isfile("BigFatHeader.tex")
and get True. But when I try to plot something using latex, python spits out a big error message from the latex process, that culminates in
! LaTeX Error: File BigFatHeader.tex
not found.
So presumably it changes to some other directory (not /tmp/
; I checked) to do its work. Any idea where this might be?
My minimal working example is:
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['text.latex.preamble'] = r'\input{BigFatHeader.tex}'
matplotlib.rcParams['text.usetex'] = True
plt.plot([1,2])
plt.savefig('MWE.pdf')
Where BigFatHeader.tex
might be as simple as
\usepackage{bm}