![计算 latex 中特定单词出现的次数](https://linux22.com/image/355763/%E8%AE%A1%E7%AE%97%20latex%20%E4%B8%AD%E7%89%B9%E5%AE%9A%E5%8D%95%E8%AF%8D%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0.png)
我已经定义了\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}