打印总字数,包括单词、表格和图片的数量

打印总字数,包括单词、表格和图片的数量

我投稿的期刊要求在标题页上显示总字数。我的问题更像是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}

在此处输入图片描述

相关内容