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:
Write scientific articles using MyST Markdown with easy-to-use citations, metadata, and cross-references.
Learn how to use computation and execution with Jupyter in MyST.
Export MyST documents to a Word document, PDF, and !
See an overview of MyST Markdown syntax with inline demos and examples.
Learn how to use MyST in Jupyter Interfaces.
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.
If port
3000
is in use on your machine, an open port will be used instead, follow the link provided in the terminal.By default the
myst clean
command doesnโt remove installed templates or cached web responses; however, the function can with a:myst clean --all
, ormyst 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:If the server stopped, you can restart the server using
myst start
.If port
3000
is in use on your machine, an open port will be used instead, follow the link provided in the terminal.