Saturday, October 1, 2016

LaTeX Makefile

The makefile script below compiles n number of .tex files to n number of .pdfs in the directory it's in and can include m number of .bib bibliography files.

SOURCES=$(wildcard $(SRC_DIR)*.tex)
BIBS=$(wildcard $(SRC_DIR)*.bib)
OUTPUT=$(patsubst %.tex, %.pdf, $(SOURCES))

.PHONY: all
all: $(OUTPUT) 

%.pdf: %.tex $(BIBS)
 pdflatex $(patsubst %.tex, %, $<)
ifneq ($(BIBS),)
 bibtex $(patsubst %.tex, %, $<)
 pdflatex $(patsubst %.tex, %, $<)
endif
 pdflatex $(patsubst %.tex, %, $<)

.PHONY: clean
clean:
 -rm -f *.pdf *.log *.out *.aux *.dvi *.blg *.bbl

If you use this script, make sure to use the actual tab character in front of lines that are tabbed over. Spaces are used on this page because of limitations of blogger to show tabs.

No comments: