I'm trying to create a matrix using nested \foreach loops. I tried following the example I found in a previous question, but I keep getting errors.
Here is the code I tried to run:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\let\mymatrixcontent\empty
\newcommand{\row}[1]{
\foreach \i in {0,...,5} {
\xappto\mymatrixcontent{\expandonce{
\node {\i}; &
}}
}
\xappto\mymatrixcontent{\\}
}
\row{1}
\begin{tikzpicture}
\matrix[matrix of nodes]{
\mymatrixcontent
};
\end{tikzpicture}
\end{document}
I'm getting an error:
! Undefined control sequence.
\\ ->\let \reserved@e
\relax \let \reserved@f \relax \@ifstar {\let \reserv...
l.16 \row{1}
I noticed that this error occurs only after adding the new row after the \foreach loop. Is there a way to avoid it?
EDIT: I completed the example.
