9

The journal I am submitting to requires a total word count on the title page. My question is more like an extension to Greg's previous question. The journal states that a table/figure is counted as 250 words, and the total word count -- which is essentially word count + figure count * 250 + table count * 250 -- cannot exceed a certain number.

From Greg's solution, I was able to print the three counts using texcount and 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

My question is, in LaTeX, how do I calculate the total word count (??) using the three counts and print it on my title page?

PS. I am new to LaTeX (and TeX.SX) so any help is highly appreciated!

7

Use \numexpr and other commands to calculate the multiplication.

However, just inputing count.txt does not make the number available for computation. I stored the number to a counter instead.

The command \totalwordcount computes the number of words from the \wordcount command and adds the table/figure word amount then, finally the counter value is printed. Afterwards the command is redefined to provide only the counter value, no computations are done in the end.

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.