# Labeling rows/columns of a matrix in MathJax

Note: This is effectively a cross post of this post from Mathematics Meta SE.

There are many posts on LaTeX SE about how to add labels to rows/columns of a matrix, e.g. Label rows of a matrix by characters, but all the proposed approaches need some third-party packages unavailable in MathJax (see here for the list of available packages).

The closest thing I have found that uses MathJax is this answer:

\begin{array}{ccc}
& & \textit{next state}\\
\textit{current state} & \begin{array}{c} 1\\ 2\\ 3\end{array} &
\left(\begin{array}{ccc}
1/2 & 0 & 1/2\\
0 & 1/2 & 1/2\\
1/4 & 1/4 & 1/2
\end{array}\right)
\end{array}


But the drawback of this approach is that once the terms in the matrix get wider, the labels will be misaligned and need manual adjustment of spacing. I also posted an answer on Math Meta SE that needs the physics package:

\begin{matrix}
\mqty{1 & 2 & 3 & 4 & 4}\\
\mqty[h & e & l & l & o \\
m & s & e & * & * \\
m & e & t & a & *]
\end{matrix}


However, MSE does not seem to include this package in its global configuration.

Question: Does there exist any method to label rows/columns of a matrix in MathJax that:

• only uses AMS-related packages available in MathJax,
• automatically adjust spacing of labels and
• does not need to define a lot of macros?

• @UlrikeFischer I didn't know that and why this mathjax exists then? Do you know where this is on-topic? Thanks. – Saad Apr 27 at 14:32