In the katex website it says global macros persist between math expressions: https://katex.org/docs/supported.html#macros

So in theory I could do:

$$

\gdef\matrix#1{\begin{bmatrix}#1\end{bmatrix}}

$$

$$

\matrix{1&2&4\1&2&3}

$$

But it doesn’t seem to work. The macro does work if it’s in the same expression. So:

$$

\gdef\matrix#1{\begin{bmatrix}#1\end{bmatrix}}

\matrix{1&2&4\1&2&3}

$$

works. Is there a way of getting this working?