1

In short: I stumbled upon a case where latexmk runs fine, but pdflatex fails, using the command outputted by latexmk.

Some details: my setup is gently exotic but I can't get why this could interfere and why pdflatex would only succeed when launched via latexmk. The only hint I have, from my scarce understanding of the sources, is that latexmk can redefine $ENV{TEXINPUTS}. I could not make other/simpler bugging cases than this one, with dot2texi and a specific build directory.

Here is the tree of my working directory:

.
├── build/
├── dot2texi.sty
└── dot.tex

I'm using the dot2texi.sty patch from here to be able to compile with all the (numerous!) build files sent to the directory build/. I use the settings proposed in this answer in the dot.tex file:

\documentclass{standalone}
\usepackage[inputdir=build/]{dot2texi}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{dot2tex}[neato]
digraph G { a -> b }
\end{dot2tex}
\end{document}

When launching latexmk -pdf --output-directory=build --shell-escape dot.tex everything runs as expected. The numerous build files are sent to build and the graph is correctly compiled.

When launching pdflatex -recorder -output-directory="build" --shell-escape "dot.tex" (which is what latexmk says it runs) I get the following error:

Opening dot2tex stream dot-dot2tex-fig1.dot
! LaTeX Error: File `dot-dot2tex-fig1.tex' not found.

This buggy behaviour was reproduced on two machines, under debian and gentoo. I also tried to play a bit with the pdflatex options, without success.

Definitely not the most critical bug of the century, but I'd like to understand what I'm doing wrong...

letax
  • 41
  • --output-directory="build" will add build as an input directory for pdflatex, but this is not passed to external commands called via shell-escape. – Ulrike Fischer May 03 '20 at 18:44
  • Thanks for the feedback. How do you explain that the compilation works as expected when the same command is called via latexmk? I'd expect both or none to fail. – letax May 03 '20 at 20:15
  • It probably setups the environment so that the other command see the folder too. But I didn't check what really happen, I only think that it is quite probable that there are differences. – Ulrike Fischer May 03 '20 at 20:21
  • Thanks. I indeed had checked in the latexmk's sources that environment variables might be modified. I also have many other use-cases with "regular" standalone tikzpictures built on the fly from a main document. Everything works as I expect, with both latexmk and pdflatex using \standaloneconfig{`build={latexoptions={--shell-escape -output-directory=build/}}}. – letax May 04 '20 at 08:58
  • Definitely, latexmk sets the environment variable TEXINPUTS to include the build directory. (It also includes it in BSTINPUTS.) That should explain the different behavior. So if you want pdflatex to have the same behavior as latexmk, you have to set TEXINPUTS yourself. – John Collins May 04 '20 at 17:01
  • @JohnCollins Thanks for the feedback. (And for latexmk by the way.) It was not clear for me, reading the documentation, that latexmk would silently redefine TEXINPUTS, without being explicitly asked. Reading the logs, I didn't find any mention of this redefinition of the variables. Did I miss the info somewhere? I think you could turn your comment into an answer, as it may be useful to others. – letax May 04 '20 at 17:33

1 Answers1

1

There is indeed a hidden difference in behavior between pdflatex invoked by latexmk and pdflatex invoked by the user with the identical command line. This happens because latexmk sets the environment variable TEXINPUTS to include the build directory in the search path for TeX source files. (Strictly speaking it's the aux_dir that's used. But that equals the out_dir if only the out_dir is set, as in this case.)

The changed environment variable is passed to any command invoked by pdflatex. Then dot2tex works properly when a build directory is used. If you want the same behavior when you start pdflatex yourself from the command line, then you have to first modify (or set) TEXINPUTS.

Historical Note: The original reason for latexmk to set TEXINPUTS is that the same variable is an analogous problem with dvips. The trigger for this was incorrect behavior by the FeynMP package, according to my notes from 2011. With dot2tex we now see another version of the same problem. It was probably in the back of my mind, that setting TEXINPUTS would solve other similar problems, as we now see with dot2tex.

John Collins
  • 11,183
  • 3
  • 32
  • 33
  • Much clearer like that. Interesting historical note. Would it be worth telling the users in latexmk's log when a variable is modified? – letax May 05 '20 at 04:48
  • I've done that, and the result will be in the next release. Thanks for the suggestion. – John Collins May 06 '20 at 14:48
  • Glad if it helps! It sounds useful to be able to reproduce step by step everything latexmk does, just reading the log. Thanks! – letax May 06 '20 at 18:57