[Tex/LaTex] Specify -output-directory when using latexmk


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?

Best Answer

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.