2

I'm writing an article for the American Geophysical Union, and they have an absurd method of quantifying length:

For most journals, Research Articles are allowed to be up to 25 publication units (PU), where 1 PU is 500 words or 1 display element (figure or table). The title, authors, affiliations, key points, keywords, text in tables (but not captions) and references are excluded from word counts. Longer papers are assessed an excess length fee. Research Letters for Geophysical Research Letters have a maximum length of 12 publication units. Longer papers are not considered in GRL and will be returned for shortening. For most journals, Commentaries are limited to 6 publication units (recommended length is about 2000 words and 1-2 figures).

I'm working on writing a few lines of LaTeX that will keep track of this for me, but struggling a bit to get the wordcount incorporated as a variable to a math equation. Here's what I've got so far:

\documentclass{article}
\usepackage[utf8]{inputenc}

% Figuring out AGU's absurd "Publication Unit" scheme:
\newcommand{\quickwordcount}[1]{%
  \immediate\write18{texcount -1 -sum -merge #1.tex> #1-words}%
  \input{#1-words}
}

\newcommand{\MyWordcount}{\quickwordcount{agujournaltemplate}}
\newcommand{\MyTestVar}{37} %for testing purposes

\usepackage{siunitx,xfp}


\usepackage{xassoccnt}
\NewTotalDocumentCounter{totalfigures}
\NewTotalDocumentCounter{totaltables}
% \NewTotalDocumentCounter{appendixchapters}
\DeclareAssociatedCounters{figure}{totalfigures}
\DeclareAssociatedCounters{table}{totaltables}
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp


\title{AGU Wordcount Test}

\begin{document}

% \maketitle


There are approximately \MyWordcount words in this article. There are \TotalValue{totalfigures} figures, and \TotalValue{totaltables} tables. That means we have a total of \num[scientific-notation=false]{\fpeval{(1/500)*\MyWordcount+ \TotalValue{totalfigures} + \TotalValue{totaltables}}} publication units, out of a maximum of 25.

\end{document}

This does not compile. If I replace \MyWordcount with \MyTestVar in the equation, it does fine. Any tips for making the wordcount into a variable for this purpose?

5
  • "Longer papers are assessed an excess length fee" --> I would balance the fee and the time you need to invest in order to get your code running :). Commented Apr 10, 2021 at 21:11
  • 2
    I plan on re-using the code a lot. ;)
    – Iotatron
    Commented Apr 10, 2021 at 21:13
  • Out of curiosity: Do they offer a web service (input: PDF, output: PU count) to test your implementation? Commented Apr 10, 2021 at 21:15
  • 1
    Not that I'm aware of, but I presume there is an internal tool. If I come up with an elegant way of doing it I may suggest they add it to their LaTeX template.
    – Iotatron
    Commented Apr 10, 2021 at 21:19
  • Related: tex.stackexchange.com/questions/534 Commented Apr 10, 2021 at 22:19

3 Answers 3

4

You can avoid writing to files.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx,xfp}
\usepackage{catchfile}

% Figuring out AGU's absurd "Publication Unit" scheme:
\newcommand{\quickwordcount}[1]{%
  \CatchFileEdef\MyWordcount{|"texcount -1 -sum -merge #1.tex"}{\endlinechar=-1 }%
}
\quickwordcount{\jobname}

\usepackage{xassoccnt}
\NewTotalDocumentCounter{totalfigures}
\NewTotalDocumentCounter{totaltables}
% \NewTotalDocumentCounter{appendixchapters}
\DeclareAssociatedCounters{figure}{totalfigures}
\DeclareAssociatedCounters{table}{totaltables}

\title{AGU Wordcount Test}

\begin{document}

% \maketitle

\begin{figure}
\caption{a}
\end{figure}
\begin{figure}
\caption{a}
\end{figure}
\begin{figure}
\caption{a}
\end{figure}
\begin{table}
\caption{a}
\end{table}
\begin{table}
\caption{a}
\end{table}


There are approximately \MyWordcount\ words in this article. 
There are \TotalValue{totalfigures} figures, and \TotalValue{totaltables} tables.
That means we have a total of 
\num[scientific-notation=false]{%
  \fpeval{(1/500)*\MyWordcount+ \TotalValue{totalfigures} + \TotalValue{totaltables}}%
} 
publication units, out of a maximum of 25.

\end{document}

enter image description here

1

Okay, this isn't quite complete, but it's close. Thanks to stianlybech on Reddit for helping me out here. This code translates the number of words into publication units, although I haven't had any luck getting them to add (maybe because xassoccnt and pgf don't play nicely together.) It's good enough for my current purposes, but if anyone can find a workable way to add the counters into a single number that'd be much appreciated.

\documentclass{article}
\usepackage[utf8]{inputenc}


\usepackage{xassoccnt}
\NewTotalDocumentCounter{totalfigures}
\NewTotalDocumentCounter{totaltables}
% \NewTotalDocumentCounter{appendixchapters}
\DeclareAssociatedCounters{figure}{totalfigures}
\DeclareAssociatedCounters{table}{totaltables}
% \usepackage[nomessages]{fp}% http://ctan.org/pkg/fp


% per reddit:
\def\wordcountfile#1#2{
  \immediate\write18{detex '#1.tex' |wc -w > '\jobname.wc'}

  \newread\wcinput
  \openin\wcinput=\jobname.wc

  % The group localizes the change to \endlinechar
  \begingroup
    \endlinechar=-1
    \read\wcinput to \localline

    % xdef to ensure result is visible outside the local scope
    \expandafter\xdef\csname #2\endcsname{\localline}
  \endgroup
  \closein\wcinput
}


\usepackage{pgf}

\def\calcns#1{%
\pgfkeys{/pgf/number format/precision = 1}%
\pgfmathparse{#1/500}%
\pgfmathprintnumber{\pgfmathresult}%
}

\def\PU#1#2#3{%
\pgfkeys{/pgf/number format/precision = 1}%
\pgfmathparse{#1/500+#2+#3}%
\pgfmathprintnumber{\pgfmathresult}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{AGU Wordcount Test}

\begin{document}
\wordcountfile{agujournaltemplate}{wordcount}

\maketitle





There are approximately \wordcount{} words in this article, which amounts to \calcns{\wordcount} publication units. There are \TotalValue{totalfigures} figures, and \TotalValue{totaltables} tables, which amount to one each.

% That means we have a total of \PU{\wordcount}{\TotalValue{totalfigures}}{\TotalValue{totaltables}} publication units, out of a maximum of 25.

See, that didn't work. But this does: \PU{\wordcount}{1}{0}

\begin{figure}
    \centering
    \includegraphics{}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}

\begin{table}[]
    \centering
    \begin{tabular}{c|c}
         &  \\
         & 
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}

1

It is possible to get TeXcount to write the count to file as TeX code by using TeXcount templates. Here's an example where the template is included as TeXcount (%TC:...) instructions within the document:

\documentclass{article}

%TC:newtemplate
%TC:template \def\CountOfAllWords{{word+hword+oword}}\n
%TC:template \def\CountOfTextWords{{word}}\n
%TC:template \def\CountOfHeaderWords{{hword}}\n

\begin{document}

\section{Word count in macro variables}

This is the text that is counted.

%TC:ignore
\section{Word count}

\immediate\write18{texcount -merge -out=\jobname.count \jobname.tex}%
\input{\jobname.count}

There are \CountOfTextWords~words in the text, and \CountOfHeaderWords~words
in headers: all words add up to \CountOfAllWords.
The `Word count' section is not included in the count.
%TC:endignore

\end{document}

Instead of the regular summary output, now the template will be written with {word} and {hword} replaced with the text and header word counts. The different counters are: word/text, headerword, otherword, header, float, inlinemath, displaymath (with shorter aliases like hword, oword, etc available).

Additional documentation can be found on the TeXcount web site and the PDF documents linked to there, including how to add new counters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .