Using MathJax with Jekyll
Solution 1:
Certainly you can use mathjax with Jekyll. To get this working make sure that
- If you're writing your post in markdown, your markdown interpreter isn't hammering your mathjax input. The best way to protect it I have found is to always put display math in
<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).
Solution 2:
If you have sufficient control over the publishing process (e.g. you are running Jekyll yourself), an easy solution is to switch the markdown parser to one that supports TeX. For example, using kramdown:
gem install kramdown
Change the markdown
line in _config.yml
to
markdown: kramdown
and add something like
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
to _layouts/default.html
. Now you can simply mark any mathematics in your posts with $$
.