2

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:

\newcommand{\home}{$HOME}

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

\graphicspath{{\home/LaTeX/logos/}{\home/LaTeX/signature}}

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

\newcommand{\home}{${HOME}}
\newcommand{\home}{${$HOME}}
\newcommand{\home}{\%HOME\%}
\newcommand{\home}{${\%HOME\%}}

and

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.

2

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.

\documentclass{article}
\usepackage{catchfile}

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

\begin{document}

\texttt{\home}

\end{document}

Real data has been masked off:

enter image description here

If you're afraid of backslashes, do

\CatchFileEdef{\home}{|"kpsewhich -var-value=HOME"}{%
  \endlinechar=-1
  \catcode`\\=12
}
  • With miktex one has to use --enable-pipes. – Ulrike Fischer 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
1

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):

\documentclass{article}
%
\usepackage{graphicx}


%log all values of os.env:

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

\begin{document}
\includegraphics{\directlua{tex.print(-2,os.getenv("USERPROFILE"))}/Pictures/babel.png}
\end{document}
  • 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 – Ulrike Fischer 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
1

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

\documentclass{article}

\newcommand\home{\directlua{tex.print(-2,os.getenv("HOME"))}}

\begin{document}

this is home: \home

\end{document}

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.