Search code examples
jekyllmathjaxkramdown

Mathjax render issues on combination of bmatrix from jekyll with kramdown


I use jekyll to build a static blog with kramdown and use mathjax to render the LaTeX equation in markdown files.

To make mathjax work for all files I write mathjax in _layout/default.html where add following:

<script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        extensions: [
          "tex2jax.js",
          "MathMenu.js",
          "MathZoom.js",
          "AssistiveMML.js",
          "a11y/accessibility-menu.js"
        ],
        tex2jax: {
          inlineMath: [['$', '$']],
          displayMath: [['$$', '$$']]
        },
        jax: ["input/TeX", "output/CommonHTML"],
        TeX: {
          extensions: [
            "AMSmath.js",
            "AMSsymbols.js",
            "noErrors.js",
            "noUndefined.js",
          ]
        }
      });
    </script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

A quick example, I can render

$(a_n)_{n=1}^{\infty}$

but failed:

$(a_n)_{n=1}^{\infty} = (a_n)_{n=1}^{\infty}$

It also appear in other equation, e.g.

Before Separate

the equation I exactly write is:

$(1 / \sqrt{n}) 1_n$ \: $ d_i = Y_i - \bar X_i 1_n = \begin{bmatrix} y_{i1} - \bar x_i \\\ y_{i2} - \bar x_i \\\ \vdots \\\ y_{in} - \bar x_i \end{bmatrix}$

But I separate them such as (first part with colon on the first line):

We also have deviation vectore which the collection of the distance of each element from $Y_i$ to its projection on $(1 / \sqrt{n}) 1_n$:

$d_i = Y_i - \bar X_i 1_n =$ 

$\begin{bmatrix} y_{i1} - \bar x_i \\\ y_{i2} - \bar x_i \\\ \vdots \\\ y_{in} - \bar x_i \end{bmatrix}$

then each of them renders correctly:

after separate

I wonder why and how can I fix it :(

For reference, see also my Markdown on GitHub and my page.


Solution

  • Markdown uses underscores to produce italics, and in systems that don't protect the mathematics from being processed by markdown, that can lead to HTML tags being inserted in the middle of the mathematics. Note that in your screen shot of the un-typeset mathematics, the underscore for 1_n is missing, and the text following it, up to the missing underscore for y_{i1} are in italics. That means Markdown has processed and removed this underscores and inserted tags to produce italics. Since MathJax doesn't process math containing HTML tags, that is why the math isn't being processed. See the MathJax documentation for more details.

    One solution is to use \_ rather than _ for the underscores, as that will prevent Markdown from processing them, and they will be sent to MathJax as plain underscores.