In the process of writing 420 final reports, SamJansen and Tom Young worked to create some makefiles useful for Latex projects. Latex and Bibtex have some strange properties which makes writing makefiles for them an interesting challenge. This page is currently a work in progress.
(remember that the indented lines need tabs, not spaces)
A very basic makefile that does not support Bibtex, images, or multiple input files looks something like the following:
# vim: tabstop=8 shiftwidth=8 noexpandtab # A very basic Latex makefile by Sam Jansen. # See http://www.wlug.org.nz/LatexMakefiles for more information # Change the following to whatever you like. Target will have '.ps' or '.pdf' # appended as need be. Tex should be the tex file WITHOUT the '.tex' suffix. TEX=report TARGET=report # You probably don't need to change anything below the following line: .PHONY: clean debug gvshow pdfshow acroshow dvishow LATEX_ARGS=--interaction batchmode LATEX=latex $(TARGET).ps: $(TARGET).dvi dvips $(TARGET) -o $(TARGET).ps $(TARGET).pdf: $(TEX).tex pdflatex $(LATEX_ARGS) $(TEX) $(TARGET).dvi: $(TEX).tex $(LATEX) $(LATEX_ARGS) $(TEX) @mv $(TEX).dvi $(TARGET).dvi clean: rm *.toc *.aux *.pdf *.ps *.eps *.log *.tex *.lof *.bib *.bbl *.blg *.dvi debug: latex $(TEX) gvshow: $(TARGET).ps gv $(TARGET).ps pdfshow: $(TARGET).pdf xpdf $(TARGET).pdf acroshow: $(TARGET).pdf acroread $(TARGET).pdf dvishow: $(TARGET).dvi xdvi $(TARGET).dvi
Probably the most interesting thing about the above makefile is that it uses --interaction batchmode as an argument to Latex. The rest is a fairly standard makefile. Things get a little more complex when Bibtex and automatic image conversion is added to the makefiles.
Serious people use bibtex to manage their references. Here is a makefile that should run bibtex and latex the appropriate number of times. (I've removed the extra targets and steps I had in here to run musixtex as well... -- JohnMcPherson)
TARGET=proposal # make pdf by default all: proposal.pdf # it doesn't really need the .dvi, but this way all the refs are right %.pdf : %.dvi pdflatex $* ${TARGET}.bbl: ../bib/music.bib # in case we don't already have a .aux file listing citations # this should probably be a separate makefile target/dependency instead # of doing it every time... but *shrug* latex ${TARGET}.tex # get the citations out of the bibliography bibtex ${TARGET} # do it again in case there are out-of-order cross-references @latex ${TARGET}.tex ${TARGET}.dvi: ${TARGET}.bbl ${TARGET}.tex @latex ${TARGET}.tex # shortcut, so we can say "make ps" ps: ${TARGET}.ps ${TARGET}.ps: ${TARGET}.dvi @dvips -t a4 ${TARGET}.dvi clean: rm -f ${TARGET}.{log,aux,ps,dvi,bbl,blg,log} reallyclean: clean rm -f ${TARGET}.{ps,pdf} PHONY : ps all clean reallyclean
Because of all the crap that Latex and Bibtex outputs, SamJansen decided to create a directory structure for the report that kept all the "work" files away from the main directory.
Usage:
Place .tex file in the root directory, a .bib file in the root directory, and .eps, .png, .jpg and .dia images/figures in the images/ directory. There are various targets used, just typing 'make' will just build a postscript file. The only editing of files needed is the top of the root makefile.
Here is what the current version looks like:
# vim: ts=8 noexpandtab # $Id: Makefile,v 1.11 2003/10/11 04:12:43 stj2 Exp $ # Edit the below: TEXFILES=$(wildcard *.tex) BIBFILE=report.bib TARGET=report # The following should not need editing: export TEXFILES BIBFILE TARGET $(TARGET).pdf: $(TEXFILES) $(BIBFILE) $(MAKE) -C images pdf $(MAKE) -C work pdf $(TARGET).ps: $(TEXFILES) $(BIBFILE) $(MAKE) -C images ps $(MAKE) -C work ps $(TARGET).dvi: $(MAKE) $(TARGET).ps .PHONY: show showx clean wordcount images debug debug: $(MAKE) -C images $(MAKE) -C work debug pdfdebug: $(MAKE) -C images pdf $(MAKE) -C work pdfdebug gvshow: $(TARGET).ps gv $(TARGET).ps pdfshow: $(TARGET).pdf xpdf $(TARGET).pdf acroshow: $(TARGET).pdf acroread $(TARGET).pdf dvishow: $(TARGET).dvi xdvi work/$(TARGET).dvi clean: @rm report.pdf 2>/dev/null; true @rm report.ps 2>/dev/null; true $(MAKE) -C work clean $(MAKE) -C images clean wordcount: @echo Approximate word count: `grep -v '^\\\\' $(TEXFILES)|grep -v '^%'|wc -w`
# vim: noexpandtab ts=8 # $Id: Makefile,v 1.10 2003/10/11 12:09:37 stj2 Exp $ .PHONY: pdf ps clean TEXS=$(foreach i,$(TEXFILES),$(addprefix ../,$i)) BIB=$(addprefix ../,$(BIBFILE)) $(TARGET).bbl: $(BIB) @cp -l $(BIB) . 2>/dev/null; true bibtex -terse $(TARGET) latex --interaction batchmode $(TARGET) $(TARGET).dvi: $(TEXS) $(TARGET).bbl @cp -l $(TEXS) . 2>/dev/null; true @cp -l ../images/*.eps . 2>/dev/null; true latex --interaction batchmode $(TARGET) pdf: $(TARGET).dvi @cp -l ../images/*.pdf . 2>/dev/null; true pdflatex --interaction batchmode $(TARGET) @cp $(TARGET).pdf .. ps: $(TARGET).dvi latex --interaction batchmode $(TARGET) dvips -q $(TARGET) -o $(TARGET).ps @cp $(TARGET).ps .. debug: @cp -l $(TEXS) . 2>/dev/null; true @cp -l $(BIB) . 2>/dev/null; true @cp -l ../images/*.{pdf,eps} . 2>/dev/null; true latex $(TARGET) pdfdebug: @cp -l $(TEXS) . 2>/dev/null; true @cp -l $(BIB) . 2>/dev/null; true @cp -l ../images/*.{pdf,eps} . 2>/dev/null; true pdflatex $(TARGET) clean: rm -f *.toc *.aux *.pdf *.ps *.eps *.log *.tex *.lof *.bib *.bbl *.blg *.dvi
# vim: noexpandtab ts=8 # $Id: Makefile,v 1.6 2003/10/02 21:21:20 stj2 Exp $ .PHONY: pdf ps clean PNGS=$(wildcard *.png) DIAS=$(wildcard *.dia) EPSS=$(wildcard *.eps) OUTPUT_EPS=$(PNGS:png=eps) $(DIAS:dia=eps) $(EPSS) OUTPUT_PDF=$(OUTPUT_EPS:eps=pdf) pdf: $(OUTPUT_PDF) ps: $(OUTPUT_EPS) clean: rm $(OUTPUT_PDF) $(DIAS:dia=eps) $(PNGS:png=eps) 2>/dev/null; true # Bitmap images -> EPS: PNG and JPG are covered at the moment, using # ImageMagick's 'convert' utility %.eps: %.png convert $< $@ %.eps: %.jpg convert $< $@ # EPS -> PDF # epstopdf is much better than ps2pdf... it preserves bounding box %.pdf: %.eps epstopdf $< # DIA -> EPS %.eps: %.dia dia --nosplash -e $@ $<
4 pages link to LatexMakefiles: