2

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..

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
yinsenm
  • 23
  • 1
  • 3

1 Answers1

8

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/.

Peter Krautzberger
  • 5,145
  • 19
  • 31
  • 1
    Thank you! You are right. Kramdown use both `$$ ... $$` as inline and display math. By `$$\begin{equation} ... \end{equation}$$`, I can display my formula with number labelled. I tried the configuration you mentioned, but it doesn't work.. Although I don't exactly why, I find articles explaining that MathJax use `\( ... \)` or `\[ ... \]` as math separators. However, those might be processed by kramdown before MathJax. Thanks for your answer! It finally works! :) – yinsenm Aug 10 '14 at 07:05
  • Glad it works to some degree. I'm guessing you could add your preferred delimiters to the kramdown parser, but that's perhaps not ideal. – Peter Krautzberger Aug 10 '14 at 08:35
  • Yes! As long as `$$...$$` works well for me, I can use Lyx (a visual latex processor) to help me translate math into LateX code. It saves me a lot of time just by replacing the single `$` with double `$`s. Thank you! Now I can put formula in my post! That's really awesome! – yinsenm Aug 10 '14 at 21:56
  • The configuration you mentioned doesn't work neither for me... Hope there's other solution. – Ray Eldath Jan 29 '18 at 08:05