This question is directly related to Foreach inside a TikZ matrix. But I can't expand it with a macro inside, such that:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{etoolbox}
\begin{document}
\newcommand{\somecommand}[1]{#1}
\begin{tikzpicture}
\let\mymatrixcontent\empty
\foreach \c in {a,b,c}{%
\expandafter\gappto\expandafter\mymatrixcontent\expandafter{\somecommand{\c} \\}%
% or
% \xappto\mymatrixcontent{\expandonce{\somemacro{\c}\\}}
}
\matrix [matrix of nodes,ampersand replacement=\&] {
\mymatrixcontent
};
\end{tikzpicture}
\end{document}
I get the error: ERROR: Missing } inserted.
\mymatrixcontentexpands to\c \\\c \\\c \\. – egreg May 29 '12 at 14:17