I need to know what is the actual output directory, as set by the -outdir or -output-dir command line switch, because I am executing external programs and I need to give them the exact location of the auxiliary file to use, similarly to this unanswered question.

The difference is that I am using LuaLaTeX, so there might be new or easier means to get this right.

To test, I tried printing this directory in the document, but \directlua{tex.print(status.list()["output_file_name"])} only gives the basename and \directlua{tex.print(os.env["PWD"])} gives the working directory of the process which is not, as I had hoped, set to the outdir.


2 Answers 2


Arguments passed to luatex are stored in the lua table arguments. They are indexed by the passed key.

To find such info, you can search the _G (or more generally, _ENV) table, where all lua globals are indexed.

There is an introspection script on the lua website for this.

By the way, lua has the . syntactic sugar to refer to string keys in a table. eg : os.env["PWD"] is the same as os.env.PWD

Below I can't do this for "output-directory" because of the -.

The output

If i have compiled my file with lualatex --output-dir=myOutDir myf.tex, I get :

enter image description here

The code

  function passedOutputDir()
    return arguments["output-directory"] or "noPassedOutputDir"
Passed output dir : 
  • Sounds interesting but does not work with me (lualatex v1.0.4 (TeX Live 2017)). The arguments table is empty (if this is correct).
    – ysalmon
    Aug 26, 2017 at 14:49
  • @ysalmon It is empty if you don't pass arguments when compiling. Also, the output directory does not seem to be passed from latexmk to lualatex directly.
    – marsupilam
    Aug 26, 2017 at 14:52
  • Of course. After further investigation, it appears that lualatex -output-dir=test mwe.tex compiles into test but arguments is empty, while lualatex --output-dir=test mwe.tex compiles to the same dir but arguments is set this time. Strange.
    – ysalmon
    Aug 26, 2017 at 14:56
  • 1
    So, the following does the trick : latexmk -pdflua -outdir=build -latexoption="--output-directory=build". It is also interesting to note that lualatex seems not to complain when it is passed arbitrary options --myprivateoption=myvalue and they are accessible through arguments : one can effectively pass parameters to the script being compiled.
    – ysalmon
    Aug 26, 2017 at 15:16
  • 1
    You can find all luatex arguments in the arg table... Aug 26, 2017 at 15:25

The value is stored in the global variable output_directory in the C source file, unfortunately it's not exported to Lua.

I thought it would be possible to do something like kpse.find_file("a.log") but that doesn't work despite claims that it should work.

One workaround (ugly but works) I can find is to use open_read_file callback, write to some tempfile (using simply jobname.log works as well without the temporary file, but not sure about MiKTeX), then read from it, and get the file name from the argument passed to the file.

Alternative includes reading the recorder file, similar to the method for other engines, but requires -recorder flag and it's impossible to determine the case where one compilation has the flag and the next compilation doesn't.

Side note, only the arg table is guaranteed to work, but parsing this is very difficult. Possible argument format includes

-output-directory a/
--output-directory a/
-output-d a/

so very hard to parse.

The arguments table seems to be some global variable leakage in older version, nowadays it can only be found in e.g. luaotfload.fontloader.arguments, but then this one only handle some formats of the above list, so not reliable.

There's also utilities.parsers.arguments_to_table but I guess this suffers from the same limitation.

You must log in to answer this question.

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