githubjekyllgithub-pagesequationmathjax

MathJax does not allow multi-row in-line math on GitHub Pages


This is my mathjax.html:

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    TeX: {
      equationNumbers: { autoNumber: "all" },
      tagSide: "right"
    },
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      processEscapes: true
    }
  });
</script>
<script
  src="https://cdn.jsdelivr.net/gh/mathjax/MathJax@legacy-v2-develop/unpacked/MathJax.js?config=TeX-AMS_CHTML">
</script>

It is being included in head.html in the _includes\ folder

% include mathjax.html %

It works very well on my GitHub Page. However, it does not allow for multiple rows in in-line math objects. For example,

Let $X = \left[ \begin{matrix} X_1 \\ X_2 \end{matrix} \right]$ follow a [bivariate normal distribution](/D/bvn):

incorrectly gives

incorrect, but desired notation

such that I have to use the undesired notation

Let $X = \left[ \begin{matrix} X_1 & X_2 \end{matrix} \right]^\mathrm{T}$ follow a [bivariate normal distribution](/D/bvn):

which correctly leads to

correct, but undesired notation

Is there a way to include multiple rows in in-line math. (In stand-alone equations, i.e. with $$ ... $$, it works!)


Solution

  • The issue is not that MathJax doesn't support line breaks in in-line math (it does), but rather the issue is probably an interaction with the Markdown engine with the mathematical notation, and in particular, with the \\, as explained below.

    In Markdown, the backslash (\) is an escape character that can be used to prevent the action of a character that would normally be interpreted by Markdown as having a special meaning. For example, the [ in [bivariate normal distribution](/D/bvn) is a special character that indicates a link, but if you used \[bivariate normal distribution](/D/bvn), that would produce a literal [ rather than a link, as in "[bivariate normal distribution](/D/bvn)" (with the \ removed`).

    Now \ only has this special meaning when the character following it is one that has an action in Markdown, so \begin, for example, will keep the \, whereas in \\, since \ has a special meaning, the first one escapes the second one, producing just \ in the HTML page. That makes your expression become

    $X = \left[ \begin{matrix} X_1 \ X_2 \end{matrix} \right]$
    

    in the resulting HTML page, and so you no longer have the row terminator \\ but rather the spacing command \ (which is why there is a space between the two X's). If you use the MathJax contextual menu to show the math as TeX code, you can check if it is \\ or just \. Or you can view the page source and check it that way.

    One possible solution would be to use \\\\ instead of \\, as that will generate two literal backslashes in Markdown.

    Alternatively, you might consider using \atop rather than the matrix environment:

    $X = \left[ X_1 \atop X_2 \right]$
    

    This will use less vertical space, and will avoid the \\ issue in Markdown.