Currently I'm trying to create an environment with several different \item-like commands. I want the arguments of the different commands to be ordered by their type.
Basically the usage of
\begin{ordered}
\fruit{Apple}
\vegetable{Salad}
\vegetable{Bell Pepper}
\fruit{Strawberry}
\end{ordered}
should result in
Apple
Strawberry
Salad
Bell Pepper
With the following Code this can be done on a basic level
\newenvironment{ordered}{
\newcommand{\fruits}{}
\newcommand{\fruit}[1]{
\begingroup\def\temp{\renewcommand{\fruits}}
\expandafter\expandafter\expandafter\endgroup
\expandafter\temp\expandafter{\fruits{##1\\}}}
\newcommand{\vegetables}{}
\newcommand{\vegetable}[1]{
\begingroup\def\temp{\renewcommand{\vegetables}}
\expandafter\expandafter\expandafter\endgroup
\expandafter\temp\expandafter{\vegetables{##1\\}}}
}{
\fruits
\vegetables
}
However, If I want my ordered environment to open a tabular containing the fruits and vegetables I get problems:
\newenvironment{ordered}{
...
\begin{tabular}{l}
}{
\fruits
\vegetables
\end{tabular}
}
Results in ! Missing } inserted. <inserted text> } l.31 \end{ordered}
Is there any way to use \fruits and \vegetables inside the ordered environment inside tabular?

\hlinebetween\fruitsand\vegetables, but only if there is at least one fruit in\fruits? I tried to check for empty\fruitsby using\IfStrEq{\fruits}{\empty{}}{}{\fruits\hline}instead of\fruitsbut this results in! Argument of \@firstoftwo has an extra }. <inserted text> \par l.16 \end{ordered}– Marcel Aug 14 '13 at 15:24\fruitsand\vegetablesto\relax, which is used for testing whether or not to insert an\hline. – Werner Aug 14 '13 at 16:10