Skip to content

Introduction

Yes, you can obtain a word count which automatically excludes the LaTeX commands by selecting Menu and then Word Count as demonstrated in this short screencast:

Wordcount.gif


This will run the texcount utility to count the words in the project's main file and any files imported into your project's main file via \include and \input. Note that your project's main document must be on the project's top level (i.e. not within a folder) for texcount to work on Overleaf.

Include references in the word count

By default, references, headers, captions, floats, displayed math etc are not included in the count. To include the citations and references:

  1. Adding %TC:incbib in your .tex file's preamble, and then
  2. Add a file named latexmkrc (no file extension) in your project, with the following line in it (change "main" to whatever your main document .tex file is named)
    END { system('cp', 'output.bbl', 'main.bbl'); }
    

Note that this workaround is only applicable if you are using a manual thebibliography list or BibTeX. texcount does not currently support biblatex.

See #Run texcount with custom parameters for showing word counts for headers, captions, floats, displayed math etc.

Ignoring some sections

At times, you may want to exclude certain sections or regions from the word count. You can place %TC:ignore and %TC:endignore around such regions. For example:

%TC:ignore
\maketitle

\begin{abstract}
...So the title page and abstract will not be word-counted...
\end{abstract}
%TC:endignore

Run texcount with custom parameters

If you'd like to use your own set of texcount parameters to customize the output, or to perform a character count, or to include captions etc, you can do so by defining a few commands in your project (though this then involves using LaTeX commands...). For example:

\usepackage{verbatim}

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

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

\newcommand{\quickcharcount}[1]{%
  \immediate\write18{texcount -1 -sum -merge -char -q #1.tex output.bbl > #1-chars.sum }%
  \input{#1-chars.sum} characters (not including spaces)%
}

Assuming your file is named main.tex, invoking these commands in your project would then have the following output in the PDF. The output includes breakdown for each sub(section), as well as for captions, floats, displayed equations etc. Note that due to how the Overleaf build process is configured, you must include `output.bbl` in the `texcount` command for BibTeX-produced reference lists to be counted as well.

% Don't count these!
%TC:ignore
\quickwordcount{main}
\quickcharcount{main}
\detailtexcount{main}
%TC:endignore

Custom-texcount.png

See the texcount documentation for what each runtime flag does. You can see these examples in action here.

"Words in headers" and "headers" in the section-by-section breakdown is for \section, \subsection etc but excluding the number 1, 1.1 etc.

"Word outside text" and "captions" in the section-by-section breakdown is for \caption, but excluding the prefix "Table 1" etc.

By default, inline citations aren't counted. If you want to count them, add these lines to your preamble:

%TC:macro \cite [option:text,text]
%TC:macro \citep [option:text,text]
%TC:macro \citet [option:text,text]
% ... and for any other \cite commands you may use

However, note that each \citep{ddd} counts only as one word in texcount (which sort of makes sense; otherwise you can artificially bump up word counts tremendously by citing references with multiple authors). So \cite{faye1996}, although rendered as (Fay, 1996), is counted as one word by texcount but 2 words by other word processors.


To include words in tabulars and tables in the "words in main text" count, you can add these texcount instructions as well:

%TC:group table 0 1
%TC:group tabular 1 1

Using the \import command with texcount

By default, texcount recognises common commands like \input, \include for counting included subfiles. However, the command \import from the import package is not supported by default.

Therefore if you are using \import in your document, you may wish to use the more common \input and \include commands instead, and texcount will work without any further changes.

If you do prefer to continue using \import, you can add a texcount instruction in the preamble so that \import{foo}{bar} looks like \include{foo/bar} to texcount, so that it'll count the words in the subfiles:

%TC:fileinclude \import dir,file

Please note that you'll have to do a recompile first after adding this line, before clicking on "Word count".

Further Reading

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX