texworks icon indicating copy to clipboard operation
texworks copied to clipboard

Shell escape on OS X

Open jlaurens opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. This may concern more than OS X. When I typeset this document in TeXworks,

\documentclass{article}
\RequirePackage{shellesc}
\begin{document}
\ShellEscape{printenv PATH}
\end{document}

the console output reads

/usr/bin:/bin:/usr/sbin:/sbin

such that the only external tools allowed are very limited. In particular, using the minted package is not possible because it relies on /usr/local.

Describe the solution you'd like Extend the PATH to contain all the search path declared in the preferences for tex programs and friends.

Describe alternatives you've considered Do not use TeXworks and launch the typesetting process from the command line.

jlaurens avatar Oct 21 '21 09:10 jlaurens

This is a known restriction of macOS: you need to symlink to (e.g.) /usr/TeXbin (Which is usually on the path used by TeXworks)

josephwright avatar Oct 21 '21 09:10 josephwright

The problem is not the path used by texworks, the problem is the PATH environment variable used when TeX launches an external command. When TeXworks launches TeX, it uses its own environment variables inherited from the process that launched it. If TeXworks is launched from the desktop (which "always" happens) then the inherited PATH is restricted to /usr/bin:/bin:/usr/sbin:/sbin. If TeXworks is launched from a terminal, then it inherits the PATH of the terminal which is far richer.

So the workaround is to launch TeXworks from the terminal

/Applications/TeXworks.app/Contents/MacOS/TeXworks

depending on where TeXworks is installed. Not very handy on multiple respects...

Of course, we could specify the full path of the external shell tool in use, but that would mean for example digging into minted source code and it goes against portability.

jlaurens avatar Oct 21 '21 09:10 jlaurens

FYI, TeXShop uses the same PATH as a terminal such that minted is usable.

jlaurens avatar Oct 21 '21 09:10 jlaurens

@jlaurens On macOS, one can't get at the command line PATH. What TeXShop does is have a dialog to add to the path that it passes to child processes (Preference -> Engine). That starts with some guesses about common locations, but it does not get all of them. For example, on my system the PATH is

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin

but

\documentclass{article}
\begin{document}
\immediate\write18{echo $PATH > test.txt}
\end{document}

run from TeXShop yields

/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/bin

josephwright avatar Oct 21 '21 10:10 josephwright

You are definitely right. TeXworks is definitely missing /usr/local/bin and maybe some other standard location related to the lua world.

The TeXShop dialog you mention already exists in TeXworks somehow. One "just" has to figure out how to pass some locations to the PATH...

jlaurens avatar Oct 21 '21 13:10 jlaurens