Part I:
Could someone please give me an example of how to configure AUCTeX to use the -output-directory
option?
I've tried inserting -output-directory="/tmp"
in a variety of ways at different locations, but it's not working — with two hyphens, with one hyphen, with double quotes, with single quotes, without any quotes, before the %t
, after the %t
, right before the closing single quote, . . . .
Here is the generic latexmk
code for the working directory in my init.el
file:
(custom-set-variables '(TeX-command-list (quote ( ("LaTeX" "%`%l%(mode)%' %t" TeX-run-TeX nil (latex-mode) :help "Run LaTeX")))) )
Part II — Extra Credit
Then, I'd like to take one step further and copy the PDF back to the working directory with the following example. I'm on OSX with TeX Live, so -aux-directory
is not supported.
Configure latexmk
so that the command it uses for pdflatex
does the ordinary pdflatex
command and then copies the output file where you want it. You'd invoke latexmk
with the -output-directory
option.
An appropriate line in one of latexmk
's configuration files is
$pdflatex .= ' && cp "%D" "%R.pdf"';
You could also persuade it to display a message about the copying of the output file:
$pdflatex .= ' && (cp "%D" "%R.pdf"; echo Output file copied from "%D" to "%R.pdf" in current directory)';
(N.B. The second suggestion was all supposed to be on one line.)
Then you invoke latexmk
by something like the following:
latexmk -outdir=/tmp
For anyone interested in synctex with the -output-directory
option on an OSX box, add -synctex=1
to the line of code proposed by T. Verron
in the answer below:
;; use Skim as default pdf viewer
;; Skim's displayline is used for forward search (from .tex to .pdf)
;; option -b highlights the current line; option -g opens Skim in the background
(setq TeX-PDF-mode t)
(setq TeX-view-program-selection '((output-pdf "Skim")))
(setq TeX-view-program-list
'(("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n /tmp/%o %b")))
(server-start); start emacs in server mode so that skim can talk to it
EDIT: The following stackoverflow
link contains an alternative method of using Emacs and start-process
to run latexmk
and copy the .pdf file back to the working directory (leaving the auxiliary files in the /tmp
folder) — if the latexmk compilation is successful, then Skim is opened (with forward sync) — if the latexmk compilation generates errors, then the error buffer is displayed. https://stackoverflow.com/questions/18705774/if-latexmk-finishes-okay-then-show-pdf-else-display-errors
Best Answer
If you want to use AUCTeX so desperately:
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: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
):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
:Note that most of this is untested, please let me know if it doesn't work.