I am relying on shell commands to include git information in my documents. This was working fine, but stopped recently. I am yet unable to figure out why. Check the following MWE. Of course this would not incude actual git information, but rather the git help. But this way it "works" outside of an actual git repository. When running this I am expecting three lines in the document:
- Hello World
- Test
- git output
The first two work, but the last one does not really.
% !TeX program = lualatex
\documentclass{article}
\begin{document}
Hello World
\input{|"echo Test"}
\input{|"git"}
\input{|"path"} % will produce errors, but one can read the path from the error log
\directlua{tex.sprint(os.getenv("path"):gsub("\\","\\textbackslash "))}
\end{document}
When I compile the document from within TeXstudio (--shell-escape enabled in the parameters for lualatex) under Windows, I get an output that indicates that the git command is not found. If I try a \input{|"where git"}
I also get a command not found for where
. So it seems that the commands are run in a shell, which has %PATH%
not properly set.
When I compile the document in a cmd or Powershell with lualatex --shell-escape filename.tex
it works as intended.
Unfortunately, I did not figure out how to print %PATH%
in the latex document to check its content. I tried to escape the percentage sign with \%
and even used \@percentchar
but in the end get an error "missing \endcsname inserted".
pdflatex run in TeXstudio works just fine.
xelatex works also fine from within TeXstudio.
What am I missing? Why does lualatex run from within TeXstudio does not find standard commands in PATH?
EDIT: Based on Ulrikes comment I found a way to include the PATH in the document. This clearly also includes the path to git. So actually it should be callable. I also tested this on a second machine with the same versions of MiKTeX and TeXstudio and it works fine there.
EDIT2: It was too easy to print the PATH variable. Instead of echo %PATH%
a simple path
does the trick. I added this in the MWE, even though it is now not working anymore. The backslahes in the paths make LaTeX think that these are commands and fails. But from the error log one still can see what paths are included. And indeed, when compiling with LuaLaTeX only the MikTeX-directory is in the PATH. When compiling with pdflatex the normal PATH environment variable is used.
\directlua{print(os.getenv("path"))}
should show the path on the terminal/console. But I would prefer a solution which doesn't require shell-escape.