Small command-line converter from Markdown to PDF. It renders A4 documents
with a compact built-in stylesheet and supports the Python-Markdown extra,
codehilite, and sane_lists extensions.
- Python 3.10 or newer.
uvfor dependency and environment management.- The native libraries required by WeasyPrint.
On Apple Silicon macOS, the script includes /opt/homebrew/lib in the dynamic
library search path. Homebrew dependencies must still be installed separately.
uv sync --lockedIf the machine has a private package index configured globally, isolate this project from that configuration and select PyPI explicitly:
env -u UV_INDEX -u UV_DEFAULT_INDEX -u UV_INDEX_URL \
-u UV_EXTRA_INDEX_URL -u UV_CONFIG_FILE \
uv sync --locked --no-config --default-index https://pypi.org/simpleCreate a PDF next to the source file:
uv run --frozen md2pdf document.mdChoose the output path explicitly:
mkdir -p output
uv run --frozen md2pdf document.md --output output/document.pdfThe input file must exist. If --output is omitted, its .md suffix is
replaced with .pdf.
md2pdf.py: converter, command-line interface, and PDF stylesheet.pyproject.toml: package metadata, dependencies, andmd2pdfentry point.uv.lock: reproducible dependency resolution.input.mdandinput.pdf: optional local scratch files, intentionally ignored by Git.output/: optional directory for generated PDFs, also ignored by Git.
There is no automated test suite yet. After a change, at minimum run:
uv run --frozen md2pdf --help
mkdir -p output
uv run --frozen md2pdf input.md --output output/input.pdfUse a real Markdown fixture for the second command; input.md is not part of
the repository.