markdownjekyllmathjaxkramdown

How to use mathjax in Jekyll?


I tried using Jekyll with kramdown to build a website of my own. Also, I want to include mathjax to render the mathematical formulae. However, the kramdown markdown seems to have conflict with mathjax. I can't render formulae correctly, if I didn't quote the formular.

I added those codes to my template file:

<script type="text/x-mathjax-config">
        MathJax.Hub.Config({
            tex2jax: {
              skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
            }
          });

        MathJax.Hub.Queue(function() {
            var all = MathJax.Hub.getAllJax(), i;
            for(i=0; i < all.length; i += 1) {
                all[i].SourceElement().parentNode.className += ' has-jax';
            }
        });

</script>

<script type="text/javascript"
        src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

Now it's working but I have to add the quotes around the formulae and kramdown translate them as this style. You can see on my webpage. Is any better solution other than this method? I find it annoying to add an extra quotation mark around my $\LaTeX$ code. I found that this solution is what I want to have. It has the same syntax as I typed in TeX, but I don't understand the code..


Solution

  • Looking at the kramdown parser (or simply the test cases), kramdown seems to default to using $$...$$ for both inline and display math, with the kramdown parser telling the difference. It actually converts such math nicely to MathJax's custom script tags in the HTML.

    It seems people have successfully used other MathJax configurations, e.g., http://www.idryman.org/blog/2012/03/10/writing-math-equations-on-octopress/.