Ryan's Blog

Handy Latex Metapost Bibtex Makefile

Posted in latex by ryanlayer on October 8, 2009

This Makefile is not the most robust thing in the world, but it is generic enough for me to use on almost all of my documents.  The command you want to run is `make FILE=<latex file name without extension>`.  If your file is doc.tex, then you will run `make FILE=doc`.  The assumption here is that the tex, mp, and bib files all have matching names (e.g., doc.tex, doc.mp, and doc.bib).  The Makefile checks to see if the metapost file and bibtex file exist before attempting to process them.  The Makefile creates dvi, ps, and pdf files.

NOTE:  You will have to insert tabs to make this work

MPOSTDIR:=./
BIBDIR:=./
LATEX_OPTS:=-halt-on-error
FILE:=$(strip $(wildcard *.tex))
MPOSTFILE:=$(wildcard $(MPOSTDIR)/$(FILE).mp)
BIBFILE:=$(wildcard $(BIBDIR)/$(FILE).bib)
all: pdf

pdf: ps
ps2pdf $(FILE).ps

ps: dvi
dvips -t letter $(FILE).dvi -o $(FILE).ps

dvi: mp bib
latex $(LATEX_OPTS) $(FILE).tex

quick: mp
latex $(LATEX_OPTS) $(FILE).tex
dvips $(FILE).dvi -o $(FILE).ps

bib:
ifdef BIBFILE
latex $(LATEX_OPTS) $(FILE).tex
bibtex $(BIBDIR)/$(FILE)
latex $(LATEX_OPTS) $(FILE).tex
endif

mp:
ifdef MPOSTFILE
cd $(MPOSTDIR) && \
mpost $(FILE).mp && \
cd ..
endif

clean:
rm -f *.aux
rm -f *.bbl
rm -f *.blg
rm -f *.log
rm -f *.dvi
rm -f *.ps
rm -f *.tex\~

Advertisements
Tagged with: ,