Skip to content

Instantly share code, notes, and snippets.

@lorepozo
Last active December 7, 2017 19:29
Show Gist options
  • Save lorepozo/cacb58c117f32a5c34f24d7a6d3f88a6 to your computer and use it in GitHub Desktop.
Save lorepozo/cacb58c117f32a5c34f24d7a6d3f88a6 to your computer and use it in GitHub Desktop.
Makefile for LaTeX
THIS_FILE := $(lastword $(MAKEFILE_LIST))
TEX := xelatex -shell-escape -interaction=nonstopmode -file-line-error
PRE := $(wildcard ./*.tex)
OBJ := $(PRE:%.tex=%.pdf)
BIB := $(wildcard ./*.bib)
BIB_OBJ := $(BIB:%.bib=%.bbl)
all: $(OBJ)
bib: $(BIB_OBJ)
%.bbl: %.bib
bibtex $(^:.bib=)
%.pdf: %.tex
$(TEX) $^
if [ -e "$(^:.tex=.bib)" ] ; then $(MAKE) -f $(THIS_FILE) $(^:.tex=.bbl) && $(TEX) $^ && $(TEX) $^ ; fi
clean:
$(RM) *.aux *.log *.out *.bbl *.blg
cleanall: clean
$(RM) $(OBJ)
@lorepozo
Copy link
Author

lorepozo commented Feb 3, 2017

Just use make in any directory with a .tex file.

If you're using bibtex for citations, name the .bib file like the associated .tex file (e.g. main.tex and main.bib).

make clean gets rid of all auxiliary files, and make cleanall will also get rid of the produced PDFs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment