Wednesday, 14 August 2013

Sorted output inside a tabular

Sorted output inside a tabular

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?

No comments:

Post a Comment