I want to add a row to a table conditionally based on the selected entry, using \foreach
and \csname...\endcsname
. But it is not working.
\documentclass{article}
\usepackage{tikz}
\usepackage{pdftexcmds}
\newcommand{\UserA}{UserA}
\newcommand{\UserB}{UserB}
\newcommand{\UserZ}{UserZ}
\newcommand{\UserIdx}{B}
\newcommand{\test}{%
\def\temp{}%
\foreach \Idx in {A,...,Z}{%
\ifcsname User\Idx \endcsname%
\ifnum\pdfstrcmp{\Idx}{\UserIdx}=0%
%\expandafter\gdef\expandafter\temp\expandafter{\temp t1 & t2 \\}% % Works
\expandafter\gdef\expandafter\temp\expandafter{\temp \csname User\Idx \endcsname & C21 \\}% % Does not work
\fi
\fi
}%
\temp}
\begin{document}
\begin{tabular}{ll}
\test
C12 & C22
\end{tabular}
\end{document}