I write a command to store the problem answer with the collect package. Mr @egreg help me expand the problem number in the aux file. Now I meet another trouble with the answer. When the answer contains a counter, it will not expand. Please help me correct the below code.
Moreover, please give some documentation of "expandafter" and ".aux" commands Thank you very much!
\documentclass{article}
\usepackage{collect}
\definecollection{btcol}
\newcounter{cbt} %the number problems
\newcounter{anschoice} %the answer key
\newenvironment{bt}
{\refstepcounter{cbt}\par
\noindent{\bfseries Problem \thecbt}.}{}
\makeatletter
\newcommand{\loigiai}[1]{%
@bsphack\expandafter\loigiai@aux\expandafter{\expanded{\thecbt}}{#1}@esphack
}
\newcommand{\loigiai@aux}[2]{%
\begin{collect}{btcol}{\par\noindent {\bfseries AP #1}.\ignorespaces}{}{}{}
#2%
\end{collect}
}
\makeatother
\begin{document}
\setcounter{anschoice}{3}
\begin{bt}
Content 1
\loigiai{Answer for Pro.1 $ \rightarrow $ Choice: \Alph{anschoice}}
\end{bt}
\begin{bt}
Content 2
\end{bt}
\setcounter{anschoice}{2}
\begin{bt}
Content 3
\loigiai{Answer for Pro.3 $ \rightarrow $ Choice: \Alph{anschoice}}
\end{bt}
\includecollection{btcol}
\end{document}


Choice: Bin the second case? – egreg Jul 19 '21 at 12:35