Markdown to PDF
Convert markdown to PDF using pandoc with xelatex. Produces clean sans-serif output with syntax-highlighted code blocks.
Prerequisites
pandoc(brew install pandoc)basictex(brew install --cask basictex)- LaTeX packages:
sudo tlmgr install fontspec unicode-math selnolig upquote microtype parskip xurl bookmark fancyvrb csquotes framed fvextra
Command
pandoc INPUT.md -o OUTPUT.pdf \
--resource-path=DIRECTORY_CONTAINING_IMAGES \
--pdf-engine=xelatex \
-H ~/.claude/skills/md-to-pdf/wrap-code.tex \
-V mainfont="Helvetica Neue" \
-V monofont="Menlo" \
-V fontsize=11pt \
-V geometry:margin=1in \
-V colorlinks=true \
-V linkcolor=NavyBlue \
-V urlcolor=NavyBlue \
--syntax-highlighting=tango
Usage Notes
--resource-pathmust point to the directory containing any images referenced in the markdown (relative paths). Usually the directory the markdown file lives in.-H wrap-code.texloadsfvextraand redefines pandoc'sHighlightingenvironment withbreaklines/breakanywhere, so long lines in code blocks wrap inside the page (with a↪continuation marker) instead of running off the right edge.- On macOS,
Helvetica NeueandMenloare always available. On Linux, substitute withDejaVu Sans/DejaVu Sans Mono. On Windows,Segoe UI/Cascadia Code. Helvetica Neuelacks some glyphs (e.g.→ U+2192). If pandoc warnsMissing character, pre-process the source to render those glyphs as math, e.g.sed 's/→/$\\rightarrow$/g' IN.md > tmp.md, then converttmp.md.- If the output PDF lands in a sandboxed-unwritable directory (e.g.
~/Downloads), write to$TMPDIRfirst andmvit to the destination. - The
tangosyntax highlighting theme works well with light backgrounds. Other options:kate,monochrome,espresso,haddock,zenburn.