First, I have seen a couple similar posts, which is how I got as far as I have gotten:
problem with using loop inside the tabular environment
I am also pretty sure this could be done with edef, but I it seems that one could do it without also.
I am using collection.sty; the relevent parts are here:
\newcommand*{\collectionnew}[1]{%
\newcounter{collection@#1@count}}
\newcommand*{\collectionadd}[3][]{%
\expandafter\def\csnamecollection@#2@item\roman{collection@#2@count}\endcsname{#3}%
\if\relax\noexpand#1\relax% if #1 is empty
\else\expandafter\def\csnamecollection@#2@key\roman{collection@#2@count}\endcsname{#1}\fi%
\stepcounter{collection@#2@count}}
\newcommand*{\collectiongetitem}[2]{%
\csname collection@#1@item\romannumeral #2\endcsname}
\newcommand*{\collectiongetkey}[2]{%
\csname collection@#1@key\romannumeral #2\endcsname}
\newcounter{collection@iterator}
\newcommand*{\collectionloop}[2]{%
\setcounter{collection@iterator}{0}%
\loop\ifnum\value{collection@iterator}<\value{collection@#1@count}%
\def\collectionloopid{\arabic{collection@iterator}}%
\def\collectionloopitem{\collectiongetitem{#1}{\collectionloopid}}%
\def\collectionloopkey{\collectiongetkey{#1}{\collectionloopid}}%
#2%
\stepcounter{collection@iterator}%
\repeat}
The full file is found at https://github.com/glittershark/resume/blob/master/collection.sty
I am trying to take a collection (with a column delimiter in collectionloop item and make a tabular
\documentclass{article}
\usepackage{collection}
\collectionnew{sEvents}
\collectionadd[A]{sEvents}{B&C}
\collectionadd[X]{sEvents}{Y&Z}
\def\schedulelines{}%
\collectionloop{sEvents}{%
\expandafter\def\expandafter\schedulelines\expandafter{\schedulelines \collectionloopkey}
\expandafter\def\expandafter\schedulelines\expandafter{\schedulelines & }
\expandafter\def\expandafter\schedulelines\expandafter{\schedulelines \collectionloopitem}
\expandafter\def\expandafter\schedulelines\expandafter{\schedulelines \\ \hline }
}
\begin{document}
\begin{tabular}{|l|c|l|}
\hline\textbf{col1}&\textbf{col2}&\textbf{col3}\\
\hline
\schedulelines
\end{tabular}
\end{document}
I should get a 3x3 tabular, every cell boxed, with row 2 being A B C and row three being X Y Z. Instead I get a 3x3 tabular with rows two and three empty and the right boarder line missing.
I have also tried replacing & with a command to hide it, \def\TAB{&}, in both the \collectionadd and the \expandafter inside the loop but it did not change anything that I could tell.
collection.sty
available?