Include the total word count in the output pdf automatically

overleafword count

I am currently writing a document using Overleaf, a Latex-editing service that provides an automatic word count. However, I do not know how it provides it nor how accurate it is.

I am looking for a way to include Overleaf’s total word count of my document in the output pdf automatically.

If inserting the exact number the Overleaf displays is not possible (i.e., because nobody knows how Overleaf counts words or whatever other reason), any other approximation of my document’s word count will suffice. The whole point is to avoid having to check the word count and writing it down every time I share my piece of work.

There are many questions about word count, but none that asks specifically how to include the total word count in the output pdf (and if there is one and I missed it, feel free to link me there!).

Thank you all very much for your time.

Best Answer

Looking through texcount's documentation, we can modify the commands from OP's link to be

\newcommand{\detailtexcount}[1]{%
  \immediate\write18{texcount -merge -sum #1.tex > #1.wcdetail }%
  \verbatiminput{#1.wcdetail}%
}

\newcommand{\quickwordcount}[1]{%
  \immediate\write18{texcount -0 -sum -merge -q #1.tex > #1-words.sum }%
  \input{#1-words.sum}% words%
}

\newcommand{\quickcharcount}[1]{%
  \immediate\write18{texcount -0 -sum -merge -char -q #1.tex > #1-chars.sum }%
  \input{#1-chars.sum}% characters (not including spaces)%
}
  • We've removed -q from \detailtexcount to show what errors are happening
  • We've changed -1 to -0 to remove a newline (and we need no errors to have no newline at all)
  • We've removed text from being output by the macro

The count can still miss generated text (for example, \lipsum paragraphs get missed entirely).

If you really need the comma, this question suggests using the packages siunitx or numprint.