[texworks] Suggestion: set the PATH before running tools
Stefan Löffler
st.loeffler at gmail.com
Sun Dec 4 16:51:47 CET 2022
Dear Duncan,
On 30.11.22 21:05, Duncan Murdoch wrote:
> TeXworks 0.6.7 on MacOS has an editable list of paths in Preferences |
> Typesetting. Presumably these are used by it when looking for any of
> the tools listed in the Processing Tools settings.
Yes. The list is initially populated (when TeXworks is first run) by a
pre-generated list of "typical default path guesses". TeXworks then uses
that list, plus the directories in PATH (as seen by TeXworks) as
fallbacks, to look for programs to run.
> However, those tools will see the standard PATH environment variable
> that TeXworks saw when it started.
Not quite. On macOS, the directory the currently executed program was
found in is appended to the PATH prior to starting the tool. This is
precisely so that additional tools available alongside the program
(hopefully) work. The key word is "alongside", if they are in a
completely different directory this approach will not help, of course.
Unfortunately, the handling of PATH is complex (particularly on macOS).
I seem to remember (though maybe incorrectly) that the initial PATH
depends on how you started TeXworks (from the GUI, with `open
TeXworks.app` from the terminal, or with
`TeXworks.app/Contents/MacOS/TeXworks` from the terminal). In some
cases, the full PATH available in a terminal might be seen, while in
other cases only a small "default set" (/usr/bin + /usr/local/bin) is
available.
> This means for example that scripts using pdflatex might not be able
> to find it, even though TeXworks itself knows where it is.
If you mean that you have, e.g., a (non-shell) script which simply
invokes pdflatex and is run from /some/custom/folder, it will not find
pdflatex if that is installed, e.g., in /opt/texlive. Invoking it with
the full path should obviously work, though.
If you have a shell script, my understanding is that first a shell would
need to be started, which would (hopefully?) set up PATH correctly
according to the config files.
> Since editing the PATH seen by apps on MacOS is a pretty obscure
> exercise, my suggestion is that TeXWorks should append the entries
> from Preferences | Typesetting to the PATH before running the other
> tools.
> (It could be fancy and only append the entries that aren't already
> there, but that's not really necessary.)
As outlined above, TeXworks does append the directory the program is
found in to PATH. This is done to act as a sort of fallback, but give
precedence to all the other directories that may be in PATH. Adding all
entries in the list would be possible, but could get rather messy (in
case there are many entries), and could result in all sorts of other
confusion (e.g., if you have two versions of TexLive installed, say 2020
and 2021, but with different installed tools, you might end up invoking
mismatching tools from different versions). Personally, I would like to
keep programmatic PATH modifications to a minimum, in case some users
more knowledgeable with macOS than me find good ways of actually
exposing the PATH they want in the first place.
HTH
Stefan
More information about the texworks
mailing list.