# MyST Markdown Overview¶

In addition to Jupyter Notebook markdown, Jupyter Book also supports a special flavor of markdown called MyST (or Markedly Structured Text). It was designed to make it easier to create publishable computational documents in Markdown. It is a superset of CommonMark markdown and draws heavy inspiration from the fantastic RMarkdown language from RStudio.

Whether you write your book’s content in Jupyter Notebooks (.ipynb) or in regular markdown files (.md), you’ll write in the same flavor of MyST Markdown. Jupyter Book will know how to parse both of them.

## Directives and roles¶

Roles and directives are two of the most powerful tools in Jupyter Book. They are kind of like functions, but written in a markup language. They both serve a similar purpose, but roles are written in one line, whereas directives span many lines. They both accept different kinds of inputs, and what they do with those inputs depends on the specific role or directive that is being called.

### Directives¶

Directives customize the look, feel, and behavior of your book. They are kind of like functions, and come in a variety of names with different behavior. This section covers how to structure and use them.

At its simplest, you can insert a directive into your book’s content like so:

{mydirectivename}
My directive content



This will only work if a directive with name mydirectivename already exists (which it doesn’t). There are many pre-defined directives associated with Jupyter Book. For example, to insert a note box into your content, you can use the following directive:

{note}
Here is a note



This results in:

Note

Here is a note

#### More arguments and metadata in directives¶

Many directives allow you to control their behavior with extra pieces of information. In addition to the directive name and the directive content, directives allow two other configuration points:

directive arguments - are a list of words that come just after the {directivename} is given.

Here’s an example use of directive arguments:

{directivename} arg1 arg2
My directive content.



directive keywords - is a collection of flags or key/value pairs that come just underneath {directivename}.

There are two ways to write directive keywords, either as :key: val pairs, or as key: val pairs inside of --- lines. They both work the same way:

Here’s an example of directive keywords using :key: val pairs:

{directivename}
My directive content.



and here’s an example of directive keywords using --- lines:

{directivename}
---
---
My directive content.



Tip

Remember, specifying directive keywords with :key: or --- will both work the same. We recommend using --- if you have many keywords you wish to specify, or if some values will span multiple lines. Use the :key: val syntax as a short-hand for just one or two keywords.

For examples of how this is used, see the sections below.

### Roles¶

Roles are very similar to directives, but they are less-complex and written entirely on one line. You can insert a role into your book’s content with this pattern:

Some content {rolename}and here is my role's content!


Again, roles will only work if rolename is a valid role’s name. For example, the doc role can be used to refer to another page in your book. You can refer directly to another page by its relative path. For example, the role syntax {doc}../intro will result in: Books with Jupyter.

## What roles and directives are available?¶

There is currently no single list of roles / directives to use as a refernece, but this section tries to give as much as information as possible. For those who are familiar with the Sphinx ecosystem, you may use any directive / role that is available in Sphinx. This is because Jupyter Book uses Sphinx to build your book, and MyST Markdown supports all syntax that Sphinx supports (think of it as a markdown version of reStructuredText).

Caution

If you search the internet (and the links below) for information about roles and directives, the documentation will generally be written with reStructuredText in mind. MyST markdown is different from reStructuredText, but all of the functionality should be the same. See the MyST Sphinx parser documentation for more information about MyST vs. rST.

For a list of directives that are available to you, there are three places to check:

1. The Sphinx directives page has a list of directives that are available by default in Sphinx.

2. The reStructuredText directives page has a list of directives in the Python “docutils” module.

3. This documentation has several directives that are specific to Jupyter Book in addition.

## Nesting content blocks in markdown¶

If you’d like to nest content blocks inside of one another with Markdown (for example, to put a {note} inside of a {margin}), you may do so by adding extra backticks () to the outer-most block. This works for literal code blocks as well.

For example, the following syntax:







Yields:





Thus, if you’d like to nest directives inside one another, you can take the same approach, for example, the following syntax:

{margin}
{note}
Here's my note!




produces:

## Other MyST Markdown syntax¶

In addition to roles and directives, there are several other kinds of syntax that it supports. MyST supports all syntax in CommonMark markdown (the kind of markdown that Jupyter Notebooks use), as well as an extended syntax that is used for scientific publishing.

The MyST-Parser is the tool that Jupyter Book uses to allow you to write your book content in MyST. It is also a good source of information about the MyST syntax. Here are some links you can use as a reference:

## What can I create with MyST markdown?¶

See Special content blocks with MyST for an introduction to what you can do with MyST markdown in Jupyter Book. In addition, the other pages in this site cover many more use-cases for how to use directives with MyST.

## Tools for writing MyST markdown¶

There is some support for MyST markdown in tools across the community, here are a few prominent ones.

### Jupyter interfaces¶

While MyST markdown does not (yet) render in traditional Jupyter interfaces, most of its syntax should “gracefully degrade”, meaning that you can still work with MyST in Jupyter, and then build your book with Jupyter Book.

### Jupytext and text sync¶

For working between Jupyter notebook and markdown files, we recommend jupytext, an open source tool for two-way conversion between .ipynb` and text files. Jupytext supports the MyST markdown format.

### VSCode¶

If editing the markdown files using VS Code, the vscode MyST markdown extension provides syntax highlighting and other features.