My Overleaf Latex project is grossly undercounting the words and equations in my document.

The actual number of words is nearly 12,000 and 60 equations. Overleaf Word Count outputs only 130 words and 0 equations.

I found the problem and a workaround, but I don't understand. In my preamble, I had moved all my \usepackage{} commands to a separate file, packages.tex, and inserted it using \input{packages.tex}. One of those packages, subfiles, causes the Word Count to fail when placed in packages.tex. Calling \usepackage{subfiles} in main.text, instead, remedies the issue (all other packages are still imported via packages.tex).

So where are the 130 words? Not solely in main.tex! Commenting out all my \subfile{} commands yields only a 20 word document. Weird.

  • 3
    Welcome to TeX.SE. Sadly, reliable psychics are not known to hang out on TeX.SE. Unless you begin to share some actionable information, there's little to nothing readers of your poosting can do except nod their heads in sympathy. If you believe there's an error in Overleaf's utility that performs word counting, you should raise this issue with Overleaf's Help Desk. I hear their LaTeX support staff are top-notch.
    – Mico
    Apr 28, 2021 at 6:29
  • 1
    @Mico, please describe what would constitute actionable info? I'd like my question to be useful as possible. Per the accepted answer below, I do not believe Overleaf is in error. Apr 28, 2021 at 16:29
  • 1
    @JohnHaTrick You would want to trim things down to three files: main.tex, subfile.tex, and packages.tex. You would want each of them to be as short as possible that still exhibits the behavior you're describing. Then you would post the content here.
    – Teepeemm
    Apr 28, 2021 at 17:44

1 Answer 1


I'm not very familiar with Overleaf, and so can't tell how Overleaf does things. But as far as I understand it uses TeXcount to do the counting which I do know.

TeXcount initially processes individual TeX files, but can add included files in two different ways:

  • -inc makes a list of included files which are counted separately
  • -merge tries to merge included files in where included

In this case, -merge is required for this to work. This will simply read the included file and insert the content in place.

If you are using -inc, the main file will be processed/counted first, and then the included files will be processed afterwards. This would give the described behaviour as \usepackage{subfiles} is only parsed when packages.tex is processed.

The macro processing rule for \subfile is only set up when TeXcount detects that the subfiles package is included, so if -inc is used it will remain undefined (TeXcount will use a default processing rule) when parsing the main file until later when packages.tex is processed.

The default rule, used if no other rule is specified by or to TeXcount, is that the macro does nothing. So this would make TeXcount process \subfile{myfile} by counting myfile as a word of text.

If this is not the cause, you would have to provide more details: like what options TeXcount is run with and some more details on what output it produces.

TeXcount comes with options to generate verbose output detailing exactly how every bit of TeX code is parsed and counted, but I suspect this cannot easily be run within Overleaf. The TeXcount web service provides this, but cannot handle multiple files.

From OP: In accordance with this advice, the following code works. Replacing -merge with -inc reproduces the Overleaf Word Count undercounting behavior.

  \immediate\write18{texcount -merge -sum #1.tex > #1.wc }%

You must log in to answer this question.

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