Makefile notes

2021, Dec 14    

I use make and Makefileto build my pdf files. It is my way of not remebering the exact pandoc syntax to build pdf from .md.

In extract:

SLIDES_MD  := $(wildcard Sessions/*_slides.md)
SLIDES_PDF := $(addsuffix .pdf,$(basename $(SLIDES_MD)))
.PHONY: slides
slides: $(SLIDES_PDF)

Sessions/%_slides.pdf: Sessions/%_slides.md
	cd Sessions; \
	pandoc -s --dpi=300 --slide-level 2 --toc --listings --shift-heading-level=0 --data-dir="." \
		--template default_mod.tex \
		-H templates/preamble.tex \
		--pdf-engine xelatex -M date="$(DATE_COVER)" -V classoption:aspectratio=169 \
		-f markdown+implicit_figures \
		-t beamer $(notdir $<) -o $(notdir $@)

Makefile stuff in use

  • Define vars using :=. See docs here
  • Use wildcard to get a filelist, addsuffix to append an extension to a filename and basename to get the filename+dir without extension. See docs here for the list of functions.
  • Define a .PHONY target to avoid issues related to filename collision.
  • Define slides target from a list
  • Define target from using static matching rules (%-notation). This way I can reuse the target for similar targets.
  • Use automatic variables in the commands. $< for dependencies and $@ for the target name

The above enables me to run make Sessions/some_slides.pdf or just make slides to build all that have updated .md files.

For info about pandoc and beamer to make slides, I suggest starting here