Skip to content

Instantly share code, notes, and snippets.

@alexjohnj alexjohnj/Makefile
Created May 16, 2016

Embed
What would you like to do?
A generic Makefile template for somewhat complicated LaTeX documents.
# This is a generic Makefile that can be used to compile somewhat complicated
# LaTeX documents. It assumes a directory structure like this
# .
# ├── figures/*.{pdf,tex}
# ├── MAIN.tex
# ├── Makefile
# ├── Preamble.tex
# ├── sections/*.tex
# └── latex.out/
# and that you want to use a LaTeX runner such as latexrun or latexmk. The
# Makefile's configured for latexrun but it should be easy to switch to
# something else by customising the variables $(LATEXRUN) and $(LATEXRUN_OPTS).
#
# The watch task uses [watchman](https://github.com/facebook/watchman) to watch
# all the files defined in the variables $(MAIN), $(BIB_FILE), $(FIGURES),
# $(PREAMBLE), $(SECTIONS) and $(OTHER_FILES) running the all task if any of
# them changes.
# Main TeX file WITHOUT extension
MAIN =
PREAMBLE = Preamble.tex
# No references? Just assign this to nothing.
BIB_FILE =
TMP_DIR = latex.out
FIGURE_DIR = figures
SECTIONS_DIR = sections
FIGURES = $(wildcard $(FIGURE_DIR)/*.tex $(FIGURE_DIR)/*.pdf)
SECTIONS = $(wildcard $(SECTIONS_DIR)/*.tex)
# Define any other files (e.g., BibLaTeX configuration files) here.
OTHER_FILES =
LATEX = lualatex
LATEX_OPTS = --interaction=nonstopmode --shell-escape
LATEXRUN = latexrun
LATEXRUN_OPTS = --latex-cmd=$(LATEX) --latex-args="$(LATEX_OPTS)" --bibtex-cmd=biber -O=$(TMP_DIR)
.PHONY: FORCE
$(MAIN).pdf: FORCE $(MAIN).tex $(FIGURES) $(SECTIONS) $(BIB_FILE) $(OTHER_FILES)
$(LATEXRUN) $(LATEXRUN_OPTS) $(MAIN).tex
.PHONY: clean
clean:
$(LATEXRUN) --clean-all
.PHONY: all
all: $(MAIN).pdf
.PHONY: watch
watch:
watchman-make -p $(MAIN).tex $(PREAMBLE) $(FIGURES) $(SECTIONS) $(BIB_FILE) $(OTHER_FILES) -t all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.