'Compiling' Your Latex Documents using a Makefile

If you're using the command line like I do most of the time, then you can use a 'Makefile' in order to create your PDFs. Notice that I use 'ps2pdf14' instead of 'ps2pdf'. Also note the values of 'PS2PDF_OPTS'; these were required in order to conform to IEEE submission standards where all fonts are embedded in the PDF.

###############################################################################
#
# NOTES:
# 
# 	- just typing 'make' will run latex/dvips/ps2pdf to produce a PDF.
#
# 	- Sometimes, when cross-references change, you need to run 'latex' again.
# 	Typing 'make' won't work because the pdf will be up to date.  To get
# 	around this problem, just type 'make again' which will force latex to 
# 	compile your document.  You'll need to type 'make' to run dvips/ps2pdf.
#
###############################################################################

LATEX=latex
DVIPS=dvips
PS2PDF=ps2pdf14
BIBTEX=bibtex

LATEX_OPTS=-interaction=nonstopmode -halt-on-error
DVIPS_OPTS=-Ppdf -t letter
PS2PDF_OPTS=-dPDFSETTINGS=/prepress -dSubsetFonts=true -dEmbedAllFonts=true
NUM=""

RERUN = "(There were undefined references|Rerun to get (cross-references|the bars) right)"
RERUNBIB = "No file.*\.bbl|Citation.*undefined"


.PHONY: all clean


all: document references.bbl

document: document.pdf *.tex

document.pdf : document.ps
	$(PS2PDF) $(PS2PDF_OPTS) $^

document.ps: document.dvi
	$(DVIPS) $(DVIPS_OPTS) $^

document.dvi: document.tex $(wildcard *.tex)
	$(LATEX) $(LATEX_OPTS) document.tex
	
	@if(grep "There were undefined references" document.log > /dev/null);\
	then \
		$(BIBTEX) document; \
		$(LATEX) $(LATEX_OPTS) document.tex; \
	fi
	
	@if(grep "Rerun" document.log > /dev/null);\
	then \
		$(LATEX) $(LATEX_OPTS) document.tex;\
	fi
	rm -f document.log

references.bbl: references.bib
	if [ -n document.aux ]; \
	then \
		$(LATEX) $(LATEX_OPTS) document.tex;\
	fi
	$(BIBTEX) document

again:
	$(LATEX) $(LATEX_OPTS) document.tex


clean:
	+rm -fv document.{dvi,ps,pdf,aux,log,bbl,blg}


AttachmentSize
Makefile.tar.gz830 bytes

Comments

latexmk seems to be a better solution

Hi,

just stumbled upon your blog post. Maybe you want to have a look at latexmk. A script designed specifically with Makefile principles in mind. The preview continously mode is especially helpful.

Regards
Marius Hennecke