# Store counter in list

I have some sort of a list and want to add the actual enumi-count to that list. I assume, that in my problem I'm somehow just storing the pointer to that counter and not the value itself, so even the stored counter-value increases as the counter itself increases. I even tried definining a tempcounter I set to the value of the enumi-counter, but I've read somewheere, that I should expand the counter, so I'm clueless what to do.

\documentclass{scrartcl}
\usepackage{ifthen}

\def\aliste{}
\def\zaliste#1\relax{\gdef\aliste{#1}}
\ifthenelse{\equal{\aliste}{}}{%
\expandafter\zaliste\aliste#1\relax
}{\expandafter\zaliste\aliste,#1\relax
}%
}

\begin{document}
Value: \aliste\\
Value: \aliste\\ %Returns A
\begin{enumerate}
\item
Output: \arabic{enumi}\\ %is 1
\aliste %returns A,1
\item
Output: \arabic{enumi}\\ %is 2
Value: \aliste %returns A,2,2
\end{enumerate}
Value: \aliste %returns A,2,2
\end{document}


I remove ifthen (since it's considered obsolete) and use a regular \ifx\aliste\relax test to see what the value of \aliste is before adding something. Note that the addition uses \xdef - a expandable version of \gdef (which is a global definition). The global definition is required in order for the list additions to survive outside the scoped (enumerate) environment.

\documentclass{article}

\let\aliste\relax
\ifx\aliste\relax
\xdef\aliste{#1}% List is empty. Just add #1
\else
\xdef\aliste{\aliste,#1}% List is non-empty. Add old list, comma and #1
\fi
}

\begin{document}
Value: \aliste \\

Value: \aliste \\ % returns A

\begin{enumerate}
\item
Output: \arabic{enumi} \\ % is 1