我已经定义了\GreenCircle
,\AmberCircle
并\RedCircle
根据段落的内容在段落开始前显示绿色、琥珀色或红色圆圈。在运行 latex 时,是否可以计算文档末尾每个圆圈的数量?例如:
Number of Green Circles:
Number of Amber Circles:
Number of Red Circles:
答案1
好吧,为每种圆圈类型定义一个计数器并\stepcounter{redcircle}
在\RedCircle
命令中使用等,最后使用\theredcircle
\documentclass{article}
\newcounter{redcircle}
\newcounter{greencircle}
\newcounter{ambercircle}
\newcommand{\RedCircle}{%
\stepcounter{redcircle}%
% Rest of the redcircle command
}
\newcommand{\GreenCircle}{%
\stepcounter{greencircle}%
% Rest of the greencircle command
}
\newcommand{\AmberCircle}{%
\stepcounter{ambercircle}%
% Rest of the amberircle command
}
\usepackage{blindtext}
\begin{document}
\RedCircle
\blindtext[10]
\RedCircle
\blindtext[10]
\GreenCircle
\blindtext
\AmberCircle
\blindtext
\GreenCircle
\blindtext
\clearpage
Number of Green Circles: \thegreencircle
Number of Red Circles: \theredcircle
Number of Amber Circles: \theambercircle
\end{document}