texlens reads the source of a LaTeX paper to set aside the clutter:
hidden text that never reaches the PDF (% comments, \iffalse ... \fi
blocks, comment environments), notes to coauthors, and markup such as the
labels in \cref{...}. Like LaTeX, it follows \input and similar commands,
but it does not run LaTeX itself.
Then, texlens can:
- count words (
texlens words) in the abstract and the main text, for submission forms that ask for a word count; - list notes to coauthors (
texlens notes), such as the text of each\todo{...}, with its file, line, and section; - list revised passages (
texlens changes), such as the text of each\rev{...}, section by section, for example to write or check a list of changes for a revision; - print the abstract as plain text (
texlens abstract), with your macros expanded and without notes, citations, or formatting, ready to paste into a submission form; - list your macros (
texlens macros) and whether they are counted or not.
Your paper stays on your computer. texlens runs locally, makes no network connections, and it collects no data. It reads the files of your paper without changing them. With
texlens words, it uses TeXcount, which also runs locally; it generates a temporary copy of the counted text and deletes it right after (--keep FILEsaves a copy if you choose to do so).
Why
TeXcount, the standard LaTeX word counter
(Overleaf's word count runs it too), counts the source as written. It does
not evaluate conditionals, so it counts hidden text, such as the text in
\iffalse ... \fi, in \if 0 ... \fi, or under a \newif switch set to
false. It also counts notes to coauthors, such as \todo{...}, and the
labels in \cref{...} and other cleveref commands. Finally, it misses the
words that your own macros print, such as a system name put in
\newcommand{\sys}{MyTool}. A paper under revision tends to accumulate
hidden text and notes, so this difference can be large!
texlens generates a copy of your source without the hidden text and passes it to TeXcount, together with rules for notes, references, and your own macros.
Install
texlens needs Python 3.10 or later. Install it with
pipx, which makes the texlens command available
everywhere:
pipx install texlens
If you do not have pipx: brew install pipx on macOS
or sudo apt install pipx on Debian and Ubuntu, then pipx ensurepath, and
open a new terminal. Plain pip works too: pip install texlens. To install
the development version instead, clone this repository and run
pipx install . in its directory.
Our command texlens words needs TeXcount, which comes with most TeX distributions:
- macOS: TeXcount comes with MacTeX. If you
have BasicTeX instead, add it with
sudo tlmgr install texcount. - Linux: on Debian and Ubuntu, run
sudo apt install texlive-extra-utils. With a TeX Live installed from tug.org, runtlmgr install texcount. - Windows: TeXcount comes with TeX Live and MiKTeX.
To check that texlens is installed, run texlens --version.
Quick start
In the directory of your paper, run:
texlens words
texlens finds your main file: main.tex, or else the only .tex file with
\documentclass. To choose it yourself, pass it as texlens words paper.tex
or texlens words ~/papers/draft.
In the same way, run texlens notes to list the notes to coauthors,
texlens changes for the revised passages, texlens abstract for the
abstract, and texlens macros for your macros.
Since most papers define custom macros (e.g., \fixme{...} for notes),
you can describe them with options or in a
texlens.toml file. See the example below.
How it works
- texlens reads the main file and the files that it includes, and drops the hidden text (see Which text texlens skips). It keeps track of the file and line that each remaining line comes from.
- For
words, it runs TeXcount on the counted range, preceded by the packages that your preamble loads (TeXcount has rules for some of them, such as\textcolorin xcolor), your own%TC:instructions, and TeXcount rules for your macros. Where your instructions conflict with the settings of texlens, the settings win. - For
notesandchanges, it finds the calls of your macros, and numbers the sections as LaTeX does by default. - For
abstract, it converts the text of theabstractenvironment (or of\abstract{...}) to plain text: it expands the macros that your preamble defines, keeps the text of formatting commands and changes, and drops notes, citations, and labels.
Example
This repository includes a small paper,
tests/paper.
In the example, we define:
\newcommand{\sys}{Foo} % the name of the system
\newcommand{\fixme}[1]{\textcolor{green}{Fix: #1}} % notes to coauthors
\newcommand{\rev}[1]{\textcolor{blue}{#1}} % revised text
The commands below run in its directory.
Tell texlens about your macros: texlens macros
Start with texlens macros. It lists the macros that the paper defines with
\newcommand, \def, \NewDocumentCommand, or similar commands, how
many arguments each takes (1+1 means one mandatory and one optional
argument), how often the main text uses it, and if texlens words counts
it or not.
$ texlens macros
macro args uses treatment
\rev 1 3 arguments counted as text
\sys 0 2 no words counted
\fixme 1 1 arguments counted as text
\finalversion 0 0 no words counted
Configure macros in texlens.toml next to main.tex, or with --note/--change/--ignore/--word.
If you do not customize the settings of a macro, then the arguments are counted as text
by default, while a macro without arguments adds no words. In
this example, the notes in \fixme are counted, while the word printed by \sys
is not. To change this default behaviour, specify a setting:
| Setting | Treatment |
|---|---|
--note NAME |
note: not counted |
--change NAME |
change: counted |
--ignore NAME |
arguments not counted |
--word NAME=N |
counts as N words |
[macros.rules] |
TeXcount rule ... |
\todo is a note, and reference macros such as \cref are ignored, without
any setting. Command-line options explains each
setting. With the settings in the example above, the table becomes:
$ texlens macros --note fixme --change rev --word sys=1
macro args uses treatment
\rev 1 3 change: counted
\sys 0 2 counts as 1 word
\fixme 1 1 note: not counted
\finalversion 0 0 no words counted
Configure macros in texlens.toml next to main.tex, or with --note/--change/--ignore/--word.
Instead of passing these options every time, write them once in a
texlens.toml file next to the main file:
[macros]
notes = ["fixme"]
changes = ["rev"]
[macros.words]
sys = 1
Count words: texlens words
$ texlens words --note fixme --change rev --word sys=1
Counted from \begin{abstract} to \bibliographystyle.
Words in text: 28
Words in headings: 3
Words in captions: 1 (not counted)
Formulas: 1 (not counted)
Word count: 31
The word count adds up the lines not marked "(not counted)". Without the three
settings, it would be 32: the three words of the note would be counted, and
the two \sys would not. What texlens words counts
explains the defaults and how to change them.
List notes to coauthors: texlens notes
texlens notes prints the text of every note in the paper: the argument of
each \todo{...}, and of each macro with the --note setting.
$ texlens notes --note fixme
main.tex:22 [1 Intro] \fixme
should not count
sections/method.tex:6 [2 Method] \todo
a note
2 notes (\fixme: 1, \todo: 1)
Each note shows its file, line, section, and macro, followed by its text.
Notes in hidden text are not listed, since they never reach the PDF. Before
you submit, texlens notes should print 0 notes!
Long notes are cut to one line; --full prints them in full, and --summary
prints only the number of notes per section.
List revised passages: texlens changes
texlens changes prints the text marked by the macros with the --change
setting, such as \rev{...}:
$ texlens changes --change rev
main.tex:23 [1 Intro] \rev
four five
sections/method.tex:2 [2 Method] \rev
thirteen fourteen
2 changes (\rev: 2)
A \rev inside another \rev is part of the outer passage: in this paper,
\rev{thirteen \rev{fourteen}} is one passage.
With --summary, texlens prints only the number of passages in each section,
and an estimate of their words. This helps to write or check a list of
changes:
$ texlens changes --change rev --summary
2 changes (\rev: 2)
1 Intro: 1 change, about 2 words
2 Method: 1 change, about 2 words
As for notes, --full prints long passages in full.
Copy the abstract: texlens abstract
Submission forms often ask for the abstract as plain text. texlens abstract
prints it as the PDF shows it, without LaTeX markup:
$ texlens abstract
warning: formatting removed; add it back if the form accepts it: \emph{tiny}
Alpha beta gamma. We present Foo, a tiny paper—for “testing”.
(10 words, 61 characters)
The source of this abstract is:
Alpha beta gamma. We present \sys{}, a \emph{tiny} paper---for ``testing''.
texlens expands the macros that the paper defines, here \sys, and keeps
the text of formatting commands such as \emph and \textcolor, of changes
such as \rev{...}, and of URLs. It drops notes, citations, labels, and
footnotes, and turns LaTeX characters into the characters they print: ---
into —, ``...'' into “...”, \'e into é, and ~ into a space.
Simple math becomes text too, as $O(n^2)$ becomes O(n²). texlens keeps
the paragraphs, separated by blank lines.
texlens also warns:
- about the formatting that it removes, such as
\emph,\textbf, and math, so that you can add it back if the form accepts LaTeX or HTML; - about text to check: a citation or a reference such as
\cref, which it drops (rewrite the text around it), or a footnote; - about what it cannot convert: math such as
$\frac{a}{b}$, which it keeps as LaTeX, a conditional that it cannot evaluate, and macros that it does not know.
The counts of words and characters go to the error output, as the warnings
do, so texlens abstract | pbcopy on macOS copies only the abstract.
Configuration
The settings file
texlens reads the settings in texlens.toml, next to your main file. All
keys are optional. This example shows every key:
[macros]
notes = ["fixme"] # notes to coauthors: not counted, listed by `notes`
changes = ["rev"] # revised text: counted, listed by `changes`
ignore = ["myref"] # arguments are not words; "name:2" for two arguments
[macros.words] # macros without arguments that print words
sys = 1
[macros.rules] # any TeXcount rule, e.g. for the changes package
replaced = "[text,ignore]"
deleted = "[ignore]"
[conditionals]
false = ["iffinal"] # conditionals to treat as false
true = [] # conditionals to treat as true
hidden_environments = ["comment"]
[count]
start = ['\begin{abstract}']
stop = ['\appendix', '\bibliographystyle', '\bibliography',
'\printbibliography', '\begin{thebibliography}', '\end{document}']
footnotes = true # count footnotes
captions = false # count figure and table captions
math = false # count each formula as one word
Write macro names without the backslash. Write LaTeX markers in single quotes
(TOML literal strings), so that their backslashes are kept as they are. The
values shown for hidden_environments and [count] are the defaults. The
macro lists add to the defaults (\todo is always a note); the other lists
replace them. A macro can be in only one of notes, changes, ignore, and
rules.
Command-line options
Most settings also have a command-line option. For macros and conditionals,
the options add to the settings file; for the rest, they replace its values.
Options that take a name can be repeated, as in
--note fixme --note ask. texlens <command> --help lists the options of
each command.
| Option | In texlens.toml |
Meaning |
|---|---|---|
--note NAME |
[macros] notes |
\NAME{...} is a note to coauthors: its text is not counted, and notes lists it. \todo is always treated this way. |
--change NAME |
[macros] changes |
\NAME{...} marks revised text: its text is counted, and changes lists it. |
--ignore NAME |
[macros] ignore |
The argument of \NAME is not counted, as for a label or a key. Write NAME:N for a macro with N arguments. Reference macros such as \cref, \autoref, and \eqref are always ignored. |
--word NAME=N |
[macros.words] |
\NAME, a macro without arguments, prints N words: for example, --word sys=1 for \newcommand{\sys}{MyTool}. |
| — | [macros.rules] |
A TeXcount rule, for macros that the options above do not cover: for example, deleted = "[ignore]" for the \deleted{...} macro of the changes package. See TeXcount's documentation for the syntax. |
--false-if NAME |
[conditionals] false |
Treat the conditional \NAME as false: keep only its \else branch. Include the if, as in --false-if iffinal for \iffinal. |
--true-if NAME |
[conditionals] true |
Treat the conditional \NAME as true: keep only the text before its \else. |
| — | [conditionals] hidden_environments |
Environments whose content never reaches the PDF (default: comment). |
--start MARKER |
[count] start |
Only for words: where counting starts, for example --start '\section{Introduction}' to skip the abstract. |
--stop MARKER |
[count] stop |
Only for words: where counting stops, for example --stop '\end{document}' to also count the appendices. |
--captions |
[count] captions = true |
Only for words: also count figure and table captions, and margin notes. |
--math |
[count] math = true |
Only for words: count each formula as one word. |
--no-footnotes |
[count] footnotes = false |
Only for words: do not count footnotes. |
--texcount CMD |
— | Only for words: run TeXcount with CMD, as in --texcount "perl /path/to/texcount.pl". By default, texlens uses the TEXLENS_TEXCOUNT environment variable, or texcount. |
--keep FILE |
— | Only for words: save the text that texlens gives TeXcount, to check what is counted. |
--full, --summary |
— | Only for notes and changes: print the texts in full, or only the totals per section. |
--config FILE |
— | Read the settings from FILE instead of the texlens.toml next to the main file. |
--json |
— | Print the result as JSON: an object with the result under the name of the command (as in "notes": [...]) and the list of "warnings". |
Which text texlens skips
As LaTeX does, texlens skips:
%comments;- the text inside
\iffalse ... \fiand\if 0 ... \fi, keeping the\elsebranch, if any (\iftruedoes the opposite, and\unlessreverses either); - the text under a switch defined with
\newifand set to false: after\newif\ifdraftand\draftfalse, the text inside\ifdraft ... \fi(switches defined with\let\ifdraft\iffalsework too); - the conditionals that you declare with
--false-ifand--true-if; - the content of
commentenvironments, of the environments hidden with the comment package's\excludecomment, and of those inhidden_environments; - the files that
\includeonlyleaves out.
To find all the text, texlens follows \input, \include, \subfile,
\import, and \subimport. Of an included file that is a document of its
own (with the standalone or subfiles packages), it keeps only the text
between \begin{document} and \end{document}. It leaves verbatim text,
such as \verb and the content of verbatim, lstlisting, minted, and
filecontents environments, as it is. texlens warns when a conditional or a
comment environment is still open at the end of a file, and handles it as
LaTeX does.
What texlens words counts
- Range. texlens counts from the first start marker (by default,
\begin{abstract}, or\begin{document}if there is no abstract) to the first stop marker after it (by default, the first of the markers listed understopin the settings file). Thus, the title, the authors, the references, and the appendices are not counted. Neither are keywords and ACM's classification concepts (\ccsdesc) and dates (\received), even when they come after the abstract; ACM's teaser figure counts as a figure. The first line of the output shows the markers that texlens used. - Counted. The words in the text, including footnotes, and in headings. As in TeXcount, the title of the abstract counts as a heading word, and a URL counts as one word if the preamble loads hyperref or url.
- Not counted, unless you ask. Figure and table captions and margin
notes (
--captions), and formulas (--math, which counts each formula as one word). - Never counted. The content of tables (
tabular), as in TeXcount; code, both inline (\verb,\lstinline) and in listings; and the ACM classification codes (CCSXML), which LaTeX does not print. %TC:ignore. As in TeXcount, the text between%TC:ignoreand%TC:endignoreis not counted. texlens warns when such a region hides more than about 20 words outside figures and tables, which usually means that%TC:endignoreis missing or in the wrong place.
For everything else, TeXcount's own rules apply.
Limitations
- Other conditionals. Some conditionals depend on information that
texlens does not have: for example,
\ifpdfdepends on the TeX engine, and\ifx\a\bcompares two macros. texlens keeps the text of both branches, unless you declare the conditional, as with--true-if ifpdfif you compile with pdfLaTeX. etoolbox toggles and booleans, such as\iftoggle{draft}{...}{...}, always keep both texts: they take the texts as arguments instead of ending with\fi, so they cannot be declared. - Switches set by macros. texlens follows a
\newifswitch through the\...trueand\...falsecommands written in your files, outside macro definitions. If one of your macros sets the switch, as in\newcommand{\finalversion}{\draftfalse}, texlens cannot know whether or when that macro runs, so it ignores the change. The same holds for switches set in a class, in a package, or on the command line. In these cases, declare the switch with--true-ifor--false-if. - Section numbers. In the output of
notesandchanges, texlens numbers the sections by counting\section,\subsection, and so on, as the standard classes do. If your class or preamble numbers them differently (for example, IEEEtran uses Roman numerals, and\setcounter{section}{...}changes the count), these numbers can differ from those in the PDF. File names and line numbers are always exact.
Testing
The tests use Python's built-in unittest module. From the repository, run:
python -m unittest discover -s tests -t .
The tests cover:
- reading a project: following
\input,\include(with\includeonly),\subfile,\import, and\subimport; missing, self-including, and deeply nested files; line endings and encodings; comments and escaped%signs; all the conditionals above, nested, declared, unclosed, or inside macro definitions, and macros that only look like conditionals; hidden and verbatim environments; and finding the main file; - listings: finding macro calls with optional, multiple, and nested arguments, outside verbatim text; reading macro definitions; numbering sections, including starred sections, appendices, and the abstract; skipping notes in hidden text; and the table of macros;
- settings: the defaults,
texlens.tomlfiles (including invalid or contradictory ones), and command-line options; - word counts: the counted range, the settings and rules given to
TeXcount,
%TC:ignoreregions, and, with TeXcount, the counts of the test paper and of a paper without hidden text, which must equal TeXcount's own; - the abstract: finding it (also in included files and in the preamble); expanding macros, with optional arguments, conditionals, and macros that never stop; notes, changes, citations, and references; formatting and its warning; accents, special characters, and math; lines joined by comments and paragraphs; broken LaTeX; and a realistic abstract;
- the command line: the output of each command,
--summaryand--json, warnings, and errors such as a missing main file or a missing TeXcount.
The tests that run TeXcount are skipped if it is not installed; set
TEXLENS_REQUIRE_TEXCOUNT=1 to make them fail instead. To use a specific
copy of TeXcount, set TEXLENS_TEXCOUNT, as described under
Command-line options. On Python 3.10, the tests that
read texlens.toml files need the tomli package, which pip install .
installs.
All tests pass with TeXcount 3.1.1 on Linux (Ubuntu 24.04), with Python 3.10 to 3.13, and on macOS 26, with Python 3.11. texlens has not been tested on Windows yet.
Contributing
Bug reports and pull requests are welcome, including new features that you would find useful. A pull request should add tests for what it changes and pass the whole test suite (see Testing), which GitHub also runs on every pull request.
License
Copyright 2026 Roberta De Viti.
texlens is released under the Apache License 2.0. You may use, modify, and redistribute it, also in proprietary software. If you redistribute it, modified or not, include the LICENSE and NOTICE files, keep the copyright notices, and mark the files that you change. Contributors also grant you a license to any of their patents that texlens would otherwise infringe.
texlens runs TeXcount, by Einar Andreas Rødland, which is distributed separately under the LaTeX Project Public License. texlens is not affiliated with TeXcount.
Metadata
Release files for texlens 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| texlens-0.2.0.tar.gz | 66.3 kB | With provenance | Details for texlens-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| texlens-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for texlens-0.2.0-py3-none-any.whl |
Total release size: 114.0 kB
Release files / texlens-0.2.0.tar.gz
| Download URL | texlens-0.2.0.tar.gz |
|---|---|
| Size | 66.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd7982426b0412e6bf5f702e65ad778263324c9787783ff810b587a3742aa68e
|
|
BLAKE2b-256 checksum How to use checksums |
b44a3be51eab6e630e9f4b8a568fa89e71820922ee1caf59b464d5f74113a7be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logRelease files / texlens-0.2.0-py3-none-any.whl
| Download URL | texlens-0.2.0-py3-none-any.whl |
|---|---|
| Size | 47.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fd2a19fd840ef940d9dddddc53ab89b718370df6a0aca5a546e7f7f65a3b791
|
|
BLAKE2b-256 checksum How to use checksums |
121c139b6a0e2df6ad0ca15640d9432cad2f9976d49a0df5ea90d8cc92910187
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logSecurity for texlens 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for texlens-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.