The ultimate Latex Makefile

After a long time of trial and errors (a.k.a. procrastination), I finally finished my “make phd” script for my thesis. The script uses bibtex (rerunning Latex as many times as needed) and can use either Latex or PDFLatex (if you want to use hyperref and nice PDF stuff) and if necessary converts all your images to PDFs.

You can use it like this:

make all                 <- build the document using latex, dvips, epstopdf
make clean             <- clean up (remove all intermediate (and final), including converted eps images (in using pdflatex)
PDF=true make all    <- builds the document using PDFLatex

Here’s the main makefile:

Makefile for Tadek's thesis

This file builds a paper - PDF file and if (PDF is defined) a PDF with hyperlinks

#

Written (c)2005 by Tadeusz Pietraszek (pie@zurich.ibm.com)

$Id: Makefile 597 2006-01-12 15:43:59Z pie $

#

Egrep trick from: http://xpt.sourceforge.net/techdocs/Latex/

MakefileForTeX/Latex08.000.html

TEXFILES=thesis.tex

TEXFILES=$(wildcard *.tex)

TARGETS=$(patsubst %.tex,%.pdf,$(TEXFILES))

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

phd: all

all: all-recursive $(TARGETS)

clean: clean-recursive rm -f *.aux *.log *.bbl *.blg *.brf *.cb *.ind *.idx *.ilg \ *.inx *.ps *.dvi *.pdf *.toc *.out *.lot *~ *.backup

all-recursive: for dir in $(wildcard *); do if [ -d $$dir ] && [ -f $$dir/Makefile ]; then cd $$dir; $(MAKE) all; cd ..; fi; done

clean-recursive: for dir in $(wildcard *); do if [ -d $$dir ] && [ -f $$dir/Makefile ]; then cd $$dir; $(MAKE) clean; cd ..; fi; done

ifndef PDF

building the document using .dvi, .ps, -> .pdf

%.dvi: %.tex echo $(SHFILES) latex $< egrep -c $(RERUNBIB) $.log && (bibtex $;latex $<); true egrep $(RERUN) $.log && (latex $<) ; true egrep $(RERUN) $.log && (latex $<) ; true

%.ps: %.dvi dvips -Ppdf -ta4 -G0 $<

%.pdf: %.ps ps2pdf $<

else

this is making the same file using pdfelatex

%.pdf: %.tex pdfelatex $< egrep -c $(RERUNBIB) $.log && (bibtex $;pdfelatex $<); true egrep $(RERUN) $.log && (pdfelatex $<) ; true egrep $(RERUN) $.log && (pdfelatex $<) ; true

endif

My pictures are built using the following Makefile (in a subdirectory of the main paper):

Makefile for Tadek's thesis - pictures!

#

Supports two targets: all and clean - and calls other makefiles recursively

If PDF is defined, converts EPS into PDFs

#

$Id:$

#

If you want to add your custom grpahic file .foo you need to

#

FOOFILES=#(wildcard *.foo)

EPSFILES=... $(patsubst %.foo,%.eps,$(FOOFILES))

#

%.eps: %.foo:

foo2eps -o $*.eps $<

source files

DIAFILES=$(wildcard *.dia) INKSCAPEFILES=$(wildcard *.svg)

target files (only those that we are building, and will be deleted)

EPSFILES=$(patsubst %.dia,%.eps,$(DIAFILES)) $(patsubst %.svg,%.eps,$(INKSCAPEFILES))

ifdef PDF

target files (if we're building PDFs)

PDFFILES=$(patsubst %.eps,%.pdf,$(EPSFILES) $(wildcard *.eps)) else PDFFILES= endif

3 Responses to “The ultimate Latex Makefile”

  1. Andrew McNabb Says:

    Chris Monson recently updated his LaTeX Makefile. I’ve been using it a while, and it’s a tremendous time-saver. The Makefile has a great number of features. Among other things, it colorizes output, runs LaTeX the minimal number of times to correctly create the document, and can auto-generate dependencies (such as .eps files from Gnuplot files). I highly recommend checking it out.

  2. tadekp Says:

    Tnx for a link. You’re right – it’s probably the most powerful Latex Makefile, I’ve seen. I will definitely give it a try… but only after I’ve submitted my thesis (tight deadline right now so don’t want to experiment/procrastinate!) I’m personally using Kile in a dual monitor setup and don’t use my makefile to debug and look for Latex errors. Still, if I had known about the makefile you pointed me to, I wouldn’t have written my own ;-)

    Tadek

  3. halfmoon Says:

    Simply ‘drag and drop’ your PDF file and then press the ‘Write CD Now’ button and you are done! ‘AutoPlay me for PDF’ does all the work. Not only does it add your file it also adds the Foxit PDF Reader* to the cd. Your PDF Document runs through this viewer so you now do not need to worry whether a PDF viewer is installed on the target computer.

    http://www.yaodownload.com/utilites/launchers/autoplay-me-for-pdf/

Leave a Reply