Is there a way to run a word count that doesn't include LaTeX commands?
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:
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:
- Adding
%TC:incbib
in your .tex file's preamble, and then - 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
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
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class