[OS X Emacs] latex + dvips + ps2pdf from Aquamacs

Braun, Michael braunm at mail.smu.edu
Mon Jan 4 12:12:31 EST 2021

I know we are getting a little off-topic here, but I found this response quite helpful in resolving some misunderstandings I had. So I would like to ask some clarifying questions, mostly related to login vs non-login shells, and interactive vs non-interactive shells.

If I understand correctly, the “best practice” would be to put PATH variables in ~/.zshenv, and then let path_helper do its thing.  Then, any changes in the order of the paths for login shells can go in ~/.zprofile. In that case, the PATH would be available pretty much everywhere, since anything spawned from the MacOS desktop (Aquamacs, Terminal, etc) would always be treated as a login shell (since I need to log in to get to the desktop). Non-login shells would get the PATH from ~/.zshenv, but not the changes from ~/.zprofile. Do I have that right?

What else should go in ~/.zshenv ? I would think that environment variables that will rarely change would go there.  For example, I am a heavy R user, so should  ~/.zshenv should include R_HOME, R_PROFILE, etc.?

I am still a little confused about interactive vs non-interactive shells. When I launch an interactive R session from Terminal, or run a batch R script from the command line, I can see zshrc is loaded.  Also, if I launch an Aquamacs session from the command line (launching the GUI), zshrc is loaded.  But clicking on the Aquamacs icon in the Dock, zshrc it is not.  Is this because everything spawned from Terminal is interactive, but anything launched from the desktop directly is not?


On Jan 2, 2021, at 3:10 PM, Ettore Aldrovandi <ealdrov at math.fsu.edu<mailto:ealdrov at math.fsu.edu>> wrote:

Yeah, that’s order _overall_ (mostly) but whether any of those files gets read depends on the kind of shell instance is running. Non login shells will _not_ read /etc/.zprofile and ~/.zprofile. Non interactive shells will _not_ read ~/.zshrc.  Most of the time, .zprofile will not be read, because, for example, single Terminal.app instances do not run login shells (they’re all children of the app) unless you explicitly configure them to be so.

Also, as per man page, /etc/zshenv is _always_ read first (can’t override this).

The PATH problems most people encounter are caused by how /etc/zprofile  is set. Note, even if the shell instance is not a login one, it will have inherited its environment from a login one. So, if say PATH is set in ~/.zshenv, as it should be, the shell reads it, and _then_ reads /etc/zprofile. The way MacOS is set up, /etc/zprofile calls /usr/libexec/path_helper which re-synthesizes the path based on: (1) /etc/paths, and (2) the content of /etc/paths.d resulting in a path that will _always_ have system directories in front of whatever was defined in .zshenv.

If nothing depends on the order in the PATH, then fine. But if you for whatever reason need something in a specific order, say because you have different versions of the same utility installed in different locations, then you need to cater for that situation specifically.

So, your solution is one of the good ones which works because .zprofile is read after /etc/zprofile has done its thing with path_helper. The only caveat is what might happen if you spawn a non-interactive non-login shell.

Here’s what I do:  my TeXLive, HomeBrew paths are set by putting one-liners in /etc/paths.d, in the same way XQuartz is set.  I don’t care for the specific order. My $HOME/bin and $HOME/.cabal/bin are added to PATH in ~/.zshenv for the reason I mentioned above. But since I also care that $HOME/.cabal/bin should be first in the path, I have that set in .zprofile. In fact it’s the only thing it does.

Oh, and /etc/zshrc_Apple_Terminal  is called by /etc/zshrc.


On Jan 2, 2021, at 15:26, Braun, Michael <braunm at mail.smu.edu<mailto:braunm at mail.smu.edu>> wrote:

I had a similar issue during the summer, where environment variables I was setting in .zshenv were not being picked up. It turns out the order of loading goes like this:


(There is also a /etc/zshrc/Apple_Terminal file, but I don’t know when that runs).

So you need to be sure that, for example, something in /etc/zshrc is not overriding something in ~/.zprofile.  This is exactly what was happing when I set my Terminal prompt format in ~/.zshenv or ~/.zprofile.  For some reason, MacOS defines a default prompt format in /etc/zshrc, which was overwriting my profile. Maybe something similar is happening to you.

So here’s what works for me.  I set all of my system environment variables (like PATH) in ~/.zprofile.  Anything related to my Terminal login shell (like prompt colors, formats, themes, etc) goes in ~/zshrc.  And it works!  I can see all of my ~/.zprofile environment variables within Aquamacs.

This appears to be the *complete opposite* of some advice I’ve seen online.  All I can say is that everything works with PATH in ~/.zprofile and terminal-related variables in ~/.zshrc.

On Jan 2, 2021, at 8:33 AM, Ettore Aldrovandi <ealdrov at math.fsu.edu<mailto:ealdrov at math.fsu.edu>> wrote:

Dear Win, Roussanka,

Happy New Year!

One more information morsel. An unrelated issue made me realize that Aquamacs, and also other variants like YAMAMOTO Mitsuharu’s Emacs port, which I also use,  read .zprofile when launched with a double-click.

To recap, in the Z shell .zprofile is read by login shells. If they are not interactive, as it appears the ones run under the window server are, they will not read .zshrc, so anything set there, in particular PATH, will not be read. So, it’s good news, at least to me, that .zprofile is read: I had an issue that I wanted  my $HOME/.cabal/bin in front of the path (in emacs too), and exporting from .zprofile did it. (I have to still do the same export from .zshrc for the Terminal: its shells are non-login and interactive, so .zprofile is not read.)

All the best and a happy and safe 2021 to everyone,


Michael Braun
Associate Professor of Marketing, and
  Corrigan Research Professor
Cox School of Business
Southern Methodist University
Dallas, TX 75275
braunm at smu.edu<mailto:braunm at smu.edu>

MacOSX-Emacs mailing list
MacOSX-Emacs at email.esm.psu.edu<mailto:MacOSX-Emacs at email.esm.psu.edu>
List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx

MacOSX-Emacs mailing list
MacOSX-Emacs at email.esm.psu.edu<mailto:MacOSX-Emacs at email.esm.psu.edu>
List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://email.esm.psu.edu/pipermail/macosx-emacs/attachments/20210104/2de891ae/attachment.htm>

More information about the MacOSX-Emacs mailing list