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?


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.

  • 2
    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
  • 1
    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';

As of Dec. 2011 with both MiKTeX and TeXLive you can use

-outdir=FOO or -output-directory=FOO

like so:

latexmk -output-directory="../out"

Source: http://mirrors.ctan.org/support/latexmk/latexmk.pdf

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.