I have a Jekyll blog and I want to use MathJax with it, in the sense that I want to be able to type something like
$$\sum_{n=1}^\infty 1/n^2 = \frac{\pi^2}{6}$$
in my markdown files, and have the correct LaTeX expression generated with MathJax, in a similar way to how it is done at math.stackexchange.
What is the easiest way to do this? Currently I have the file jsmath.js (GitHub gist) in my directory, and I thought I could have a simple file named mathjs
in my _includes
directory with the line
<script src="path/to/jsmath.js></script>
and include that in each post via
{% include mathjs %}
but this doesn't seem to work - when I run jekyll --server
the page is generated, but none of the content is visible.
Am I going about this the right way? Is there a better way to use MathJax with Jekyll?
The support for TeX and LaTeX in MathJax consists of two parts: the tex2jax preprocessor, and the TeX input processor. The first of these looks for mathematics within your web page (indicated by math delimiters like $$... $$ ) and marks the mathematics for later processing by MathJax.
MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers.
Certainly you can use mathjax with Jekyll. To get this working make sure that
<div>
elements and inline math in <span>
elements, which most markdown interpreters will leave alone. Is the javascript line displaying correctly in the html source? I find it easier and faster to point to the mathjax CDN rather than provide my own copy. Try using the line
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
(Those configuration options allow you to use more tex notation to start your math environment, such as \begin{equation}
, etc).
Perhaps there is some issue with your jsmath.js
script; the CDN version will be faster and probably more reliable. (I have the javascript load in my footer on every page, but of course your strategy with include makes sense if you don't want to load the javascript when you don't need it.)
We could help more if you give us a link to your blog? You can see some examples on my blog (has link to Jekyll setup on github too if that helps).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With