# Configuring Auctex for emacs

I need help with configuring auctex in emacs. I have downloaded and installed auctex but I cannot get anything to work. I am running MAC OS X 10.8.4 and am running emacs through the terminal. If I use Aquamacs emacs (a GUI emacs for MAC) then I can at least get the View command to work (it opens up the default PDF viewer, which is called Preview).

However, I wish to use emacs through the terminal. I've added the following to my .emacs file:

(load "auctex.el" nil t t) ;; loads tex-site in such a way so that it can be undone
(load "preview-latex.el" nil t t) ;; actual preview-latex
(setq TeX-view-program-list '(("Shell Default" "open %o")))
(setq TeX-view-program-selection '((output-pdf "Shell Default")))
(setq TeX-PDF-mode t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq reftex-plug-into-AUCTeX t)


Is it even possible to run Latex through the terminal in emacs? I am relatively new to all of this (however I did manage to install everything else I needed such as multiple interpreters and even a web browser!). What I have tried so far is to open up a TeX document (which loads fine and switches to a mode called "LaTeX/MP Ref Wrap" (is that right for Auctex?). I type:C-c C-c

emacs gives me the prompt:Command: (default LaTeX)

My options are:

Possible completions are:
BibTeX       Check        Clean        Clean All    File         Index
LaTeX        Other        Print        Queue        Spell        View


If I choose to use LaTeX then I get this from emacs:

LaTeX errors in *~/path/to/file output*'. Use C-c  to display.

So I type C-c  to display the errors and this is what I get from emacs:

--- TeX said ---

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name:
! Emergency stop.

l.28 \def
\NN{\tabularnewline}^^M
--- HELP ---
From the .log file...

*** (cannot \read from terminal in nonstop modes)

1. How would I fix this?

Also, instead of typing LaTeX I tried View. Emacs prompted and auto-completed : View command: dvi2tty -q -w 132 file_name

I hit enter to execute that command and emacs replies:

View: done.

Now there is a new buffer with content:

unning View' on combinatorics_bin_trees' with dvi2tty -q -w 132 combinatorics_bin_trees''

View exited abnormally with code 127 at Fri Jun 14 16:55:35


Note as stated above with Aquamacs Emacs (Emacs for MAC OS X) the View command will open the default PDF viewer, which is called Preview. So I must be missing some kind of package? (this is disappointing considering that I use package managers which do work out dependencies to download all my programs...)

How can I fix this problem? All help is GREATLY appreciated! I am also welcoming any suggestions in tuning auctex settings for emacs and any general links that are helpful (I did not find the emacswiki about auctex to be useful at all!)

-

## migrated from stackoverflow.comJun 15 '13 at 13:51

This question came from our site for professional and enthusiast programmers.

If Emacs is not finding *.sty, then you need to set the path. This is for MacTeX.pkg installation. If you use the Macports or Homebrew, then the path would be different, but similar. Fix that problem and then report back and we'll help you get further along if there are still errors.

(setenv "PATH" (concat (getenv "PATH") ":/usr/texbin"))
(setq exec-path (append exec-path '("/usr/texbin")))

-
What should I enter for the path? I do use Macports, and the directory used is /opt/local so in the terminal I entered find / -type f -name etoobox.sty' and it found nothing... –  CodeKingPlusPlus Jun 17 '13 at 11:40
You'll need to look in /opt/local and find the . . ./bin -- it may be a level or two deeper than that. Your full path to the . . ./bin gets inserted into the code in this answer, which is placed in your .emacs or init.el file. If you haven't already installed the tex stuff through macports, you will need to do that. –  lawlist Jun 17 '13 at 14:14

The AUCTeX should be loaded when you open a tex file. Its major mode is LaTeX. I noticed in your compile message: etoolbox.sty' is missing. So make sure the package is present and available. You may try to compile the tex file through system terminal to see if there is something wrong with AUCTeX.

Also you have to import "SHELL" paths into variable "exec-path". To do this, I put the following function in init.el.

(defun set-exec-path-from-shell-PATH ()
"Set exec-path' from PATH' environment variable"
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]\n]*$" "" (shell-command-to-string "$SHELL -l -c 'echo $PATH'")))) (setenv "PATH" path-from-shell) (setq exec-path (split-string path-from-shell path-separator)))) (when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))  - How would I run this through the terminal? – CodeKingPlusPlus Jun 17 '13 at 11:24 How would I compile the tex file through the terminal? Also, I have imported the SHELL paths into variable exec-path but nothing has changed. Why do we want the SHELL paths into exec-path anyway? – CodeKingPlusPlus Jun 17 '13 at 11:43 Yue Zhu is likely assuming that if you type echo$PATH from the terminal, then it will include the path to your macports installation, which occurs through the normal installation of macports (or homebrew or mactex) -- it modifies the bash_profile or the profile in the user home directory. I have chosen to remove that and have a little more control when the macports stuff is available to other programs. –  lawlist Jun 17 '13 at 14:19
It is usually only one question per customer. In your case, just getting past the initial installation issue is your most important question. Once you resolve that, you should open a new thread / question on any other issue. I use latexmk.pl in conjunction with AUCTex -- considering that latexmk.pl works through the terinal without AUCTex, I don't see any reason why you could not do that through the terminal in conjunction with Emacs. –  lawlist Jun 17 '13 at 14:29