# pdflatex fails within Emacs.app, but works in terminal

LaTeX rookie here.

I'm running OS X 10.7 with Emacs 24, Auctex 11.86 and TexLive 2011 via MacTex.

When i run LaTeX through Emacs in the terminal it outputs my `test.tex` as `test.pdf` just fine.

However, when i run the same file through Auctex in Emacs.app it fails and i'm given:

``````LaTex: problems after [0] pages'
``````

``````Running `LaTeX' on `test2' with ``pdflatex -synctex=1  -interaction=nonstopmode "\input" test2.tex''
``````

I've been googling this and know this is a fairly common problem, but for the life of me I haven't been able to implement a fix. From what i've read it seems Emacs has a different `PATH` than terminal, no? Can someone please explain to me how to fix the `PATH` or `environment variable` (i'm not sure which) so that Emacs can find pdflatex. Is there something I need to change in my `~/.emacs` ?

thanks, any help is appreciated.

-
You run emacs in the terminal and it outputs a pdf? You mean you run latex in the terminal? – Seamus Jul 30 '11 at 22:14
yes latex, my mistake. – idclark Jul 30 '11 at 23:05
This isn't really a TeX question, but an emacs question. Here are some solutions: EmacsApp. I don't recommend using the `environment.plist` solutions, as they can interfere with other applications. The "quick and ugly" solution seems the best; you need to change the path accordingly (the path there assume Darwin Ports). For MacTeX you want to make sure that `/usr/texbin/` is early in the path. (You also might want to try Aquamacs.) – Alan Munn Jul 30 '11 at 23:20
finally got it! – idclark Jul 31 '11 at 2:32
If you have found a solution please report it here as an answer of your own question, so everyone can enjoy of it – Spike Jul 31 '11 at 7:06

ok, sorry for the delay- i wasn't allowed to post a self-answer earlier. Indeed Emacs.app was operating in a different environment than the terminal.

`M-x getenv` for `PATH` showed that `/usr/texbin` was missing, which explains why LaTex was not working inside the Emacs.app shell.

following @Alan Munn's idea to stay away from editing a .plist I found some good info here and hacked together this in `~/.emacs`

``````(getenv "PATH")
(setenv "PATH"
(concat
"/usr/texbin" ":"

(getenv "PATH")))
``````

`/usr/texbin` is now part of the`PATH` and LaTeX will play nice with Emacs.app

In El Captain, PATH changed. So you should use `which latex` in terminal to decide the real location. In my machine, it returns `/Library/TeX/texbin/latex`, so I should use `/Library/TeX/texbin/` instead of `/usr/textbin'.

thanks for the help everyone!

-

``````(setq exec-path (append exec-path '("YOUR/PATH/TO/LATEXB/BIN/")) )
``````
-
I tried this earlier and unfortunately it didn't work. It's frustrating because I thought this would do the same thing as my fix in the answer post. – idclark Jul 31 '11 at 13:07

There is an emacs package for dealing with this problem on OSX called `exec-path-from-shell`. You can install it via the `list-packages` interface. You need to activate it with

``````(exec-path-from-shell-initialize)
``````

in your emacs init file. See http://emacs.stackexchange.com/q/10722/2710.

-

If you have the root right, you can add the path to the end of `/etc/profile` like this:

``````export PATH=\$PATH:/work/tools/arc/arcanist/bin:/work/tools/jdk1.6.0_25/bin
``````

I have the same problem in my Linux/Ubuntu 12.04, and it works!

-