Skip to content

Instantly share code, notes, and snippets.

@willprice
Created May 29, 2019 15:55
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 willprice/8d261ae45cecd81d46aa156103cc7b72 to your computer and use it in GitHub Desktop.
Save willprice/8d261ae45cecd81d46aa156103cc7b72 to your computer and use it in GitHub Desktop.
LaTeX workflow
# You want latexmk to *always* run, because make does not have all the info.
# Also, include non-file targets in .PHONY so they are run regardless of any
# file of the given name existing.
NAME:=paper
DOC_SRC:=$(shell find . -maxdepth 1 -iregex './[^.].*\.tex')
MEDIA_SRC:=$(shell find images -type f)
SVG_SRC := $(shell find images -type f -iname '*.svg')
PDF_SVG := $(patsubst %.svg,%.pdf,$(SVG_SRC))
DEPS := $(DOC_SRC) $(MEDIA_SRC) $(PDF_SVG) $(BIB_FILES)
BIB_FILES:= ~/references.bib
.PHONY: all clean
all: $(NAME).pdf
# -pdf tells latexmk to generate PDF directly (instead of DVI).
# -pdflatex="" tells latexmk to call a specific backend with specific options.
# -use-make tells latexmk to call make for generating missing files.
# -interaction=nonstopmode keeps the pdflatex backend from stopping at a
# missing file reference and interactively asking you for an alternative.
%.pdf: %.tex $(DEPS)
latexmk -f -pdf -pdflatex="pdflatex -interaction=nonstopmode --shell-escape" -use-make $<
%.pdf: %.svg
inkscape $< --export-area-drawing --without-gui --export-type=pdf --export-file=$@
clean:
latexmk -C $(DOC_SRC)
#!/usr/bin/env bash
find . -regextype posix-extended \
-iregex '.*.(tex|bib|svg|png|pdf)' \
| entr -c make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment