[Tex/LaTex] latexmk -outdir with \include

includelatexmk

I'm trying to get latexmk to compile a .tex file with external \include{...} references to a specific build directory so I don't pollute my directory tree with .aux files, etc.

However, it appears latexmk doesn't do as I'd expect when it compiles the included files. For example, consider a file file1.tex which has something like

%%%%%
\include{chapters/test}
%%%%%

When I run

latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode -file-line-error" file1.tex

everything works fine, but

latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode -file-line-error" -outdir=build file1.tex

gives me the error

Latexmk: Missing input file: 'chapters/test.aux' from line
  'No file chapters/test.aux.'

If I don't have the \include statement, using \input instead, everything compiles nicely to the build directory as you would expect.

For reference, I'm working on Mac OSX w/ MacTeX, as I understand there are a few differences in the implementation of latexmk between MacTeX and MikeTeX… any help would be much appreciated, as I've been beating my head against this for a while now.

Best Answer

Actually, this isn't a latexmk problem. If you look at the .log file or at the actual screen output, you'll see that it is pdflatex that had a problem. If you run pdflatex from the command line with the -output-directory=build option, you will get exactly the same errors. The primary error is that pdflatex can't create the file chapters/test.aux.

The solution is simply to create a chapters subdirectory of your build directory.

(The messages you saw from latexmk are its summary of what it is currently programmed to treat as common significant warnings and errors. But it's an incomplete summary. In general, if you find an error and don't understand what to do about it, it's worth going through the .log file; that provides much more information than latexmk's summary.)