Currently, I am able to make a command shortcut that produces a matrix given a fixed amount of arguments. For example, the command
\newcommand{\MAT}[4]{\begin{bmatrix}
#1 & #2 \\
#3 & #4 \\
\end{bmatrix}
}
produces a matrix with arguments inputted row by row. My question is: is there a way to define a similar matrix but for any dimension, especially for nonsquare matrices?
I'd like to be able to have two arguments that defines the dimensions of the matrix, and then an arbitrary amount of arguments where each entry is added along the rows. Something like \MAT{2}{2}{a}{b}{c}{d} that outputs a 2x2 matrix with entries a, b, c, d would be very nice.

&or two at end of line\\and your shortcut requires two}{so it takes more markup especially for larger matricies.\newcommand\MAT[1]{begin{bmatrix}#1\end{bmatrix}}allows\MAT{a&b\\c&d}which is shorter and easier to read than\MAT{2}{2}{a}{b}{c}{d}– David Carlisle Jun 28 '23 at 08:30