在下面的 MWE 中,excoutP
添加了 来存储 的值excout
。我们怎么能只使用计数器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}
答案1
除了在exam
环境中收集计数器外,我们还可以将计数器扩展为collectTempt
命令,收集计数器。
\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}