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.

FeatureExtensionSyntaxNotes
YAML metadatayaml_metadata_block--- title: My doc author: Ana ---Must start with --- (no blank line after) and end with --- or ...
Heading attributesheader_attributes# Intro {#intro .unnumbered}Also {-} as shorthand for .unnumbered.
Fenced divfenced_divs::: {.warning} Text :::Nestable; a bare word (::: warning) is a class.
Bracketed spanbracketed_spans[some text]{.smallcaps #id}Inline element with attributes.
Definition listdefinition_listsTerm : DefinitionMarker : or ~; blank line between items.
FootnotefootnotesText[^1] [^1]: Note.Definition can go anywhere outside blocks.
Inline footnoteinline_notesText^[Inline note.]Single paragraph only.
Citationcitations[@doe99; @smith04, p. 3]Needs --citeproc and --bibliography.
Pipe tablepipe_tables| a | b | |--:|:--|No block content in cells.
Grid tablegrid_tables+---+---+ | a | b | +===+===+Block content and spans allowed.
Multiline tablemultiline_tables----- ----- Head Head ----- -----Rows separated by blank lines.
Table captiontable_captionsTable: Caption textBefore or after the table; ":" alone also works.
Inline mathtex_math_dollars$x^2$No space after opening or before closing $.
Display mathtex_math_dollars$$ \\int_0^1 f $$No blank lines inside.
Superscript / subscriptsuperscript, subscript2^10^ H~2~OEscape inner spaces: P~a\\ cat~.
Strikeoutstrikeout~~deleted~~Same as GFM.
Line blockline_blocks| Line one | Line twoPreserves line breaks (verse, addresses).
Example listexample_lists(@good) Example. See (@good).Numbered continuously across the document.
Fenced code attributesfenced_code_attributes```{.python .numberLines startFrom="10"}Classes, id and key=value on fences.
Raw blockraw_attribute```{=latex} \ ewpage ```Passed through only to that output format.
Link / image attributeslink_attributes![Alt](img.png){width=50%}width, height, #id, .class.
Implicit figureimplicit_figures![Caption](img.png)An image alone in a paragraph becomes a captioned figure.
Task listtask_lists- [x] done - [ ] todoSame as GFM.
Smart punctuationsmart"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.

Front matter generator →

Heading identifiers and classes

# My heading {#foo}

## Appendix {.unnumbered}

## Also unnumbered {-}

See [the heading](#foo).

My heading

Appendix

Also unnumbered

See the heading.

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.

Definition list guide →

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.]

Here is a footnote reference,1 and another.2

Here is an inline note.3

Footnotes

  1. Here is the footnote. ↩

  2. Here's one with multiple blocks.

    Subsequent paragraphs are indented. ↩

  3. 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.
RightLeftDefaultCenter
12121212
123123123123

Table: Demonstration of pipe table syntax.

Cells cannot hold block elements; relative column widths come from the dash counts when any line exceeds --columns.

Table guide →

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.

Math guide →

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 clean

Line 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

GoalCommandNotes
Markdown to Wordpandoc doc.md -o doc.docxFormat inferred from the extension.
Word with your stylespandoc doc.md --reference-doc=template.docx -o doc.docxStyles (Heading 1, Body Text…) copied from the reference file.
Markdown to PDF (LaTeX)pandoc doc.md -o doc.pdfNeeds pdflatex/xelatex installed.
PDF without LaTeXpandoc doc.md --pdf-engine=typst -o doc.pdfAlso wkhtmltopdf, weasyprint, context, lualatex.
Standalone HTMLpandoc doc.md -s -o doc.html-s adds <html>, <head> and CSS; omit for a fragment.
Single-file HTMLpandoc doc.md -s --embed-resources -o doc.htmlInlines images and CSS; --self-contained is the deprecated synonym.
HTML with mathpandoc doc.md -s --mathjax -o doc.html--mathjax is now spelled --math-method=mathjax.
HTML with a stylesheet and TOCpandoc doc.md -s --toc -c style.css -o doc.html--toc-depth=2 limits levels.
EPUBpandoc doc.md -o book.epub --metadata title="Title"Chapters split at level-1 headings; add --epub-cover-image.
With citationspandoc doc.md --citeproc --bibliography=refs.bib --csl=apa.csl -o doc.docxBibliography appended automatically.
Explicit formatspandoc -f markdown -t gfm doc.md -o README.mdPandoc markdown to GitHub Flavored Markdown.
Toggle an extensionpandoc -f markdown-smart+hard_line_breaks doc.md -o doc.html-name disables, +name enables.
Jira / Confluence wiki markuppandoc -t jira doc.mdWriter for Atlassian wiki markup.
Many files to one bookpandoc ch1.md ch2.md ch3.md metadata.yaml -s -o book.htmlInputs are concatenated; metadata can live in its own YAML file.
Reverse: Word/HTML to markdownpandoc doc.docx -t gfm -o doc.mdAdd --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

GoalR Markdown ```{r …}Quarto #|Meaning
Hide code, show outputecho=FALSEecho: falsePrevents code, but not results, from appearing.
Run but hide everythinginclude=FALSEinclude: falseCode runs; no code or results in the document.
Do not runeval=FALSEeval: falseCode is shown but not executed.
Hide warningswarning=FALSEwarning: falseWarnings generated by the code are dropped.
Hide messagesmessage=FALSEmessage: falseMessages (e.g. package loading) are dropped.
Continue on errorerror=TRUEerror: trueErrors are printed instead of stopping the render.
Figure captionfig.cap="…"fig-cap: "…"Caption under a plot; Quarto also has fig-alt.
Chunk label{r my-label}label: my-labelNames the chunk; fig- prefix enables cross-references in Quarto.
Output handlingresults='asis'output: asisTreat 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.

Browser-side markdown to Word (no install) →

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 ":".

Pipe table generator →

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.

Footnotes guide →

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.

Markdown math guide →

Related

Markdown cheat sheet · MDX cheat sheet · Jira wiki markup · Markdown to Word · Markdown to PDF · Footnotes guide · Page break guide