Skip to main content

texlens: a lens on your TeX, without the clutter

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 (except to build the PDF of texlens diff).

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;
  • build a PDF of the changes since a git commit (texlens diff), with the new text in red, for example to show reviewers what a revision changed;
  • 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;
  • write the whole paper as plain text (texlens text), one .txt file per chapter, with the numbers of references and citations as the PDF shows them;
  • 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 FILE saves a copy if you choose to do so). texlens diff works on temporary copies that it takes from git, and deletes them after writing the PDF (--keep keeps them). texlens text writes its .txt files to a folder of its own, and never over a file of your paper.

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, run tlmgr install texcount.
  • Windows: TeXcount comes with TeX Live and MiKTeX.

Our command texlens diff needs git, a LaTeX distribution, and its tools latexdiff and latexmk. They come with MacTeX, with a full TeX Live, and with MiKTeX; on Debian and Ubuntu, run sudo apt install latexdiff latexmk.

Our command texlens text needs no other tools, but it takes the numbers of references and citations from your compiled paper: compile it first.

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 and texlens changes for the revised passages. If your paper is in git, texlens diff HEAD~3 builds a PDF with the changes of the last three commits in red. texlens abstract prints the abstract as plain text, texlens text writes the whole paper as plain text, and texlens macros lists 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

  1. 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.
  2. 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 \textcolor in xcolor), your own %TC: instructions, and TeXcount rules for your macros. Where your instructions conflict with the settings of texlens, the settings win.
  3. For notes and changes, it finds the calls of your macros, and numbers the sections as LaTeX does by default.
  4. For diff, it takes two versions of the paper from git, compares the text that reaches the PDF paragraph by paragraph with latexdiff, and compiles the new version with the changes in red.
  5. For abstract, it converts the text of the abstract environment (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.
  6. For text, it converts the whole document in the same way, chapter by chapter, but keeps its structure (headings, paragraphs, lists, formulas, captions, and footnotes) and prints references and citations with the numbers that LaTeX wrote to the .aux file of the compiled paper.

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.

Show what changed: texlens diff

For a revision, reviewers and coauthors often want to see what changed since the version they read. If your paper is in git, texlens diff BASE builds the PDF of the paper as committed (HEAD), with every change since the commit BASE in red:

$ texlens diff submitted
repository paper
  1a2b3c4 2026-03-01 Submitted version
  -> 9f8e7d6 2026-05-20 Address the reviews
  marked main.tex
  marked sections/method.tex
2 files with changes
compiling ...
wrote main_revision_1a2b3c4d_0103.pdf

BASE can be any commit: a hash, a tag such as submitted above, or HEAD~3. The PDF is named after the main file, the base commit, and its date (day and month); choose another name with -o FILE.

In red are the words that were added or changed, new citations and references ([4], Figure 2), new footnotes, including their marks, and new paragraphs, figures, tables, and headings, including their entries in the table of contents. Deleted text is left out, so the PDF has the same text as the paper at HEAD; with --show-deletions, it is printed in red and struck through instead. Text that moved, within a file or to another one, is marked only where it was also edited, and so is a paragraph split in two or two paragraphs merged into one.

texlens compares only the text that reaches the PDF: it leaves out comments, hidden text, and the branches of \newif switches that the preamble turns off (see Which text texlens skips). It compares each file paragraph by paragraph, so that latexdiff does not match words across paragraphs or figures, and then compiles the paper with latexmk, with pdfLaTeX unless a latexmkrc next to the main file sets $pdf_mode.

A few things to know:

  • Committed files only. texlens takes both versions from git into a temporary directory: your working tree is not touched, and changes that are not committed are left out.
  • Several repositories. A paper may include files from another git repository, as in \input{\shared/method} with \newcommand{\shared}{../shared-text}. texlens finds every repository that the paper reads from. BASE may be a commit of any of them; each other repository is taken at its last commit not newer than BASE.
  • Not marked. Changes in the preamble and in macro definitions (they show only through their effect), in figures, and in the bibliography (a new citation shows as a red number), as well as the text of deleted files, which has no place in the new version. Under [diff] unmarked in texlens.toml, list files to take as they are, such as TikZ drawings kept in .tex files.
  • When something may be unmarked, texlens warns and exits with status 1 (the PDF is still written): when LaTeX reports errors, when an included file cannot be found, and when a .tex file next to the included ones changed although no version includes it. The last one catches files that your paper loads in a way texlens cannot follow, such as a macro that takes the file name. If the paper leaves such a file out on purpose, list it under [diff] not_in_document. texlens also warns about a file that includes itself, directly or through other files: it follows such a loop only once. LaTeX would never finish reading it, unless the file stops itself with \endinput, as include guards do.

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.

Write the paper as plain text: texlens text

To read your paper without LaTeX markup, to paste a chapter into a grammar checker, or to give it to a tool that wants plain text, texlens text writes the whole document to .txt files: one per chapter, named after its number and title, plus 0-front-matter.txt for the text before the first chapter (the title page and the abstract). For a book with chapters:

$ texlens text snails.tex
snails_text/0-front-matter.txt: 412 words
snails_text/acknowledgments.txt: 160 words
snails_text/1-introduction.txt: 5210 words
snails_text/2-garden-snails.txt: 9874 words
snails_text/A-proofs.txt: 2301 words

A chapter without a number (\chapter*, or a \chapter in a book's front or back matter) is named after its title alone, and an appendix after its letter. A paper without chapters, such as the example paper, gives a single file, named after the main file:

$ texlens text --note fixme --change rev
warning: main.aux not found: compile the paper (or point --aux to its .aux file) to get the numbers of references and citations; until then, references print ?? and citations are left out
main_text/main.txt: 49 words

main_text/main.txt starts with:

Abstract

Alpha beta gamma. We present Foo, a tiny paper—for “testing”.

1 Intro

One two Foo three. four five See ??. six Footnote (Footnote: seven eight).

The ?? stands for the number that LaTeX prints for \cref{sec:intro}: texlens takes such numbers from the .aux file that LaTeX writes when it compiles the paper. Once the paper is compiled, the line reads See section 1., as in the PDF.

In the text files:

  • Headings are on lines of their own, with their numbers, as in 2.1 Setup, and blank lines separate paragraphs.
  • Lists have one item per line, starting with - or 1. ((a) and i. in nested lists), indented by level.
  • Formulas in display, as in \begin{equation} or \begin{align}, are on lines of their own, one per row, with the number of their label: E = mc² (3).
  • Math is written as text where texlens can: it expands your macros in it, and writes symbols, letters such as 𝒜 and ℝ, simple fractions and roots, and scripts, in Unicode where Unicode has them and with _ and ^ where it does not, for every script of that formula: $x_1$ gives x₁, but $x_1, \dots, x_k$ gives x_1, ..., x_k, and $\frac{d_i}{t_i}$ gives d_i/t_i. With \newcommand{\nshell}{n_{\mathrm{shell}}}, $\sqrt{\nshell}$ gives √n_shell. Other math, such as an array, stays LaTeX, with your macros expanded so that it reads on its own, and a warning.
  • Figures and tables are left out, but their captions are kept as paragraphs, as in Figure 1.1: A shell., followed by the captions of their subfigures, as in (a) A spiral.
  • Footnotes are kept where their mark is, as in slowly (Footnote: Mostly at night.).
  • Theorems and proofs start with their name and number, as in Lemma 2.1 (Shells).
  • References and citations print what the PDF shows: \ref the number, \eqref the number in parentheses, \pageref the page, \cite and natbib's \citep the labels in brackets, as in [2, 5] (sorted, compressed as in [3–6], or separated by semicolons, as natbib's options or the cite package ask), and natbib's \citet the authors and the label. \autoref, and cleveref's \cref and \Cref, add the name of what they refer to, as hyperref and cleveref name it: section 2, or Section 2 with cleveref's capitalise option, or as your preamble sets with \crefname or \renewcommand{\sectionautorefname}{...}. With biblatex, a citation prints the number of its entry in the bibliography that biber writes (the .bbl file), in each refsection, or with an alphabetic style its label, as in [ML20].
  • Citations without a number are left out, with a warning: in a paper that is not compiled yet, for a key that the .aux file lacks, and with biblatex styles that do not number citations, such as authoryear. A reference without a number prints ??, as in LaTeX.
  • Left out, as in the abstract: hidden text, notes, labels, and formatting; also the bibliography, the table of contents, the lists of figures, tables, and algorithms, the index and the glossaries (a chapter that holds only one of these gets no file), the content of tables and pictures (tabular, tikzpicture), and code.

The numbers come from the .aux file next to the main file (main.aux for main.tex), and from the .aux files of the chapters that it includes with \include. If LaTeX writes it elsewhere, as with latexmk -outdir=build, pass it with --aux build/main.aux. The numbers of headings come from the table of contents in the .aux file too, so that a chapter in a book's front matter has no number, as in the PDF. Without a .aux file, texlens numbers headings and captions itself, as the standard classes do, while references print ??, as LaTeX does before its first run, and citations are left out. texlens warns:

  • when there is no .aux file;
  • when the .aux file is older than a file of the paper, so that the numbers may be out of date: compile the paper again;
  • about labels that the .aux file lacks, which print ??, and citations without a number, which are left out: check the text around them;
  • with biblatex, when biber has not written the .bbl file, or when the style does not number citations.

The files go to the folder MAIN_text in the current directory (main_text for main.tex), or to the folder given with --output-dir DIR. texlens replaces the files that it wrote before, but never a file of the paper. It prints the name and the number of words of each file on the error output, or, with --json, as JSON.

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

[diff]
not_in_document = ["response.tex"]  # files the paper leaves out on purpose
unmarked = ["figures/*.tex"]        # files to take as they are, unmarked

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. The files under [diff] are paths relative to the main file's directory, as texlens prints them; * matches any characters.

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, notes lists it, and abstract and text leave it out. \todo is always treated this way.
--change NAME [macros] changes \NAME{...} marks revised text: its text is counted, changes lists it, and abstract and text keep it.
--ignore NAME [macros] ignore The argument of \NAME is not counted, as for a label or a key, and abstract and text leave the macro out. Write NAME:N for a macro with N arguments. The word count always ignores reference macros such as \cref, \autoref, and \eqref.
--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.
--show-deletions — Only for diff: print deleted text in red and struck through, instead of leaving it out.
-o FILE, --output FILE — Only for diff: the PDF to write, instead of MAIN_revision_BASE_DDMM.pdf in the current directory.
--keep — Only for diff: keep the temporary directory with both versions and the marked files, and print its path.
— [diff] not_in_document Only for diff: files that the paper leaves out on purpose, so that their changes do not cause a warning.
— [diff] unmarked Only for diff: included files to take as they are, without marking their changes.
--output-dir DIR — Only for text: the folder for the .txt files, instead of MAIN_text in the current directory.
--aux FILE — Only for text: the .aux file of the compiled paper, instead of MAIN.aux next to the main file; for example, build/main.aux with latexmk -outdir=build.
--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 ... \fi and \if 0 ... \fi, keeping the \else branch, if any (\iftrue does the opposite, and \unless reverses either);
  • the text under a switch defined with \newif and set to false: after \newif\ifdraft and \draftfalse, the text inside \ifdraft ... \fi (switches defined with \let\ifdraft\iffalse work too);
  • the conditionals that you declare with --false-if and --true-if;
  • the content of comment environments, of the environments hidden with the comment package's \excludecomment, and of those in hidden_environments;
  • the files that \includeonly leaves out.

To find all the text, texlens follows \input, \include, \subfile, \import, and \subimport, also when a path uses a macro, as \input{\shared/method} with \newcommand{\shared}{../shared-text}. 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 under stop in 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. texlens warns when a marker comes right after \\, as in x\\appendix, which LaTeX reads as a line break and the word "appendix".
  • 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:ignore and %TC:endignore is not counted. texlens warns when such a region hides more than about 20 words outside figures and tables, which usually means that %TC:endignore is 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, \ifpdf depends on the TeX engine, and \ifx\a\b compares two macros. texlens keeps the text of both branches, unless you declare the conditional, as with --true-if ifpdf if 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 \newif switch through the \...true and \...false commands 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-if or --false-if.
  • Section numbers. In the output of notes and changes, 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. texlens text takes the numbers from the .aux file instead, if there is one.
  • Plain text. texlens text prints natbib's citations as numbers, as [1], also with author-year styles, and leaves out those of biblatex's author-year styles. It lists references one by one, as sections 1, 2 and 3 where cleveref prints sections 1 to 3. It numbers only the formulas that have a label, and only with a .aux file, and it keeps math such as arrays and sums with limits as LaTeX. A heading that one of your macros prints, as with \newcommand{\mychapter}[1]{\chapter{#1}}, is not numbered and does not start a file.

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, also with macros in their paths; 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.toml files (including invalid or contradictory ones), and command-line options;
  • word counts: the counted range, the settings and rules given to TeXcount, %TC:ignore regions, and, with TeXcount, the counts of the test paper and of a paper without hidden text, which must equal TeXcount's own;
  • diff: cleaning the text as LaTeX reads it (comments, verbatim text and URLs, hidden environments, switches inline and nested, other conditionals, and macros that only look like conditionals); following includes whose paths use macros, skipping hidden branches; aligning split, merged, moved, and new paragraphs; choosing the commits of two repositories; and, with LaTeX, building the PDF of a paper spread over two repositories, with the warnings for files that no version includes;
  • 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 plain text of the paper: reading .aux files (hyperref and cleveref fields, natbib citations, and the .aux files of included chapters) and biblatex's .bbl files; references and citations as LaTeX, hyperref, cleveref, natbib, and biblatex print them, also in refsections, with natbib's options, and for labels without a number, and citations without a number left out; math with the paper's macros, as text or as LaTeX; headings, lists, display math, floats and their captions, theorems, footnotes, the title page, and commands that print nothing; chapters, appendices, parts, and front matter, numbered from the table of contents; missing and out-of-date .aux files; file names, and never overwriting the paper's files; and, with LaTeX, a paper compiled with latexmk, whose numbers must match the PDF;
  • the command line: the output of each command, --summary and --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. Likewise, the tests that build a PDF are skipped without git, latexmk, latexdiff, and pdfLaTeX; set TEXLENS_REQUIRE_LATEX=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.14, and on macOS 26, with Python 3.11 and 3.13. 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.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for texlens 0.3.0
File Size Uploaded Provenance Actions
texlens-0.3.0.tar.gz 144.4 kB With provenance Details for texlens-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for texlens 0.3.0
File Interpreter ABI Platform Actions
texlens-0.3.0-py3-none-any.whl Python 3 none any Details for texlens-0.3.0-py3-none-any.whl

Total release size: 238.1 kB

Release files / texlens-0.3.0.tar.gz

Download URL texlens-0.3.0.tar.gz
Size 144.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c1bd66092a7539871337d9e4bb1180d279aac0de70a9a1f1009d8c55cf9fd12d
BLAKE2b-256 checksum
How to use checksums
eda624baab73740a8a5d4fa3fb1541bae814e65d7b851cbeb094def6073b69ed
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 Dec 1, 2026.

Transparency log

Release files / texlens-0.3.0-py3-none-any.whl

Download URL texlens-0.3.0-py3-none-any.whl
Size 93.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
921880afd1e75ae770e579cbd818c3ca2ed9fe9941498c0fa6106c7f56df0f1a
BLAKE2b-256 checksum
How to use checksums
9e348b59e31dad2be4075e8a514b05da645e45747fc3fcfe1bfdb75123fb601d
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 Dec 1, 2026.

Transparency log

Security for texlens 0.3.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.

Select from 2 files

Attestation for texlens-0.3.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 Dec 1, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page