md2pdf
Convert Markdown files to beautifully typeset PDF using Pandoc + LaTeX.
Prerequisites
- pandoc —
winget install pandocor https://pandoc.org/installing.html - LaTeX engine — XeLaTeX recommended (bundled with TeX Live or MiKTeX). Install via:
winget install MiKTeXor https://miktex.org/download- Or
winget install TeXLivefor TeX Live
The script auto-detects available engines in order: xelatex > lualatex > pdflatex.
Quick Start
Run the bundled script:
python scripts/md2pdf.py <input.md> [output.pdf]
Options:
--toc— Include table of contents--css <file>— Apply custom CSS stylesheet--highlight <style>— Code highlight style (default:tango)
Default Behavior
The script applies these defaults when using XeLaTeX/LuaLaTeX (the preferred engines):
- CJK support: SimSun (serif), SimHei (sans), Microsoft YaHei (mono)
- Margin: 1 inch all sides
- Code blocks: syntax highlighted with Pygments
Workflow
- Confirm the input
.mdfile exists and is readable - Run
scripts/md2pdf.pywith appropriate options - If pandoc or LaTeX is missing, report the installation instructions to the user
- Return the generated PDF path to the user (send the file if applicable)
Advanced: Direct Pandoc Calls
For options not covered by the script, call pandoc directly:
# Custom LaTeX template
pandoc input.md -o output.pdf --pdf-engine=xelatex --template=custom.tex
# Specific page size
pandoc input.md -o output.pdf --pdf-engine=xelatex -V geometry:margin=2cm -V papersize:a4
# Metadata
pandoc input.md -o output.pdf --pdf-engine=xelatex -V title="My Report" -V author="Author"
微信扫一扫