Markdown guide for PDFs

A PDF has pages, margins and a file name, which a web page doesn't. Each section below says how a Markdown element comes out in the PDF, then how to write it.

For more on one element, with examples to try, see the topic guides: tables, math, code blocks, footnotes, task lists and page breaks. The how-to guides cover particular jobs: writing a résumé, page size and margins and troubleshooting.

Tips for great PDFs

Headings

No page ends on a heading: md2pdf.me carries it over to sit with the text it introduces. Your first # heading also names the PDF file, and in the Report, Sandwake, Elvish, Cyberpunk, Newspaper and Fiendish styles it runs along the top of every page after the first. Academic numbers the sections below it for you.

Start a line with one to six # characters, one # for the title:

# Document title
## Section
### Subsection

Emphasis

Fonts are embedded in the PDF, so bold, italic and code look the same on any computer that opens it.

You typeYou get
*italic* or _italic_italic
**bold**bold
***bold italic***bold italic
~~strikethrough~~strikethrough
`code`code

Lists

Numbered lists number themselves, so 1. on every line still prints 1, 2, 3, and each level of a nested list steps in further.

Use -, * or + for bullets, a number and a period for steps, and two or more spaces to nest:

- Apples
- Oranges
  - Blood oranges

1. Preheat the oven
2. Mix the batter
3. Bake for 25 minutes

Links to web pages stay clickable in the PDF. On paper only the link's words show, so make them say where it goes. Images shrink to fit the width of the page, and one too tall for what's left of a page starts on the next.

[md2pdf.me](https://md2pdf.me)
<https://example.com>
![A description of the picture](https://example.com/photo.jpg)

Bare web addresses become links too. Images need to be on the web for the online converter to reach them; the command-line version can also use images on your computer.

Code

A long line of code folds onto the next line instead of running off the edge of the paper, and a short block that won't fit at the bottom of a page starts on the next rather than splitting. Name the language and the code is colored to suit the style.

Put three backticks above and below the code, with the language after the first:

```javascript
function greet(name) {
  return `Hello, ${name}!`;
}
```

The code blocks guide lists the language names and shows how code looks in each style.

Diagrams

Diagrams are drawn as shapes, not pictures, so they never blur when zoomed, and one that won't fit at the bottom of a page moves whole to the next page. They're greyscale in the Classic, Academic and Résumé styles, blue in the Modern and Report styles, in full color in the GitHub style, and in their own colors in the Worksheet style and the themed styles.

A code block named mermaid becomes a diagram, as on GitHub:

```mermaid
flowchart LR
  Draft --> Review --> Publish
  Review -- changes --> Draft
```

If a diagram has a mistake, the preview shows its code with the error above it, so you can fix it before downloading. The Mermaid cheat sheet has an example of each diagram type.

Math

Formulas print in LaTeX-style fonts embedded in the PDF, so they stay crisp when zoomed. An equation on a line of its own is kept in one piece, and one wider than the page is scaled down to fit.

One $ on each side puts math in a sentence, and $$ gives an equation its own line. LaTeX's \(…\) and \[…\] work too.

The area of a circle is $A = \pi r^2$.

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

The math guide covers the LaTeX you'll use most and numbered equations.

Tables

Page breaks fall between rows, so no row is cut in half, and Chrome and Edge print the header row again at the top of each page. A wide table wraps its cell text first and is scaled down only if it still overflows, so five or six short columns print at full size.

Put pipes between columns and a row of dashes under the header. Colons in the dashes align a column:

| Item    | Qty | Price  |
| :------ | :-: | -----: |
| Coffee  |  2  |  $6.00 |
| Bagel   |  1  |  $3.50 |

The tables guide shows how tables look in each style and what to do with a wide one.

Quotes & dividers

A quote is set off from the text and kept on one page when it fits. A divider prints as a line or an ornament that suits the style; in Classic it's a small ⁂, like a scene break in a book.

Start a line with > for a quote. Three dashes on a line of their own make a divider:

> The best way to predict the future is to invent it.

---

A quote that starts with [!, a type and ] prints as an alert, with its title and its own color, as in GitHub and Obsidian:

> [!TIP]
> Save your work before you print.

The types are NOTE, TIP, IMPORTANT, WARNING and CAUTION. README to PDF has more on these alerts, and Obsidian to PDF on Obsidian's callouts.

One exception to dividers: on a document's first line, followed by another --- line further down, three dashes start properties instead, which stay out of the PDF. That happens only when every line between the two --- lines is a property such as title: My notes. Otherwise the block isn't hidden, and prints as ordinary Markdown.

Task lists, footnotes & emoji

Each task gets a box, empty or ticked, that the style draws itself, so it looks right in whatever viewer opens the PDF. Footnotes are numbered for you and gathered at the end of the document, each number a link to its note. Emoji shortcodes, with the same names as GitHub and Slack, print as the emoji.

- [x] Draft the proposal
- [ ] Send it for review

Markdown was created in 2004.[^1]

[^1]: By John Gruber, with help from Aaron Swartz.

Ship it :rocket: :tada:

There's more on task lists and footnotes in their own guides.

Page breaks

This line ends the page, and doesn't show in the PDF. Markdown has no syntax for a page break, so it's a line of HTML; put a blank line before and after it:

<div class="page-break"></div>

The page breaks guide explains how to keep things together and check where pages end.

If something doesn't come out as expected, the troubleshooting guide covers the usual causes, from formatting lost on paste to images that don't load.

Open the converter