[OS X TeX] Staying on the right PATH (or something)

Morten Høgholm morten.hoegholm at gmail.com
Thu Nov 15 03:29:24 EST 2007


On Wed, 14 Nov 2007 17:19:47 +0100, Charilaos Skiadas wrote:

Hi Charilaos and others,

Thanks for all the answers - it seems like you all agree so I'll do what  
I'd do on Who Wants to be a Millionaire and follow the group. :-)

> I'm sure other people will give much more enlightening answers, but the  
> gist of it is that GUI applications don't get to call the shell  
> initialization scripts that get run when a terminal opens. So anything  
> that is defined in files like .bash_profile, .tchrc doesn't get read  
> when in a GUI.

OK this makes sense. This is also what Peter wrote.

> For instance if you open TeXShop/Texmaker or whatnot from the terminal  
> using "open", then it will inherit the environment from the terminal and  
> hence will have the things defined.

Aha. Yes, that does indeed work.

> But if you open the app from finder by double-clicking, then the process  
> calling it is not the terminal, hence it will not have these variables  
> there.

OK, I got it now.

I think it is best (and easiest) if one does not have to know the full  
path to the executable. Granted, it is much better on OS X now with  
/usr/texbin but it still requires specifying the path rather than just the  
name of the executable. When doing support for this large group of people,  
we would like to ease our own task and just make it work with the  
executables.

Now knowing roughly what to look for, I dug into the Aquamacs Emacs  
sources and found that it during startup runs the function  
mac-read-environment-vars-from-shell

(defun mac-read-environment-vars-from-shell ()
"Import the environment from the system's default login shell
specified in `shell-file-name'."
     (with-temp-buffer
       ;; execute 'printenv' with the default login shell,
       ;; running the shell with -l (to load the environment)
       (setq default-directory "~/")	; ensure it can be executed
       ;; To Do: use call-process instead -> this here
       ;; will invoke two bashes

       (let ((shell-login-switch
	     (or shell-login-switch
		 (if (string-match ".*/\\(ba\\|z\\)sh" shell-file-name)
		     "-l"
		   (if (string-match ".*/\\tcsh" shell-file-name)
		     ""
		   (if (string-match ".*/ksh" shell-file-name)
		       "" ;; works for ksh
		     (message "Could not retrieve login shell environment with login  
shell: %s" shell-file-name)
		   ;; won't work for csh, because it doesn't take -l -c ...
		   ))))))
		
	(call-process shell-file-name nil
	       t nil
	        shell-login-switch
		shell-command-switch
		"printenv"))
       (goto-char (point-min))
       (while (re-search-forward "^[A-Za-z_0-9]+=()\s*[^\x]*?
\s*}\s*$" nil t)
	(replace-match "..." nil nil))
       (goto-char (point-min))
       (while (search-forward-regexp "^\\([A-Za-z_0-9]+\\)=\\(.*\\)$" nil t)
	(setenv
	 (match-string 1)
	 (if (equal (match-string 1) "PATH")
	     (concat (match-string 2) ":" (getenv "PATH"))
	     (match-string 2))))))


I'll see if we can use this somehow.

Thanks,
-- 
Morten



More information about the MacOSX-TeX mailing list