TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using latexmk for the automatic resolution of needed reruns. I would like to put all build files (aux, log, bbl, pdf, etc.) in a subdirectory.

I cannot find an option for latexmk to do this. If I specify -output-directory in the pdflatex rule like this

$pdflatex="pdflatex -interaction=nonstopmode -output-directory=build";

latexmk fails to find the files when doing a second run.

Has anyone found a suitable solution?

share|improve this question
up vote 11 down vote accepted

You can use latexmk's -jobname option like this:

latexmk -pdf -jobname=/path/to/new/output/newfilename currentfile

and all of the output files will be routed to the directory specified and given the basename 'newfilename'. E.g., all the files associated with processing currentfile.tex will now be in output/ and be called newfilename.pdf, newfilename.bbl, etc.

share|improve this answer
Works nicely if a relative path is passed to -jobname. If an absolute path is used the following message from pdflatex crops up: pdflatex: Not writing to /full/path/build/out.aux (openout_any = p). – Nickolay Kolev Feb 22 '11 at 14:47
Aha ... I tested it on a relative path (within the current directory) so I missed that. – Kieran Feb 22 '11 at 14:57
The failure with absolute paths is for security reasons. You can always use a local symlink pointing to the global directory though. – mforbes Oct 6 '11 at 18:02

As announced at Use MiKTeX option through latexmk, I've made a new version of latexmk, which supports -output-directory. It's v. 4.27a and can be found at http://www.phys.psu.edu/~collins/latexmk/versions.html (It'll be on CTAN soon.)

Just use the following settings in your latexmkrc file

$pdflatex="pdflatex -interaction=nonstopmode %O %S";
$out_dir = 'build';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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