> For the complete documentation index, see [llms.txt](https://docs.overleaf.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.overleaf.com/writing-and-editing/using-word-count.md).

# Using Word Count

You can obtain a word count which automatically excludes the LaTeX commands by selecting **File** and then **Word Count** as demonstrated below:

<figure><picture><source srcset="/files/ofRObSlCPin70P7dT5Zu" media="(prefers-color-scheme: dark)"><img src="/files/mapnm55bOSFSLPHRYFUd" alt="The Word Count option in the File menu" width="242"></picture><figcaption></figcaption></figure>

\
This will run the [TeXcount](http://app.uio.no/ifi/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 in 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. Add `%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:

   <pre class="language-ssh-config"><code class="lang-ssh-config">END { system('cp', 'output.bbl', '<a data-footnote-ref href="#user-content-fn-1">main</a>.tex'); }
   </code></pre>

{% hint style="warning" %}
Note that this workaround is only applicable if you are using a manual `thebibliography` list or BibTeX. [TeXcount does not currently support BibLaTeX](https://tex.stackexchange.com/q/102882/226).
{% endhint %}

See [#run-texcount-with-custom-parameters](#run-texcount-with-custom-parameters "mention") 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:

```latex
%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](http://app.uio.no/ifi/texcount/documentation.html) 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 involves using LaTeX commands). For example:

```latex
\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)%
}
```

{% hint style="info" %}
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.
{% endhint %}

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.

{% columns %}
{% column %}

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

{% endcolumn %}

{% column %}
{% code title="Output displayed in PDF" %}

```
File: main.tex
Encoding: ascii
Sum count: 865
Words in text: 781
Words in headers: 66
Words outside text (captions, etc.): 11
Number of headers: 14
Number of floats/tables/figures: 2
Number of math inlines: 6
Number of math displayed: 1
Subcounts:
    text+headers+captions (#headers/#floats/#inlines/#displayed)
    2+3+0 (2/0/0/0) _top_
    86+1+0 (1/0/0/0) Section: Introduction
    0+5+0 (1/0/0/0) Section: Some examples to get started
    49+6+0 (1/0/0/0) Subsection: How to create Sections and Subsections
    111+4+8 (1/1/0/0) Subsection: How to include Figures
    23+4+3 (1/1/0/0) Subsection: How to add Tables
    122+7+0 (1/0/0/0) Subsection: How to add Comments and Track Changes
    20+4+0 (1/0/0/0) Subsection: How to add Lists
    37+4+0 (1/0/6/1) Subsection: How to write Mathematics
    122+8+0 (1/0/0/0) Subsection: How to change the margins and paper size
    81+10+0 (1/0/0/0) Subsection: How to change the document language and spell check settings
    78+8+0 (1/0/0/0) Subsection: How to add Citations and a References List
    50+2+0 (1/0/0/0) Subsection: Good luck!
File: output.bbl
Encoding: ascii
Sum count: 0
Words in text: 0
Words in headers: 0
Words outside text (captions, etc.): 0
Number of headers: 0
Number of floats/tables/figures: 0
Number of math inlines: 0
Number of math displayed: 0
```

{% endcode %}

{% endcolumn %}
{% endcolumns %}

See the [TeXcount documentation](http://app.uio.no/ifi/texcount/documentation.html#options) for what each runtime flag does. You can see these examples in action [here](https://www.overleaf.com/read/dqvrqghbtmbc).

{% hint style="info" %}
"Words in headers" and "headers" in the section-by-section breakdown is for `\section`, `\subsection`, etc. but excluding the numbers 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.
{% endhint %}

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

```latex
%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
```

{% hint style="info" %}
Note that each `\citep{ddd}` counts only as one word in TeXcount; 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 two words by other word processors.
{% endhint %}

To include words in tabulars and tables in the "words in main text" count, you can [add these TeXcount instructions](https://tex.stackexchange.com/a/37777/226) as well:

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

## Using the `\import` command with TeXcount

By default, TeXcount recognises common commands like `\input` and `\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:

```latex
%TC:fileinclude \import dir,file
```

{% hint style="warning" %}
Please note that you'll have to do a recompile first after adding this line, before clicking on "Word count".
{% endhint %}

[^1]: Change "main" to your main document file name.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overleaf.com/writing-and-editing/using-word-count.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
