leo-colisson / robust-externalize

A LaTeX library to cache pictures (including tikz, python code, and more) in a robust, customizable, and pure way.
7 stars 2 forks source link

Doesn't work with `-output-directory` set #19

Closed NickHu closed 5 months ago

NickHu commented 5 months ago
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{cd}
\usepackage{robust-externalize}
\cacheEnvironment{tikzcd}{tikz, add to preamble={\usetikzlibrary{cd}}}
\begin{document}
\begin{tikzcd}
    A \rar & B
\end{tikzcd}
\end{document}

Compile with

mkdir -p build/robustExternalize # this also should probably be fixed
pdflatex -shell-escape -output-directory=build test.tex

It seems to make pdflatex hang forever on my system.

NickHu commented 5 months ago

Workaround:

ln -s build/robustExternalize robustExternalize
tobiasBora commented 5 months ago

Thanks, good point. The reason it hangs foreover, I think, is that the file does not exist and pdflatex just waits foreover to get an input from the command line maybe? Anyway, your workaround does work, and I basically just need to prepend all compilation commands with cd build to make it work without the workaround. For now, the main issue is that I don't know how to programmatically get the path to -output-directory. Hopefully, someone will answer here https://tex.stackexchange.com/questions/707152/programmatically-get-the-output-directory

NickHu commented 5 months ago

Indeed your observation is correct that the spawned pdflatex is just waiting forever unable to find the files it needs (verified by looking at the log of the spawned pdflatex process)

tobiasBora commented 5 months ago

Since it seems like there is no programmatic way to find the value of the output directory, you can configure it with either \robExtConfigure{set output directory=build} in your file if you always use the same output directory, or you can do:

$ pdflatex -shell-escape -output-directory=build "\def\robExtOutputDirectory{build}\input{test.tex}"

for instance if you use different build directories. Let me know if the latest version works for your, and feel free to reopen if it does not work for you.

NickHu commented 5 months ago

Thanks for fixing this so promptly. I like your second suggestion as a way to not have to hardcode the output directory in your document file. Can you think of a way to make that work with vimtex + latexmk, which is my primary workflow?

tobiasBora commented 5 months ago

It seems like latexmk can accept a configuration containing something like this:

&alt_tex_cmds;
$pre_tex_code = '\def\robExtOutputDirectory{build}';

(the alt_tex_cmds is apparently needed to make it work for any engine like lualatex as documented in https://manpages.ubuntu.com/manpages/lunar/man1/latexmk.1.html)

I guess it should solve your problem.