Locally hosting MathJax under Jekyll
MathJax is a JavaScript library that, when loaded within a web page, enables the inclusion of beautifully typeset mathematical equations; for example: or . Among other formats, you can specify the equations to be rendered using LaTeX’s syntax.
To enable MathJax within a page, one can include a <script> tag that loads the MathJax library from MathJax’s CDN.
While this seems to be the most commonly recommended approach, it does mean introducing an external dependency in your site.
An alternative is to host a copy of the MathJax code yourself.
You can download the latest MathJax source (at the time of writing the filename is v2.4-latest.zip) from the MathJax website.
Since the distribution is large and contains many files, when serving from a Jekyll enabled site, you don’t want the MathJax distribution processed by Jekyll. To achieve this, edit your site’s _config.yml file to include the line:
keep_files: [MathJax]
and then move the unpacked contents of the zip file to a MathJax directory within your _site folder (if you are running jekyll serve, you’ll want to restart that so it knows about your configuration changes.
Then go into your site’s _includes/head.html file and add (within the <head> section) the line:
<script type="text/javascript" src="/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>To test the installation, while jekyll serve is running, point your browser to http://127.0.0.1:4000/MathJax/test/; you should see a nicely formatted equaiton.
To embed equations in your own Jekyll pages, enclose LaTeX math expressions within a pair of $$, just like you would with in-line LaTeX math; for example, the first equation in the first paragraph of this post in encoded as: $$ \nabla \cdot E = \frac{\rho}{\epsilon_0} $$.