Disclaimer: I've barely started to learn LaTeX so bear with me.
Problem: I use a lot of matrices like this
Which I absolutely hate to code manually. Obvious solution would be a nested for loop, something like this:
\begin{equation}
A =
\begin{bmatrix}
\pgfplotsforeachungrouped \m in {1,...,3}
{
\pgfplotsforeachungrouped \n in {1,...,3}
{
a_{\m,\n} &
} \\
}
\end{bmatrix}
\end{equation}
(I got the idea to use \pgfplotsforeachungrouped
from this answer). Unfortunately there are two problems:
- The
&
and\\
tokens break the compilation process and pdfLaTeX barfs a bunch ofUndefined control sequence
errors. - Even if this works, I'll still need a way to disable these tokens at the last iteration, otherwise I'll end up with one empty column and one empty row. (Or maybe even worse because the last empty row won't contain proper amount of
&
's).
If there is a proper way of constructing such matrices it will suffice, although I'll still be curious about whether if-branching inside a for-loop is possible.
\newline
or\hfill \break
not the double backslash.