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

Path environment not set correctly when running from within a Mac OSX .app bundle. #23

Closed
jamiek opened this issue May 5, 2020 · 5 comments

Comments

@jamiek
Copy link

jamiek commented May 5, 2020

First off I'll note that this may not necessarily be an issue with WriteTeX, but it can be addressed in your code base. I was not able to find a similar report related to inkscape in their issue tracker.

Behavior: WriteTeX is not able to find latex interpreter or .svg converter when run from inkscape launched from an .app bundle on OS X. Apparently this is because .app bundles do not respect the environment variables set in various locations (.profile, /etc/profiles, and so forth).

Expected behavior: WriteTeX should rely on the user set PATH environment variable to search for latex interpreter and svg converter.

Other info: The issue only occurs when launching inkscape from an .app bundle. Calling the inscape executable inside the bundle via terminal correctly passes the PATH environment variable.

Here are the PATHS returned by calling 'echo $PATH' from within writetex.py:
inkscape from terminal: /Applications/Inkscape.app/Contents/MacOS:/Applications/Inkscape.app/Contents/MacOS/../Resources/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
inkscape launched as .app:
/Applications/Inkscape.app/Contents/MacOS:/Applications/Inkscape.app/Contents/MacOS/../Resources/bin:/usr/bin:/bin:/usr/sbin:/sbin

entering the full path to the latex interpreter in the modal window can fix the latex interpreter issue, but there is no way to provide the full path to the svg converter.

There area bunch of ways I've been able to club this into submission such as: symlinks located in the .app bundle to point to the latex interpreter and svg converters, getting and altering the path within writetex.py using os.environ and using the env= flag in subprocess.call(), etc. None of these are particularly convenient from a user standpoint.

As mentioned up front, it is possible that there is a clean way to fix this within inkscape, but I expect that the developers here are much more familiar with the extension codebase than I am.

Inkscape 1.0 binary from inkscape.org
OS X 15.4
writeTex 1.0.x

@wanglongqi
Copy link
Owner

@jamiek Thanks for the information provided. You are absolutely right. Previously, I simply symbol link all the required programs to Applications/Inkscape.app/Contents/Resources/bin.

App launching from .app bundle does not use the same shell as Terminal. In the case where default shell for user is bash, the variable may be set in .bash_profile and several other places. I do not know whether there is a proper way to set the shell used to launch .app bundle, or to load user's PATH settings of the default shell used in Terminal. Any idea?

@jamiek
Copy link
Author

jamiek commented May 11, 2020

@wanglongqi I've done some digging and have some more info.

So when launched from the Finder by double clicking an .app bundle the path is set by launchd which has the default PATH of /usr/bin:/bin:/usr/sbin:/sbin apprently prepended by predefined locations inside the bundle (e.g. /Applications/Inkscape.app/Contents/MacOS:/Applications/Inkscape.app/Contents/MacOS/../Resources/bin)

launchctl can be used to modify the default PATH, but note that this updates the PATH for ALL apps launched via the finder.
sudo launchctl config user path /usr/bin:/bin:/usr/sbin:/usr/local/bin:/Library/TeX/texbin
followed by a reboot has added the locations of pdflatex and pdf2svg to the PATH seen by processes spawned by inkscape. The extension runs fine after doing this and is indeed seeing the updated PATH /Applications/Inkscape.app/Contents/MacOS:/Applications/Inkscape.app/Contents/MacOS/../Resources/bin:/usr/bin:/bin:/usr/sbin:/usr/local/bin:/Library/TeX/texbin

I will caution that the launchctl command above will overwrite any previously set custom PATH for launchd. This can be addressed by using launchctl getenv PATH to get the existing path and then append the locations for pdflatex etc.

This seems like a reasonable solution but my only hesitation is that it affects all apps launched via the finder. That said, these apps tend to look inside the .app bundle first so this should't risk breaking things.

An alternative might be to try to use python to set the appropriate PATH using os.environ and try to read the path from the "usual" locations, or read from a writeTex configuration file.

One other possibility is to modify the info.plist file in the .app bundle to include the updated PATH. i've tested this and it works, but requires a restart.

@wanglongqi
Copy link
Owner

Maybe another way is to add a text field for user to set additional search paths. Inkscape will remember the field value used for last run, so user also only need to set that field once.

@jamiek
Copy link
Author

jamiek commented May 12, 2020

User configurable text fields sounds like a clean way to handle it. Especially if you could put the config settings on a separate tab. It would keep the UI looking clean.

@wanglongqi
Copy link
Owner

I tried to add a settings tab in this commit 85458b1, when have time please help do some tests.

screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants