Skip to content

Commit 71ad6f5

Browse files
Improved math documentation
1 parent a154c64 commit 71ad6f5

File tree

1 file changed

+83
-38
lines changed

1 file changed

+83
-38
lines changed

docs/reference/math.md

+83-38
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22
icon: material/alphabet-greek
33
---
44

5-
# MathJax
5+
# Math
66

7-
[MathJax] is a beautiful and accessible way to display mathematical content
8-
in the browser, adds support for mathematical typesetting in different notations
9-
(e.g. [LaTeX], [MathML], [AsciiMath], [KaTeX]), and can be easily integrated with
10-
Material for MkDocs.
7+
[MathJax] and [KaTeX] are two popular libraries for displaying
8+
mathematical content in browsers. Although both libraries offer similar
9+
functionality, they use different syntaxes and have different configuration
10+
options. This documentation site provides information on how to integrate them
11+
with Material for MkDocs easily.
1112

1213
[MathJax]: https://www.mathjax.org/
1314
[LaTeX]: https://en.wikibooks.org/wiki/LaTeX/Mathematics
1415
[MathML]: https://en.wikipedia.org/wiki/MathML
1516
[AsciiMath]: http://asciimath.org/
1617
[KaTeX]: https://katex.org/
1718

19+
1820
## Configuration
1921

20-
This configuration enables support for rendering block and inline block
21-
equations through [MathJax]. Create a configuration file and add the following
22-
lines to `mkdocs.yml`:
22+
The following configuration enables support for rendering block and
23+
inline block equations using [MathJax] and [KaTeX].
24+
25+
### MathJax
26+
27+
[MathJax] is a powerful and flexible library that supports multiple input formats,
28+
such as [LaTeX], [MathML], [AsciiMath], as well as various output formats like
29+
HTML, SVG, MathML. To use MathJax within your project, add the following lines
30+
to your `mkdocs.yml`.
2331

2432
=== ":octicons-file-code-16: `docs/javascripts/mathjax.js`"
2533

@@ -44,37 +52,51 @@ lines to `mkdocs.yml`:
4452

4553
1. This integrates MathJax with [instant loading].
4654

47-
=== ":octicons-file-code-16: `docs/javascripts/katex.js`"
48-
49-
``` js
50-
document$.subscribe(() => { // (1)!
51-
renderMathInElement(document.body, {
52-
delimiters: [
53-
{left: '$$', right: '$$', display: true},
54-
{left: '$', right: '$', display: false},
55-
{left: '\\(', right: '\\)', display: false},
56-
{left: '\\[', right: '\\]', display: true},
57-
],
58-
});
59-
})
60-
```
61-
62-
1. This integrates KaTeX with [instant loading].
63-
64-
=== ":octicons-file-code-16: `mkdocs.yml` for MathJax"
55+
=== ":octicons-file-code-16: `mkdocs.yml`"
6556

6657
``` yaml
6758
markdown_extensions:
6859
- pymdownx.arithmatex:
6960
generic: true
7061

7162
extra_javascript:
72-
- javascripts/mathjax.js
63+
- javascripts/mathjax.js
7364
- https://polyfill.io/v3/polyfill.min.js?features=es6
7465
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
7566
```
7667

77-
=== ":octicons-file-code-16: `mkdocs.yml` for KaTeX"
68+
See additional configuration options:
69+
70+
- [Arithmatex]
71+
72+
[Arithmatex]: ../setup/extensions/python-markdown-extensions.md#arithmatex
73+
[instant loading]: ../setup/setting-up-navigation.md#instant-loading
74+
75+
76+
### KaTeX
77+
78+
[KaTeX] is a lightweight library that focuses on speed and simplicity. It
79+
supports a subset of LaTeX syntax and can render math to HTML and SVG. To use
80+
[KaTeX] within your project, add the following lines to your `mkdocs.yml`.
81+
82+
=== ":octicons-file-code-16: `docs/javascripts/katex.js`"
83+
84+
``` js
85+
document$.subscribe(({ body }) => { // (1)!
86+
renderMathInElement(body, {
87+
delimiters: [
88+
{ left: "$$", right: "$$", display: true },
89+
{ left: "$", right: "$", display: false },
90+
{ left: "\\(", right: "\\)", display: false },
91+
{ left: "\\[", right: "\\]", display: true }
92+
],
93+
})
94+
})
95+
```
96+
97+
1. This integrates KaTeX with [instant loading].
98+
99+
=== ":octicons-file-code-16: `mkdocs.yml`"
78100

79101
``` yaml
80102
extra_javascript:
@@ -86,15 +108,8 @@ lines to `mkdocs.yml`:
86108
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css
87109
```
88110

89-
1. Or you can adgitd these JS/CSS via `<script>` tag by overriding HTML files.
90-
91-
92-
See additional configuration options:
111+
1. Alternatively, you can add these JavaScript and CSS files via `script` tags by overriding HTML files.
93112

94-
- [Arithmatex]
95-
96-
[Arithmatex]: ../setup/extensions/python-markdown-extensions.md#arithmatex
97-
[instant loading]: ../setup/setting-up-navigation.md#instant-loading
98113

99114
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
100115
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
@@ -113,14 +128,15 @@ See additional configuration options:
113128
};
114129
</script>
115130

131+
116132
## Usage
117133

118134
### Using block syntax
119135

120136
Blocks must be enclosed in `#!latex $$...$$` or `#!latex \[...\]` on separate
121137
lines:
122138

123-
``` latex title="MathJax, block syntax"
139+
``` latex title="block syntax"
124140
$$
125141
\operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}}
126142
$$
@@ -138,7 +154,7 @@ $$
138154

139155
Inline blocks must be enclosed in `#!latex $...$` or `#!latex \(...\)`:
140156

141-
``` latex title="MathJax, inline syntax"
157+
``` latex title="inline syntax"
142158
The homomorphism $f$ is injective if and only if its kernel is only the
143159
singleton set $e_G$, because otherwise $\exists a,b\in G$ with $a\neq b$ such
144160
that $f(a)=f(b)$.
@@ -151,3 +167,32 @@ singleton set $e_G$, because otherwise $\exists a,b\in G$ with $a\neq b$ such
151167
that $f(a)=f(b)$.
152168

153169
</div>
170+
171+
172+
## Comparing MathJax and KaTeX
173+
174+
When deciding between MathJax and KaTeX, there are several key factors to
175+
consider:
176+
177+
- __Speed__: KaTeX is generally faster than MathJax. If your site requires rendering large
178+
quantities of complex equations quickly, KaTeX may be the better choice.
179+
180+
- __Syntax Support__: MathJax supports a wider array of LaTeX commands and can
181+
process a variety of mathematical markup languages (like AsciiMath and MathML).
182+
If you need advanced LaTeX features, MathJax may be more suitable.
183+
184+
- __Output Format__: Both libraries support HTML and SVG outputs. However,
185+
MathJax also offers MathML output, which can be essential for accessibility, as
186+
it is readable by screen readers.
187+
188+
- __Configurability__: MathJax provides a range of configuration options,
189+
allowing for more precise control over its behavior. If you have specific
190+
rendering requirements, MathJax might be a more flexible choice.
191+
192+
- __Browser Support__: While both libraries work well in modern browsers,
193+
MathJax has broader compatibility with older browsers. If your audience uses a
194+
variety of browsers, including older ones, MathJax might be a safer option.
195+
196+
In summary, KaTeX shines with its speed and simplicity, whereas MathJax offers
197+
more features and better compatibility at the expense of speed. The choice
198+
between the two will largely depend on your specific needs and constraints.

0 commit comments

Comments
 (0)