0

In the MWE below, the excoutP is added to store the value of excout. How can we only use the counter excout?

    \documentclass{article}
    \usepackage{etoolbox}
    \usepackage{xcolor}
    \usepackage{collect}
    \definecollection{excol}
    \newcounter{excoutP}
    \def\st{}
    \newcommand{\inso}{
        \refstepcounter{excoutP}
        \appto\st{\theexcoutP}
        \st
    }
    \newcounter{excout}
    \newenvironment{exam}{
        \refstepcounter{excout}
        \begin{center}
            THE EXAM \textcolor{red}{\theexcout}
        \end{center}
        \begin{collect}{excol}{}{}{}{}
            The exam {\Large \textcolor{red}{\inso}} 
        \end{collect}
    }{}
    \begin{document}
    \begin{exam}
    Content 1
    \end{exam} 
    \begin{exam}
    Content 1
    \end{exam}
\bigskip
\includecollection{excol}

\end{document}

Ingmar
  • 6,690
  • 5
  • 26
  • 47
  • Mr @egreg has had a related answer. https://tex.stackexchange.com/questions/161187/a-problem-with-counters/161188#161188 – Nam Tran Le May 05 '22 at 11:25

1 Answers1

0

Instead of collecting counter in exam environment. We can expand the counter to collectTempt command, collect the counter.

\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{collect}
\definecollection{excol}

\newcounter{excout}

\newcommand{\collectTempt}[1]{ \begin{collect}{excol}{}{}{}{} The exam {\bfseries\textcolor{red}{#1}} \end{collect} }

\newenvironment{exam}{ \refstepcounter{excout} \begin{center} THE EXAM \textcolor{red}{\theexcout} \end{center} \begingroup\edef\xttt{\endgroup\noexpand\collectTempt{\theexcout}}\xttt }{} \begin{document} \begin{exam} Content 1 \end{exam} \begin{exam} Content 1 \end{exam}

\bigskip \includecollection{excol} \end{document}