# latexmk: Multiple custom-generated files and \input

Referring to this question, I found that having multiple custom-generated files in a document generated by latexmk doesn't really work for me.

The modus operandi is that latexmk runs pdflatex, checking that noteable's output for missing file errors, then generating that file, then re-running pdflatex.

However, I have many files to be generated this way, and every pass of the above process only generates one of them (then re-running, finding the next missing file, generating that, rerunning... until latexmk gives up due to too many re-runs.)

Apparently I am doing something wrong, am missing a crucial command-line option or somesuch. But perusing the manual didn't enlighten me. Help, please?

Edit: I am aware that I could just use a common Makefile rule to generate those files outside the control of latexmk, with the document depending on those generated files. But I would like to know how it could be done without adding the dependencies to the Makefile, either manually or by having latexmk print Makefile rules, through -use-make or add_cus_dep() or somesuch.

Edit2: A MWE for this:

Makefile:

test.pdf:
latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make test.tex

%.tex:
echo "Foo" > \$@

clean:
rm foo* test.pdf


test.tex:

\documentclass{article}

\begin{document}

\input{foo1}
\input{foo2}
\input{foo3}
\input{foo4}
\input{foo5}
\input{foo6}

\end{document}


Edit3: As a sidenote, latexmk -CA does not remove the files that are generated, either. There is a message of "checking foo1.log for generated files", but foo1.tex remains, which isn't what I would expect from a "clear all" option...

Edit4: This only happens with \input. If I use \include in the MWE above, everything works as I would expect: All custom file generation happens in the first pass. How can I get that behaviour with \input, too?

-
Could you please provide a minimal example where latexmk fails doing what you want? –  N.N. Jan 12 '12 at 9:09
@N.N.: Done.... –  DevSolar Jan 12 '12 at 10:03
Could you please explain what happens when you make the MWE and what you would like to happen? The clearer you are the greater are your chance of getting a good answer. –  N.N. Jan 12 '12 at 10:07
@N.N.: I think I've been pretty clear. Observed behaviour: pdflatex is re-run after every single generated file, eventually ending in a "too many re-runs" error message. Desired behaviour: All files being generated, ideally in a single pass instead of re-starting after each file (re performance), and the PDF eventually being created successfully. –  DevSolar Jan 12 '12 at 10:18
@N.N.: Please note Edit4 above - this seems to be specific to files referred to via \input, with \include working as expected. –  DevSolar Jan 12 '12 at 10:46

If you look carefully at the output from the run, you'll see that on the first run, pdflatex detects a first missing file. Since nonstopmode is being used, that causes a fatal error, and pdflatex goes no further. Then latexmk sees a message about a single missing file, makes it, and repeats the run. Then an error comes up about the second missing file, etc, with the annoying phenomenon you observed. The situation is different when \include is used instead of \input. This macro behaves differently: the missing file is no longer a fatal error; instead there are messages in the log file for all the missing files, all on the first run.

There are two solutions. One is to run pdflatex in its normal mode, where it will stop and ask you to correct the filename. Just hitting the enter key will cause pdflatex to continue, ignoring the missing file. To automate this, change the second line of your Makefile to

latexmk -pdf -pdflatex="cat responses | pdflatex -interaction=nonstopmode" -use-make test.tex


where responses is a file containing many blank lines.

A more systematic solution is to replace \input by a macro which gives a warning instead of a fatal error when a file is missing:

\documentclass{article}
\newcommand\inputA[1]{%
\InputIfFileExists{#1}{}{\typeout{No file #1.}}%
}
\begin{document}
\inputA{foo1}
\inputA{foo2}
\inputA{foo3}
\inputA{foo4}
\inputA{foo5}
\inputA{foo6}
\end{document}


I've used this trick quite a few times.

-
Ah... excellent. I'd daresay that this would be a nice feature to add to pdflatex - a mode where missing \input files aren't fatal, so that latexmk` could do its thing. –  DevSolar Jan 13 '12 at 5:46