I'd like to use latexmk in a Makefile, so I've read the manual section on that. However, the dependency generation step seems less than ideal. Specifically, it seems that latexmk can only show dependencies after fully building an output file (which can take a long time in my case). Is there a way to have latexmk only output dependencies to a file and not mark the actual output file as up-to-date?

I've tried the following rule in my Makefile, but it seems to mark the output file as up-to-date. I'd also think it could run multiple times (or think it has failed) depending on what's in the log file.

%.d: %.tex
    @echo "Generating $@ from $<"
    @set -e; \
     $(LATEXMK) -M -MF $@ -quiet -pdf \
      -pdflatex="echo Generating dependencies from %T" $<
  • 1
    This might be a problem as some of the dependencies arise only during compilation (like tikz-externalize, automatic epstopdf etc.). Even bibliography usage is actually known only during the compilation. – yo' Aug 22 '12 at 16:50

@tohecz: You are correct.

The problem is that the dependencies depend in a complicated way on the detailed contents of the TeX file (and all the files it calls in, including the class file and the style files). The only easy way to determine the dependencies is to run pdflatex (or latex as appropriate), and then analyze the resulting files (the relevant ones are the .fls, .log and .aux files). If the .tex file changes, then both the .pdf and the dependency information are simultaneously out of date.

Therefore, if you want to run pdflatex to determine the dependencies, you get a new .pdf file as a side effect. So there's no point to trying to update the dependency information without updating the .pdf file.

  • This isn't entirely true, though. If you employ make (e.g. GNU make) to build stuff only when things changed, it's make that needs to know the dependencies. The only alternative is to make your main .tex file a phony target (in GNU make lingo) in an attempt to have latexmk figure it all out on its own. But it means latexmk always runs, even though it would not have to if make knew the "top-level dependencies". – 0xC0000022L Apr 4 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.