Configuration#
MyST-NB can be configured at three levels of specificity; globally, per file, and per notebook cell, with the most specific configuration taking precedence.
Global configuration#
Overriding the default configuration at the global level is achieved by specifying variables in the Sphinx conf.py
file.
All myst_nb
configuration variables are prefixed with nb_
, e.g.
nb_execution_timeout = 60
Reading#
Control how files are read.
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Custom formats for reading notebook; suffix -> reader |
Execution#
This configuration is used to control how Jupyter Notebooks are executed at build-time.
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Mapping of kernel name regex to replacement kernel name(applied before execution) |
|
|
|
Regex that matches permitted values of eval expressions |
|
|
|
Execution mode for notebooks |
|
|
|
Path to folder for caching notebooks (default: |
|
|
|
Exclude (POSIX) glob patterns for notebooks |
|
|
|
Execution timeout (seconds) |
|
|
|
Use temporary folder for the execution current working directory |
|
|
|
Allow errors during execution |
|
|
|
Raise an exception on failed execution, rather than emitting a warning |
|
|
|
Print traceback to stderr on execution error |
Rendering#
These configuration options affect the look and feel of notebook parsing and output rendering.
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Merge stdout/stderr execution output streams |
|
|
|
The entry point for the execution output render class (in group |
|
|
|
Remove code cell source |
|
|
|
Remove code cell outputs |
|
|
|
Prompt to expand hidden code cell {content|source|outputs} |
|
|
|
Prompt to collapse hidden code cell {content|source|outputs} |
|
|
|
Number code cell source lines |
|
|
|
Overrides for the base render priority of mime types: list of (builder name, mime type, priority) |
|
|
|
Behaviour for stderr output |
|
|
|
Pygments lexer applied to stdout/stderr and text/plain outputs |
|
|
|
Pygments lexer applied to error/traceback outputs |
|
|
|
Options for image outputs (class|alt|height|width|scale|align) |
|
|
|
Options for figure outputs (classes|name|caption|caption_before) |
|
|
|
The format to use for text/markdown rendering |
|
|
|
Javascript to be loaded on pages containing ipywidgets |
File level configuration#
Overriding the default configuration at a per-file level is achieved by specifying variables in the files metadata, under the mystnb
key.
In Jupyter notebooks, this is added in the notebook-level metadata, e.g.
{
"metadata": {
"mystnb": {
"execution_timeout": 60
}
}
}
In text-based notebooks, this is added in the YAML top-matter, e.g.
---
file_format: mystnb
mystnb:
execution_timeout: 60
---
Execution#
This configuration is used to control how Jupyter Notebooks are executed at build-time.
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Regex that matches permitted values of eval expressions |
|
|
|
Execution mode for notebooks |
|
|
|
Path to folder for caching notebooks (default: |
|
|
|
Execution timeout (seconds) |
|
|
|
Use temporary folder for the execution current working directory |
|
|
|
Allow errors during execution |
|
|
|
Raise an exception on failed execution, rather than emitting a warning |
|
|
|
Print traceback to stderr on execution error |
Rendering#
These configuration options affect the look and feel of notebook parsing and output rendering.
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Merge stdout/stderr execution output streams |
|
|
|
The entry point for the execution output render class (in group |
|
|
|
Remove code cell source |
|
|
|
Remove code cell outputs |
|
|
|
Prompt to expand hidden code cell {content|source|outputs} |
|
|
|
Prompt to collapse hidden code cell {content|source|outputs} |
|
|
|
Number code cell source lines |
|
|
|
Overrides for the base render priority of mime types: list of (builder name, mime type, priority) |
|
|
|
Behaviour for stderr output |
|
|
|
Pygments lexer applied to stdout/stderr and text/plain outputs |
|
|
|
Pygments lexer applied to error/traceback outputs |
|
|
|
Options for image outputs (class|alt|height|width|scale|align) |
|
|
|
Options for figure outputs (classes|name|caption|caption_before) |
|
|
|
The format to use for text/markdown rendering |
Cell level configuration#
Overriding the default configuration at a per-cell level is achieved by specifying variables in the cell metadata, under the mystnb
key.
In Jupyter notebooks, this is added in the cell-level metadata, e.g.
{
"cell_type": "code",
"source": ["print('hello world')"],
"metadata": {
"mystnb": {
"number_source_lines": true
}
}
}
In text-based notebooks, this is added in the code cell YAML, e.g.
```{code-cell} ipython3
---
mystnb:
number_source_lines: true
---
print('hello world')
```
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Merge stdout/stderr execution output streams |
|
|
|
Remove code cell source |
|
|
|
Remove code cell outputs |
|
|
|
Prompt to expand hidden code cell {content|source|outputs} |
|
|
|
Prompt to collapse hidden code cell {content|source|outputs} |
|
|
|
Number code cell source lines |
|
|
|
Behaviour for stderr output |
|
|
|
Pygments lexer applied to stdout/stderr and text/plain outputs |
|
|
|
Pygments lexer applied to error/traceback outputs |
|
|
|
Options for image outputs (class|alt|height|width|scale|align) |
|
|
|
Options for figure outputs (classes|name|caption|caption_before) |
|
|
|
The format to use for text/markdown rendering |
Markdown parsing configuration#
The MyST-NB parser derives from the base MyST-Parser, and so all the same configuration options are available. As referenced in MyST configuration options, the full set of global options are:
Name |
Type |
Default |
Description |
---|---|---|---|
|
|
|
Use strict CommonMark parser |
|
|
|
Use strict Github Flavoured Markdown parser |
|
|
|
Enable syntax extensions |
|
|
|
Disable Commonmark syntax elements |
|
|
|
Parse all links as simple hyperlinks |
|
|
|
URI schemes that are converted to external links |
|
|
|
Sphinx domain names to search in for link references |
|
|
|
Interpret a code fence as a directive, for certain language names. This can be useful for fences like dot and mermaid, and interoperability with other Markdown renderers. |
|
|
|
Add line numbers to code blocks with these languages |
|
|
|
Convert a |
|
|
|
Heading level depth to assign HTML anchors |
|
|
|
Function for creating heading anchors, or a python import path e.g. |
|
|
|
HTML meta tags |
|
|
|
Place a transition before any footnotes |
|
|
|
For reading speed calculations |
|
|
|
Substitutions mapping |
|
|
|
Substitution delimiters |
|
|
|
Recognise URLs without schema prefixes |
|
|
|
Parse |
|
|
|
Allow initial/final spaces in |
|
|
|
Allow initial/final digits |
|
|
|
Parse inline |
|
|
|
Update sphinx.ext.mathjax configuration to ignore |
|
|
|
MathJax classes to add to math HTML |
|
|
|
Enable checkboxes |
|
|
|
A list of warning types to suppress warning messages |
|
|
|
Syntax highlight code blocks with pygments |
|
|
|
Mapping of key to (url, inv file), for intra-project referencing |
Warning suppression#
When Sphinx encounters and error or raises a warning, it will print the location and source file of the text that generated that error. This works slightly differently depending on whether you use markdown files or Jupyter Notebook files.
For markdown (.md
) files, Sphinx will correctly report the line number that the error or warning is associated with:
source/path:4: (WARNING/2) Unknown mime type: 'xyz' [mystnb.unknown_mime_type]
For Jupyter Notebook (.ipynb
) files, these errors also correspond to a cell index.
To allow for this, we use a special format of line number corresponding to: <CELL_INDEX> * 10000 + LINE_NUMBER
.
For example, the following error corresponds to Cell 1, line 4:
source/path:10004: (WARNING/2) Unknown mime type: 'xyz' [mystnb.unknown_mime_type]
In general, if your build logs any warnings, you should either fix them or raise an Issue if you think the warning is erroneous. However, in some circumstances if you wish to suppress the warning you can use the Sphinx suppress_warnings
configuration option.
All myst-nb warnings are prepended by their type, and can be suppressed by e.g.
suppress_warnings = ["mystnb.unknown_mime_type"]