0

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:

  1. Hello World
  2. Test
  3. 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.

8
  • There are already a couple of packages that provide git wrappers for latex, maybe you could use one of those: e.g. latexgit or gitinfo2
    – DG'
    Commented Nov 18, 2022 at 8:07
  • Thanks for this suggestion. Actually, I do not know why I did not consider this in the first place (or discarded it). However, for now I would consider this a workaround, because I would like to have the tool of shell commands in my shed.
    – Gunter
    Commented Nov 18, 2022 at 8:13
  • I checked out the documentation. latexgit relys on linux commands like e.g. grep. This is not a suitable dependency for Windows. gitinfo2 uses githooks, which might also cause some issues in my current repo layout (multiple documents in one repo).
    – Gunter
    Commented Nov 18, 2022 at 8:49
  • 1
    \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. Commented Nov 18, 2022 at 10:46
  • where is this printed? I do not see it in the document and in the log file.
    – Gunter
    Commented Nov 18, 2022 at 11:26

1 Answer 1

0

Some update seems to have fixed this issue. At least it is working again. Unfortunately, I did not keep track of the updates I lately installed until I tried it again.

You must log in to answer this question.

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