Example Makefile:
MAIN=$(sh grep -l '\documentclass' *.tex)
TEXFILES=$(filter-out $(MAIN), $(sh ls *.tex))
PDFLATEX=pdflatex
PDF=$(MAIN:.tex=.pdf)
DEFAULT: pdf
pdf : $(PDF)
$(PDF) : $(MAIN) $(TEXFILES)
$(PDFLATEX) $(MAIN)
$(PDFLATEX) $(MAIN)
- The variable
MAINis automatically populated with grep searching for a file that contains the string\documentclass(hopefully finds the correct one...) TEXFILESare all other files with the file extension .tex.PDFwill become the name of the generated PDF. It is taken from theMAINfile. You can change this according to your preference.PDFLATEXis the program name to generate PDF from LaTeX input.- The first rule is the default when
makeis invoked without parameters. To avoid confusion and accidental overwriting, a strikingDEFAULT-target is used that just tellsmaketo build the PDF. - The rule for
make pdfis propably only useful, if also rules for Postscript and DVI are implemented. For beginners: stick to usingpdflatexto directly generate PDF files. The old way with DVI is obsolete (unless your printing service can only handle Postscript). - The PDF is generated from all .tex files.
To get the references right,
pdflatexis called twice. - If you're using an index or BibLaTeX/BibTeX, then append their invokation and add another two calls to
pdflatex. -
If the generation takes too long, add a
quicktarget, that unconditionally callspdflatexonce. After fixing typos or only minor modifications, this often suffices.::make quick : $(PDFLATEX) $(MAIN)