Markdown Matrix: LaTeX Matrices That Render (2026)
September 11, 2026 · 9 min read
Markdown Matrix: Write Matrices with LaTeX Syntax
A markdown matrix is written in LaTeX inside math delimiters: $$\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$$ renders a 2 by 2 matrix in parentheses. Columns are separated by & and rows by \\. This guide gives every matrix environment as a paste-ready block and shows which delimiter each platform needs.
Markdown Matrix Syntax: The pmatrix Block
Markdown has no matrix syntax of its own. What every platform does is hand anything between math delimiters to a LaTeX renderer, KaTeX or MathJax, and both support the amsmath matrix environments. So a matrix in Markdown is a display math block containing one of those environments.
$$
\begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{pmatrix}
$$
That renders as a 3 by 3 grid wrapped in tall round parentheses, with the numbers centred in each column:
( 1 2 3 )
( 4 5 6 )
( 7 8 9 )
Three rules cover the whole syntax. An ampersand separates columns, a double backslash ends a row, and the last row needs no \\. Whitespace and line breaks inside the block are ignored, so you can write the matrix on one line or lay it out like a grid. We prefer the grid because a missing & is easy to spot.
For the general math syntax (inline versus display, escaping dollar signs, enabling math on each platform), see the Markdown equation guide. This post stays on matrices.
Every Matrix Environment as a Copy-Paste Block
The environment name sets the brackets. All of these are listed in the KaTeX supported functions table under Environments, and MathJax renders them too.
| Environment | Brackets | Typical use |
|---|---|---|
matrix | None | Building block inside other delimiters |
pmatrix | Round parentheses | Vectors and most matrices in papers |
bmatrix | Square brackets | Linear algebra, code documentation |
Bmatrix | Curly braces | Sets written as columns |
vmatrix | Single vertical bars | Determinants |
Vmatrix | Double vertical bars | Norms |
smallmatrix | None, compact | Inline matrices in running text |
array | None, with column spec | Custom alignment and vertical rules |
Swap the name and everything else stays the same:
$$\begin{bmatrix} a & b \\ c & d \end{bmatrix}$$
$$\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$$
$$\begin{Bmatrix} x \\ y \\ z \end{Bmatrix}$$
Two variants are worth knowing. The starred forms take an alignment argument, as in \begin{pmatrix*}[r], which right-aligns every column so negative numbers line up. And array takes a column spec like {cc|c} to draw a vertical line between columns. That's how you write an augmented matrix:
$$
\left[\begin{array}{cc|c}
1 & 2 & 5 \\
3 & 4 & 6
\end{array}\right]
$$
KaTeX's docs note one limitation of array. It doesn't support \cline or \multicolumn yet, so horizontal partial rules and merged cells aren't available.
Where Does a Markdown Matrix Render?
Anywhere the platform renders LaTeX math. Here's the delimiter each host expects and the engine behind it.
| Platform | Display block | Inline | Engine |
|---|---|---|---|
| GitHub | $$ ... $$ on its own lines, or a ```math fence | $ ... $ or $` ... `$ | MathJax |
| GitLab | $$ ... $$ or a ```math fence | $` ... `$ or $ ... $ | KaTeX |
| Obsidian | $$ ... $$ | $ ... $ | MathJax |
| Jupyter Markdown cells | $$ ... $$ | $ ... $ | MathJax |
| VS Code preview | $$ ... $$ | $ ... $ | KaTeX |
| Pandoc, R Markdown, Quarto | $$ ... $$ | $ ... $ | Output-dependent |
| This site's editor | $$ ... $$ | $ ... $ | KaTeX |
| Plain CommonMark, Discord, Slack | Not rendered | Not rendered | None |
GitHub's math documentation lists issues, discussions, pull requests, wikis, and Markdown files as the places math renders, and names MathJax as the engine. GitLab's Markdown docs use KaTeX and accept the same two block forms. Obsidian's advanced syntax page even uses a determinant, \begin{vmatrix}, as its math example. The Jupyter cheat sheet covers the notebook side.
Matrix in Markdown on GitHub: the row separator trap
The most common complaint about a matrix in markdown on GitHub is that rows collapse into one line. The usual cause is the \\ separator. Inside a $$ block that sits in ordinary Markdown, a double backslash can be read by the Markdown parser before MathJax sees it. Table cells and list items are the usual trouble spots. The fix is the fenced form, because nothing inside a code fence is parsed as Markdown:
```math
\begin{bmatrix}
1 & 0 \\
0 & 1
\end{bmatrix}
```
Use the fence for anything longer than one row on GitHub. For a matrix inside a table cell, GitHub's docs recommend the $` ... `$ inline form for the same reason: it protects characters that overlap with Markdown syntax.
How Do You Type a Matrix in Markdown?
Build it in four steps, and it comes out right the first time.
- Open a display block. Put
$$on its own line (or open a```mathfence on GitHub and GitLab). - Choose the brackets. Write
\begin{pmatrix}for parentheses or\begin{bmatrix}for square brackets. - Fill the rows. Separate columns with
&and end each row with\\. Every row must have the same number of columns. - Close it. Write the matching
\end{pmatrix}and the closing$$.
For large or symbolic matrices, three commands fill the gaps: \cdots for a horizontal run of dots, \vdots for vertical, and \ddots for the diagonal.
$$
A = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \cdots & a_{mn}
\end{bmatrix}
$$
For a matrix in a sentence, use smallmatrix inside inline delimiters and add the brackets by hand with \left( and \right), because smallmatrix has none of its own: $\left(\begin{smallmatrix} 1 & 0 \\ 0 & 1 \end{smallmatrix}\right)$. It renders at text height instead of pushing the line apart.
Try a Markdown Matrix in the Editor
The editor renders math with KaTeX, so every block below appears as a typeset matrix in the preview. Change an environment name or add a row and watch it update.
If a block shows raw LaTeX instead of a matrix, the delimiters are unbalanced or an environment name is misspelled. The Markdown to HTML tool shows the generated markup so you can see where parsing stopped.
Matrix Fallback Without Math: Table or Code Block
Some destinations never render math: plain CommonMark, Discord, Slack, and most email clients. Two fallbacks work there.
A Markdown table is the readable option for numeric matrices. It has no brackets, but column alignment keeps the grid clear:
| | | |
|--:|--:|--:|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
The Markdown table guide covers the alignment colons. Tables can't carry symbolic entries like a_{11} with real subscripts, so keep this for numbers.
A code block preserves exact spacing and works even where tables don't:
```
| 1 2 3 |
| 4 5 6 |
```
Both fallbacks lose the mathematical meaning; they're pictures of a matrix, not a matrix. If the document will ever move to a platform with math, write the LaTeX version and keep the fallback in a comment.
Common Markdown Matrix Mistakes
Uneven rows. 1 & 2 \\ 3 gives a row with two columns and a row with one. Renderers pad or reject the short row rather than flagging the typo. Count the ampersands per row.
A trailing \\ on the last row. Some renderers add an empty row, so the matrix gets taller than intended. Drop the separator after the final row.
Wrong bracket size on an inline matrix. (\begin{smallmatrix} ... \end{smallmatrix}) with plain parentheses gives brackets that are too short. Use \left( and \right) so they stretch to the matrix height.
Dollar signs elsewhere on the line. A price such as "costs $5" before a $...$ matrix opens math early on GitHub, Obsidian, and Jupyter. Escape it as \$5.
Markdown Matrix FAQ
A markdown matrix is a LaTeX environment inside math delimiters: pick the brackets with the environment name, separate columns with &, and end rows with \\. Use $$ blocks on Obsidian and Jupyter, the math fence on GitHub and GitLab, and a table where math doesn't render. Paste the demo into the editor to see each environment typeset live.