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:


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

    echo "Foo" > $@

    rm foo* test.pdf






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?

  • 1
    Could you please provide a minimal example where latexmk fails doing what you want?
    – N.N.
    Jan 12, 2012 at 9:09
  • @N.N.: Done....
    – DevSolar
    Jan 12, 2012 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, 2012 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, 2012 at 10:18
  • 1
    @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, 2012 at 10:46

2 Answers 2


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:

    \InputIfFileExists{#1}{}{\typeout{No file #1.}}%

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, 2012 at 5:46
  • 2
    Took me a while to find this answer while trying to solve this problem. Since @JohnCollins is the owner of latexmk: Wouldn't this trick be worth mentioning in the official doc?
    – m8mble
    Apr 14, 2018 at 9:45
  • Note that your \inputA macro is exactly equivalent to LaTeX's internal \@input@ macro.
    – user202729
    May 14, 2023 at 9:18

The answer by John Collins outlines well the reasons for the problem. Here is an update on his fix. Change the line of your Makefile to

latexmk -pdf -pdflatex="yes '' | pdflatex -interaction=nonstopmode" -use-make test.tex

This eliminates the need for an dummy file (and it what yes was designed for).

You must log in to answer this question.

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