MathJax 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 \( ... \)
.
Usage
To enable MathJax support be sure Kramdown is your Markdown flavor of choice and MathJax is set to true in your _config.yml
file.
markdown: kramdown
mathjax: true
Here is an example MathJax inline rendering \\( 1/x^{2} \\), and here is a block rendering:
\\[ \frac{1}{n^{2}} \\]
Here is an example MathJax inline rendering \( 1/x^{2} \), and here is a block rendering: \[ \frac{1}{n^{2}} \]
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.
The default math delimiters are $$...$$
and \[...\]
for displayed mathematics, and \(...\)
for in-line mathematics. Note in particular that the $...$
in-line delimiters are not used by default. That is because dollar signs appear too often in non-mathematical settings, which could cause some text to be treated as mathematics unexpectedly. For example, with single-dollar delimiters, ”… the cost is $2.50
for the first one, and $2.00
for each additional one …” would cause the phrase “2.50 for the first one, and” to be treated as mathematics since it falls between dollar signs. For this reason, if you want to use single-dollars for in-line math mode, you must enable that explicitly in your configuration:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async src="path-to-mathjax/MathJax.js?config=TeX-AMS_CHTML"></script>
Example: When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are \[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\tag{1}\]
\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\tag{2}\] \[2+3=5,\sqrt{2}=1.414\cdots\]