I've run into an issue with variable expansion in the different distributions of LuaLaTeX (chiefly MikTeX and TeXLive). In TeXLive (both 2014 and 2016), I can use the following to reference my home directory:


and subsequently have commands like the following to allow me to reference both my Windows (work) and Linux (home) filesystems.


The problem that I'm running into is that I can't figure out how to make the MikTeX version of LuaLaTeX expand the path variable.

I've tried just about every combination of



miktex-lualatex --enable-write18
miktex-lualatex -enable-write18
miktex-lualatex --shell-escape
miktex-lualatex -shell-escape

but nothing I do allows me to find the font I'm trying to reference. I get varying versions of

luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: "File not found: ${$HOME}/LaTeX/fonts/

depending on what I try to make the combo of options above.

If someone could shed some light on what I'm missing or perhaps present a better solution that what I have been doing, it would be greatly appreciated. I compile with both pdfLaTeX and LuaLaTeX depending on whether or not I need the OTF fonts.


If you pass \newcommand{\home}{$HOME} in the command line, then the shell will interpret the variable, but in a TeX file it would not work.

You can use catchfile and kpsewhich that, I believe, also works in MiKTeX.


\CatchFileEdef{\home}{|"kpsewhich -var-value=HOME"}{\endlinechar=-1 }




Real data has been masked off:

enter image description here

If you're afraid of backslashes, do

\CatchFileEdef{\home}{|"kpsewhich -var-value=HOME"}{%
  • With miktex one has to use --enable-pipes. Jul 21 '16 at 17:00
  • This seems to work across everything that I want it to. I needed to add --enable-pipes for miktex-pdflatex but not for miktex-lualatex.
    – aepksbuck
    Jul 21 '16 at 17:10

I can't really believe that $HOME works, but on windows you can use something like this (to avoid problems with the backslash in pathes, one should print the path with another catcode table):


%log all values of os.env:

\directlua{for k, v in pairs( os.env ) do
   texio.write_nl ("key: "..k .. " value: ".. v)

  • This solves the problem for miktex-lualatex and the texlive version, but leaves miktex-pdflatex in a lurch. It also breaks my Linux lualatex.
    – aepksbuck
    Jul 21 '16 at 16:30
  • Your question didn't mention pdflatex, it also didn't mention linux. Perhaps you can use a variant of this solution tex.stackexchange.com/a/62032/2388 Jul 21 '16 at 16:37
  • My question did initially mention Linux and I updated it to mention pdflatex, which I hadn't gotten to yet. Sorry for the confusion.
    – aepksbuck
    Jul 21 '16 at 16:58

There is os.getenv function provided by Lua, so I would use that:




this is home: \home


enter image description here

  • This works for Linux, but has issues on Windows with backslashes.
    – aepksbuck
    Jul 21 '16 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.