I like to have the auxiliary files in a separate directory, using the following customisation for emacs/AUCTeX:

  Hello world!

%%% Local Variables: 
%%% mode: latex
%%% LaTeX-command: "pdflatex -synctex=-1 -aux-directory auto %s"
%%% End: 

This worked fine with emacs 24.3.1 and AUCTeX 11.86. But on a new machine I use emacs 25.3.1 and AUCTeX 12.1, and invoking LaTeX with C-c C-C gives the following result (the file is test.tex):

Running `LaTeX' on `test' with 
``pdfpdflatex -synctex=-1 -aux-directory auto "test"  -file-line-error  --synctex=1 -interaction=nonstopmode "\input" "test.tex"''

Evidently, my custom LaTeX-command is inserted in another LaTeX command, replacing the "latex" in pdflatex, and of course that gives an error. I could not find out where the other (default?) LaTeX command was defined.

I can work around this by changing the customisation to %%% LaTeX-command: "latex -aux-directory auto", but that seems like a weird hack, and it doesn't work on the other machine I'm using. Is there a smarter way of doing that?


I don't think it is much in the AUCTeX spirit to tune LaTeX-command in order to specify that you want to use pdflatex. AUCTeX knows about TeX engines and how to activate DVI or PDF mode depending on the engine. See the documentation of processor options, in particular about TeX-engine, TeX-engine-alist and TeX-PDF-mode:

Command: TeX-PDF-mode

(C-c C-t C-p) This command toggles the PDF mode of AUCTeX, a buffer-local minor mode which is enabled by default. You can customize TeX-PDF-mode to give it a different default or set it as a file local variable on a per-document basis. This option usually results in calling either PDFTeX or ordinary TeX.


User Option: TeX-engine

This variable allows you to choose which TeX engine should be used for typesetting the document, i.e. the executables which will be used when you invoke the ‘TeX’ or ‘LaTeX’ commands. The value should be one of the symbols defined in TeX-engine-alist-builtin or TeX-engine-alist. The symbols ‘default’, ‘xetex’, ‘luatex’ and ‘omega’ are available from the built-in list.


User Option: TeX-engine-alist

Alist of TeX engines and associated commands. Each entry is a list with a maximum of five elements. The first element is a symbol used to identify the engine. The second is a string describing the engine. The third is the command to be used for plain TeX. The fourth is the command to be used for LaTeX. The fifth is the command to be used for the ‘--engine’ parameter of ConTeXt’s ‘texexec’ program. Each command can either be a variable or a string. An empty string or nil means there is no command available.

If you just want to change the engine or PDF vs. DVI mode for the current document, the easiest way is probably to use the Command → TeXing options menu, otherwise for your particular options mentioned here (-synctex=-1 -aux-directory auto), I believe the following variable is the appropriate one:

User Option: TeX-command-extra-options

String with the extra options to be given to the TeX processor. For example, if you need to enable the shell escape feature to compile a document, add the following line to the list of local variables of the source file:

%%% TeX-command-extra-options: "-shell-escape"

By default this option is not safe as a file-local variable because a specially crafted document compiled with shell escape enabled can be used for malicious purposes.

In your particular case, if you really want to customize the parameters you gave using Emacs file variables, you could use this:

%%% Local Variables:
%%% TeX-PDF-mode: t
%%% TeX-engine: default
%%% TeX-command-extra-options: "-synctex=-1 -aux-directory=auto"
%%% End:

If for instance you would like to use the LuaTeX engine instead of the default (which is normally pdfTeX for LaTeX documents), just replace default with luatex. In such a case, if AUCTeX detects that you have a LaTeX document, it will compile it with the lualatex command, thanks to TeX-engine-alist-builtin, which gives the defaults for things you haven't overridden via TeX-engine-alist:

TeX-engine-alist-builtin is a variable defined in ‘tex.el’.
Its value is
((default "Default" TeX-command LaTeX-command ConTeXt-engine)
 (xetex "XeTeX" "xetex" "xelatex" "xetex")
 (luatex "LuaTeX" "luatex" "lualatex --jobname=%s" "luatex")
 (omega "Omega" TeX-Omega-command LaTeX-Omega-command ConTeXt-Omega-engine))

Alist of built-in TeX engines and associated commands.
For a description of the format see ‘TeX-engine-alist’.

But for the selection of DVI vs. PDF mode, I believe I would rather use the Command → TeXing options menu or set the mode globally with something like this in your Emacs configuration:

;; Use nil for DVI mode
(setq-default TeX-PDF-mode t)

The following would also work but is less efficient if you have many TeX files opened when you start Emacs, because the hook is run every time for each TeX/LaTeX/etc. file:

(add-hook 'TeX-mode-hook
            #'(lambda ()
                (TeX-global-PDF-mode t)))

If you use desktop.el in Emacs, beware that it saves and restores buffer-local values of variables. This can be very confusing when testing Emacs' init config dealing with variables that are automatically buffer-local when set (TeX-PDF-mode is one of these, so this applies here).


In order to have AUCTeX use a directory that is different from your auto dir and clearly belongs to AUCTeX, you might want to customize TeX-auto-local and TeX-style-local. I use something like this:

(defun my-TeX-mode-hook ()
  (setq TeX-auto-local "auctex-auto"
        TeX-style-local "auctex-style")
  ;; Use the new dirs in `TeX-style-path' instead of the default ones,
  ;; otherwise AUCTeX won't find them.
  (mapc #'(lambda (arg)
            (when (member (car arg) TeX-style-path)
              (delete (car arg) TeX-style-path)
              (push (cdr arg) TeX-style-path)))
        '(("auto" . "auctex-auto")
          ("style" . "auctex-style"))))

(add-hook 'TeX-mode-hook 'my-TeX-mode-hook)

Since it's a bit complicated, though, you may rather choose to rename your auto to something else, or accept the possibility that there might be conflicts one day, between what AUCTeX writes there and what your use of -aux-directory could cause to be written there (if -aux-directory is only about the .aux file, it's probably safe).

  • Thanks! I had to set TeX-PDF-mode: nil to avoid pdfpdflatex, but then TeX-command-extra-options did the trick. – Toffomat May 4 '18 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.