LaTeX matrix not rendering correctly on Github Markdown
Asked Answered
S

3

5

I am trying to represent a basic vector, the following code works in Visual Studio Code.

I am using the following line $\begin{bmatrix}X\\Y\end{bmatrix}$

All whitespace removed. It should look like this,

https://i.sstatic.net/kDxdg.png

However, when pushed to Github it does not render correctly and instead just renders to entire text letter for letter like it is unsupported. Does anybody know how to get get the following vector to display correctly?

Septicidal answered 26/10, 2022 at 7:4 Comment(0)
F
7

One solution is to use the code block highlighting like so,

```math
begin{bmatrix}X\\Y\end{bmatrix}
```

You can see how this looks in a gist I created below.

Resources

  1. Reddit post where I originally found this solution — https://www.reddit.com/r/github/comments/yen375/comment/itzwbrn/?utm_source=share&utm_medium=web2x&context=3
  2. Gist showing how it works — https://gist.github.com/jesshart/8dd0fd56feb6afda264a0f7c3683abbf
Fulgurate answered 8/11, 2022 at 22:59 Comment(0)
E
2

The GitHub implementation of MathJax has a number of problems, and it does not seem to want to process some commands in in-line mode. In particular arrays and matrices don't seem to be processed in in-line math on GitHub. I could not find a work-around that would process your expression, however, an alternative for this matrix would be to use $\left[X\atop Y\right]$ instead. A bit more awkward, but perhaps that will be sufficient for your needs. I do wish GitHub would improve their processing of math.

Edlin answered 31/10, 2022 at 10:21 Comment(1)
This is the correct solution for this GitHub-specific problem as of now (Jan 13, 2023). This is also a workaround for the block display of matrices with the use of "$$". i.e. $$\left[X \atop Y\right]$$.Emmalynne
R
2

The GitHub/MathJax implementation seems to be lacking. I couldn't get column vectors or matrices to render correctly unless I added whitespace and split rows over multiple lines.

I think using the \\ as an instruction to move onto the next row followed by \end to finish the matrix confuses MathJax when it attempts to render the matrix, with the whitespace it seems to render correctly on GitHub.

Row Vector Example:

$$\begin{bmatrix} a & b & c \end{bmatrix}$$

This seems to work without whitespace.

Column Vector Example:

$$  \begin{bmatrix}
    a \\
    b \\
    c \\
    \end{bmatrix} $$ 

If all whitespace is removed, this doesn't render...

Matrix Example:

$$ \begin{bmatrix} 
   a & b & c \\
   c & e & f \\
   g & h & i \\
   \end{bmatrix} $$

If all whitespace is removed, this doesn't render...

Risible answered 1/2, 2023 at 8:9 Comment(1)
doesn't work for me ...Flabellate

© 2022 - 2025 — McMap. All rights reserved.