In order to solve this issue, I would need to programmatically get the -output-directory when running a commands like:

$ pdflatex -shell-escape -output-directory=build test.tex

The reason is that I would need to change commands run via \write18 depending on the location of the build folder.

(I also tried to directly read ${TEXMF_OUTPUT_DIRECTORY} from the command line, but this environment variable is empty as well: EDIT after checking the source, this seems to be available starting from TexLive 2024)

  • 4
    adding the output-directory option to tex was such a bad idea, it adds far more problems than it solves Commented Jan 16 at 0:21
  • I got once the request to support that in newpax github.com/u-fischer/newpax/issues/21 Commented Jan 16 at 0:31
  • @UlrikeFischer Actually, I'd love support for subfolders in newpax, the number of files cached when using robust-externalize is so large that no-one would like to have it in its current directory.
    – tobiasBora
    Commented Jan 16 at 0:37
  • putting generated files in a cache-subfolder is something quite different to the general --output-directory option. Commented Jan 16 at 9:35
  • @UlrikeFischer yeah, but it means that to includes files from this subfolder with newpax support, I'm screwed since all files must be in the current folder for newpax to work.
    – tobiasBora
    Commented Jan 16 at 11:59

2 Answers 2


--output-directory is certainly more trouble than its worth but since it's there I suppose you have to support it.

Assuming the output directory is below the current directory and a unix find is available then you can do for example

\input{|find . -name \jobname.log}


which will print the path to the log file, including output-directory you could similarly \input into a definition that to get the path for further processing.

  • Thanks, but I have a few issues with this: first it would not work in windows out of the box, and, more importantly, if the file has been compiled before without any output directory, there might be several files with the name \jobname.log.
    – tobiasBora
    Commented Jan 16 at 0:34
  • Also, any idea why the ${TEXMF_OUTPUT_DIRECTORY} is not set?
    – tobiasBora
    Commented Jan 16 at 0:37
  • 1
    for the second issue you could first write a unique file eg using current time, then find that, why would you expect any setting in the shell environment? Commented Jan 16 at 0:58
  • Hum, that could work, thanks, but seems a bit hacky. For now, I guess I will just ask the user to specify this folder manually like pdflatex -shell-escape -output-directory=build "\def\robExtOutputDirectory{build}\input{test.tex}"… For the environment, I read the code of pdflatex where I can find stuff like Furthermore, if the ‘-output-directory’ option is specified, its argument is saved in the environment variable ‘TEXMF_OUTPUT_DIRECTORY’. This is for the benefit of any subprograms that might be called via write 18, such as kpsewhich.
    – tobiasBora
    Commented Jan 16 at 1:07
  • 1
    @tobiasBora ooh you mean "will be" not "was" tl2024 isn't even in public test yet so that will be a while, but for future reference do you want to post (and accept) that as an answer I'll leave this answer as is for older systems. Commented Jan 16 at 10:57

I ended up asking the user to compile with something like:

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

(see also pre_latex in latexmk)

But starting from TeXLive 2024, a new environment variable should be defined:


which should help to run commands with -shell-escape correctly.

  • thanks, you should accept this answer which is clearly much better than the other answer:-) Commented Jan 18 at 12:54

Not the answer you're looking for? Browse other questions tagged .