Why Pandoc Is the Markdown to PDF Tool
Pandoc is the universal document converter. From Markdown source, it produces PDF (via LaTeX or weasyprint), HTML, EPUB, DOCX, and dozens of other formats.
For technical writing, academic papers, books, and documentation: Pandoc + Markdown is the production-grade alternative to Word + Acrobat. The source files are version-control friendly (Git), the output is publishing-quality, and the workflow is automatable.
This post covers the practical Pandoc workflow for high-quality PDF from Markdown. For broader document conversion, see our document converter.
Pandoc Installation
# Mac
brew install pandoc
# Linux (Ubuntu/Debian)
sudo apt install pandoc
# Windows
choco install pandoc
For PDF output via LaTeX:
# Mac
brew install --cask mactex
# Linux
sudo apt install texlive-full
# Windows
choco install miktex
LaTeX is the typesetting engine that produces print-quality PDF. Total install: ~3-5 GB.
Basic Markdown to PDF
pandoc input.md -o output.pdf
Default LaTeX template produces clean output. For most documents: this is sufficient.
For Pandoc with specific options:
pandoc input.md \
--pdf-engine=xelatex \
--toc \
--number-sections \
--highlight-style=tango \
--metadata title="Document Title" \
--metadata author="Author Name" \
-o output.pdf
Parameters:
--pdf-engine=xelatex: better Unicode/font support--toc: table of contents--number-sections: numbered headings--highlight-style: code syntax highlighting style--metadata: document metadata
YAML Frontmatter for Metadata
Markdown supports YAML frontmatter for document metadata:
---
title: My Document Title
author: Jane Doe
date: 2026-05-08
toc: true
toc-depth: 3
numbersections: true
geometry: margin=1in
fontsize: 11pt
mainfont: "Liberation Sans"
mathfont: "Latin Modern Math"
---
# Introduction
This is the document body.
Pandoc reads the frontmatter and applies the metadata to the LaTeX template. No need for command-line flags.
Custom LaTeX Templates
For book-quality output, use a custom template:
pandoc input.md \
--template=my-template.tex \
--pdf-engine=xelatex \
-o output.pdf
Pandoc has community templates for academic papers, books, theses, and more. Browse at github.com/Wandmalfarbe/pandoc-latex-template or similar.
For custom design: write your own LaTeX template. Steep learning curve but produces exactly the look you want.
Code Highlighting
Pandoc highlights code blocks automatically:
def hello():
print("Hello, world!")
Highlight styles:
- pygments (default)
- tango
- breezedark
- espresso
- haddock
- kate
- zenburn
- monochrome (no color)
pandoc input.md --highlight-style=tango -o output.pdf
For code-heavy documentation: tango or breezedark provide good readability.
Tables and Math
Pandoc handles complex tables and LaTeX math:
| Column 1 | Column 2 |
| -------- | -------- |
| Data | Data |
| Data | Data |
The equation is $E = mc^2$.
Block math:
$$
\int_a^b f(x) \, dx
$$
Math renders via LaTeX in PDF output. Browser-rendered HTML output uses MathJax or KaTeX.
Table of Contents
For automatic TOC:
pandoc input.md --toc --toc-depth=3 -o output.pdf
--toc-depth=3 includes H1, H2, H3 in TOC.
For YAML frontmatter equivalent:
---
toc: true
toc-depth: 3
---
Citations and Bibliography
For academic writing, Pandoc supports BibTeX citations:
This research [@smith2020] showed...
# References
pandoc input.md \
--bibliography=references.bib \
--csl=apa.csl \
--citeproc \
-o output.pdf
CSL (Citation Style Language) files define citation formats. Hundreds available at zotero.org.
For broader academic writing context, see our document converter.
Cover Page and Page Layout
For professional documents:
---
title: My Document
author: Jane Doe
date: 2026-05-08
documentclass: book
classoption: openany
geometry: a4paper, margin=2.5cm, top=3cm
header-includes:
- \usepackage{graphicx}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
The documentclass: book produces book-style output (chapter pages, full-page formatting). report is for shorter documents. article is the default.
Multiple Files
For long documents (books, theses), split into multiple Markdown files:
pandoc \
cover.md \
chapter1.md \
chapter2.md \
chapter3.md \
--toc \
-o book.pdf
Pandoc concatenates the files in order. Useful for collaborative writing where each chapter is a separate file.
For batch processing patterns, see Batch Processing Files Guide.
Filters and Lua Scripts
Pandoc supports filters that modify the document during conversion:
pandoc input.md --lua-filter=mycustom.lua -o output.pdf
Common filter use cases:
- Custom syntax highlighting
- Auto-numbering sections
- Cross-references
- Custom output styling
The Lua filter ecosystem is extensive. github.com/pandoc/lua-filters has community filters.
Alternative Backends
Pandoc supports multiple PDF engines:
| Engine | Quality | Speed | Setup |
|---|---|---|---|
| pdflatex (default) | Excellent | Fast | LaTeX install |
| xelatex | Better Unicode | Slower | LaTeX install |
| lualatex | Most flexible | Slowest | LaTeX install |
| weasyprint (HTML/CSS) | Good | Fast | Python package |
| wkhtmltopdf | Decent | Fast | Standalone binary |
For Unicode-heavy documents (international): xelatex. For simplest install (no LaTeX): weasyprint.
File Size
For typical 50-page document:
| Engine | Output size |
|---|---|
| pdflatex | 200-400 KB |
| xelatex | 400-800 KB |
| weasyprint | 300-600 KB |
| wkhtmltopdf | 200-500 KB |
For simple documents: 100 KB. For image-heavy documents: file size depends on image resolution and compression.
Common Issues
LaTeX error on first run: missing package. Install full TeX distribution (mactex, texlive-full).
Unicode characters fail: pdflatex doesn't handle all Unicode. Switch to xelatex with --pdf-engine=xelatex.
Large fonts in headings render badly: font not available. Specify with mainfont and mathfont in YAML.
Math formula doesn't compile: check syntax. Pandoc strict math mode requires proper LaTeX.
Code highlighting wrong language: specify language explicitly:
```python
def hello():
pass
```
For broader publishing workflow, see [PowerPoint to MP4](/blog/pptx-to-mp4-narrated-video-export).
## Frequently Asked Questions
### Should I use Pandoc or Word?
For technical writing: Pandoc (Markdown source, version control friendly). For complex layouts: Word may be faster initially. For long documents and books: Pandoc + LaTeX produces better output.
### Can I convert PDF back to Markdown?
Yes via Pandoc, but layout is lost. Better: keep Markdown source as primary, regenerate PDF as needed.
### What about EPUB output?
```bash
pandoc input.md -o output.epub
Pandoc generates EPUB cleanly from Markdown. For ebook publishing.
Does Pandoc handle MDX?
MDX (Markdown + JSX) is React-specific. Pandoc handles standard Markdown. For MDX: use the React/Next.js build pipeline.
How do I add a logo or watermark?
Use LaTeX \includegraphics in custom template, or Pandoc's header-includes YAML field.
Can I produce books for Kindle?
Yes via Pandoc to EPUB to KFX (via Kindle Previewer). Quality is good for text-heavy books.
For ebook context, see M4B Audiobook Chapters.
Related Reading
Bottom Line
For Markdown to PDF in 2026: Pandoc with LaTeX backend (pdflatex or xelatex). Use YAML frontmatter for metadata, custom templates for design, citation processing for academic writing. Output rivals book-quality typography. Our document converter handles related format conversions.



