1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-12-18 10:25:58 +01:00
mkdocs-material/docs/reference/mathjax.md

135 lines
3.7 KiB
Markdown
Raw Normal View History

2020-07-24 16:11:42 +02:00
---
template: overrides/main.html
---
# MathJax
[MathJax][1] is a beautiful and accessible way to display _mathematical content_
in the browser, allows for writing formulas in different notations, including
[LaTeX][2], [MathML][3] and [AsciiMath][4], and can be easily integrated with
Material for MkDocs.
[1]: https://www.mathjax.org/
[2]: https://en.wikibooks.org/wiki/LaTeX/Mathematics
[3]: https://en.wikipedia.org/wiki/MathML
[4]: http://asciimath.org/
## Configuration
### Arithmatex
[:octicons-file-code-24: Source][5] · [:octicons-workflow-24: Extension][6]
The [Arithmatex][6] extension, which is part of of [Python Markdown
2020-07-24 18:29:34 +02:00
Extensions][7], allows the rendering of block and inline block equations, and
can be enabled via `mkdocs.yml`:
2020-07-24 16:11:42 +02:00
``` 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 [additional
JavaScript][8]:
2020-08-04 22:22:47 +02:00
=== "docs/javascripts/config.js"
2020-07-24 16:11:42 +02:00
``` js
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
```
=== "mkdocs.yml"
``` yaml
extra_javascript:
- javascripts/config.js
- https://polyfill.io/v3/polyfill.min.js?features=es6
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
```
_MathJax can be configured in many different ways, for which Material for MkDocs
might not provide native support. See the [official documentation][6] for more
information._
!!! tip "Using MathJax with [instant loading][9]"
There's no additional effort necessary to integrate _MathJax 3_ with
[instant loading][7] it's expected to work straight away. However, a
previous version of this document explained how to integrate Material for
MkDocs with _MathJax 2_, which doesn't exhibit this behavior. It's therefore
highly recommended to switch to _MathJax 3_.
2020-07-24 16:11:42 +02:00
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script>
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
</script>
[5]: https://github.com/squidfunk/mkdocs-material/blob/master/src/assets/stylesheets/main/extensions/pymdownx/_arithmatex.scss
[6]: https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/
[7]: https://facelessuser.github.io/pymdown-extensions/extensions/
[8]: ../customization.md#additional-javascript
[9]: ../setup/setting-up-navigation.md#instant-loading
2020-07-24 16:11:42 +02:00
## Usage
### Using block syntax
2020-07-24 18:29:34 +02:00
Blocks must be enclosed in `#!latex $$...$$` or `#!latex \[...\]`on separate lines:
2020-07-24 16:11:42 +02:00
_Example_:
``` latex
$$
\operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}}
$$
```
_Result_:
$$
\operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}}
$$
2020-07-24 18:29:34 +02:00
### Using inline block syntax
2020-07-24 16:11:42 +02:00
2020-07-24 18:29:34 +02:00
Inline blocks must be enclosed in `#!latex $...$` or `#!latex \(...\)`:
2020-07-24 16:11:42 +02:00
_Example_:
``` latex
The homomorphism $f$ is injective if and only if its kernel is only the
singleton set $e_G$, because otherwise $\exists a,b\in G$ with $a\neq b$ such
that $f(a)=f(b)$.
```
_Result_:
The homomorphism $f$ is injective if and only if its kernel is only the
singleton set $e_G$, because otherwise $\exists a,b\in G$ with $a\neq b$ such
that $f(a)=f(b)$.