Skip to content

Commit 456a13c

Browse files
committed
Added Mathjax feature and examples. Squashed commits
1 parent 023fe7e commit 456a13c

File tree

6 files changed

+225
-1
lines changed

6 files changed

+225
-1
lines changed

exampleSite/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defaultContentLanguageInSubdir= true
1717
disableNextPrev = false
1818
disableMermaid = false
1919
customMermaidURL = "https://unpkg.com/mermaid@8.8.0/dist/mermaid.min.js"
20+
disableMathJax = false
2021
titleSeparator = "::"
2122

2223
[outputs]
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
title: "MathJax"
3+
description: "Display engine for LaTeX, MathML, and AsciiMath
4+
notation that works in all modern browsers."
5+
---
6+
7+
[Mathjax](https://github.com/mathjax/MathJax) is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath
8+
notation that works in all modern browsers. By default mathjax is **enabled** in the config.toml by default and can be
9+
disabled if library is not used.
10+
11+
Examples, in this page are taken from [here](https://mathjax.github.io/MathJax-demos-web/tex-svg.html).
12+
13+
Automatic equation numbering is on by default as shown in Example 2
14+
15+
Just insert your mathjax code in the `mathjax` shortcode and that's it.
16+
17+
18+
### Example 1
19+
20+
```
21+
{{</*mathjax*/>}}
22+
23+
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
24+
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
25+
26+
{{</*/mathjax*/>}}
27+
```
28+
renders as
29+
30+
{{<mathjax>}}
31+
32+
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
33+
34+
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
35+
36+
{{</mathjax>}}
37+
38+
### Example 2
39+
40+
The Lorenz Equations
41+
42+
```
43+
{{</*mathjax*/>}}
44+
45+
\begin{align}
46+
\dot{x} &amp; = \sigma(y-x) \\
47+
\dot{y} &amp; = \rho x - y - xz \\
48+
\dot{z} &amp; = -\beta z + xy
49+
\end{align}
50+
51+
{{</*/mathjax*/>}}
52+
```
53+
renders as
54+
55+
{{<mathjax>}}
56+
57+
\begin{align}
58+
\dot{x} &amp; = \sigma(y-x) \\
59+
\dot{y} &amp; = \rho x - y - xz \\
60+
\dot{z} &amp; = -\beta z + xy
61+
\end{align}
62+
63+
{{</mathjax>}}
64+
65+
### Example 3
66+
67+
The Cauchy-Schwarz Inequality
68+
69+
```
70+
{{</*mathjax*/>}}
71+
72+
\[
73+
\left( \sum_{k=1}^n a_k b_k \right)^{\!\!2} \leq
74+
\left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
75+
\]<
76+
77+
{{</*/mathjax*/>}}
78+
```
79+
80+
renders as
81+
82+
{{<mathjax>}}
83+
84+
\[
85+
\left( \sum_{k=1}^n a_k b_k \right)^{\!\!2} \leq
86+
\left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
87+
\]<
88+
89+
{{</mathjax>}}
90+
91+
### Example 4
92+
93+
A Cross Product Formula
94+
95+
```
96+
{{</*mathjax*/>}}
97+
98+
\[
99+
\mathbf{V}_1 \times \mathbf{V}_2 =
100+
\begin{vmatrix}
101+
\mathbf{i} &amp; \mathbf{j} &amp; \mathbf{k} \\
102+
\frac{\partial X}{\partial u} &amp; \frac{\partial Y}{\partial u} &amp; 0 \\
103+
\frac{\partial X}{\partial v} &amp; \frac{\partial Y}{\partial v} &amp; 0 \\
104+
\end{vmatrix}
105+
\]
106+
107+
{{</*/mathjax*/>}}
108+
```
109+
110+
renders as
111+
112+
{{<mathjax>}}
113+
\[
114+
\mathbf{V}_1 \times \mathbf{V}_2 =
115+
\begin{vmatrix}
116+
\mathbf{i} &amp; \mathbf{j} &amp; \mathbf{k} \\
117+
\frac{\partial X}{\partial u} &amp; \frac{\partial Y}{\partial u} &amp; 0 \\
118+
\frac{\partial X}{\partial v} &amp; \frac{\partial Y}{\partial v} &amp; 0 \\
119+
\end{vmatrix}
120+
\]
121+
122+
{{</mathjax>}}
123+
124+
### Example 5
125+
126+
The probability of getting \(k\) heads when flipping \(n\) coins is:
127+
128+
```
129+
{{</*mathjax*/>}}
130+
131+
\[P(E) = {n \choose k} p^k (1-p)^{ n-k} \]
132+
133+
{{</*/mathjax*/>}}
134+
135+
```
136+
137+
renders as
138+
139+
{{<mathjax>}}
140+
141+
\[P(E) = {n \choose k} p^k (1-p)^{ n-k} \]
142+
143+
{{</mathjax>}}
144+
145+
### Example 6
146+
147+
An Identity of Ramanujan
148+
149+
```
150+
{{</*mathjax*/>}}
151+
152+
\[
153+
\frac{1}{(\sqrt{\phi \sqrt{5}}-\phi) e^{\frac25 \pi}} =
154+
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
155+
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
156+
\]
157+
158+
{{</*/mathjax*/>}}
159+
```
160+
161+
renders as
162+
163+
{{<mathjax>}}
164+
165+
\[
166+
\frac{1}{(\sqrt{\phi \sqrt{5}}-\phi) e^{\frac25 \pi}} =
167+
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
168+
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
169+
\]
170+
171+
{{</mathjax>}}
172+
173+
174+
### Example 7
175+
176+
In-line Mathematics
177+
178+
```
179+
{{</*mathjax*/>}}
180+
181+
Finally, while display equations look good for a page of samples, the
182+
ability to mix math and text in a paragraph is also important. This
183+
expression $\sqrt{3x-1}+(1+x)^2$ is an example of an inline equation. As
184+
you see, MathJax equations can be used this way as well, without unduly
185+
disturbing the spacing between lines.
186+
187+
{{</*/mathjax*/>}}
188+
189+
```
190+
191+
renders as
192+
193+
{{<mathjax>}}
194+
Finally, while display equations look good for a page of samples, the
195+
ability to mix math and text in a paragraph is also important. This
196+
expression $\sqrt{3x-1}+(1+x)^2$ is an example of an inline equation. As
197+
you see, MathJax equations can be used this way as well, without unduly
198+
disturbing the spacing between lines.
199+
{{</mathjax>}}
200+
201+

layouts/partials/footer.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@
7878
mermaid.initialize({ startOnLoad: true });
7979
</script>
8080
{{ end }}
81+
82+
{{ if (or (and (ne .Params.disableMathJax nil) (not .Params.disableMathJax)) (not .Site.Params.disableMathJax)) }}
83+
<script>
84+
MathJax = {
85+
tex: {
86+
inlineMath: [['$', '$'], ['\\(', '\\)']],
87+
tags: 'ams'
88+
},
89+
svg: {fontCache: 'global'},
90+
options: {
91+
ignoreHtmlClass: "no-mathjax",
92+
processHtmlClass: "mathjax",
93+
94+
}
95+
};
96+
</script>
97+
<script src="{{"js/mathjax.min.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
98+
{{ end }}
99+
81100
{{ partial "custom-footer.html" . }}
82101
</body>
83102
</html>

layouts/partials/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</style>
4040
{{ partial "custom-header.html" . }}
4141
</head>
42-
<body class="" data-url="{{ .RelPermalink }}">
42+
<body class="no-mathjax" data-url="{{ .RelPermalink }}">
4343
{{ partial "menu.html" . }}
4444
<section id="body">
4545
<div id="overlay"></div>

layouts/shortcodes/mathjax.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ $_hugo_config := `{ "version": 1 }` }}
2+
<div class="mathjax">{{ safeHTML .Inner }}</div>

static/js/mathjax.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)