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
emacs
and one aboutlatexmk
. For the emacs part, I don't see the difference between "your genericlatexmk
code" and the default option for latex-ing documents. Maybe somewhere else, you have some code which tells auctex to substitute%l
withlatexmk
instead of(pdf)latex
? (1/3)latexmk
, the-output-directory
option should be given in the config file forlatexmk
, instead of yourinit.el
. See this answer for a way of doing it : tex.stackexchange.com/a/31253/9517 . In any case, there is good chance that I missed your point, since as I said, I don't understand what is the question. (2/3)