Tools to convert markdown to pdf
  • Shell 52%
  • Python 48%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-27 13:34:02 +01:00
bin [IMP] add img-mm script to prepare images for inclusion 2026-10-27 13:03:12 +01:00
examples [INZ] Initial commit 2026-10-27 11:50:02 +01:00
src [IMP] Also find images through parent path 2026-10-27 13:34:02 +01:00
templates [INZ] Initial commit 2026-10-27 11:50:02 +01:00
tests [INZ] Initial commit 2026-10-27 11:50:02 +01:00
.gitignore [INZ] Initial commit 2026-10-27 11:50:02 +01:00
.pre-commit-config.yaml [INZ] Initial commit 2026-10-27 11:50:02 +01:00
.ruff.toml [INZ] Initial commit 2026-10-27 11:50:02 +01:00
AGENTS.md [IMP] Also find images through parent path 2026-10-27 13:34:02 +01:00
install.sh [IMP] Add install script 2026-10-27 13:19:00 +01:00
LICENSE [INZ] Initial commit 2026-10-27 11:50:02 +01:00
README.md [IMP] Also find images through parent path 2026-10-27 13:34:02 +01:00
requirements.txt [IMP] Add install script 2026-10-27 13:19:00 +01:00

openeyedev-markdown-tools

A small CLI that converts Markdown to PDF using pandoc + a LaTeX engine (default: lualatex), with the bundled Eisvogel pandoc LaTeX template.

Built for generating customer proposals/contracts from Markdown, but works for any Markdown document.

Requirements

  • pandoc (≥ 3.x)
  • A TeX distribution with lualatex (e.g. texlive-full on Debian/Ubuntu)
  • Python ≥ 3.10
  • convert (ImageMagick or GraphicsMagick) — only needed by bin/img-mm

On Debian/Ubuntu:

sudo apt install pandoc texlive-full python3 graphicsmagick

Install

cd ~/git/openeyedev/openeyedev-markdown-tools
./install.sh

install.sh checks OS requirements, creates a uv venv at .venv/ (falls back to a stdlib venv if uv is missing) and installs requirements.txt, then symlinks bin/md2pdf and bin/img-mm into ~/.local/bin.

  • Run as your normal user: if a system requirement is missing, it prints the exact apt-get install command to fix it and exits without installing anything system-wide. The venv + symlinks are created once requirements are satisfied.
  • Run as root (sudo ./install.sh): installs missing system packages via apt-get first, then sets the venv + symlinks up for the invoking user (via SUDO_USER), not for root.

Or run the tools in place without installing:

./bin/md2pdf --help
./bin/img-mm --help

Resizing images for the PDF (bin/img-mm)

Images (e.g. company logos) need to be sized in millimetres to look right on an A4 PDF. bin/img-mm computes the pixel width from a target DPI and resizes with the convert CLI (ImageMagick or GraphicsMagick):

px = round(mm / 25.4 × dpi)
# Default: 60mm @ 300 DPI → 709px, written to <stem>-60mm.<ext>
img-mm logo.png

# Other widths / DPIs
img-mm logo.png --mm 35              # 35mm @ 300 DPI → 413px
img-mm logo.png --dpi 150            # 60mm @ 150 DPI → 354px

# Overwrite the source, or write to an explicit path
img-mm logo.png --in-place
img-mm logo.png --out /tmp/logo.png

# Batch (shell expands the glob)
img-mm *.png

Aspect ratio is always preserved; only the width is constrained. Requires the convert command on PATH (e.g. apt install graphicsmagick or imagemagick).

Usage

# Single file — output lands next to the .md
md2pdf 2026-09-16-overeenkomst-openeyedev-therpbv.md

# Batch (shell expands the glob)
md2pdf *.md

# Use a different bundled template (or pass a path to your own .tex)
md2pdf proposal.md --template pandoc-template.tex

# Switch LaTeX engine
md2pdf proposal.md --engine xelatex

# Forward extra pandoc template variables (repeatable)
md2pdf proposal.md -V fontsize=12pt -V lang=nl -V titlepage=true

# Keep the temp build dir for debugging (under ~/tmp/<stem>_*…/)
md2pdf proposal.md --keep-temp

# Quiet mode
md2pdf proposal.md --quiet

How it works

For each foo.md:

  1. Creates a temp dir ~/tmp/foo_<random>/.
  2. Runs pandoc foo.md --template templates/eisvogel.latex --resource-path <md dir>:<md dir's parent> -o foo.tex. graphics=true is always passed so eisvogel loads graphicx (needed for raw \includegraphics{...} blocks as used in the proposal templates).
  3. Runs the LaTeX engine twice (foo.tex → foo.pdf) so cross-references / TOC settle. TEXINPUTS is set to the markdown file's directory and its parent so \includegraphics{images/...} resolves whether the images sit next to the md or one level up (common when shared assets live above a per-customer subfolder) — without copying or symlinking them into the temp dir.
  4. Copies foo.pdf next to the source foo.md and removes the temp dir (unless --keep-temp).

Only the final PDF is written next to the source; the .tex/.aux/.log intermediates stay in the temp dir and are cleaned up by default.

Bundled templates

File Notes
eisvogel.latex Default. Fancy template with optional title page, logo, color blocks. Use xelatex/lualatex.
pandoc-template.tex Minimal: libertine font, section numbers suppressed, no title page. Works with pdflatex.

Options

files                     one or more .md files (shell globs are expanded by your shell)
-e, --engine              lualatex (default) | xelatex | pdflatex
-t, --template            path to a .tex template, or a bare name from templates/
-V, --var KEY=VAL         extra pandoc template variable (repeatable)
-k, --keep-temp           keep the temp build directory
-q, --quiet               suppress pandoc/LaTeX output

Development

Pre-commit hooks enforce linting and formatting. After running ./install.sh (which creates the .venv/ with pre-commit installed), set up the hooks:

source .venv/bin/activate        # or: .venv/bin/pre-commit ...
pre-commit install

Run the full suite on all files at any time:

pre-commit run --all-files

Hooks (pinned in .pre-commit-config.yaml):

Hook What it does
ruff Python lint, with --fix and --exit-non-zero-on-fix
ruff-format Python formatting
trailing-whitespace Strip trailing whitespace
end-of-file-fixer Ensure files end with a newline
debug-statements Catch leftover breakpoint() / pdb calls
check-case-conflict Detect case-filesystem collisions
check-executables-have-shebangs Warn on executable scripts without shebang
check-merge-conflict Detect unresolved <<<<<<< markers
check-yaml Validate YAML files
mixed-line-ending Normalize to LF
shellcheck Shell script linting
prettier Format Markdown / YAML / JSON (LaTeX templates excluded)

Ruff is configured in .ruff.toml (targets Python 3.10, enables B/C90/I/UP/EXE

  • PLW1510). The bundled templates/ and examples/ are excluded from Python formatting.

A smoke test lives in tests/smoke.sh:

./tests/smoke.sh   # converts examples/minimal-proposal.md and checks the PDF

License

MIT.