Pandoc markdown cheat sheet (with R Markdown and Quarto)
Updated
Pandoc's Markdown is standard markdown plus the extensions a document converter needs: a YAML header, {#id .class} attributes on anything, ::: fenced divs, definition lists, footnotes, [@key] citations, four table syntaxes and TeX math. R Markdown and Quarto add executable ```{r} chunks on top. Every example below is taken from the pandoc manual, quarto.org and rmarkdown.rstudio.com.
Pandoc extensions table
Extension names are what you pass after the format: -f markdown+emoji-smart.
| Feature | Extension | Syntax | Notes |
|---|---|---|---|
| YAML metadata | yaml_metadata_block | ---
title: My doc
author: Ana
--- | Must start with --- (no blank line after) and end with --- or ... |
| Heading attributes | header_attributes | # Intro {#intro .unnumbered} | Also {-} as shorthand for .unnumbered. |
| Fenced div | fenced_divs | ::: {.warning}
Text
::: | Nestable; a bare word (::: warning) is a class. |
| Bracketed span | bracketed_spans | [some text]{.smallcaps #id} | Inline element with attributes. |
| Definition list | definition_lists | Term
: Definition | Marker : or ~; blank line between items. |
| Footnote | footnotes | Text[^1]
[^1]: Note. | Definition can go anywhere outside blocks. |
| Inline footnote | inline_notes | Text^[Inline note.] | Single paragraph only. |
| Citation | citations | [@doe99; @smith04, p. 3] | Needs --citeproc and --bibliography. |
| Pipe table | pipe_tables | | a | b |
|--:|:--| | No block content in cells. |
| Grid table | grid_tables | +---+---+
| a | b |
+===+===+ | Block content and spans allowed. |
| Multiline table | multiline_tables | ----- -----
Head Head
----- ----- | Rows separated by blank lines. |
| Table caption | table_captions | Table: Caption text | Before or after the table; ":" alone also works. |
| Inline math | tex_math_dollars | $x^2$ | No space after opening or before closing $. |
| Display math | tex_math_dollars | $$
\\int_0^1 f
$$ | No blank lines inside. |
| Superscript / subscript | superscript, subscript | 2^10^ H~2~O | Escape inner spaces: P~a\\ cat~. |
| Strikeout | strikeout | ~~deleted~~ | Same as GFM. |
| Line block | line_blocks | | Line one
| Line two | Preserves line breaks (verse, addresses). |
| Example list | example_lists | (@good) Example.
See (@good). | Numbered continuously across the document. |
| Fenced code attributes | fenced_code_attributes | ```{.python .numberLines startFrom="10"} | Classes, id and key=value on fences. |
| Raw block | raw_attribute | ```{=latex}
\
ewpage
``` | Passed through only to that output format. |
| Link / image attributes | link_attributes | {width=50%} | width, height, #id, .class. |
| Implicit figure | implicit_figures |  | An image alone in a paragraph becomes a captioned figure. |
| Task list | task_lists | - [x] done
- [ ] todo | Same as GFM. |
| Smart punctuation | smart | "quotes" -- --- ... | Curly quotes, en/em dashes, ellipsis. |
Metadata, attributes, divs and spans
YAML metadata block
---
title: Quarterly report
author:
- Ana Ruiz
- Ben Okafor
date: 2026-10-15
abstract: |
Two paragraphs are fine here.
---String values are themselves parsed as markdown; the block may appear anywhere if preceded by a blank line, but the top is conventional.
Heading identifiers and classes
# My heading {#foo}
## Appendix {.unnumbered}
## Also unnumbered {-}
See [the heading](#foo).Identifiers are used for links and LaTeX labels; .unnumbered (or -) keeps a heading out of --number-sections.
Fenced divs
::::: {#special .sidebar}
Here is a paragraph.
And another.
:::::
::: Warning ::::::
This is a warning.
::: Danger
This is a warning within a warning.
:::
::::::::::::::::::Opening fences must carry attributes (or a single class word); a fence without attributes always closes. Nesting works, with any number of colons ≥ 3.
Bracketed spans and raw blocks
[This is *some text*]{.class key="val"}
This is `<a>html</a>`{=html} inline.
```{=latex}
\newpage
```{=format} marks raw content passed only to that writer (html, latex, openxml for docx, typst).
Definition lists, footnotes, example lists
Definition list
Term 1
: Definition 1
Term 2 with *inline markup*
: Definition 2
{ some code, part of Definition 2 }
Third paragraph of definition 2.Each term on one line, followed by one or more definitions starting with : or ~; a term may have several definitions.
Footnotes, regular and inline
Here is a footnote reference,[^1] and another.[^longnote]
[^1]: Here is the footnote.
[^longnote]: Here's one with multiple blocks.
Subsequent paragraphs are indented.
Here is an inline note.^[Inline notes are easier to write.]Identifiers may not contain spaces or ^ [ ]; footnotes are renumbered sequentially in output.
Numbered example lists
(@) My first example will be numbered (1).
(@) My second example will be numbered (2).
Explanation of examples.
(@good) This is a good example.
As (@good) illustrates, ...The @ marker counts across the whole document, and labelled examples can be referenced later by label.
Citations
Citation forms
Blah blah [@doe99; @smith2000; @smith2004].
Blah blah [see @doe99, pp. 33-35 and *passim*; @smith04, chap. 1].
Smith says blah [-@smith04].
@smith04 says blah.
@smith04 [p. 33] says blah.Keys come from a BibTeX/CSL JSON/YAML bibliography; run pandoc --citeproc --bibliography refs.bib, and put ::: {#refs} ::: where the bibliography should go.
Locators and odd keys
[@smith{ii, A, D-Z}, with a suffix]
[@{https://example.com/bib?name=foobar&date=2000}, p. 33]Curly braces force a locator or protect a key that contains punctuation such as a URL.
Tables: pipe, grid, multiline, simple
Pipe table with caption
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
: Demonstration of pipe table syntax.| Right | Left | Default | Center |
|---|---|---|---|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
Table: Demonstration of pipe table syntax.
Cells cannot hold block elements; relative column widths come from the dash counts when any line exceeds --columns.
Grid table (block content, spans)
: Sample grid table.
+---------------+---------------+--------------------+
| Fruit | Price | Advantages |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Oranges | $2.10 | - cures scurvy |
| | | - tasty |
+---------------+---------------+--------------------+The = row separates header from body (omit it for a headerless table); cells may contain lists, paragraphs and code, and can span rows or columns.
Multiline table
-------------------------------------------------------------
Centered Default Right Left
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of a row that
spans multiple lines.
Second row 5.0 Here's another one. Note
the blank line between
rows.
-------------------------------------------------------------
Table: Here's the caption.Rows are separated by blank lines so cell text can wrap; alignment follows where the header text sits relative to the dashes.
Simple table
Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
Table: Demonstration of simple table syntax.Columns are defined by the dashed line; one row per line, no wrapping.
Math, super/subscript, line blocks, code attributes
TeX math
Inline: $E = mc^2$ and display:
$$
\int_0^1 x^2 \, dx = \frac{1}{3}
$$The opening $ needs a non-space to its right and the closing $ a non-space to its left (and no digit after), so $20,000 and $30,000 stay plain text.
Superscript and subscript
H~2~O is a liquid. 2^10^ is 1024. P~a\ cat~H<sub>2</sub>O is a liquid. 2<sup>10</sup> is 1024. P<sub>a cat</sub>
Spaces inside ^…^ or ~…~ must be backslash-escaped; a single tilde is subscript, not strikethrough.
Line block
| The limerick packs laughs anatomical
| In space that is quite economical.
| But the good ones I've seen
| So seldom are cleanLine breaks and leading spaces are preserved; inline formatting still applies.
Fenced code with attributes
~~~~ {#mycode .haskell .numberLines startFrom="100"}
qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
qsort (filter (>= x) xs)
~~~~Tildes or backticks both fence; .numberLines turns on line numbers in HTML and LaTeX output.
R Markdown and Quarto
Both wrap pandoc markdown around executable code chunks. The chunk header differs: R Markdown puts options in the braces, Quarto puts them on #| lines.
R Markdown document (.Rmd)
---
title: "Air quality"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Temperature vs ozone
```{r ozone-plot, echo=FALSE, fig.cap="Temperature and ozone level.", warning=FALSE}
plot(airquality$Temp, airquality$Ozone)
```
The mean temperature was `r mean(airquality$Temp)` degrees.Chunk options are comma-separated R arguments after the optional label; inline code `r expr` prints a value in prose and accepts no options.
Quarto document (.qmd)
---
title: "ggplot2 demo"
author: "Norah Jones"
date: "5/22/2021"
format:
html:
code-fold: true
execute:
echo: false
---
```{r}
#| label: fig-airquality
#| fig-cap: "Temperature and ozone level."
#| warning: false
library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) + geom_point() + geom_smooth(method = "loess")
```
See @fig-airquality.Lines at the top of a cell prefixed with #| are options; execute: in the header sets document-wide defaults; ```{python} and ```{julia} cells work the same way.
Render commands
quarto render document.qmd # all formats in the header
quarto render document.qmd --to pdf
Rscript -e 'rmarkdown::render("document.Rmd")'Both call pandoc underneath, so every pandoc extension on this page is available inside .Rmd and .qmd files.
Conversion command table
| Goal | Command | Notes |
|---|---|---|
| Markdown to Word | pandoc doc.md -o doc.docx | Format inferred from the extension. |
| Word with your styles | pandoc doc.md --reference-doc=template.docx -o doc.docx | Styles (Heading 1, Body Text…) copied from the reference file. |
| Markdown to PDF (LaTeX) | pandoc doc.md -o doc.pdf | Needs pdflatex/xelatex installed. |
| PDF without LaTeX | pandoc doc.md --pdf-engine=typst -o doc.pdf | Also wkhtmltopdf, weasyprint, context, lualatex. |
| Standalone HTML | pandoc doc.md -s -o doc.html | -s adds <html>, <head> and CSS; omit for a fragment. |
| Single-file HTML | pandoc doc.md -s --embed-resources -o doc.html | Inlines images and CSS; --self-contained is the deprecated synonym. |
| HTML with math | pandoc doc.md -s --mathjax -o doc.html | --mathjax is now spelled --math-method=mathjax. |
| HTML with a stylesheet and TOC | pandoc doc.md -s --toc -c style.css -o doc.html | --toc-depth=2 limits levels. |
| EPUB | pandoc doc.md -o book.epub --metadata title="Title" | Chapters split at level-1 headings; add --epub-cover-image. |
| With citations | pandoc doc.md --citeproc --bibliography=refs.bib --csl=apa.csl -o doc.docx | Bibliography appended automatically. |
| Explicit formats | pandoc -f markdown -t gfm doc.md -o README.md | Pandoc markdown to GitHub Flavored Markdown. |
| Toggle an extension | pandoc -f markdown-smart+hard_line_breaks doc.md -o doc.html | -name disables, +name enables. |
| Jira / Confluence wiki markup | pandoc -t jira doc.md | Writer for Atlassian wiki markup. |
| Many files to one book | pandoc ch1.md ch2.md ch3.md metadata.yaml -s -o book.html | Inputs are concatenated; metadata can live in its own YAML file. |
| Reverse: Word/HTML to markdown | pandoc doc.docx -t gfm -o doc.md | Add --extract-media=./img to pull images out. |
Flags from the pandoc options reference. No pandoc installed? The markdown to Word, markdown to PDF and markdown to HTML tools run in the browser.
Chunk options: R Markdown vs Quarto
| Goal | R Markdown ```{r …} | Quarto #| | Meaning |
|---|---|---|---|
| Hide code, show output | echo=FALSE | echo: false | Prevents code, but not results, from appearing. |
| Run but hide everything | include=FALSE | include: false | Code runs; no code or results in the document. |
| Do not run | eval=FALSE | eval: false | Code is shown but not executed. |
| Hide warnings | warning=FALSE | warning: false | Warnings generated by the code are dropped. |
| Hide messages | message=FALSE | message: false | Messages (e.g. package loading) are dropped. |
| Continue on error | error=TRUE | error: true | Errors are printed instead of stopping the render. |
| Figure caption | fig.cap="…" | fig-cap: "…" | Caption under a plot; Quarto also has fig-alt. |
| Chunk label | {r my-label} | label: my-label | Names the chunk; fig- prefix enables cross-references in Quarto. |
| Output handling | results='asis' | output: asis | Treat printed text as raw markdown. |
What is Pandoc markdown?
Pandoc's Markdown is the input dialect of the pandoc document converter: original markdown plus a long list of extensions — YAML metadata, fenced divs and bracketed spans with attributes, definition lists, four table syntaxes, footnotes, citations, TeX math, superscript and subscript, example lists and raw format blocks. Each extension has a name (footnotes, fenced_divs, citations) that can be switched with +name or -name after the format, e.g. -f markdown-smart.
How do I convert markdown to Word, PDF or HTML with pandoc?
pandoc input.md -o output.docx for Word, pandoc input.md -o output.pdf (needs a LaTeX engine, or add --pdf-engine=wkhtmltopdf / typst) for PDF, and pandoc input.md -s -o output.html for a standalone HTML page. The output format is inferred from the extension; -t sets it explicitly. Add --toc for a table of contents and --reference-doc=styles.docx to apply Word styles.
How do citations work in pandoc markdown?
Write [@doe99] for a parenthetical citation, @doe99 for author-in-text, [-@doe99] to suppress the author, and [see @doe99, pp. 33-35; @smith04, chap. 1] for prefixes, locators and multiple items. Run pandoc with --citeproc --bibliography refs.bib (and optionally --csl style.csl); the bibliography is appended where a div with id="refs" is placed, or at the end.
What is the difference between a pipe table and a grid table in pandoc?
Pipe tables are the familiar | a | b | syntax: easy to write, but cells cannot contain block elements and cannot span lines. Grid tables draw the cell borders with +, - and |; cells may contain paragraphs, lists and code blocks, and can span rows and columns. Simple and multiline tables are whitespace-aligned alternatives; all four accept a caption line starting with "Table:" or ":".
What is the difference between R Markdown and Quarto?
Both put executable code chunks (```{r}) inside pandoc markdown and render through pandoc. R Markdown (rmarkdown + knitr) sets chunk options inside the braces: ```{r name, echo=FALSE}. Quarto (.qmd, the quarto CLI) sets them on #| comment lines inside the chunk (#| echo: false), uses hyphenated names (fig-cap instead of fig.cap), supports Python and Julia natively through Jupyter, and reads document-wide defaults from an execute: block in the YAML header.
How do I add a footnote or a definition list in pandoc markdown?
Footnote: a reference [^note] in the text and a definition [^note]: text anywhere outside other blocks, or an inline note ^[like this] with no identifier. Definition list: the term on one line, then one or more lines starting with a colon or tilde (": definition"), each definition indented to align after the marker.
How do I write math in pandoc markdown?
Inline math between single dollar signs ($E = mc^2$) with no space inside the dollars; display math between double dollars ($$ … $$). For HTML output add --mathjax (now --math-method=mathjax) or --katex; LaTeX and PDF output render it natively; docx output converts it to Word equations.
Related
Markdown cheat sheet · MDX cheat sheet · Jira wiki markup · Markdown to Word · Markdown to PDF · Footnotes guide · Page break guide