Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit e701696

Browse files
committed
Add support for MathJax v3
1 parent 6a9563a commit e701696

8 files changed

+144
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased] -
99

10+
### Changed
11+
- Updated MathJax to v3. Added options to select component
12+
combination (e.g. tex-svg) and equation numbering (e.g. AMS).
13+
1014
### Added
1115
- Add Turkish translations to `text.yml`. [#355](https://github.com/mmistakes/so-simple-theme/pull/355)
1216

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,26 @@ words_per_minute: 200
407407

408408
### Mathematics
409409

410-
Enable [**MathJax**](https://www.mathjax.org) (a JavaScript display engine for mathematics) site-wide with `mathjax: true`.
410+
Enable [**MathJax**](https://www.mathjax.org) (a JavaScript display engine for mathematics) site-wide with
411+
412+
``` yaml
413+
mathjax:
414+
enable: true
415+
```
416+
417+
The `combo` option lets you to choose a [MathJax component
418+
combination](http://docs.mathjax.org/en/latest/web/components/combined.html)--the
419+
default is "tex-svg." And, the `tags` option lets you control
420+
equation numbering--choices are "ams" (default), "all", and "none."
421+
422+
Sample configuration:
423+
424+
``` yaml
425+
mathjax:
426+
enable: true # MathJax equations, e.g. true, false (default)
427+
combo: "tex-svg" # "tex-svg" (default), "tex-mml-chtml", etc.
428+
tags: "ams" # "none", "ams" (default), "all"
429+
```
411430

412431
### Google Fonts
413432

_config.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ logo: # path of site logo, e.g. "/images/logo.png"
2525
date_format: "%B %-d, %Y"
2626
read_time: # reading time estimates, e.g. true
2727
words_per_minute: # 200
28-
mathjax: # MathJax equations, e.g. true
28+
mathjax:
29+
enable: # MathJax equations, e.g. true, false (default)
30+
combo: # "tex-svg" (default), "tex-mml-chtml", etc.: docs.mathjax.org/en/latest/web/components/combined.html
31+
tags: # "none", "ams" (default), "all"
2932
google_fonts:
3033
- name: "Source Sans Pro"
3134
weights: "400,400i,700,700i"

_includes/scripts.html

+28-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,35 @@
2626
</script>
2727
{%- endif %}
2828

29-
{% if site.mathjax == true %}
29+
{% if site.mathjax == true or site.mathjax.enable == true %}
3030
<!-- MathJax -->
31-
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
31+
{% capture mathjaxjs %}https://cdn.jsdelivr.net/npm/mathjax@3/es5/{{ site.mathjax.combo | default: "tex-svg" }}.js{% endcapture %}
32+
<script>
33+
// http://docs.mathjax.org/en/latest/upgrading/v2.html
34+
MathJax = {
35+
tex: {
36+
tags: "{{ site.mathjax.tags | default: 'ams' }}" // eq numbering options: none, ams, all
37+
},
38+
options: {
39+
renderActions: {
40+
// for mathjax 3, handle <script "math/tex"> blocks inserted by kramdown
41+
find: [10, function (doc) {
42+
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
43+
const display = !!node.type.match(/; *mode=display/);
44+
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
45+
const text = document.createTextNode('');
46+
node.parentNode.replaceChild(text, node);
47+
math.start = {node: text, delim: '', n: 0};
48+
math.end = {node: text, delim: '', n: 0};
49+
doc.math.push(math);
50+
}
51+
}, '']
52+
}
53+
}
54+
}
55+
</script>
56+
57+
<script type="text/javascript" id="MathJax-script" async src="{{ mathjaxjs }}"></script>
3258
{% endif %}
3359

3460
{%- if page.layout == "search" -%}

docs/_config.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ logo: "/images/so-simple-site-logo.png"
2626
date_format: "%B %-d, %Y"
2727
read_time: true
2828
words_per_minute: # 200
29-
mathjax: true
29+
mathjax:
30+
enable: true
31+
combo: "tex-svg"
32+
tags: "ams"
3033
google_fonts:
3134
- name: "Source Sans Pro"
3235
weights: "400,400i,700,700i"

docs/_posts/2015-08-10-mathjax-example.md

+40-8
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,55 @@ title: "MathJax Example"
33
date: 2015-08-10T08:08:50-04:00
44
---
55

6-
[MathJax](http://www.mathjax.org/) is a simple way of including Tex/LaTex/MathML based mathematics in HTML webpages. To get up and running you need to include the MathJax script in the header of your github pages page, and then write some maths. For LaTex, there are two delimiters you need to know about, one for block or displayed mathematics `\[ ... \]`, and the other for inline mathematics `\( ... \)`.
6+
[MathJax](http://www.mathjax.org/) is a simple, yet powerful, way of
7+
including Tex/LaTex/MathML based mathematics in HTML webpages.
78

89
## Usage
910

10-
To enable MathJax support be sure Kramdown is your Markdown flavor of choice and MathJax is set to true in your `_config.yml` file.
11+
To enable MathJax support configure your `_config.xml` to:
12+
* Set `kramdown` as the Markdown parser.
13+
* Enable MathJax.
14+
15+
The version of MathJax enabled is v3.
16+
17+
An example setting for `_config.xml` is shown below:
1118

1219
```yaml
1320
markdown: kramdown
14-
mathjax: true
21+
mathjax:
22+
enable: true
23+
combo: "tex-svg"
24+
tags: "ams"
1525
```
1626
17-
$$a^2 + b^2 = c^2$$
27+
Use `$$` as delimiters to enable TeX math mode, both for inline and display (i.e. block) rendering.
28+
29+
Here is an example equation that is inline: $$a^2 + b^2 = c^2$$, where
30+
$$a$$, $$b$$, and $$c$$ are variables.
31+
32+
Here is a block rendering with no default equation numbering:
33+
34+
$$
35+
\frac{1}{n^{2}}
36+
$$
37+
38+
And, below is a block using the `\begin{equation}` and
39+
`\end{equation}` LaTeX delimiters. This equation will be numbered in
40+
the `ams` and `all` setting for `mathjax.tags`.
1841

19-
Here is an example MathJax inline rendering \\( 1/x^{2} \\), and here is a block rendering:
42+
$$
43+
\begin{equation}
44+
\mathbf{X}_{n,p} = \mathbf{A}_{n,k} \mathbf{B}_{k,p} \label{test}
45+
\end{equation}
46+
$$
2047

21-
\\[ \frac{1}{n^{2}} \\]
48+
If equation numbering is turned on, we should see an equation number here: $$\eqref{test}$$.
2249

23-
The only thing to look out for is the escaping of the backslash when using markdown, so the delimiters become `\\[ ... \\]` and `\\( ... \\)` for inline and block maths respectively.
50+
An example using the `{align}` LaTeX environment is below. The first equation has a `\notag` directive.
2451

25-
$$ \mathbf{X}\_{n,p} = \mathbf{A}\_{n,k} \mathbf{B}\_{k,p} $$
52+
$$
53+
\begin{align}
54+
(x + y) (x - y) &= x^2 + xy - xy + y^2 \notag \\
55+
&= x^2 - y^2
56+
\end{align}
57+
$$

example/_config.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ logo: "/images/so-simple-site-logo.png" # path of site logo, e.g. "/assets/image
2525
date_format: "%B %-d, %Y"
2626
read_time: true
2727
words_per_minute: 200
28-
mathjax: true
28+
mathjax:
29+
enable: true
30+
# combo: "tex-mml-chtml"
31+
# tags: "none"
2932
google_fonts:
3033
- name: "Source Sans Pro"
3134
weights: "400,400i,700,700i"

example/_posts/2015-08-10-mathjax-example.md

+40-8
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,55 @@ title: "MathJax Example"
33
date: 2015-08-10T08:08:50-04:00
44
---
55

6-
[MathJax](http://www.mathjax.org/) is a simple way of including Tex/LaTex/MathML based mathematics in HTML webpages. To get up and running you need to include the MathJax script in the header of your github pages page, and then write some maths. For LaTex, there are two delimiters you need to know about, one for block or displayed mathematics `\[ ... \]`, and the other for inline mathematics `\( ... \)`.
6+
[MathJax](http://www.mathjax.org/) is a simple, yet powerful, way of
7+
including Tex/LaTex/MathML based mathematics in HTML webpages.
78

89
## Usage
910

10-
To enable MathJax support be sure Kramdown is your Markdown flavor of choice and MathJax is set to true in your `_config.yml` file.
11+
To enable MathJax support configure your `_config.xml` to:
12+
* Set `kramdown` as the Markdown parser.
13+
* Enable MathJax.
14+
15+
The version of MathJax enabled is v3.
16+
17+
An example setting for `_config.xml` is shown below:
1118

1219
```yaml
1320
markdown: kramdown
14-
mathjax: true
21+
mathjax:
22+
enable: true
23+
combo: "tex-svg"
24+
tags: "ams"
1525
```
1626
17-
$$a^2 + b^2 = c^2$$
27+
Use `$$` as delimiters to enable TeX math mode, both for inline and display (i.e. block) rendering.
28+
29+
Here is an example equation that is inline: $$a^2 + b^2 = c^2$$, where
30+
$$a$$, $$b$$, and $$c$$ are variables.
31+
32+
Here is a block rendering with no default equation numbering:
33+
34+
$$
35+
\frac{1}{n^{2}}
36+
$$
37+
38+
And, below is a block using the `\begin{equation}` and
39+
`\end{equation}` LaTeX delimiters. This equation will be numbered in
40+
the `ams` and `all` setting for `mathjax.tags`.
1841

19-
Here is an example MathJax inline rendering \\( 1/x^{2} \\), and here is a block rendering:
42+
$$
43+
\begin{equation}
44+
\mathbf{X}_{n,p} = \mathbf{A}_{n,k} \mathbf{B}_{k,p} \label{test}
45+
\end{equation}
46+
$$
2047

21-
\\[ \frac{1}{n^{2}} \\]
48+
If equation numbering is turned on, we should see an equation number here: $$\eqref{test}$$.
2249

23-
The only thing to look out for is the escaping of the backslash when using markdown, so the delimiters become `\\[ ... \\]` and `\\( ... \\)` for inline and block maths respectively.
50+
An example using the `{align}` LaTeX environment is below. The first equation has a `\notag` directive.
2451

25-
$$ \mathbf{X}\_{n,p} = \mathbf{A}\_{n,k} \mathbf{B}\_{k,p} $$
52+
$$
53+
\begin{align}
54+
(x + y) (x - y) &= x^2 + xy - xy + y^2 \notag \\
55+
&= x^2 - y^2
56+
\end{align}
57+
$$

0 commit comments

Comments
 (0)