The double backslash, ‘\\’, when specified in math formula in LaTeX and KaTeX might not render correctly. Here’s how to avoid that.

This is due to the ‘\’ character being used as an escape character in some rendering frameworks.

Within the context of $\KaTeX$ (which is math specific) and when specifying math formula in $\LaTeX$, a possible workaround is to use ‘\cr’ as a replacement for ‘\\’.

$\KaTeX$ Examples

Matrices

The double backslash, ‘\\’, in the matrix below:

1$$
2\begin{pmatrix}
3a & b \\
4c & d
5\end{pmatrix}
6$$

Might render as:

$$ \begin{pmatrix} a & b \ c & d \end{pmatrix} $$

Where as changing ‘\\’ to ‘\cr’, like this:

1$$
2\begin{pmatrix}
3a & b \cr
4c & d
5\end{pmatrix}
6$$

Renders as:

$$ \begin{pmatrix} a & b \cr c & d \end{pmatrix} $$

Aligned Expressions

The double backslash, ‘\\’, in the aligned expressions below:

1$$
2\begin{alignedat}{2}
310&x+ &3&y = 2 \\
43&x+&13&y = 4
5\end{alignedat}
6$$

Might render as:

$$ \begin{alignedat}{2} 10&x+ &3&y = 2 \ 3&x+&13&y = 4 \end{alignedat} $$

Where as:

1$$
2\begin{alignedat}{2}
310&x+ &3&y = 2 \cr
43&x+&13&y = 4
5\end{alignedat}
6$$

Renders as:

$$ \begin{alignedat}{2} 10&x+ &3&y = 2 \cr 3&x+&13&y = 4 \end{alignedat} $$

So when using $KaTeX$ in Markdown, consider using ‘\cr’ rather than ‘\\’.