Consider the following table:
\begin{tabular}{ll}
a & A\\
b & B\\
c & C\\
\end{tabular}
I would like to define commands \addtableline{...}{...} and \printtable in order to build this table dynamically, i.e. I want to be able to write
% no tabular environment here
...
\addtableline{a}{A} % remembers line
...
\addtableline{b}{B} % remembers line
...
\addtableline{c}{C} % remembers line
...
\printtable % now generates table and typesets it
I played around with \edef and \noexpand, trying to recursively generate a command \tablecontent storing the table content, but I failed miserably. I guess the problem lies in the fact that the & is interpreted too early, outside the table environment. What brings me to this assumption is the fact that I was able to solve the problem if the result should be not a table, but rather simple text.
How can I solve the problem?
My try (might be complete nonsense):
\def\generatetableline#1#2{#1 & #2\\}
\gdef\tablecontent{}
\def\addtableline#1#2{\xdef\tablecontent{\tablecontent\noexpand\generatetableline{#1}{#2}}}
\def\printtable{\begin{tabular}\tablecontent\end{tabular}}
