5

I wrote several standalone tex files for drawing a figure with tikz, I named them with the pattern tikz_*.tex, and now I want to compile them all at once using a make file. First I tried the following

tikz_%.pdf:  tikz_%.tex                                                                                                                                                                          
             pdflatex tikz_$*.tex   

Secondly, how can I make a rule to generate all the pdf files in Makefile? I know I could make another rule and list all the pdfs I want to compile but there are too many such files.

  • 1
    If you install latexmk, it's just latexmk tikz_*.tex. It will rebuild only the ones they need to be rebuilt. – Rmano Aug 25 at 18:57
  • What flavour is your make utility? If it's GNU make, I have a solution. For other versions, I don't. (But of course, using latexmk as suggested above should work regardless.) – Harald Hanche-Olsen Aug 25 at 19:24
  • @HaraldHanche-Olsen, yes latexmk works perfectly, but i also want to know how that works for GNU make? – sunxd Aug 25 at 19:46
  • BTW, you can produce multiple standalones using the [tikz] or [multi=tikcpicture] options (one per page). You can select which page to use with the [page=...] option of \includegraphcs. – John Kormylo Aug 25 at 21:52
  • I added an answer with GNU make. Another tip: In your implicit rule, you can replace tikz_$*.tex by $<, meaning the first prerequisite. – Harald Hanche-Olsen Aug 26 at 6:53
1

Here is how to do it with GNU make:

tikz_%.pdf:  tikz_%.tex
    pdflatex $<  # Note: This must be indented with a TAB, not 4 Spaces!

PDFs = $(addsuffix .pdf, $(basename $(wildcard tikz_*.tex)))
all: $(PDFs)

Make sure to add your implicit rule at the top of the makefile, and you should be good to go.

The functions are documented in the GNU make manual.

Important caveat: Using this with your implicit rules depends on the tex files needing only one run. If they don't, use latexmk -pdf or similar tools instead of pdflatex.

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.