Display mathematical notation in web pages with MathJax.
The support of displaying math symbols with html tags is limited. Though you can use UTF-8 to display some special characters, it is hard to remember them and it is inconvenient to use.
| Title | Formula | HTML Tag |
|---|---|---|
| Square | n2 | n<sup>2</sup> |
| Square Root | √, √ | √, or √ |
| Summary | ∑, ∑ | ∑, or ∑ |
MathJax is a cross-browser JavaScript library that displays mathematical notation in web browsers.
The preferred way to use MathJax on a web page is by linking to the publicly available MathJax Content Delivery Network(CDN). This can be done by adding the following code snippet into the HTML header block(the code between <head> and </head>) of your HTML or XHTML document:
<script
type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
For greater security, it is also possible to access the CDN via https:
<script
type="text/javascript"
async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML"
></script>
With the link to MathJax in the HTML header in place, MathJax will recognize and render MathML elements that are included in the document with the standard <math> tags. A minimal example of a fully functional HTML page with embedded MathML using MathJax from the CDN could be the following:
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
</head>
<body>
Let's consider <math><mi>a</mi><mo>≠</mo><mn>0</mn></math
>.
</body>
</html>

Create a file named with mathjax.html in _include directory as follows:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: {
autoNumber: "AMS"
}
},
tex2jax: {
inlineMath: [ ['$','$'], ['\\(', '\\)'] ],
displayMath: [ ['$$','$$'] ],
processEscapes: true,
}
});
</script>
<script
type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
></script>
Update file _inlude/head.html, include the above template file if page.mathjax is true.
{% if page.mathjax %}
{% include mathjax.html %}
{% endif %}
In order to use the math formula in markdown page, it must have a variable mathjax and set its value to true. For example, the following example is a markdown page using mathjax.
---
title: "Using MathJax in Jekyll"
date: 2018-07-10
tags: [MathJax, Mathematic]
mathjax: true
---
$a^2 + b^2 = c^2$
Then you will get the formula as follows.
$a^2 + b^2 = c^2$
$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $
Then you will get the formula as follows.
$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $
$$\begin{eqnarray}
x' &=& &x \sin\phi &+& z \cos\phi \\
z' &=& - &x \cos\phi &+& z \sin\phi \\
\end{eqnarray}$$
Then you will get the formula as follows.
\[\begin{eqnarray} x' &=& &x \sin\phi &+& z \cos\phi \\ z' &=& - &x \cos\phi &+& z \sin\phi \\ \end{eqnarray}\]Here are some notes about the above example:
$ ... $.$$ ... $$.\begin{equation}...\end{equation} or \begin{align}...\end{align}.* must be escaped.\\ should be escaped, i.e., use four backslash \\\\.