I want to generate a table from a list. However for some reason it fails to work. I searched:
PGFplots foreach equivalent to TikZ's with multiple variables separated by a slash
and tried different solutions but none of them work for some reason :(
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tabular}{ll}
\foreach \x/\y in {-2/a,-1/b,1/c,2/d} {%
\edef\temp{\noexpand \x & \y \\ }%
\temp
}%
\end{tabular}
\end{document}
Edit...
\documentclass{minimal}
\usepackage{tikz,etoolbox}
\makeatletter
\newtoks\@tabtoks
\newcommand\addtabtoks[1]{\global\@tabtoks\expandafter{\the\@tabtoks#1}}
\newcommand\eaddtabtoks[1]{\edef\mytmp{#1}\expandafter\addtabtoks\expandafter{\mytmp}}
\newcommand*\resettabtoks{\global\@tabtoks{}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother
\begin{document}
\resettabtoks
\foreach \x/\y in {-2/a,-1/b,1/c,2/d}{%
\eaddtabtoks{\x & \y \\ }%
}%
\begin{tabular}{ll}
\printtabtoks
\end{tabular}
\end{document}
Does not seem to work.
(/usr/local/texlive/2013/texmf-dist/tex/generic/oberdiek/etexcmds.sty))) (/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) ! Undefined control sequence. \ ->\let \reserved@e \relax \let \reserved@f \relax \@ifstar {\let \reserv... l.17 } % ?

\protect\\inside\eaddtabtoks– egreg May 23 '14 at 14:24\eaddtabtoks{\x & \y \protect\\ }%does not help. But I got it working. I changed to code to...\eaddtabtoks{\x} \addtabtoks{&} \eaddtabtoks{\y} \addtabtoks{\\}– WG- May 23 '14 at 14:28