![打印总字数,包括单词、表格和图片的数量](https://linux22.com/image/315426/%E6%89%93%E5%8D%B0%E6%80%BB%E5%AD%97%E6%95%B0%EF%BC%8C%E5%8C%85%E6%8B%AC%E5%8D%95%E8%AF%8D%E3%80%81%E8%A1%A8%E6%A0%BC%E5%92%8C%E5%9B%BE%E7%89%87%E7%9A%84%E6%95%B0%E9%87%8F.png)
我投稿的期刊要求在标题页上显示总字数。我的问题更像是Greg 的上一个问题。期刊规定表格/图形计为 250 个字,总字数(基本上是字数 + 图形数 * 250 + 表格数 * 250)不能超过一定数字。
从Greg的解决方案中,我能够使用texcount
和打印三个计数totcount
:
\newcommand\wordcount{
\immediate\write18{texcount -sum -1 \jobname.tex > count.txt} \input{count.txt}}
\usepackage{totcount}
\regtotcounter{table} %count tables
\regtotcounter{figure} %count figures
Word Count: \wordcount words + \total{figure} figure(s) + \total{table} table(s) = ?? words
我的问题是,在 LaTeX 中,如何使用三个计数来计算总字数(??)并将其打印在标题页上?
附言:我是 LaTeX (和) 的新手,TeX.SX
因此非常感谢您的帮助!
答案1
使用\numexpr
和其他命令来计算乘法。
但是,仅仅输入数字count.txt
并不能使数字可用于计算。我将数字存储到计数器中。
该命令\totalwordcount
计算来自命令的字数\wordcount
,并添加表格/图形字数,最后打印计数器值。之后,重新定义该命令以仅提供计数器值,最后不进行任何计算。
\documentclass{article}
\newread\somefile
\usepackage{xparse}
\newcounter{totalwordcounter}
\newcounter{wordcounter}
\makeatletter
\NewDocumentCommand{\wordcount}{s}{%
\immediate\write18{texcount -sum -1 \jobname.tex > count.txt}%
\immediate\openin\somefile=count.txt%
\read\somefile to \@@localdummy%
\immediate\closein\somefile%
\setcounter{wordcounter}{\@@localdummy}%
\IfBooleanF{#1}{%
\@@localdummy% print only if not starred version
}%
}
\makeatother
\usepackage{totcount}
\regtotcounter{table} %count tables
\regtotcounter{figure} %count figures
\newcommand{\numberofwordsthejournalthinksforafigure}{250}
\newcommand{\numberofwordsthejournalthinksforatable}{250}
\newcommand{\totalwordcount}{%
\wordcount*% Just get the number, don't print it
\setcounter{totalwordcounter}{\value{wordcounter}}%
\addtocounter{totalwordcounter}{\numexpr\numberofwordsthejournalthinksforafigure*\totvalue{figure}}%
\addtocounter{totalwordcounter}{\numexpr\numberofwordsthejournalthinksforatable*\totvalue{table}} %
\number\value{totalwordcounter}% Output the number: Do not use \thetotalwordcounter here!
\renewcommand{\totalwordcount}{\number\value{totalwordcounter}}% Prevent the call again, otherwise the figure/table counter would be added again.
}
\setcounter{figure}{100}
\setcounter{table}{10}
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem % 12 words
Word Count: \wordcount words + \total{figure} figure(s) + \total{table} table(s) = \totalwordcount~words
\end{document}