Pandoc Cheatsheet

Universal document converter

Tool
Contents
🔄

Basic Conversion

# Basic syntax
pandoc input.md -o output.html
pandoc input.md -o output.pdf
pandoc input.md -o output.docx

# Specify formats explicitly
pandoc -f markdown -t html input.md
pandoc -f html -t markdown page.html

# From stdin
echo "# Hello" | pandoc -t html

# Multiple input files
pandoc ch1.md ch2.md ch3.md -o book.pdf

# Standalone (full HTML with head)
pandoc -s input.md -o output.html
📋

Supported Formats

# Input formats (-f / --from):
markdown, gfm, commonmark,
html, latex, rst, textile,
docx, odt, epub, mediawiki,
org, csv, json, yaml

# Output formats (-t / --to):
html, html5, latex, pdf,
docx, odt, epub, epub3,
rst, asciidoc, mediawiki,
pptx, revealjs, beamer,
man, plain, json, icml

# List all formats
pandoc --list-input-formats
pandoc --list-output-formats
📝

Markdown Options

# GitHub Flavored Markdown
pandoc -f gfm -t html input.md

# Enable extensions
pandoc -f markdown+emoji+task_lists

# Disable extensions
pandoc -f markdown-smart

# Common extensions:
+task_lists          - [ ] checkboxes
+emoji               :smile:
+pipe_tables         | tables |
+footnotes           [^1] style
+yaml_metadata_block YAML front matter
+tex_math_dollars    $math$ support
+smart               Smart quotes/dashes
+strikeout           ~~strikethrough~~

# Table of contents
pandoc --toc -s input.md -o output.html
📄

PDF Output

# Requires LaTeX (pdflatex, xelatex, etc.)
pandoc input.md -o output.pdf

# Use XeLaTeX (better Unicode)
pandoc --pdf-engine=xelatex input.md -o output.pdf

# Custom margins
pandoc -V geometry:margin=1in input.md -o out.pdf

# Font
pandoc --pdf-engine=xelatex \
  -V mainfont="Helvetica" input.md -o out.pdf

# Via HTML (wkhtmltopdf or weasyprint)
pandoc --pdf-engine=weasyprint input.md -o out.pdf

# Paper size
pandoc -V papersize:a4 input.md -o out.pdf

# Syntax highlighting style
pandoc --highlight-style=tango input.md -o out.pdf
🎨

Templates & Variables

# YAML front matter (in .md file):
---
title: "My Document"
author: "Name"
date: "2024-01-01"
---

# Pass variables from CLI
pandoc -V title="Report" -V author="Me"

# Use custom template
pandoc --template=custom.html input.md -o out.html

# Print default template
pandoc -D html > template.html
pandoc -D latex > template.tex

# Custom CSS
pandoc -s --css=style.css input.md -o out.html

# Include in header/before/after body
pandoc -H header.html -B before.html -A after.html

Advanced Features

# Slide shows
pandoc -t revealjs -s slides.md -o slides.html
pandoc -t beamer slides.md -o slides.pdf

# Filters (Lua)
pandoc --lua-filter=filter.lua input.md

# Bibliography (citations)
pandoc --citeproc --bibliography=refs.bib

# Number sections
pandoc --number-sections

# Extract media from docx
pandoc --extract-media=./media input.docx -o out.md

# Convert notebook
pandoc notebook.ipynb -o output.md

# Batch convert
for f in *.md; do
  pandoc "$f" -o "${f%.md}.html"
done