I use mylatexformat to easily build format files. Consider the following file:
\documentclass{article}
% This is file t.tex
\usepackage{pythontex}
\begin{document}
Test
\end{document}
Then, I run pdflatex -ini -jobname="myfmt" "&pdflatex" mylatexformat.ltx """t.tex""" to get myfmt.fmt.
Now, I have another file:
%&myfmt
\documentclass{NoMatterItIsNotReadAnyway}
% This is s.tex
\begin{document}
\begin{pygments}{python}
def foo():
return 'bar'
\end{pygments}
\end{document}
When I compile it, the format myfmt.fmt is loaded and it comes with pythontex preloaded. A pdf file is produced: compilation is fine. Then, I run pythontex s.tex: no warnings. Then, I compile once again s.tex. Unfortunately, the python code does not show up in the pdf file. All I get is ?? PythonTeX ??.
The log tells me that
Package PythonTeX Warning: Non-existent Pygments content on input line 8.
and also
No file pythontex-files-myfmt/myfmt.pytxmcr
So I guess there me be some "hard coded" filenames and directory names defined when the format is created.
Is there a workaround so that I could use mylatexformat with pythontex the way I showed here?
pythontexuses\jobnameto create a directory name for saving output, among other things. You are probably running into the issues with precompiling discussed in this answer. When I usepythontexwith a precompiled preamble, I generally load it separately, after the precompiled material. I don't know if that's possible withmylatexformat. – G. Poore Nov 25 '15 at 01:13\jobnamewith someetoolboxhooks (\AtEndPreambleor\AfterEndPreamble). I could probably hack something if I knew where to look. The reason why I'd like to avoidusepackagingpythontexafter precompiled material is that I'd like to avoid my users the pain to do it. – cjorssen Nov 25 '15 at 12:07\setpythontexoutputdir{<dirname>}to set the directory manually. The bigger problem is that the temp files using\jobnameare opened immediately when the package is loaded, and that breaks with precompiling. I suppose it might be possible to reopen them at the end of the preamble, to try to correct for the file issues caused by precompiling. The*.pytxcodefile would be the one to worry about (unless you're usingdepythontex). – G. Poore Nov 25 '15 at 12:56etoolbox)? – cjorssen Nov 25 '15 at 20:54