I have a macro called « \addsol » that appends solutions for given exercises to a fixed \solutions macro, in order to list the solution of the exercises at the end of the document.
I wish to add to it an automatic mechanism such that each solution is preceded by it’s label in the enumerate bloc.
Ideally, it would be great if there exists some instruction that imitates the label used in the enumerate list, wether it its A, B, C or 1) 2) 3) without having to reconfigure the command to each case. As this seems to me difficult to obtain, I tried to use the enumi counter, as shown in the MWE below, but the output doesn’t give the number of each question, instead, it gives the final value of enumi.
Any suggestions would be very appreciated
\documentclass[12pt,a4paper]{report}
\usepackage[french]{babel}
\usepackage{fontspec}
\usepackage[shortlabels]{enumitem}
\usepackage{amsmath}
\newcommand{\equal}{=}
\newcommand{\addsol}[1]{%
\ifdefined\solutions
\expandafter\gdef\expandafter\solutions\expandafter{\solutions,\ $\Alph{enumi}\equal$ #1}%
\else
\gdef\solutions{\textbf{Solutions:} $\Alph{enumi}\equal$ #1}%
\fi
}
\begin{document}
\begin{enumerate}[label=$\Alph*\equal$]
\item $3 + 5$ \addsol{$8$}
\item $4 \times 6$ \addsol{$24$}
\item $54 \div 9$ \addsol{$6$}
\end{enumerate}
% Print the contents of solutions
\solutions
\end{document}
Here is the output of the preceding exemple :