Skip to content

Instantly share code, notes, and snippets.

@ckirsch
Created March 1, 2013 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckirsch/5062623 to your computer and use it in GitHub Desktop.
Save ckirsch/5062623 to your computer and use it in GitHub Desktop.
Makefile for LaTeX'ing and Bibtex'ing papers that may include xfig'ures. Supports pdflatex as well as latex, dvips, and epstopdf.
##########################################################################
# LaTeX Makefile by Christoph Kirsch
#
# Do not remove any tab characters.
# Tab characters distinguish dependencies from commands.
##########################################################################
# Define the main file that includes all others and the bib file
# In local make script, define, e.g., 'export MAIN=other' to overwrite default
MAIN := paper
BIB := paper
##########################################################################
# Get all .fig files in current directory
# and replace .fig suffix by .pdf and .pdf_t, respectively.
FIGURES := $(wildcard *.fig)
FIGPDF := $(patsubst %.fig,%.pdf,$(FIGURES))
FIGPDFT := $(patsubst %.fig,%.pdf_t,$(FIGURES))
FIGPSTEX := $(patsubst %.fig,%.pstex,$(FIGURES))
FIGPSTEXT := $(patsubst %.fig,%.pstex_t,$(FIGURES))
FIGEEPIC := $(patsubst %.fig,%.eepic,$(FIGURES))
##########################################################################
# Get all .eps files in current directory
# and replace .eps suffix by .pdf suffix.
EPS := $(wildcard *.eps)
EPSPDF := $(patsubst %.eps,%.pdf,$(EPS))
##########################################################################
# Define the pattern rules
#
# Example:
# The following rule tells 'make' how to generate
# .dvi files from .tex files:
#
# %.dvi : %.tex $(FIGURES)
# latex $<
#
# The generation depends on the .tex file as well as on the $(FIGURES).
# % matches any non-empty substring, e.g., 'foo'.
# Then $< is 'foo.tex', $@ is 'foo.dvi', and $* is 'foo'.
%.bbl : $(BIB).bib %.tex
bibtex $*
%.pdf : %.tex $(FIGURES)
pdflatex $<
%.dvi: %.tex $(FIGURES)
latex $<
%.ps : %.dvi
dvips -P cmz -t letter -o $@ $<
%.pdf : %.fig
fig2dev -L pdftex -n $@ $< $@
%.pdf_t : %.fig
fig2dev -L pdftex_t -p $*.pdf $< $@
%.pstex : %.fig
fig2dev -L pstex -n $@ $< $@
%.pstex_t : %.fig
fig2dev -L pstex_t -p $*.pstex $< $@
%.eepic : %.fig
fig2dev -L eepic $< $@
%.pdf : %.eps
epstopdf $<
%.ps.gz : %.ps
gzip -c $< > $@
%.rtf : %.tex
latex2rtf $<
##########################################################################
# Define the rules
#
# The first rule is the default rule and will be invoked by 'make'.
.PHONY : paper again dgain bib fig pdf ps dvi all clean
paper: fig pdf bib
again: pdf
pdflatex $(MAIN)
dgain: dvi
latex $(MAIN)
bib: $(MAIN).bbl
fig: $(FIGPDF) $(FIGPDFT) $(FIGEEPIC) $(EPSPDF)
pdf: $(MAIN).pdf
ps: fig dvi bib $(MAIN).ps
dvi: $(MAIN).dvi
rtf: $(MAIN).rtf
all: paper
pdflatex $(MAIN)
pdflatex $(MAIN)
clean:
/bin/rm -f *~ *.aux *.bbl *.blg *.dvi *.idx *.ilg *.ind *.lof \
*.log *.lot *.ps *.ps.gz *.pdf *.toc *.pstex *.pstex_t \
*.pdf_t *.eepic *.fig.bak *.pdfsync *.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment