How do I label the rows/columns of a matrix in MathJax?

$$\qquad \quad \ \ 1 \ \ \ \ 2 \ \ \ \ \ 3 \ \ \ \ 4 \ \ \ \ 5 \ \ \ \ \ \\ A = \begin{bmatrix} h & e & l & l & o \\ m & s & e & * & * \\ m & e & t & a & * \end{bmatrix}$$

$$\qquad \qquad 1 \ \ \ \ 2 \ \ \ \ \ 3 \ \ \ \ 4 \ \ \ \ 5 \ \ \ \ \ \\ A = \begin{bmatrix} h & e & l & l & o \\ m & s & e & * & * \\ m & e & t & a & * \end{bmatrix}$$


Is there a way I can indicate the numbers of the rows and columns to the sides/top/bottom of my matrix less painfully? If not, this is a feature request.

Here is something close to what you wanted: $$\begin{array}{cc} & \begin{array}{ccccc} 1 & 2 & 3 & 4 & 5\\ \end{array} \\ A = & \left[ \begin{array}{ccccc} h & e & l & l & o \\ m & s & e & * & * \\ m & e & t & a & * \end{array} \right] \end{array}$$

Essentially you use the nested array environment here so that you don't need to adjust the spaces between the labels.

$$\begin{array}{cc} & \begin{array}{ccccc} 1 & 2 & 3 & 4 & 5\\ \end{array} \\ A = & \left[ \begin{array}{ccccc} h & e & l & l & o \\ m & s & e & * & * \\ m & e & t & a & * \end{array} \right] \end{array}$$


[Added] The example in the linked post above gave the following example, which also has row labels: $$\begin{array}{c c} & \begin{array}{c c c} a & b &c \\ \end{array} \\ \begin{array}{c c c} p \\ q\\ r \end{array} & \left[ \begin{array}{c c c} .1 & .1 & 0 \\ .4 & 1 & 0 \\ .8 & 0 & .4 \end{array} \right] \end{array}$$

$$\begin{array}{c c} & \begin{array}{c c c} a & b &c \\ \end{array} \\ \begin{array}{c c c}p\\q\\r \end{array} & \left[ \begin{array}{c c c} .1 & .1 & 0 \\ .4 & 1 & 0 \\ .8 & 0 & .4 \end{array} \right] \end{array}$$

• Thanks for the tip. Any way to label the rows? May 2 '20 at 0:54
• @jeremy909: yes, basically it is in the linked blog post. What kind of row labels are you expecting?
– user9464
May 3 '20 at 15:24
• Your edit is exactly what I wanted. Thanks for the help!! May 3 '20 at 17:29
• @jeremy909: You are welcome!
– user9464
May 3 '20 at 19:57

Not a working answer on MSE since the physics package cannot be imported via \require{physics} here, but if otherwise, the following code would produce what you want:

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


Note that AMS-related packages available in MathJax provide no functionality to achieve the desired effect. Having reposted this question on LaTeX SE (see here), I learned from @DavidCarlisle's comment that currently this might be impossible to achieve with MathJax:

… [M]athjax doesn't use tex at all, some javascript emulates some latex packages but any such emulation has to be written from scratch in javascript, it can't use the package code.

If you really need this effect, you may ask a question on SE using the mathjax tag.