Skip To Article

Executable Documents

Execute content and insert it into your pages when you build your MyST project.

๐Ÿ›  Throughout the tutorial, whenever youโ€™re supposed to do something you will see a ๐Ÿ› 

Start MyST ๐Ÿš€ยถ

From the MyST quickstart tutorial, you should already have created a myst.yml configuration file that is required to render your project. To confirm this, run a MyST server to serve the MyST quickstart content:

๐Ÿ›  Run myst start to serve your quickstart content

$ cd mystmd-quickstart
$ myst start
๐Ÿ“– Built README.md in 33 ms.
๐Ÿ“– Built 01-paper.md in 30 ms.
๐Ÿ“– Built 02-notebook.ipynb in 6.94 ms.
๐Ÿ“š Built 3 pages for myst in 76 ms.

      โœจโœจโœจ  Starting Book Theme  โœจโœจโœจ

โšก๏ธ Compiled in 510ms.

๐Ÿ”Œ Server started on port 3000!  ๐Ÿฅณ ๐ŸŽ‰

      ๐Ÿ‘‰  http://localhost:3000  ๐Ÿ‘ˆ

๐Ÿ›  Open your web browser to http://localhost:3000[1]

To fully explore myst start see Get Started.

Install the packages needed for executionยถ

To execute the content in the myst-quickstart site, we must ensure that the proper environment is installed. To do so, install the packages listed in myst-quickstart/requirements.txt.

๐Ÿ›  Use pip to install the packages for executing

$ pip install -r requirements.txt

Execute demo content at build timeยถ

Note that the content in 02-notebook/ has no outputs. By default, MyST will not execute any notebooks when your site builds. To execute your content at build time, use the --execute flag.

๐Ÿ›  Execute your content and build your MyST docs

$ myst start --execute

This will execute your notebook file before spinning up your MyST server. Go back to 02-notebook/ and youโ€™ll see the outputs there.

Label, reference, and embed an outputยถ

You can attach labels to notebook outputs so that you can reference them later on in your site. MyST uses a special comment syntax for attaching metadata to Jupyter Notebook cells. Each of them use comments (# in Python) and the pipe operator (|) to add metadata.

For example, this content would assign the label mylabel to the cell output:

#| label: mylabel
print("hi")

Your quickstart notebook already defines a cell output in one of its cells, find it to experiment with this feature.

๐Ÿ›  Find the cell that defines a label with the following code:

#| label: horsepower
points & bars

This assigns the label horsepower to the output of that code cell.

You can reference it and embed it like you would any other item in MyST.

๐Ÿ›  Add a reference to this cell, as well as an embedding in a figure by copy and pasting this into a markdown block of the notebook.

Here we reference [](#horsepower).

And below we embed it:

![](#horsepower)

Add an executable cell to your Markdown fileยถ

You can add any executable content to a MyST markdown file. This is useful if you want to more natively version control your executable content in a system like git.

To add executable content, use the {code-cell} directive. This will tell MyST to execute anything inside.

๐Ÿ›  Add the following code cell directive to 01-paper.md

```{code-cell}
:label: markdown-myst
print("Here's some python!")
```

And here I reference [](#markdown-myst).

If you re-build your MyST site with --execute, the cell will be executed. Notice how weโ€™ve also added a label to the code block, but using the directive option rather than the Python comments syntax we used above.

Conclusion ๐Ÿฅณยถ

Thatโ€™s it for this quickstart tutorial! Youโ€™ve just learned how to add computational materials and execute your MyST document!

Check out the following tutorials for more step-by-step guides:

Footnotesยถ
  1. If you arenโ€™t familiar with git, it isnโ€™t required for this tutorial, you can download the zip file with the contents from the quickstart repository.

  2. If port 3000 is in use on your machine, an open port will be used instead, follow the link provided in the terminal.

  3. By default the myst clean command doesnโ€™t remove installed templates or cached web responses; however, the function can with a:
    myst clean --all, or
    myst clean --templates --cache.

    Before deleting any folders myst will confirm what is going to happen, or you can bypass this confirmation with the -y option. For example:

  4. If the server stopped, you can restart the server using myst start.

  5. If port 3000 is in use on your machine, an open port will be used instead, follow the link provided in the terminal.

MyST MarkdownMyST Markdown
Community-driven tools for the future of technical communication and publication, part of Jupyter.