Using Markdown

Markdown is a special kind of markup language that lets you format text with simple syntax. You can then use a converter program like pandoc to convert Markdown into whatever format you want: HTML, PDF, Word, PowerPoint, etc. (see the full list of output types here)

Basic Markdown formatting

Type… …or… …to get
Some text in a paragraph.

More text in the next paragraph. Always
use empty lines between paragraphs.

Some text in a paragraph.

More text in the next paragraph. Always use empty lines between paragraphs.

*Italic* _Italic_ Italic
**Bold** __Bold__ Bold
# Heading 1

Heading 1

## Heading 2

Heading 2

### Heading 3

Heading 3

(Go up to heading level 6 with ######)
[Link text](http://www.example.com) Link text
![Image caption](/path/to/image.png) Penguins
`Inline code` with backticks Inline code with backticks
> Blockquote

Blockquote

- Things in
- an unordered
- list
* Things in
* an unordered
* list
  • Things in
  • an unordered
  • list
1. Things in
2. an ordered
3. list
1) Things in
2) an ordered
3) list
  1. Things in
  2. an ordered
  3. list
Horizontal line

---
Horizontal line

***

Horizontal line


Mathematical formulas

Markdown uses LaTeX to create fancy mathematical equations. There are like a billion little options and features available for math equations—you can find helpful examples of the the most common basic commands here.

You can use math in two different ways: inline or in a display block. To use math inline, wrap it in single dollar signs, like $y = mx + b$:

Type… …to get
Based on the DAG, the regression model for
estimating the effect of education on wages
is $\hat{y} = \beta_0 + \beta_1 x_1 + \epsilon$, or
$\text{Wages} = \beta_0 + \beta_1 \text{Education} + \epsilon$.
Based on the DAG, the regression model for estimating the effect of education on wages is \(\hat{y} = \beta_0 + \beta_1 x_1 + \epsilon\), or \(\text{Wages} = \beta_0 + \beta_1 \text{Education} + \epsilon\).

To put an equation on its own line in a display block, wrap it in double dollar signs, like this:

Type…

The quadratic equation was an important part of high school math:

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

But now we just use computers to solve for $x$.

…to get…

The quadratic equation was an important part of high school math:

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

But now we just use computers to solve for \(x\).


Because dollar signs are used to indicate math equations, you can’t just use dollar signs like normal if you’re writing about actual dollars. For instance, if you write This book costs $5.75 and this other costs $40, Markdown will treat everything that comes between the dollar signs as math, like so: “This book costs $5.75 and this other costs $40”.

To get around that, put a backslash (\) in front of the dollar signs, so that This book costs \$5.75 and this other costs \$40 becomes “This book costs $5.75 and this other costs $40”.

Tables

There are 4 different ways to hand-create tables in Markdown—I say “hand-create” because it’s normally way easier to use R to generate these things with packages like pander (use pandoc.table()) or knitr (use kable()). The two most common are simple tables and pipe tables. You can find the full documentation here.

For simple tables, type…

  Right     Left     Center     Default
-------     ------ ----------   -------
     12     12        12            12
    123     123       123          123
      1     1          1             1

Table: Caption goes here

…to get…

Caption goes here
Right Left Center Default
12 12 12 12
123 123 123 123
1 1 1 1

For pipe tables, type…

| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |

Table: Caption goes here

…to get…

Caption goes here
Right Left Default Center
12 12 12 12
123 123 123 123
1 1 1 1

Front matter

You can include a special section at the top of a Markdown document that contains metadata (or data about your document) like the title, date, author, etc. This section uses a special simple syntax named YAML (or “YAML Ain’t Markup Language”) that follows this basic outline: setting: value for setting. Here’s an example YAML metadata section. Note that it must start and end with three dashes (---).

---
title: Title of your document
date: "January 13, 2020"
author: "Your name"
---

You can put the values inside quotes (like the date and name in the example above), or you can leave them outside of quotes (like the title in the example above). I typically use quotes just to be safe—if the value you’re using has a colon (:) in it, it’ll confuse Markdown since it’ll be something like title: My cool title: a subtitle, which has two colons. It’s better to do this:

---
title: "My cool title: a subtitle"
---

If you want to use quotes inside one of the values (e.g. your document is An evaluation of "scare quotes"), you can use single quotes instead:

---
title: 'An evaluation of "scare quotes"'
---

Other references

These websites have additional details and examples and practice tools: