If you want to use AUCTeX so desperately:
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("Latex_outdir" "%`pdflatex --output-directory=/tmp %(mode)%' %t"
TeX-run-TeX nil (latex-mode doctex-mode)
:help "Run pdflatex with output in /tmp")
TeX-command-list)))
The question you linked to in your last comment is still unanswered, and will cause a serious problem with this setup: AUCTeX won't be able to locate your auxiliary files, and thus deduce the next step in the compilation step.
I suggest you use latexmk
for the whole process instead:
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("Make" "latexmk -outdir=/tmp %t" TeX-run-TeX nil t
:help "Make pdf output using latexmk.")
TeX-command-list)))
Latexmk is aware of the option outdir
, and will automatically search for the auxiliary files in this directory.
Either way, note the following point (from man latexmk
):
Commonly, the directory specified for output files is a subdirectory of the current working directory. However, if you specify some other directory, e.g., "/tmp/foo" or "../output", be aware that this could cause problems, e.g., with makeindex or bibtex. This is because modern versions of these programs, by default, will refuse to work when they find that they are asked to write to a file in a directory that appears not to be the current working directory or one of its subdirectories. This is part of security measures by the whole TeX system that try to prevent malicious or errant TeX documents from incorrectly messing with a user's files. If for $out_dir or $aux_dir you really do need to specify an absolute pathname (e.g., "/tmp/foo") or a path (e.g., "../output") that includes a higher-level directory, then you need to disable the security measures (and assume any risks). This can be done by temporarily setting the operating system's environment variable openout_any to "a" (as in "all"), to override the default "paranoid" setting.
Another potential problem with this setting is that all your documents will share the same temporary directory, so you will need to make sure they all have different names.
For your cp
step, you can use this line in your .latexmkrc
:
$pdflatex .= ' && cp -v %Z/%D %D';
Note that most of this is untested, please let me know if it doesn't work.
Starting from version 11.88 of AUCTeX, you can add an option to the TeX processor with the file-local variable TeX-command-extra-options
:
%%% TeX-command-extra-options: "-shell-escape"
As explained in the manual, you have to manually make this variable safe as a local variable because of the security holes it can open.
Note: this question inspired me to add this feature.
Until version 11.87, AUCTeX hadn't a facility to add easily an option to the compiler (at least I always missed to find it). I see at least three strategies you can follow:
- edit
LaTeX-command-style
(the suggested way if you want to activate shell escape for all documents)
- add a new element to
TeX-engine-alist
- add a new element to
TeX-command-list
I'll try to outline 1 and 2. 3 is similar to 2 in spirit.
Note: in a previous version of the answer I suggested to edit LaTeX-command
, but that variable should be reserved to the actual latex
binary name. Setting it to latex -shell-escape
doesn't play well with forward/inverse search (for the curious person: TeX-source-correlate-determine-method
would fail because there is no latex -shell-escape
binary and so forward/inverse search would fall back on source specials, even if SyncTeX is actually available).
LaTeX-command-style
This variable allows to change the options passed to the compiler, its syntax is a bit cumbersome, though. In addition, this isn't a file local variable so you can't set (by default) it on a per-document basis.
The customize way
Issue M-x customize-variable
RET LaTeX-command-style
RET. In the String
field of the variable add -shell-escape
after %(latex)
. E.g., if the value of the field is
%(PDF)%(latex) %S%(PDFout)"
change it into
%(PDF)%(latex) -shell-escape %S%(PDFout)"
The do-it-for-me way
Add the following code to your .emacs
.
(setq LaTeX-command-style '(("" "%(PDF)%(latex) -shell-escape %S%(PDFout)")))
TeX-engine-alist
Insert a new element, called for example default-shell-escape
, similar to the default
element of TeX-engine-alist-builtin
. You can do it by using the customization interface or adding an Elisp code to your .emacs
.
After creating this new engine, you'll be able to activate it by using the menu Command > TeXing Options > Use Default with shell escape
. If you want to set it by default for all documents or on a per-document basis see below.
The customize way
Issue M-x customize-variable
RET TeX-engine-alist
RET. Press the INS
button and fill the fields in the following way:
- Symbol:
default-shell-escape
- Name:
Default with shell escape
- Plain TeX command:
tex -shell-escape
- LaTeX command:
latex -shell-escape
- ConTeXt command: leave empty
The do-it-for-me way
Add the following code to your .emacs
(eval-after-load "tex"
'(progn
(add-to-list
'TeX-engine-alist
'(default-shell-escape "Default with shell escape"
"pdftex -shell-escape"
"pdflatex -shell-escape"
ConTeXt-engine))
;; (setq-default TeX-engine 'default-shell-escape)
))
Set the default-shell-escape
engine as default
Now you can set the new fictitious engine as default for all documents
- by customizing
TeX-engine
(M-x customize-varaiable
RET TeX-engine
RET) and selecting Default with shell escape
in the drop-down Value Menu
, or
- by uncommenting (ie, removing
;;
at the beginning of) the
(setq TeX-engine 'default-shell-escape)
line in the previous Elisp code.
Use the default-shell-escape
engine on a per-document basis
Alternatively, you can leave the default engine as it is and pick up the default-shell-escape
engine only in the documents in which you actually need it. In those documents, issue M-x add-file-local-variable
RET TeX-engine
default-shell-escape
RET.
Best Answer
AUCTeX complains that
pdflatex
cannot be found. However, according to your comments you checked and foundpdftex
, notpdflatex
, which still can be missing.Today,
pdflatex
if often just a symbolic link topdftex
. For example, on my Ubuntu system with TeX Live 2011:It finally points to
pdftex
.So, you could
pdftex
instead ofpdflatex
, since LaTeX is just the format, not the engine or executableor create a symbolic link, such as by
in your path, where it can be found.
or use the TeX Live Manager, start it by
and have a look in the menu Actions/ Managing symbolic links to the point update symbolic links or let it create symbolic links, this is also possible via command line option to
tlmgr
(seetlmgr --help
).