Simple makefile for LaTeX

(Updated 06-07-10)

I do not know squat about make files, but by reading the info pages I whipped up a makefile for simple LaTeX usage. Since I do almost all my figures in xfig, this makefile is set up to handle making eps files from fig files. More info on that, including fig files with special text, here.

Supported uses are make to create the dvi file, and make ps, make pdf, and make tarball.

It is pretty trivial, but it is a start. And it is simple enought to understand and modify.

Doing references via BibTeX correctly is impossible, because there is no way of knowing when internal references in the .tex file change, among other reasons; these will require running BibTeX by hand. However, a new .bib file is a sign that a BibTeX run is required.

Important! The indented lines here must have tabs, not spaces. That is just the way make works.

# set latexfile to the name of the main file without the .tex
latexfile = short
# put the names of figure files here.  include the .eps
figures = smiley.eps logo.eps

# if no references, run "touch latexfile.bbl; touch referencefile.bib"
# or delete dependency in .dvi and tarball sections
referencefile = refs

TEX = latex

# support subdirectories
VPATH = Figs

# reruns latex if needed.  to get rid of this capability, delete the
# three lines after the rule.  Delete .bbl dependency if not using
# BibTeX references.
# idea from http://ctan.unsw.edu.au/help/uk-tex-faq/Makefile
$(latexfile).dvi : $(figures) $(latexfile).tex $(latexfile).bbl
	while ($(TEX) $(latexfile) ; \
	grep -q "Rerun to get cross" $(latexfile).log ) do true ; \
	done


# keep .eps files in the same directory as the .fig files
%.eps : %.fig
	fig2dev -L eps $< > $(dir $< )$@

$(latexfile).pdf : $(latexfile).ps
	ps2pdf $(latexfile).ps $(latexfile).pdf

pdf : $(latexfile).pdf

$(latexfile).ps : $(latexfile).dvi
	dvips $(latexfile)

ps : $(latexfile).ps 

# make can't know all the sourcefiles.  some file may not have
# sourcefiles, e.g. eps's taken from other documents. 
$(latexfile).tar.gz : $(figures) $(latexfile).tex $(referencefile).bib
	tar -czvf $(latexfile).tar.gz $^

tarball: $(latexfile).tar.gz