I'm using a macro I've defined based on some suggestions here to automate the creation of tables.
For example something like
\newcommand{\clearrows}{\let\matrixcontent\empty}
\newcommand{\actionsrow}[3]{%
\foreach \i in #3 {%
\pgfmathparse{#1[\i-1]}
\let\c\pgfmathresult
\pgfmathparse{#2[\i-1]}
\let\s\pgfmathresult
\begingroup\edef\x{\endgroup
\noexpand\gappto\noexpand\matrixcontent{\noexpand\node[\s]{\c}; \&}}\x
}%
\gappto\matrixcontent{\\}%
}
lets me easily create the tables I need, with a few lines of code. For example,
\newcommand{\rowhv}[1]{
\actionsrow{{"$e$","$h$","$v$","$hv$"}}{{{"fill=gray!3"},{"fill=gray!33"},{"fill=gray!67"},{"fill=gray!100"}}}{#1} }
\clearrows
\rowhv{{1,2,3,4}} \rowhv{{2,1,4,3}} \rowhv{{3,4,1,2}} \rowhv{{4,3,2,1}}
\begin{tikzpicture}
\matrix[ampersand replacement=\&,nodes={minimum size=7mm}]{\matrixcontent};
\end{tikzpicture}
produces

which may not seem like much of an accomplishment, but I need to build quite large tables, and a lot of them, so these macros are essential.
I need to be able to put arbitrary content in the cells, ranging from arbitrary formatting (e.g., \textsf{..}) to imported images (using, for example, \includegraphics) or other macros I define to draw node contents. But the code above only works for cell contents that are plain text. If I supply anything other other than plain text among the items in the first argument to \actionsrow, which is used for \c in the loop there, I get an error,
Argument of \reserved@a has an extra }.
even though such content is perfectly valid for nodes. I suspect there's something going on with the way my (pilfered) macro is parsing \c, but I don't even know where to begin track that down.
How can I modify my \actionsrow macro so that I can specify arbitrary LaTeX as contents for my nodes?
\documentclass[]{article}
\usepackage{etoolbox}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
% See -- https://tex.stackexchange.com/a/47649/7844
\newcommand{\clearrows}{\let\matrixcontent\empty}
\newcommand{\actionsrow}[3]{%
\foreach \i in #3 {%
\pgfmathparse{#1[\i-1]} % See -- https://tex.stackexchange.com/a/56838/7844; note \let vs \def
\let\c\pgfmathresult
\pgfmathparse{#2[\i-1]}
\let\s\pgfmathresult
\begingroup\edef\x{\endgroup
\noexpand\gappto\noexpand\matrixcontent{\noexpand\node[\s]{\c}; \&}}\x
}%
\gappto\matrixcontent{\\}%
}
% This works fine
\newcommand{\rowhv}[1]{
\actionsrow{{"$e$","$h$","$v$","$hv$"}}{{{"fill=gray!3"},{"fill=gray!33"},{"fill=gray!67"},{"fill=gray!100"}}}{#1} }
\clearrows
\rowhv{{1,2,3,4}} \rowhv{{2,1,4,3}} \rowhv{{3,4,1,2}} \rowhv{{4,3,2,1}}
\begin{center}
\begin{tikzpicture}
\matrix[ampersand replacement=\&,nodes={minimum size=7mm}]{\matrixcontent};
\end{tikzpicture}
\end{center}
% Here, arbitrary specifications work for the nodes, if done manually
\begin{center}
\begin{tikzpicture}
\matrix [nodes={minimum size=7mm}]
{
\node[fill=gray!3]{\texttt{e}}; & \node[fill=gray!33]{\color{red}$h$}; & \node[fill=gray!67]{$v$}; & \node[fill=gray!100]{$hv$}; \\
\node[fill=gray!33]{\color{red}$h$}; & \node[fill=gray!3]{\texttt{e}}; & \node[fill=gray!100]{$hv$}; & \node[fill=gray!67]{$v$}; \\
\node[fill=gray!67]{$v$}; & \node[fill=gray!100]{$hv$}; & \node[fill=gray!3]{\texttt{e}}; & \node[fill=gray!33]{\color{red}$h$}; \\
\node[fill=gray!100]{$hv$}; & \node[fill=gray!67]{$v$}; & \node[fill=gray!33]{\color{red}$h$}; & \node[fill=gray!3]{\texttt{e}}; \\
};
\end{tikzpicture}
\end{center}
% But this fails
\renewcommand{\rowhv}[1]{
\actionsrow{{"\texttt{e}","\color{red}$h$","$v$","$hv$"}}{{{"fill=gray!3"},{"fill=gray!33"},{"fill=gray!67"},{"fill=gray!100"}}}{#1} }
\clearrows
\rowhv{{1,2,3,4}} \rowhv{{2,1,4,3}} \rowhv{{3,4,1,2}} \rowhv{{4,3,2,1}}
\begin{center}
\begin{tikzpicture}
\matrix[ampersand replacement=\&,nodes={minimum size=7mm}]{\matrixcontent};
\end{tikzpicture}
\end{center}
\end{document}