Skip to content

Instantly share code, notes, and snippets.

@sstallion
Created March 20, 2022 18:15
Show Gist options
  • Save sstallion/9b43e9779c8fb222e06e63ade3624c92 to your computer and use it in GitHub Desktop.
Save sstallion/9b43e9779c8fb222e06e63ade3624c92 to your computer and use it in GitHub Desktop.
LaTeX Makefile
# Copyright (C) 2022 Steven Stallion <sstallion@gmail.com>
#
# This work is licensed under a Creative Commons Attribution 4.0
# International License.
#
# You should have received a copy of the license along with this
# work. If not, see <http://creativecommons.org/licenses/by/4.0/>.
LATEXMK = latexmk
LATEXMKFLAGS = -xelatex -use-make
SOURCES ?= $(wildcard *.tex)
TARGETS ?= $(SOURCES:.tex=.pdf)
TARGET ?= $(basename $(firstword $(TARGETS)))
.PHONY: all
all: $(TARGETS)
.PHONY: clean
clean:
-$(LATEXMK) $(LATEXMKFLAGS) -C
.PHONY: preview
preview:
$(LATEXMK) $(LATEXMKFLAGS) -pvc $(TARGET)
.PHONY: watch
watch:
$(LATEXMK) $(LATEXMKFLAGS) -pvc -view=none $(TARGET)
# Latexmk tracks several dependencies that are not known to this Makefile.
# The following suffix rule will always be out-of-date to force delegation:
%.pdf: %.tex FORCE
$(LATEXMK) $(LATEXMKFLAGS) $<
.PHONY: FORCE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment