2

This question stems from my question here about minted and lualatex, with similar issues reported by another user here.

I think I've isolated the issue to the following. minted relies on \ShellEscape from shellesc, which seems to fail in specific cases when compiling with lualatex, at least on Windows.

For example the following compiles as expected with pdflatex --shell-escape and xelatex --shell-escape.

\documentclass{article}
\usepackage{shellesc}

\begin{document}

\ShellEscape{mkdir myfolder} \ShellEscape{echo hello world} \ShellEscape{python --version} % this line is the problem

\end{document}

With lualatex --shell-escape, the commands mkdir and echo work as expected: a directory myfolder is created and hello world is printed in the terminal. But instead of printing Python 3.11.1 in the terminal like pdflatex and xelatex, compiling with lualatex prints

'python' is not recognized as an internal or external command,
operable program or batch file.

So for some reason lualatex with shell escape can't find the same programs installed on my computer as pdflatex and xelatex. For reference, I'm compiling with lualatex 1.16.0 from miktex on a machine with Windows 10. The document above works perfectly with a Linux machine and a slightly older lualatex, so my assumption is that Windows is part of the issue.

I have no idea what about lualatex, the Windows file system, or shellesc may be causing the issue. Any help is appreciated.


Edit

As David Carlisle helped determine in the comments, adding \ShellEscape{echo \@percentchar PATH\@percentchar } shows that lualatex only has access to the programs in C:\Users\mbert\AppData\Local\Programs\MiKTeX\miktex\bin\x64. Running the same with pdflatex or xelatex shows all the locations added to my PATH variable, including the one to python.

Why would this issue of a restricted PATH only arise with lualatex and not pdflatex or xelatex?

mbert
  • 4,171
  • works for me hello world Python 3.9.10 lualatex cygwin , though, not windows – David Carlisle Jan 31 '23 at 22:33
  • @DavidCarlisle yes it works fine for me too with wsl. Windows seems the culprit – mbert Jan 31 '23 at 22:37
  • what does \makeatletter \ShellEscape{echo \@percentchar PATH\@percentchar } show is the directory with python in the path used by Lua ? – David Carlisle Jan 31 '23 at 22:39
  • "I have no idea what about lualatex, the Windows file system, or shellesc may be causing the issue. " It can't possibly be the last of these:-) – David Carlisle Jan 31 '23 at 22:42
  • @DavidCarlisle Good suggestion. It shows C:\Users\mbert\AppData\Local\Programs\MiKTeX\miktex\bin\x64\, while pdflatex shows my full PATH – mbert Jan 31 '23 at 23:15
  • Do you have any guess why lualatex would restrict the PATH? Could it be miktex specific? – mbert Jan 31 '23 at 23:30
  • if have no problems with miktex and lualatex. It finds python without problems. But I'm on windows 11 here, I would have to check windows 10 tomorrow. – Ulrike Fischer Jan 31 '23 at 23:33
  • and check the virus+thread protection settings in windows. Perhaps windows has decided that lualatex is a thread. – Ulrike Fischer Jan 31 '23 at 23:45
  • @UlrikeFischer Do you know where I'd check such a thing? I've got the default windows virus protection. Nothing obvious from a look through the settings. It also seems odd that it would allow access to a single directory in my path instead of blocking access to everything – mbert Jan 31 '23 at 23:55
  • you could try with a process monitor: https://learn.microsoft.com/en-us/sysinternals/downloads/procmon. Perhaps it gives you a clue, what is restricting lualatex. – Ulrike Fischer Feb 01 '23 at 00:04
  • @mbert sorry I have no idea about that.are you calling lualatex directly from a commandline or from some editor?, it does mean workaroud would be a python.bat in miktex bin that set the path back and called a real python – David Carlisle Feb 01 '23 at 00:13
  • @DavidCarlisle for these examples command line. I'm not too worried about a workaround because I can use wsl, it's more just figuring out what's going wrong – mbert Feb 01 '23 at 00:16

1 Answers1

1

I'm also stuck with the same problem on Windows 11 with MiKTex (after a fresh install of Windows).

I could reproduce everything that mbert wrote above: pdflatex/xelatex works, but in lualatex the PATH variable in \ShellEscape is wrongly set to contain only the directory of "lualatex.exe".

As suggested above by Ulrike Fischer, I checked lualatex.exe in the process monitor of Windows but couldn't find anything that would suggest that it is more restricted than pdflatex. I also turned off virus and threat protections under Windows, but it did not help.

The only work-around that currently works for me is to run (as suggested here) "latexmk -lualatex --enable-write18 FILENAME".

I made the following additional observations after a fresh install of Windows with MiKTex, TexStudio and TexMaker:

  • TexMaker: Surprisingly, lualatex worked for me for some time (in the sense that the PATH was correct in \ShellEscape), but after several computer restarts it stopped.
  • TexStudio, TexWorks, Powershell: It did not work right from the beginning.

So, at the same time when PATH worked in lualatex\ShellEscape for TexMaker, it failed for the others. I couldn't find out any relevant differences in the compilation settings of TexMaker/TexStudio. After some time, it stopped working for TexMaker, too. So I find this whole issue very strange.

As maybe others might find it helpful: I run into this whole issue with the Moodle package. When one wants to embed pictures in the produced output files, Moodle.sty is using \ShellEscape to run various commands from the PATH. And it fails for the reasons discussed above.

krfl
  • 121
  • Thanks for the debugging and suggestions :-) I've given up and just switched to texlive where this issue isn't present (and as a bonus, texlive updates packages more frequently) – mbert Sep 15 '23 at 15:27
  • Thank you very much for the suggestion. Now, I also switched to TexLive! – krfl Oct 06 '23 at 16:09
  • This problem still persist, so I am switching from MiKTeX to TeXLive as suggested. – Mane32 Dec 04 '23 at 05:58