--- icon: material/alphabet-greek --- # Math [MathJax] and [KaTeX] are two popular libraries for displaying mathematical content in browsers. Although both libraries offer similar functionality, they use different syntaxes and have different configuration options. This documentation site provides information on how to integrate them with Material for MkDocs easily. [MathJax]: https://www.mathjax.org/ [LaTeX]: https://en.wikibooks.org/wiki/LaTeX/Mathematics [MathML]: https://en.wikipedia.org/wiki/MathML [AsciiMath]: http://asciimath.org/ [KaTeX]: https://katex.org/ ## Configuration The following configuration enables support for rendering block and inline block equations using [MathJax] and [KaTeX]. ### MathJax [MathJax] is a powerful and flexible library that supports multiple input formats, such as [LaTeX], [MathML], [AsciiMath], as well as various output formats like HTML, SVG, MathML. To use MathJax within your project, add the following lines to your `mkdocs.yml`. === ":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 markdown_extensions: - pymdownx.arithmatex: generic: true extra_javascript: - javascripts/mathjax.js - https://polyfill.io/v3/polyfill.min.js?features=es6 - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js ``` See additional configuration options: - [Arithmatex] [Arithmatex]: ../setup/extensions/python-markdown-extensions.md#arithmatex [instant loading]: ../setup/setting-up-navigation.md#instant-loading ### KaTeX [KaTeX] is a lightweight library that focuses on speed and simplicity. It supports a subset of LaTeX syntax and can render math to HTML and SVG. To use [KaTeX] within your project, add the following lines to your `mkdocs.yml`. === ":octicons-file-code-16: `docs/javascripts/katex.js`" ``` js document$.subscribe(({ body }) => { // (1)! renderMathInElement(body, { delimiters: [ { left: "$$", right: "$$", display: true }, { left: "$", right: "$", display: false }, { left: "\\(", right: "\\)", display: false }, { left: "\\[", right: "\\]", display: true } ], }) }) ``` 1. This integrates KaTeX with [instant loading]. === ":octicons-file-code-16: `mkdocs.yml`" ``` yaml markdown_extensions: - pymdownx.arithmatex: generic: true extra_javascript: - javascripts/katex.js - https://unpkg.com/katex@0/dist/katex.min.js - https://unpkg.com/katex@0/dist/contrib/auto-render.min.js extra_css: - https://unpkg.com/katex@0/dist/katex.min.css ``` ## Usage ### Using block syntax Blocks must be enclosed in `#!latex $$...$$` or `#!latex \[...\]` on separate lines: ``` latex title="block syntax" $$ \operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}} $$ ```