38

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?

3 Answers 3

32

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 path/to/new/output/ and be called newfilename.pdf, newfilename.bbl, etc. Mind that only relative paths work for security reasons (see comments).

4
  • 3
    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). Feb 22, 2011 at 14:47
  • Aha ... I tested it on a relative path (within the current directory) so I missed that.
    – Kieran
    Feb 22, 2011 at 14:57
  • 2
    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, 2011 at 18:02
  • I've tried this and I still get a <filename>.aux file for all tex files that are included in the main.tex file.
    – Thomas
    May 23, 2023 at 16:29
39

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';
5

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .