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.
EDIT 2
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?
latexmk
. However, formake
, you need to tell it that the final PDF requires the plot's PDF. Then it will know not to apply the rule to make the final PDF until it has made the plot's PDF. (Or the plot's PGF or whatever it needs.) Then you just need a rule to make the plot's PDF. That's howmake
works: you tell it what ingredients each target needs and provide a recipe for turning the ingredients into the target. One target can have another target as an ingredient andmake
will figure out what to do in what order.%.pdf: %.tex
shouldn't tell make that only one ingredient is needed for all PDFs because that's a lie! One of the PDFs needs another ingredient, so you need to list that ingredient, too.latexmk
, but isn't it odd to uselatexmk
inside amake
file, especially whenlatexmk
is (additionally) told to (try to) 'usemake
?make
would calllatexmk
(without me having to type all the arguments each time like-lualatex
), thenlatexmk
would callmake
to build the dependencies. So it shouldn't actually require the dependencies in the Makefile, because it's a separatemake
process that builds the plots.latexmk
given in the first Makefile, the options given tolatexmk
tell it to generate dependency information in a form that is read bymake
when it executes the-include
line. That's been removed from the second version, which shows an incorrect way of callinglatexmk
from a Makefile. The first Makefile is a good way of combining the use oflatexmk
andmake
.