Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeXworks doesn't set correctly the PATH on macOS #861

Closed
eg9 opened this issue May 6, 2019 · 4 comments
Closed

TeXworks doesn't set correctly the PATH on macOS #861

eg9 opened this issue May 6, 2019 · 4 comments

Comments

@eg9
Copy link

@eg9 eg9 commented May 6, 2019

Steps to reproduce the problem:

Run a file \input|"kpsewhich plain.tex"\bye with pdftex from the menu

Expected output:

/usr/local/texlive/2019/texmf-dist/tex/plain/base/plain.tex

Actual output:

Nothing. The console shows

sh: kpsewhich: command not found

TeXworks version: 0.6.3
TeXworks obtained from: GitHub
Operating system: macOS Mojave 10.14

Please provide any additional information below:

If I define a “pdftex+shell-escape" engine and run a file containing

\input|"echo $PATH"
\bye

I get in the PDF file /usr/bin:/bin:/usr/sbin:/sbin.

If I launch TeXworks from a terminal with

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

the PATH variable is set correctly.

@stloeffler
Copy link
Member

@stloeffler stloeffler commented Jul 13, 2019

@eg9
Copy link
Author

@eg9 eg9 commented Mar 16, 2020

I saw the new version 0.6.4. The malfunctioning has not been fixed.

I repeat: version 0.6.2 executes shell commands without any problem on macOS 10.15 Catalina. So it is not a macOS feature.

@stloeffler
Copy link
Member

@stloeffler stloeffler commented Mar 17, 2020

As far as I can tell, there was no change to the source code in TeXworks. 0.6.2 uses QProcess:systemEnvironment in pretty much the same way as 0.6.3 does. Things were moved around a bit, but other than that nothing major changed.

It does generally seem to be a Mac OS "feature" (i.e. intended behavior) that GUI apps are treated differently than terminal apps (both Google and StackExchange have many hits for this topic, and there is even a dedicated script intended to try mitigate this), and things seem to change from version of version of Mac OS X. From what I can tell (without having a Mac to test on), GUI apps are launched by some launchctl which has its own way of keeping track of/setting environment variables, but generally does not take .bash_profile and similar things into account.

About TeXworks 0.6.2. After a lot of digging, I seem to have found a difference in how Qt, the underlying framework used by TeXworks, handles environment variables. Tw 0.6.2 uses a version of Qt somewhere around 5.8.0, whereas Tw 0.6.3 uses Qt somewhere around 5.12.1 (could you verify that from Help > About TeXworks please?). Qt 5.8.0 uses the _NSGetEnviron command, whereas Qt 5.12.1 uses NSProcessInfo. Why they changed that, what that entails, and whether or not that indeed causes the differences you see I don't know - the only way of finding out would be to compile Tw 0.6.3 (or 0.6.4) with Qt 5.8.0 or similar and try it out.

@stloeffler
Copy link
Member

@stloeffler stloeffler commented Mar 30, 2020

As documented, e.g., in QTBUG-42656, an application launched from the GUI has different environmental variable settings than if launched from a terminal. Presumably, the reason is that the application inherits the environment of the calling process. If this is the terminal (e.g., bash), it will have parsed all sorts of config files (e.g., (.bash_profile) that will have modified the environment variables.

BTW, the same happens on Linux.

You can try redefining the typesetting tool to not run pdftex directly but rather a shell and pdftex in that shell. Maybe that would force the config files to be parsed...

Also note that Tw does not (directly) use $PATH. Instead, it keeps its own list of directories in which to look for TeX-related programs. By default, the directories in $PATH are added to the list, but you can also add your own (and they will have a higher priority than the auto-added ones). Thus, you could in principle have several side-by-side installations of TeX and quickly change between them by simply reordering the list. Because it keeps its own list, Tw does not rely on $PATH when executing programs but instead calls them with their full path.

For all these reasons, I currently see no way to easily implement what you want. TeXworks can only rely on the environment it gets during invocation - any custom parsing of config files is bound to break sooner or later; and forcefully messing with environment variables would probably break stuff, too.

@stloeffler stloeffler closed this Mar 30, 2020
stloeffler added a commit that referenced this issue May 27, 2020
…, fixes #897)

This way, programs in the same directory as the typesetting tool can be
found, even though .bash_profile etc. are not parsed when running
TeXworks from the Finder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants