7. MyST Markdown cheatsheet


Credits: This page is copied from the Jupyterbook Myst Cheatsheet


7.1. Headers

Syntax

Example

Note

# Heading level 1
## Heading level 2
### Heading level 3
#### Heading level 4
##### Heading level 5
###### Heading level 6
Copy to clipboard
# MyST Cheat Sheet
Copy to clipboard

Level 1-6 headings, denoted by number of #

7.2. Target headers

Syntax

Example

Note

(target_header)=
Copy to clipboard
(myst_cheatsheet)=
# MyST Cheat Sheet
Copy to clipboard

See below how to reference target headers.

7.2.1. Referencing target headers

Targets can be referenced with the ref inline role which uses the section title by default:

{ref}`myst_cheatsheet`
Copy to clipboard

You can specify the text of the target:

{ref}`MyST syntax lecture <myst_cheatsheet>`
Copy to clipboard

Another alternative is to use Markdown syntax:

[MyST syntax lecture](myst_cheatsheet)
Copy to clipboard

7.3. Quote

Syntax

Example

Note

> text
Copy to clipboard
> this is a quote
Copy to clipboard

quoted text

7.4. Thematic break

Syntax

Example

Note

---
Copy to clipboard
This is the end of some text.

---

## New Header
Copy to clipboard

Creates a horizontal line in the output

7.5. Line comment

Syntax

Example

Note

% text
Copy to clipboard
a line
% a comment
another line
Copy to clipboard

See Comments for more information.

7.6. Block break

Syntax

Example

Result

+++
Copy to clipboard
This is an example of
+++ {"meta": "data"}
a block break
Copy to clipboard

This is an example of

a block break

7.7. HTML block

Syntax

Example

Result

<tagName> text <tagName>
Copy to clipboard
<p> This is a paragraph </p>
Copy to clipboard

This is a paragraph

7.9. Lists

7.9.1. Ordered list

Example

Result

1. First item
2. Second item
    1. First sub-item
Copy to clipboard
  1. First item

  2. Second item

    1. First sub-item

1. First item
2. Second item
    * First sub-item
Copy to clipboard
  1. First item

  2. Second item

    • First subitem

7.9.2. Unordered list

Example

Result

* First item
* Second item
  * First subitem
Copy to clipboard
  • First item

  • Second item

    • First subitem

* First item
  1. First subitem
  2. Second subitem
Copy to clipboard
  • First item

    1. First subitem

    2. Second subitem

7.10. Tables

Syntax

Example

Result

| a    | b    |
| :--- | ---: |
| c    | d    |
Copy to clipboard
|    Training   |   Validation   |
| :------------ | -------------: |
|        0      |        5       |
|     13720     |      2744      |
Copy to clipboard

Training

Validation

0

5

13720

2744

 ```{list-table}
:header-rows: 1

* - Col1
  - Col2
* - Row1 under Col1
  - Row1 under Col2
* - Row2 under Col1
  - Row2 under Col2
```
Copy to clipboard
 ```{list-table}
:header-rows: 1
:name: example-table

* - Training
  - Validation
* - 0
  - 5
* - 13720
  - 2744
```
Copy to clipboard
Table 7.1 My table title

Training

Validation

0

5

13720

2744

 ```{list-table} Table title
:header-rows: 1

* - Col1
  - Col2
* - Row1 under Col1
  - Row1 under Col2
* - Row2 under Col1
  - Row2 under Col2
```
Copy to clipboard
 ```{list-table} This table title
:header-rows: 1

* - Training
  - Validation
* - 0
  - 5
* - 13720
  - 2744
```
Copy to clipboard
Table 7.2 This table title

Training

Validation

0

5

13720

2744

7.10.1. Referencing tables

Note

In order to reference a table you must add a label to it. To add a label to your table simply include a :name: parameter followed by the label of your table. In order to add a numbered reference, you must also include a table title. See example above.

Syntax

Example

Result

{numref}`label`
Copy to clipboard
{numref}`example-table` is an example.
Copy to clipboard

Table 7.1 is an example.

{ref}`text <label>`
Copy to clipboard
This {ref}`table <example-table>` is an example.
Copy to clipboard

This table is an example.

{numref}`text %s <label>`
Copy to clipboard
{numref}`Tbl %s <example-table>` is an example.
Copy to clipboard

Tbl 7.1 is an example.

7.11. Admonitions

Syntax

Example

Result

```{admonition} Title
text
```
Copy to clipboard
```{admonition} This is a title
An example of an admonition with a title.
```
Copy to clipboard

This is a title

An example of an admonition with a title.

```{note}
text
```
Copy to clipboard

or

```{note} text
some more text...
```
Copy to clipboard
```{note} Notes require **no** arguments,
so content can start here.
```
Copy to clipboard

Note

Notes require no arguments, so content can start here.

```{warning} text
some more text...
```
Copy to clipboard
```{warning} This is an example
of a warning directive.
```
Copy to clipboard

Warning

This is an example of a warning directive.

```{tip} text
some more text...
```
Copy to clipboard
```{tip} This is an example
of a tip directive.
```
Copy to clipboard

Tip

This is an example of a tip directive.

```{caution} text
some more text...
```
Copy to clipboard
```{caution} This is an example
of a caution directive.
```
Copy to clipboard

Caution

This is an example of a caution directive.

```{attention} text
some more text...
```
Copy to clipboard
```{attention} This is an example
of an attention directive.
```
Copy to clipboard

Attention

This is an example of an attention directive.

```{danger} text
some more text...
```
Copy to clipboard
```{danger} This is an example
of a danger directive.
```
Copy to clipboard

Danger

This is an example of a danger directive.

```{error} text
some more text...
```
Copy to clipboard
```{error} This is an example
of an error directive.
```
Copy to clipboard

Error

This is an example of an error directive.

```{hint} text
some more text...
```
Copy to clipboard
```{hint} This is an example
of a hint directive.
```
Copy to clipboard

Hint

This is an example of a hint directive.

```{important} text
some more text...
```
Copy to clipboard
```{important} This is an example
of an important directive.
```
Copy to clipboard

Important

This is an example of an important directive.

7.12. Figures and images

Syntax

Example

Result

```{figure} ./path/to/figure.jpg
:name: label

caption
```
Copy to clipboard
```{figure} ./images/C-3PO_droid.png
:height: 150px
:name: figure-example

Here is my figure caption!
```
Copy to clipboard
../../../_images/C-3PO_droid.png

Fig. 7.29 Here is my figure caption!

```{image} ./path/to/figure.jpg
:name: label
```
Copy to clipboard
```{image} ./images/C-3PO_droid.png
:height: 150px
:name: image-example
```
Copy to clipboard
../../../_images/C-3PO_droid.png

See ../content/figures and ../file-types/markdown for more information.

7.12.1. Referencing figures

Syntax

Example

Result

{numref}`label`
Copy to clipboard
{numref}`figure-example`is a
figure example.
Copy to clipboard

Fig. 7.29 is a figure example.

{numref}`text %s <label>`
Copy to clipboard
{numref}`Figure %s <figure-example>`
is an example.
Copy to clipboard

Figure 7.29 is an example.

{ref}`text <label>`
Copy to clipboard
This {ref}`figure <figure-example>`
is an example.
Copy to clipboard

This figure is an example.

7.12.2. Referencing images

Syntax

Example

Result

{ref}`text <label>`
Copy to clipboard
This {ref}`image <image-example>`
is an example.
Copy to clipboard

This image is an example.

7.13. Math

Syntax

Example

Result

Inline

This is an example of an
inline equation $z=\sqrt{x^2+y^2}$.
Copy to clipboard

This is an example of an inline equation z=x2+y2.

Math blocks

This is an example of a
math block

$$
z=\sqrt{x^2+y^2}
$$
Copy to clipboard

This is an example of a math block

z=x2+y2

Math blocks with labels

This is an example of a
math block with a label

$$
z=\sqrt{x^2+y^2}
$$ (mylabel)
Copy to clipboard

This is an example of a math block with a label

(7.1)z=x2+y2

Math directives

This is an example of a
math directive with a
label
```{math}
:label: eq-label

z=\sqrt{x^2+y^2}
```
Copy to clipboard

This is an example of a math directive with a label

(7.2)z=x2+y2

See ../content/math for more information.

7.13.1. Referencing math directives

Syntax

Example

Result

{eq}`label`
Copy to clipboard
Check out equation {eq}`eq-label`.
Copy to clipboard

Check out equation (7.2).

7.14. Code

7.14.1. In-line code

Example:

Wrap in-line code blocks in backticks: `boolean example = true;`.
Copy to clipboard

Result:

Wrap in-line code blocks in backticks: boolean example = true;.

7.14.2. Code and syntax highlighting

Example:

```python
note = "Python syntax highlighting"
print(node)
```
Copy to clipboard

or

```
No syntax highlighting if no language
is indicated.
```
Copy to clipboard

Result:

note = "Python syntax highlighting"
print(node)
Copy to clipboard

or

No syntax highlighting if no language
is indicated.
Copy to clipboard

7.14.3. Executable code

Warning

Make sure to include this front-matter YAML block at the beginning of your .ipynb or .md files.

---
jupytext:
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
kernelspec:
  display_name: Python 3
  language: python
  name: python3
---
Copy to clipboard

Example:

```{code-cell} ipython3
note = "Python syntax highlighting"
print(note)
```
Copy to clipboard

Result:

See ../file-types/myst-notebooks for more information.

7.14.3.1. Tags

The following tags can be applied to code cells by introducing them as options:

Tag option

Description

Example

"full-width"

Cell takes up all of the horizontal space

```{code-cell} ipython3
:tags: ["full-width"]
print("This is a test.")
```
Copy to clipboard

"output_scroll"

Make output cell scrollable

```{code-cell} ipython3
:tags: ["output_scroll"]
for ii in range(100):
  print("This is a test.")
```
Copy to clipboard

"margin"

Move code cell to the right margin

```{code-cell} ipython3
:tags: ["margin"]
print("This is a test.")
```
Copy to clipboard

"hide-input"

Hide cell but the display the outputs

```{code-cell} ipython3
:tags: ["hide-input"]
print("This is a test.")
```
Copy to clipboard

"hide-output"

Hide the outputs of a cell

```{code-cell} ipython3
:tags: ["hide-output"]
print("This is a test.")
```
Copy to clipboard

"hide-cell"

Hides inputs and outputs of code cell

```{code-cell} ipython3
:tags: ["hide-cell"]
print("This is a test.")
```
Copy to clipboard

"remove-input"

Remove the inputs of a cell

```{code-cell} ipython3
:tags: ["remove-input"]
print("This is a test.")
```
Copy to clipboard

"remove-output"

Remove the outputs of a cell

```{code-cell} ipython3
:tags: ["remove-output"]
print("This is a test.")
```
Copy to clipboard

"remove-cell"

Remove the entire code cell

```{code-cell} ipython3
:tags: ["remove-cell"]
print("This is a test.")
```
Copy to clipboard

"raises-exception"

Mark cell as “expected to error”

```{code-cell} ipython3
:tags: ["raises-exception"]
while True print('Hello world')
```
Copy to clipboard

7.14.4. Gluing variables

Example:

```{code-cell} ipython3
from myst_nb import glue
my_variable = "here is some text!"
glue("glued_text", my_variable)
```

Here is an example of how to glue text: {glue:}`glued_text`
Copy to clipboard

Result:

Here is an example of how to glue text:

See glue/gluing for more information.

7.14.5. Gluing numbers

Example:

```{code-cell} ipython3
from myst_nb import glue
import numpy as np
import pandas as pd

ss = pd.Series(np.random.randn(4))
ns = pd.Series(np.random.randn(100))

glue("ss_mean", ss.mean())
glue("ns_mean", ns.mean(), display=False)
```

Here is an example of how to glue numbers: {glue:}`ss_mean` and {glue:}`ns_mean`.
Copy to clipboard

Result:

Here is an example of how to glue numbers: and .

See glue/gluing for more information.

7.14.6. Gluing visualizations

Example:

```{code-cell} ipython3
from myst_nb import glue
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 200)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y, 'b-', linewidth=2)

glue("glued_fig", fig, display=False)
```

This is an inline glue example of a figure: {glue:}`glued_fig`.
This is an example of pasting a glued output as a block:
```{glue:} glued_fig
```
Copy to clipboard

Result:

This is an inline glue example of a figure: . This is an example of pasting a glued output as a block:

See glue/gluing for more information.

7.14.7. Gluing math

Example:

```{code-cell} ipython3
import sympy as sym
x, y = sym.symbols('x y')
z = sym.Function('z')
z = sym.sqrt(x**2+y**2)
glue("example_eq", z, display=False)
```

To glue a math equation try
```{glue:math} example_eq
:label: glue-eq-example
```
Copy to clipboard

Result:

To glue a math equation try:

See for more information.

7.15. Reference documents

Syntax

Example

Result

{doc}`path/to/document`
Copy to clipboard
See {doc}`../content/citations`
for more information.
Copy to clipboard

See ../content/citations for more information.

{doc}`text <path/to/document>`
Copy to clipboard
See {doc}`here <../content/citations>`
for more information.
Copy to clipboard

See here for more information.

7.16. Footnotes

Syntax

Example

Result

[^ref]

[^ref]: Footnote text
Copy to clipboard
This is an example of a footnote.[^footnote1]

[^footnote1]: The definition for referencing
 footnotes is generally placed at the bottom
 of the document.
Copy to clipboard

This is a footnote reference.1

See Footnotes for more information.

7.17. Citations

Note

Make sure you have a reference bibtex file. You can create one by:

  • running touch bibliography-faircookbook.bib

Syntax

Example

Result

{cite}`mybibtexcitation`
Copy to clipboard
This example generates the following
citation {cite}`Gu2020`.
Copy to clipboard

This example generates the following citation [GHRSS20].

To include a list of citations mentioned in the document, introduce the bibliography directive

```{bibliography}
:filter: docname in docnames
```
Copy to clipboard

GHRSS20

W. Gu, S. Hasan, P. Rocca-Serra, and V. P. Satagopam. Road to effective data curation for translational research. Drug Discov Today, Dec 2020.


1

This is the footnote definition.