# Python Markdown Extensions The [Python Markdown Extensions] package is an excellent collection of additional extensions perfectly suited for advanced technical writing. Material for MkDocs lists this package as an explicit dependency, so it's automatically installed with a supported version. [Python Markdown Extensions]: https://facelessuser.github.io/pymdown-extensions/ ## Supported extensions In general, all extensions that are part of [Python Markdown Extensions] should work with Material for MkDocs. The following list includes all extensions that are natively supported, meaning they work without any further adjustments. ### Arithmatex The [Arithmatex] extension allows for rendering of block and inline block equations and integrates seamlessly with [MathJax][^1] – a library for mathematical typesetting. Enable it via `mkdocs.yml`: [^1]: Other libraries like [KaTeX] are also supported and can be integrated with some additional effort. See the [Arithmatex documentation on KaTeX] for further guidance, as this is beyond the scope of Material for MkDocs. ``` yaml markdown_extensions: - pymdownx.arithmatex: generic: true ``` Besides enabling the extension in `mkdocs.yml`, a MathJax configuration and the JavaScript runtime need to be included, which can be done with a few lines of [additional JavaScript]: === ":octicons-file-code-16: `docs/javascripts/mathjax.js`" ``` js window.MathJax = { tex: { inlineMath: [["\\(", "\\)"]], displayMath: [["\\[", "\\]"]], processEscapes: true, processEnvironments: true }, options: { ignoreHtmlClass: ".*|", processHtmlClass: "arithmatex" } }; document$.subscribe(() => { // (1)! MathJax.startup.output.clearCache() MathJax.typesetClear() MathJax.texReset() MathJax.typesetPromise() }) ``` 1. This integrates MathJax with [instant loading] === ":octicons-file-code-16: `mkdocs.yml`" ``` yaml extra_javascript: - javascripts/mathjax.js - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js ``` The other configuration options of this extension are not officially supported by Material for MkDocs, which is why they may yield unexpected results. Use them at your own risk. See reference for usage: - [Using block syntax] - [Using inline block syntax] [Arithmatex]: https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/ [Arithmatex documentation on KaTeX]: https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/#loading-katex [MathJax]: https://www.mathjax.org/ [KaTeX]: https://github.com/Khan/KaTeX [additional JavaScript]: ../../customization.md#additional-javascript [instant loading]: ../setting-up-navigation.md#instant-loading [Using block syntax]: ../../reference/math.md#using-block-syntax [Using inline block syntax]: ../../reference/math.md#using-inline-block-syntax ### BetterEm The [BetterEm] extension improves the detection of Markup to emphasize text in Markdown using special characters, i.e. for `**bold**` and `_italic_` formatting. Enable it via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.betterem ``` The configuration options of this extension are not specific to Material for MkDocs, as they only impact the Markdown parsing stage. See the [BetterEm documentation][BetterEm] for more information. [BetterEm]: https://facelessuser.github.io/pymdown-extensions/extensions/betterem/ ### Caption The [Caption] extension adds the ability to add captions to any Markdown block, including images, tables, and code blocks. Enable it via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.blocks.caption ``` The configuration options of this extension are not specific to Material for MkDocs, as they only impact the Markdown parsing stage. See the [Caption documentation][Caption] for more information. [Caption]: https://facelessuser.github.io/pymdown-extensions/extensions/blocks/plugins/caption/ ### Caret, Mark & Tilde The [Caret], [Mark] and [Tilde] extensions add the ability to highlight text and define sub- and superscript using a simple syntax. Enable them together via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.caret - pymdownx.mark - pymdownx.tilde ``` The configuration options of this extension are not specific to Material for MkDocs, as they only impact the Markdown parsing stage. See the [Caret], [Mark] and [Tilde documentation][Tilde] for guidance. See reference for usage: - [Highlighting text] - [Sub- and superscripts] [Caret]: https://facelessuser.github.io/pymdown-extensions/extensions/caret/ [Mark]: https://facelessuser.github.io/pymdown-extensions/extensions/mark/ [Tilde]: https://facelessuser.github.io/pymdown-extensions/extensions/tilde/ [Highlighting text]: ../../reference/formatting.md#highlighting-text [Sub- and superscripts]: ../../reference/formatting.md#sub-and-superscripts ### Critic The [Critic] extension allows for the usage of [Critic Markup] to highlight added, deleted or updated sections in a document, i.e. for tracking changes in Markdown syntax. Enable it via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.critic ``` The following configuration options are supported: : This option defines how the markup should be parsed, i.e. whether to just `view` all suggested changes, or alternatively `accept` or `reject` them: === "View changes" ``` yaml markdown_extensions: - pymdownx.critic: mode: view ``` === "Accept changes" ``` yaml markdown_extensions: - pymdownx.critic: mode: accept ``` === "Reject changes" ``` yaml markdown_extensions: - pymdownx.critic: mode: reject ``` See reference for usage: - [Highlighting changes] [Critic]: https://facelessuser.github.io/pymdown-extensions/extensions/critic/ [Critic Markup]: https://github.com/CriticMarkup/CriticMarkup-toolkit [Highlighting changes]: ../../reference/formatting.md#highlighting-changes ### Details The [Details] extension supercharges the [Admonition] extension, making the resulting _call-outs_ collapsible, allowing them to be opened and closed by the user. Enable it via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.details ``` No configuration options are available. See reference for usage: - [Collapsible blocks] [Details]: https://facelessuser.github.io/pymdown-extensions/extensions/details/ [Admonition]: python-markdown.md#admonition [Collapsible blocks]: ../../reference/admonitions.md#collapsible-blocks ### Emoji The [Emoji] extension automatically inlines bundled and custom icons and emojis in `*.svg` file format into the resulting HTML page. Enable it via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.emoji: emoji_index: !!python/name:material.extensions.emoji.twemoji # (1)! emoji_generator: !!python/name:material.extensions.emoji.to_svg ``` 1. [Python Markdown Extensions] uses the `pymdownx` namespace, but in order to support the inlining of icons, the `materialx` namespace must be used, as it extends the functionality of `pymdownx`. The following configuration options are supported: : This option defines which set of emojis is used for rendering. Note that the use of `emojione` is not recommended due to [restrictions in licensing][Emoji index]: ``` yaml markdown_extensions: - pymdownx.emoji: emoji_index: !!python/name:material.extensions.emoji.twemoji ``` : This option defines how the resolved emoji or icon shortcode is render. Note that icons can only be used together with the `to_svg` configuration: ``` yaml markdown_extensions: - pymdownx.emoji: emoji_generator: !!python/name:material.extensions.emoji.to_svg ``` : This option allows to list folders with additional icon sets to be used in Markdown or `mkdocs.yml`, which is explained in more detail in the [icon customization guide]: ``` yaml markdown_extensions: - pymdownx.emoji: emoji_index: !!python/name:material.extensions.emoji.twemoji emoji_generator: !!python/name:material.extensions.emoji.to_svg options: custom_icons: - overrides/.icons ``` The other configuration options of this extension are not officially supported by Material for MkDocs, which is why they may yield unexpected results. Use them at your own risk. See reference for usage: - [Using emojis] - [Using icons] - [Using icons in templates] [Emoji]: https://facelessuser.github.io/pymdown-extensions/extensions/emoji/ [Emoji index]: https://facelessuser.github.io/pymdown-extensions/extensions/emoji/#default-emoji-indexes [icon customization guide]: ../changing-the-logo-and-icons.md#additional-icons [Using emojis]: ../../reference/icons-emojis.md#using-emojis [Using icons]: ../../reference/icons-emojis.md#using-icons [Using icons in templates]: ../../reference/icons-emojis.md#using-icons-in-templates ### Highlight The [Highlight] extension adds support for syntax highlighting of code blocks (with the help of [SuperFences][pymdownx.superfences]) and inline code blocks (with the help of [InlineHilite][pymdownx.inlinehilite]). Enable it via `mkdocs.yml`: ``` yaml markdown_extensions: - pymdownx.highlight: anchor_linenums: true - pymdownx.superfences # (1)! ``` 1. [Highlight] is used by the [SuperFences][pymdownx.superfences] extension to perform syntax highlighting on code blocks, not the other way round, which is why this extension also needs to be enabled. The following configuration options are supported: : This option allows to control whether highlighting should be carried out during build time using [Pygments] or in the browser with a JavaScript syntax highlighter: === "Pygments" ``` yaml markdown_extensions: - pymdownx.highlight: use_pygments: true - pymdownx.superfences ``` === "JavaScript" ``` yaml markdown_extensions: - pymdownx.highlight: use_pygments: false ``` As an example, [Highlight.js], a JavaScript syntax highlighter, can be integrated with some [additional JavaScript] and an [additional style sheet] in `mkdocs.yml`: === ":octicons-file-code-16: `docs/javascripts/highlight.js`" ``` js document$.subscribe(() => { hljs.highlightAll() }) ``` === ":octicons-file-code-16: `mkdocs.yml`" ``` yaml extra_javascript: - https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/highlight.min.js - javascripts/highlight.js extra_css: - https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/styles/default.min.css ``` Note that [Highlight.js] has no affiliation with the [Highlight][pymdownx.highlight] extension. All following configuration options are only compatible with build-time syntax highlighting using [Pygments], so they don't apply if `use_pygments` is set to `false`. : This option instructs [Pygments] to add a CSS class to identify the language of the code block, which is essential for custom annotation markers to function: ``` yaml markdown_extensions: - pymdownx.highlight: pygments_lang_class: true ``` : This option will automatically add a [title] to all code blocks that shows the name of the language being used, e.g. `Python` is printed for a `py` block: ``` yaml markdown_extensions: - pymdownx.highlight: auto_title: true ``` : This option will add line numbers to _all_ code blocks. If you wish to add line numbers to _some_, but not all code blocks, consult the section on [adding line numbers][Adding line numbers] in the code block reference, which also contains some tips on working with line numbers: ``` yaml markdown_extensions: - pymdownx.highlight: linenums: true ``` : The [Highlight] extension provides three ways to add line numbers, two of which are supported by Material for MkDocs. While `table` wraps a code block in a `