Skip to content

Instantly share code, notes, and snippets.

Last active November 24, 2022 08:55
What would you like to do?
Makefile for Markdown -> PDF using pandoc
# Generate PDFs from the Markdown source files
# In order to use this makefile, you need some tools:
# - GNU make
# - Pandoc
# - LuaLaTeX
# - DejaVu Sans fonts
# Directory containing source (Markdown) files
source := src
# Directory containing pdf files
output := print
# All markdown files in src/ are considered sources
sources := $(wildcard $(source)/*.md)
# Convert the list of source files (Markdown files in directory src/)
# into a list of output files (PDFs in directory print/).
objects := $(patsubst,%.pdf,$(subst $(source),$(output),$(sources)))
all: $(objects)
# Recipe for converting a Markdown file into PDF using Pandoc
$(output)/%.pdf: $(source)/
pandoc \
--variable mainfont="DejaVu Sans" \
--variable monofont="DejaVu Sans Mono" \
--variable fontsize=11pt \
--variable geometry:"top=1.5cm, bottom=2.5cm, left=1.5cm, right=1.5cm" \
--variable geometry:a4paper \
--table-of-contents \
--number-sections \
-f markdown $< \
--latex-engine=lualatex \
-o $@
.PHONY : clean
rm -f $(output)/*.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment