I am trying to create a Makefile for my paper where I can type just
make and it will compile everything in one go. The paper has several figures which are generated from scripts. However, everything I've tried requires several runs of
make to get both the scripts to run and the paper itself.
I started with something based on this answer
all: paper.pdf paper.pdf: %.pdf: %.tex $(LATEXMK) -lualatex -halt-on-error -pdf -M -MP -MF $*.d $* some-plot.pgf: script_to_generate_plot.py -include *.d
However, from a clean build, or whenever I add a plot, this requires running
make twice, once to generate the
.d file and once to actually build the paper. And annoyingly the first time you just have to bypass an annoying "file not found" prompt.
I then noticed that
latexmk has a flag to use
make to build missing files, so I'm trying that:
all: paper.pdf paper.pdf: %.pdf: %.tex $(LATEXMK) -lualatex -interaction=nonstopmode -pdf -dvi- -ps- -use-make $* some-plot.pgf: python script_to_generate_plot.py
Now what this does is finds one plot missing, build it, then fails with
Latexmk: 'pdflatex': source file 'some-plot.pgf' doesn't exist. I'll try making it... ------------ Running 'make "some-plot.pgf"' ------------ python script_to_generate_plot.py Latexmk: Summary of warnings: Latex failed to resolve 1 reference(s) Latexmk: Errors, so I did not complete making targets Collected error summary (may duplicate other messages): pdflatex: Command for 'pdflatex' gave return code 256 Latexmk: Use the -f option to force complete processing, unless error was exceeding maximum runs of latex/pdflatex. make: *** [paper.pdf] Error 12
If I run
make again that plot was built, but it does the same thing with another one.
If I keep running
make it eventually builds all my plots one by one (I have several plots, some of which take a while to generate so I'd like to keep the scripts to generate them separate).
How can I make it so that it builds everything in one go, regardless of which and how many files need to be regenerated?
EDIT I guess I forgot to mention that my other goal here is to avoid manually stating every .tex/.pgf/.pdf file dependency in my Makefile. If I do that, there's no point to using latexmk. I've done the manual Makefile before, but I'm always forgetting to update the dependency graph whenever I add a new file or rearrange things. My understanding is that the strength of latexmk is that it can figure that stuff out automatically. If I can get something that does that, that would be ideal. That and latexmk automatically rebuilds the paper and bib files as many times as necessary.
I tried using the suggestion from the output, to use the
-f flag to
latexmk. This builds about 5 or so plots, then errors with
Rule 'pdflatex': File changes, etc: Changed files, or newly in use since previous run(s): 'origen-meeseeks.pgf' Latexmk: Maximum runs of pdflatex reached without getting stable files Failure to make 'paper.pdf' Latexmk: Errors, in force_mode: so I tried finishing targets Collected error summary (may duplicate other messages): pdflatex: Command for 'pdflatex' gave return code 256 Latexmk: Did not finish processing file 'paper': 'pdflatex' needed too many passes make: *** [paper.pdf] Error 12 transmutagen-papermaster*=$latexmk -
So it almost does what I want. How do I increase the max number of passes?