I would like to keep track of all the \AddRef commands in a document and then process them one at a time, for instance print them in the document on one line per value. It seems that this should be doable as the functionality is not that different than list of figures that, but I can' seem to get this to work. I did not even attempt the \foreach command required at the end of the file so if someone knows how to do that that would be appreciated.
\documentclass[12pt]{article}
\begin{document}
\newtoks{\Ref}
\newcommand{\AddRef}[1]{%
\let\OldRef=\the\Ref\relax
\let\Ref=\the\OldRef{#1}\relax
}
\AddRef{Ref 1}
\AddRef{Ref 2}
\AddRef{Ref 3}
The list of Ref are:
\the\Ref
\end{document}
At the end, I would like to process the list, say to print a line at a time:
Ref 1
Ref 2
Ref 3
The original question above required the case where this list of strings is a global macro so that it is complete at the end of the document. Another application requires that this list of strings be local to a scope so a local version would also be useful.