2
2
icon : material/alphabet-greek
3
3
---
4
4
5
- # MathJax
5
+ # Math
6
6
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.
11
12
12
13
[ MathJax ] : https://www.mathjax.org/
13
14
[ LaTeX ] : https://en.wikibooks.org/wiki/LaTeX/Mathematics
14
15
[ MathML ] : https://en.wikipedia.org/wiki/MathML
15
16
[ AsciiMath ] : http://asciimath.org/
16
17
[ KaTeX ] : https://katex.org/
17
18
19
+
18
20
## Configuration
19
21
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 ` .
23
31
24
32
=== ":octicons-file-code-16: ` docs/javascripts/mathjax.js ` "
25
33
@@ -44,37 +52,51 @@ lines to `mkdocs.yml`:
44
52
45
53
1. This integrates MathJax with [instant loading].
46
54
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 ` "
65
56
66
57
``` yaml
67
58
markdown_extensions:
68
59
- pymdownx.arithmatex:
69
60
generic: true
70
61
71
62
extra_javascript:
72
- - javascripts/mathjax.js
63
+ - javascripts/mathjax.js
73
64
- https://polyfill.io/v3/polyfill.min.js?features=es6
74
65
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
75
66
```
76
67
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 ` "
78
100
79
101
``` yaml
80
102
extra_javascript:
@@ -86,15 +108,8 @@ lines to `mkdocs.yml`:
86
108
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css
87
109
```
88
110
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.
93
112
94
- - [ Arithmatex]
95
-
96
- [ Arithmatex ] : ../setup/extensions/python-markdown-extensions.md#arithmatex
97
- [ instant loading ] : ../setup/setting-up-navigation.md#instant-loading
98
113
99
114
<script src =" https://polyfill.io/v3/polyfill.min.js?features=es6 " ></script >
100
115
<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:
113
128
};
114
129
</script >
115
130
131
+
116
132
## Usage
117
133
118
134
### Using block syntax
119
135
120
136
Blocks must be enclosed in ` #!latex $$...$$ ` or ` #!latex \[...\] ` on separate
121
137
lines:
122
138
123
- ``` latex title="MathJax, block syntax"
139
+ ``` latex title="block syntax"
124
140
$$
125
141
\operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}}
126
142
$$
138
154
139
155
Inline blocks must be enclosed in ` #!latex $...$ ` or ` #!latex \(...\) ` :
140
156
141
- ``` latex title="MathJax, inline syntax"
157
+ ``` latex title="inline syntax"
142
158
The homomorphism $f$ is injective if and only if its kernel is only the
143
159
singleton set $e_G$, because otherwise $\exists a,b\in G$ with $a\neq b$ such
144
160
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
151
167
that $f(a)=f(b)$.
152
168
153
169
</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