Skip To Article

This section provides a high-level overview of the main concepts and tools in the MyST ecosystem. See the guiding principles of the MyST ecosystem for some more high-level context.

Overview of the MyST build process

The MyST Build process takes input documents from authors and converts them into outputs that are meant for consumption by readers. The MyST CLI contains logic to use the MyST Document Engine, renderers, and themes to carry out this entire process. Here’s a high-level breakdown of the major steps of that process:

PhaseInputOutput
(1) Writing: An author writes content with MyST Markdown in a file.IdeasContent (.md, .ipynb, etc)
(2) Parsing: A MyST Document Engine parses content into structured data called the MyST AST. See How does parsing work?.Raw content (.md, .ipynb, etc)Raw MyST AST
(3) Resolving: Transform raw MyST AST into AST that can be rendered. See How do MyST Transformers work?.Raw MyST ASTResolved / Processed MyST AST
(4) Rendering: A MyST Renderer transforms the MyST AST into components that can be used by a MyST Theme.Resolved MyST ASTComponents that can be rendered into a final output with a template and/or theme (e.g., LaTeX, React, etc).
(5) Theming / templating: Rendered components are used by a MyST Theme to generate final artifacts. See How do MyST themes and templates work?.Template components that have been rendered by a MyST renderer.Output formats that are ready for final consumption (e.g., a website or PDF).

Here is a brief overview of these steps:

An overview of the “Parsing and Resolving” phase using the MyST Document Engine.
In this stage, a text file written in MyST Markdown is parsed by the  which outputs  that follows the . This file undergoes a number of transformations to add metadata, resolve links, and enrich the document. The final output is MyST AST (usually a .json file) that can be rendered into many different kinds of outputs.

An overview of the “Parsing and Resolving” phase using the MyST Document Engine. In this stage, a text file written in MyST Markdown is parsed by the MyST Document Engine which outputs MyST AST that follows the MyST Specification. This file undergoes a number of transformations to add metadata, resolve links, and enrich the document. The final output is MyST AST (usually a .json file) that can be rendered into many different kinds of outputs.

An overview of the “Rendering and Theming” phase using one or more MyST renderers / themes. In this stage, a resolved MyST AST is rendered into multiple components by a MyST renderer. These are building blocks that a theme knows how to convert into a final output. For example, the MyST React Renderer and the MyST React Themes know how to use these React components to create a final website.

An overview of the “Rendering and Theming” phase using one or more MyST renderers / themes. In this stage, a resolved MyST AST is rendered into multiple components by a MyST renderer. These are building blocks that a theme knows how to convert into a final output. For example, the MyST React Renderer and the MyST React Themes know how to use these React components to create a final website.

How does parsing work?

The MyST Document engine knows how to parse many kinds of documents into MyST AST. This is most-commonly done with markdown files (.md) or Jupyter Notebooks (.ipynb) written in MyST Markdown, a flavor of markdown that was designed for the MyST Document Engine.

However, the MyST Engine knows how to parse other kinds of syntax into MyST AST as well. For example, for admonition compatibility with GitHub Markdown. This is because we see the MyST AST as the primary point of standardization for the MyST ecosystem, not the Markdown flavor. Input documents may have many different forms, but once it is parsed into MyST AST, the document should have a standardized structure defined by the MyST Specification.

What is the MyST AST and Specification?

The MyST AST is a version of parsed MyST content that follows a specific structure so that Renderers can convert into different outputs. MyST AST conforms to the MyST Specification. The MyST Specification is a superset of the mdast specification (meaning that MyST includes all of the syntax that mdast supports, plus some extra ones like Directives).

Here’s an example of MyST content, and the same content parsed as MyST AST:

ContentAST
**Hello there!**
- type: block
children:
  - type: paragraph
    children:
      - type: strong
        children:
          - type: text
            value: Hello there!

The easiest way to understand how MyST Markdown gets converted to MyST AST is to explore the MyST Sandbox. Click the AST tab to see the underlying AST structure for anything that you type. The PRE tab represents the initial parsing phase, and the POST tab represents the AST after the resolving phase.

How do MyST Transformers work?

MyST Transformers are a way to convert a MyST AST node into another type of node. Transformers operate on AST rather than on raw Markdown because AST has more standardized structure to work with.

For example, consider a Markdown link like [some text](#a-label). In MyST Markdown, this defines a cross-reference to #a-label, but it uses Markdown link syntax. We use a MyST Transformer to convert that Markdown to a cross-reference AST node like so:

  • First parse the Markdown [some text](#a-label).
  • The result is a MyST AST node for a Markdown link.
  • Next, search the document AST for any Markdown link nodes with a target that starts with #. Check if there’s a target for the link. If so, it is meant to be a cross reference.
  • If so, converts the Markdown Link node into a Cross Reference node.

Some other uses for Transformers include:

  • Lifting metadata from code-cells to their parent structures
  • Check that figures have alt-texts
  • Convert non-standard AST nodes (e.g., ones generated from a custom user directive) into ones that MyST knows how to render[1].

See Concepts: MyST Transformers for more details about how transforms operate on an AST and what intermediate steps look like.

How do MyST themes and templates work?

MyST Themes and MyST Templates are both related to exporting a resolved MyST AST into one or more final output formats. They differ in the amount of customizability that a user has in altering their behavior, but the end-result is the same (generating an export artifact).

Templates
Templates are usually used for static exports (like LaTeX or Typst). The are structured like a final document (e.g., a LaTeX template for a specific journal), but with fields that MyST uses to insert document metadata at export time (e.g., a doc.author field if you want to insert the author name). See the myst-templates GitHub repository for a list of templates that you can use and contribute to.
Themes
Themes are similar to templates because they expose more customizability than a template (which simply generates static outputs via a Jinja-like filter), but they function similar to a template because they take rendered components as inputs and export a final output. Themes are usually meant for websites, because there is a lot more control a website exposes compared to a static document like LaTeX. Themes have more complex logic, and thus their source-code is often in a dedicated repository. For examples, see the build outputs of the book and article web themes are myst-templates, but their source code is in myst-theme.

For a more technical explanation see the developer guide on themes, templates, and renderers.

Are there other MyST engines?

The MyST Specification and MyST Markdown Syntax was designed so that others could implement their own parsers, document engines, and renderers using MyST. Although there are presently no independent examples of a true MyST Document Engine, the MyST Parser for Sphinx project fulfills a similar role in the Sphinx ecosystem.

The MyST Parser for Sphinx is an extension for Sphinx that can parse MyST Markdown into Sphinx’s internal document structure. It was created to allow users to parse MyST Markdown syntax into Sphinx for V1 of Jupyter Book. It now exists as an independent extension for the Sphinx community, as Jupyter Book now uses the MyST Document Engine.

How does Jupyter Book relate to MyST?

The MyST Markdown Syntax was originally created to allow Jupyter Book V1 to use the Sphinx Document engine with Markdown content[2], rather than the less well-known ReStructuredText language.

Over time, the Jupyter Book team decided that the most sustainable path forward was to maintain its own document engine, the MyST Document Engine. An early version of the MyST Document Engine was created by Curvenote. To promote its long-term sustainability, the project was open sourced and further developed in collaboration with the Jupyter Book team. It serves as the engine behind Jupyter Book V2.

You can think of Jupyter Book as a distribution of the MyST Document Engine. In other words, Jupyter Book wraps the MyST Document Engine application, with out-of-the-box configuration that supports a multi-page community knowledge base or documentation site. MyST is created and maintained by the Jupyter Book team.

Currently, Jupyter Book and the MyST Document Engine share much of the same functionality. Over time, we imagine that the MyST Document Engine will be a more flexible tool that makes fewer assumptions about the end use-case that it’s being used for. Jupyter Book will then have “more opinions” above the base configuration of the MyST Document Engine. That said — we are still figuring this out! We aren’t sure the exact relationship the two will have, and will revisit this as we learn more. See next.jupyterbook.org for Jupyter Book V2 documentation, and see this section of the Contributing Guide for our approach to documenting the two projects.

How do MyST and Sphinx compare?

Sphinx is an open-source documentation system used in many software projects, especially in the Python ecosystem. It builds an internal representation of technical documents as a tree (see docutils) similar to the MyST AST. Whilst Sphinx partially defines a specification of sorts[3], a MyST Document Engine explicitly publishes its MyST AST for other tools to consume.

The Sphinx ecosystem has excellent support for Python documentation, referencing content, as well as externally providing an inventory of references known as intersphinx. You can link to Sphinx documentation with a MyST Document Engine by using intersphinx references, and the official MyST Document Engine automatically exposes the information required to allow Sphinx documentation to reference your MyST project.

At this time, the official MyST Document Engine does not support the authoring of software API documentation[4]. As such, if your project is documenting Python software we suggest that you use Sphinx. If your project is primarily tutorials, educational textbooks (including with Jupyter Notebooks), a presentation, or scientific paper, we hope that you find a better fit with the MyST stack!

Sphinx and MyST take very different approaches to publishing to the web. In Sphinx, themes are used to customize the generation of HTML and JavaScript. Sites built using these themes can be deployed to static web servers like ReadTheDocs. In the MyST world, the equivalent to a Sphinx theme is a MyST Renderer that consumes the MyST AST and outputs HTML and JavaScript for your browser. Formally separating the MyST Document Engine that generates MyST AST and the MyST Renderer that consumes it makes it possible to create rich new experiences with MyST, such as the SciPy Conference Proceedings website that renders MyST AST on the fly.

Although the official engine also supports static HTML outputs, implementing themes as applications makes it easier to build more powerful MyST viewing experiences.

Footnotes
  1. For example, see this Executable Transform example from Project Pythia. It is an example of an executable transform, which takes custom pythia-cookbooks nodes and converts them (via some HTTP fetches) to a grid of cards by outputting the relevant grid and card AST nodes.

  2. Specifically, the MyST Parser for Sphinx was created to move beyond the functionality of the recommonmark project in order to natively support docutils roles and directives in markdown.

  3. The Docutils source-code is the specification.

  4. In the future, mystmd may offer support for Python and Javascript documentation, and if you want to contribute please reach out!

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