Convert a markdown file to PDF using pandoc
Convert markdown files to professionally formatted PDF documents using pandoc.
When the user asks to convert a markdown file to PDF, follow these steps:
Verify pandoc is installed
pandoc --version to check if pandoc is availablebrew install pandocsudo apt-get install pandoc or sudo yum install pandocCheck for PDF engine
pdflatex --versionbrew install --cask mactex-no-gui (smaller) or brew install --cask mactex (full)sudo apt-get install texlive-latex-base texlive-fonts-recommendedwkhtmltopdf as PDF engineConvert the markdown file
pandoc input.md -o output.pdfpandoc input.md -o output.pdf \
--pdf-engine=pdflatex \
-V geometry:margin=1in \
-V fontsize=11pt \
--highlight-style=tango
Common options
--toc: Add table of contents--toc-depth=2: Set TOC depth-V geometry:margin=1in: Set page margins-V fontsize=11pt: Set font size (10pt, 11pt, 12pt)--highlight-style=tango: Syntax highlighting for code blocks-V colorlinks=true: Enable colored links in PDF--metadata title="Document Title": Set PDF title--metadata author="Author Name": Set PDF authorVerify output
User: Convert README.md to PDF
Assistant: I'll convert README.md to PDF using pandoc.
[Runs: pandoc README.md -o README.pdf]
Successfully converted README.md to README.pdf
User: Convert CLAUDE.md to PDF with a table of contents
Assistant: I'll convert CLAUDE.md to PDF with a table of contents and formatting.
[Runs: pandoc CLAUDE.md -o CLAUDE.pdf --toc -V geometry:margin=1in -V fontsize=11pt]
Successfully converted CLAUDE.md to CLAUDE.pdf with table of contents
User: Convert docs/guide.md to a PDF called user-guide.pdf
Assistant: I'll convert docs/guide.md to user-guide.pdf
[Runs: pandoc docs/guide.md -o user-guide.pdf -V geometry:margin=1in --highlight-style=tango]
Successfully converted docs/guide.md to user-guide.pdf
User: Convert all markdown files in the docs/ folder to PDF
Assistant: I'll convert all markdown files in docs/ to PDF
[Runs: for file in docs/*.md; do pandoc "$file" -o "${file%.md}.pdf"; done]
Successfully converted:
- docs/guide.md → docs/guide.pdf
- docs/api.md → docs/api.pdf
- docs/tutorial.md → docs/tutorial.pdf
--pdf-engine-opt=-shell-escape if needed