texlens 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- texlens-0.1.0/LICENSE +202 -0
- texlens-0.1.0/MANIFEST.in +2 -0
- texlens-0.1.0/NOTICE +2 -0
- texlens-0.1.0/PKG-INFO +470 -0
- texlens-0.1.0/README.md +450 -0
- texlens-0.1.0/pyproject.toml +34 -0
- texlens-0.1.0/setup.cfg +4 -0
- texlens-0.1.0/src/texlens/__init__.py +3 -0
- texlens-0.1.0/src/texlens/__main__.py +5 -0
- texlens-0.1.0/src/texlens/cli.py +240 -0
- texlens-0.1.0/src/texlens/config.py +229 -0
- texlens-0.1.0/src/texlens/latex.py +307 -0
- texlens-0.1.0/src/texlens/listing.py +108 -0
- texlens-0.1.0/src/texlens/source.py +754 -0
- texlens-0.1.0/src/texlens/words.py +288 -0
- texlens-0.1.0/src/texlens.egg-info/PKG-INFO +470 -0
- texlens-0.1.0/src/texlens.egg-info/SOURCES.txt +28 -0
- texlens-0.1.0/src/texlens.egg-info/dependency_links.txt +1 -0
- texlens-0.1.0/src/texlens.egg-info/entry_points.txt +2 -0
- texlens-0.1.0/src/texlens.egg-info/requires.txt +3 -0
- texlens-0.1.0/src/texlens.egg-info/top_level.txt +1 -0
- texlens-0.1.0/tests/__init__.py +5 -0
- texlens-0.1.0/tests/paper/main.tex +59 -0
- texlens-0.1.0/tests/paper/sections/method.tex +7 -0
- texlens-0.1.0/tests/test_cli.py +105 -0
- texlens-0.1.0/tests/test_config.py +113 -0
- texlens-0.1.0/tests/test_listing.py +130 -0
- texlens-0.1.0/tests/test_source.py +328 -0
- texlens-0.1.0/tests/test_words.py +180 -0
- texlens-0.1.0/tests/util.py +53 -0
texlens-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
texlens-0.1.0/NOTICE
ADDED
texlens-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: texlens
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Count the words of a LaTeX paper without its hidden text, and list its notes to coauthors and revised passages.
|
|
5
|
+
Author: Roberta De Viti
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/rdeviti/texlens
|
|
8
|
+
Project-URL: Issues, https://github.com/rdeviti/texlens/issues
|
|
9
|
+
Keywords: latex,word count,texcount,academic writing,revision
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Text Processing :: Markup :: LaTeX
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
License-File: NOTICE
|
|
18
|
+
Requires-Dist: tomli>=1.1; python_version < "3.11"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<img src="https://raw.githubusercontent.com/rdeviti/texlens/main/assets/banner.svg" alt="texlens: a lens on your TeX, without the clutter" width="100%">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
texlens reads the source of a LaTeX paper to set aside the clutter:
|
|
26
|
+
hidden text that never reaches the PDF (`%` comments, `\iffalse ... \fi`
|
|
27
|
+
blocks, `comment` environments), notes to coauthors, and markup such as the
|
|
28
|
+
labels in `\cref{...}`. Like LaTeX, it follows `\input` and similar commands,
|
|
29
|
+
but it does not run LaTeX itself.
|
|
30
|
+
|
|
31
|
+
Then, texlens can:
|
|
32
|
+
|
|
33
|
+
- **count words** (`texlens words`) in the abstract and the main text, for
|
|
34
|
+
submission forms that ask for a word count;
|
|
35
|
+
- **list notes to coauthors** (`texlens notes`), such as the text of each
|
|
36
|
+
`\todo{...}`, with its file, line, and section;
|
|
37
|
+
- **list revised passages** (`texlens changes`), such as the text of each
|
|
38
|
+
`\rev{...}`, section by section, for example to write or check a list of
|
|
39
|
+
changes for a revision;
|
|
40
|
+
- **list your macros** (`texlens macros`) and whether they are counted or not.
|
|
41
|
+
|
|
42
|
+
> **Your paper stays on your computer.** texlens runs locally, makes no
|
|
43
|
+
> network connections, and it collects no data. It reads the files of your
|
|
44
|
+
> paper without changing them. With `texlens words`, it uses TeXcount, which
|
|
45
|
+
> also runs locally; it generates a temporary copy of the counted text and
|
|
46
|
+
> deletes it right after (`--keep FILE` saves a copy if you choose to do so).
|
|
47
|
+
|
|
48
|
+
## Why
|
|
49
|
+
|
|
50
|
+
[TeXcount](https://app.uio.no/ifi/texcount/), the standard LaTeX word counter
|
|
51
|
+
(Overleaf's word count runs it too), counts the source as written. It does
|
|
52
|
+
not evaluate conditionals, so it counts hidden text, such as the text in
|
|
53
|
+
`\iffalse ... \fi`, in `\if 0 ... \fi`, or under a `\newif` switch set to
|
|
54
|
+
false. It also counts notes to coauthors, such as `\todo{...}`, and the
|
|
55
|
+
labels in `\cref{...}` and other cleveref commands. Finally, it misses the
|
|
56
|
+
words that your own macros print, such as a system name put in
|
|
57
|
+
`\newcommand{\sys}{MyTool}`. A paper under revision tends to accumulate
|
|
58
|
+
hidden text and notes, so this difference can be large!
|
|
59
|
+
|
|
60
|
+
texlens generates a copy of your source without the hidden text and
|
|
61
|
+
passes it to TeXcount, together with rules for notes, references,
|
|
62
|
+
and your own macros.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
texlens needs Python 3.10 or later. Install it with
|
|
67
|
+
[pipx](https://pipx.pypa.io/), which makes the `texlens` command available
|
|
68
|
+
everywhere:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
pipx install texlens
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If you do not have pipx: `brew install pipx` on macOS
|
|
75
|
+
or `sudo apt install pipx` on Debian and Ubuntu, then `pipx ensurepath`, and
|
|
76
|
+
open a new terminal. To install the development version instead, clone this
|
|
77
|
+
repository and run `pipx install .` in its directory.
|
|
78
|
+
|
|
79
|
+
Our command `texlens words` needs TeXcount, which comes with most TeX distributions:
|
|
80
|
+
|
|
81
|
+
- **macOS:** TeXcount comes with [MacTeX](https://www.tug.org/mactex/). If you
|
|
82
|
+
have BasicTeX instead, add it with `sudo tlmgr install texcount`.
|
|
83
|
+
- **Linux:** on Debian and Ubuntu, run
|
|
84
|
+
`sudo apt install texlive-extra-utils`. With a TeX Live installed from
|
|
85
|
+
[tug.org](https://www.tug.org/texlive/), run `tlmgr install texcount`.
|
|
86
|
+
- **Windows:** TeXcount comes with TeX Live and MiKTeX.
|
|
87
|
+
|
|
88
|
+
To check that texlens is installed, run `texlens --version`.
|
|
89
|
+
|
|
90
|
+
## Quick start
|
|
91
|
+
|
|
92
|
+
In the directory of your paper, run:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
texlens words
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
texlens finds your main file: `main.tex`, or else the only `.tex` file with
|
|
99
|
+
`\documentclass`. To choose it yourself, pass it as `texlens words paper.tex`
|
|
100
|
+
or `texlens words ~/papers/draft`.
|
|
101
|
+
|
|
102
|
+
In the same way, run `texlens notes` to list the notes to coauthors,
|
|
103
|
+
`texlens changes` for the revised passages, and `texlens macros` for your macros.
|
|
104
|
+
Since most papers define custom macros (e.g., `\fixme{...}` for notes),
|
|
105
|
+
you can describe them with options or in a
|
|
106
|
+
[`texlens.toml`](#configuration) file. See the example below.
|
|
107
|
+
|
|
108
|
+
## How it works
|
|
109
|
+
|
|
110
|
+
1. texlens reads the main file and the files that it includes, and drops the
|
|
111
|
+
hidden text (see [Which text texlens skips](#which-text-texlens-skips)).
|
|
112
|
+
It keeps track of the file and line that each remaining line comes from.
|
|
113
|
+
2. For `words`, it runs TeXcount on the counted range, preceded by the
|
|
114
|
+
packages that your preamble loads (TeXcount has rules for some of them,
|
|
115
|
+
such as `\textcolor` in xcolor), your own `%TC:` instructions, and
|
|
116
|
+
TeXcount rules for your macros. Where your instructions conflict with the
|
|
117
|
+
settings of texlens, the settings win.
|
|
118
|
+
3. For `notes` and `changes`, it finds the calls of your macros, and numbers
|
|
119
|
+
the sections as LaTeX does by default.
|
|
120
|
+
|
|
121
|
+
## Example
|
|
122
|
+
|
|
123
|
+
This repository includes a small paper,
|
|
124
|
+
[`tests/paper`](https://github.com/rdeviti/texlens/tree/main/tests/paper).
|
|
125
|
+
In the example, we define:
|
|
126
|
+
|
|
127
|
+
```latex
|
|
128
|
+
\newcommand{\sys}{Foo} % the name of the system
|
|
129
|
+
\newcommand{\fixme}[1]{\textcolor{green}{Fix: #1}} % notes to coauthors
|
|
130
|
+
\newcommand{\rev}[1]{\textcolor{blue}{#1}} % revised text
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The commands below run in its directory.
|
|
134
|
+
|
|
135
|
+
### Tell texlens about your macros: `texlens macros`
|
|
136
|
+
|
|
137
|
+
Start with `texlens macros`. It lists the macros that the paper defines with
|
|
138
|
+
`\newcommand`, `\def`, `\NewDocumentCommand`, or similar commands, how
|
|
139
|
+
many arguments each takes (`1+1` means one mandatory and one optional
|
|
140
|
+
argument), how often the main text uses it, and if `texlens words` counts
|
|
141
|
+
it or not.
|
|
142
|
+
|
|
143
|
+
```console
|
|
144
|
+
$ texlens macros
|
|
145
|
+
macro args uses treatment
|
|
146
|
+
\rev 1 3 arguments counted as text
|
|
147
|
+
\fixme 1 1 arguments counted as text
|
|
148
|
+
\sys 0 1 no words counted
|
|
149
|
+
\finalversion 0 0 no words counted
|
|
150
|
+
|
|
151
|
+
Configure macros in texlens.toml next to main.tex, or with --note/--change/--ignore/--word.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If you do not customize the settings of a macro, then the arguments are counted as text
|
|
155
|
+
by default, while a macro without arguments adds no words. In
|
|
156
|
+
this example, the notes in `\fixme` are counted, while the word printed by `\sys`
|
|
157
|
+
is not. To change this default behaviour, specify a setting:
|
|
158
|
+
|
|
159
|
+
| Setting | Treatment |
|
|
160
|
+
|---|---|
|
|
161
|
+
| `--note NAME` | note: not counted |
|
|
162
|
+
| `--change NAME` | change: counted |
|
|
163
|
+
| `--ignore NAME` | arguments not counted |
|
|
164
|
+
| `--word NAME=N` | counts as N words |
|
|
165
|
+
| `[macros.rules]` | TeXcount rule ... |
|
|
166
|
+
|
|
167
|
+
`\todo` is a note, and reference macros such as `\cref` are ignored, without
|
|
168
|
+
any setting. [Command-line options](#command-line-options) explains each
|
|
169
|
+
setting. With the settings in the example above, the table becomes:
|
|
170
|
+
|
|
171
|
+
```console
|
|
172
|
+
$ texlens macros --note fixme --change rev --word sys=1
|
|
173
|
+
macro args uses treatment
|
|
174
|
+
\rev 1 3 change: counted
|
|
175
|
+
\fixme 1 1 note: not counted
|
|
176
|
+
\sys 0 1 counts as 1 word
|
|
177
|
+
\finalversion 0 0 no words counted
|
|
178
|
+
|
|
179
|
+
Configure macros in texlens.toml next to main.tex, or with --note/--change/--ignore/--word.
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Instead of passing these options every time, write them once in a
|
|
183
|
+
`texlens.toml` file next to the main file:
|
|
184
|
+
|
|
185
|
+
```toml
|
|
186
|
+
[macros]
|
|
187
|
+
notes = ["fixme"]
|
|
188
|
+
changes = ["rev"]
|
|
189
|
+
|
|
190
|
+
[macros.words]
|
|
191
|
+
sys = 1
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Count words: `texlens words`
|
|
195
|
+
|
|
196
|
+
```console
|
|
197
|
+
$ texlens words --note fixme --change rev --word sys=1
|
|
198
|
+
Counted from \begin{abstract} to \bibliographystyle.
|
|
199
|
+
Words in text: 20
|
|
200
|
+
Words in headings: 3
|
|
201
|
+
Words in captions: 1 (not counted)
|
|
202
|
+
Formulas: 1 (not counted)
|
|
203
|
+
Word count: 23
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The word count adds up the lines not marked "(not counted)". Without the three
|
|
207
|
+
settings, it would be 25: the three words of the note would be counted, and
|
|
208
|
+
`\sys` would not. [What `texlens words` counts](#what-texlens-words-counts)
|
|
209
|
+
explains the defaults and how to change them.
|
|
210
|
+
|
|
211
|
+
### List notes to coauthors: `texlens notes`
|
|
212
|
+
|
|
213
|
+
`texlens notes` prints the text of every note in the paper: the argument of
|
|
214
|
+
each `\todo{...}`, and of each macro with the `--note` setting.
|
|
215
|
+
|
|
216
|
+
```console
|
|
217
|
+
$ texlens notes --note fixme
|
|
218
|
+
main.tex:22 [1 Intro] \fixme
|
|
219
|
+
should not count
|
|
220
|
+
sections/method.tex:6 [2 Method] \todo
|
|
221
|
+
a note
|
|
222
|
+
2 notes (\fixme: 1, \todo: 1)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Each note shows its file, line, section, and macro, followed by its text.
|
|
226
|
+
Notes in hidden text are not listed, since they never reach the PDF. Before
|
|
227
|
+
you submit, `texlens notes` should print `0 notes`!
|
|
228
|
+
|
|
229
|
+
Long notes are cut to one line; `--full` prints them in full, and `--summary`
|
|
230
|
+
prints only the number of notes per section.
|
|
231
|
+
|
|
232
|
+
### List revised passages: `texlens changes`
|
|
233
|
+
|
|
234
|
+
`texlens changes` prints the text marked by the macros with the `--change`
|
|
235
|
+
setting, such as `\rev{...}`:
|
|
236
|
+
|
|
237
|
+
```console
|
|
238
|
+
$ texlens changes --change rev
|
|
239
|
+
main.tex:23 [1 Intro] \rev
|
|
240
|
+
four five
|
|
241
|
+
sections/method.tex:2 [2 Method] \rev
|
|
242
|
+
thirteen fourteen
|
|
243
|
+
2 changes (\rev: 2)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
A `\rev` inside another `\rev` is part of the outer passage: in this paper,
|
|
247
|
+
`\rev{thirteen \rev{fourteen}}` is one passage.
|
|
248
|
+
|
|
249
|
+
With `--summary`, texlens prints only the number of passages in each section,
|
|
250
|
+
and an estimate of their words. This helps to write or check a list of
|
|
251
|
+
changes:
|
|
252
|
+
|
|
253
|
+
```console
|
|
254
|
+
$ texlens changes --change rev --summary
|
|
255
|
+
2 changes (\rev: 2)
|
|
256
|
+
1 Intro: 1 change, about 2 words
|
|
257
|
+
2 Method: 1 change, about 2 words
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
As for `notes`, `--full` prints long passages in full.
|
|
261
|
+
|
|
262
|
+
## Configuration
|
|
263
|
+
|
|
264
|
+
### The settings file
|
|
265
|
+
|
|
266
|
+
texlens reads the settings in `texlens.toml`, next to your main file. All
|
|
267
|
+
keys are optional. This example shows every key:
|
|
268
|
+
|
|
269
|
+
```toml
|
|
270
|
+
[macros]
|
|
271
|
+
notes = ["fixme"] # notes to coauthors: not counted, listed by `notes`
|
|
272
|
+
changes = ["rev"] # revised text: counted, listed by `changes`
|
|
273
|
+
ignore = ["myref"] # arguments are not words; "name:2" for two arguments
|
|
274
|
+
|
|
275
|
+
[macros.words] # macros without arguments that print words
|
|
276
|
+
sys = 1
|
|
277
|
+
|
|
278
|
+
[macros.rules] # any TeXcount rule, e.g. for the changes package
|
|
279
|
+
replaced = "[text,ignore]"
|
|
280
|
+
deleted = "[ignore]"
|
|
281
|
+
|
|
282
|
+
[conditionals]
|
|
283
|
+
false = ["iffinal"] # conditionals to treat as false
|
|
284
|
+
true = [] # conditionals to treat as true
|
|
285
|
+
hidden_environments = ["comment"]
|
|
286
|
+
|
|
287
|
+
[count]
|
|
288
|
+
start = ['\begin{abstract}']
|
|
289
|
+
stop = ['\appendix', '\bibliographystyle', '\bibliography',
|
|
290
|
+
'\printbibliography', '\begin{thebibliography}', '\end{document}']
|
|
291
|
+
footnotes = true # count footnotes
|
|
292
|
+
captions = false # count figure and table captions
|
|
293
|
+
math = false # count each formula as one word
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Write macro names without the backslash. Write LaTeX markers in single quotes
|
|
297
|
+
(TOML literal strings), so that their backslashes are kept as they are. The
|
|
298
|
+
values shown for `hidden_environments` and `[count]` are the defaults. The
|
|
299
|
+
macro lists add to the defaults (`\todo` is always a note); the other lists
|
|
300
|
+
replace them. A macro can be in only one of `notes`, `changes`, `ignore`, and
|
|
301
|
+
`rules`.
|
|
302
|
+
|
|
303
|
+
### Command-line options
|
|
304
|
+
|
|
305
|
+
Most settings also have a command-line option. For macros and conditionals,
|
|
306
|
+
the options add to the settings file; for the rest, they replace its values.
|
|
307
|
+
Options that take a name can be repeated, as in
|
|
308
|
+
`--note fixme --note ask`. `texlens <command> --help` lists the options of
|
|
309
|
+
each command.
|
|
310
|
+
|
|
311
|
+
| Option | In `texlens.toml` | Meaning |
|
|
312
|
+
|---|---|---|
|
|
313
|
+
| `--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. |
|
|
314
|
+
| `--change NAME` | `[macros] changes` | `\NAME{...}` marks revised text: its text is counted, and `changes` lists it. |
|
|
315
|
+
| `--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. |
|
|
316
|
+
| `--word NAME=N` | `[macros.words]` | `\NAME`, a macro without arguments, prints N words: for example, `--word sys=1` for `\newcommand{\sys}{MyTool}`. |
|
|
317
|
+
| — | `[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](https://ctan.org/pkg/texcount) for the syntax. |
|
|
318
|
+
| `--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`. |
|
|
319
|
+
| `--true-if NAME` | `[conditionals] true` | Treat the conditional `\NAME` as true: keep only the text before its `\else`. |
|
|
320
|
+
| — | `[conditionals] hidden_environments` | Environments whose content never reaches the PDF (default: `comment`). |
|
|
321
|
+
| `--start MARKER` | `[count] start` | Only for `words`: where counting starts, for example `--start '\section{Introduction}'` to skip the abstract. |
|
|
322
|
+
| `--stop MARKER` | `[count] stop` | Only for `words`: where counting stops, for example `--stop '\end{document}'` to also count the appendices. |
|
|
323
|
+
| `--captions` | `[count] captions = true` | Only for `words`: also count figure and table captions, and margin notes. |
|
|
324
|
+
| `--math` | `[count] math = true` | Only for `words`: count each formula as one word. |
|
|
325
|
+
| `--no-footnotes` | `[count] footnotes = false` | Only for `words`: do not count footnotes. |
|
|
326
|
+
| `--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`. |
|
|
327
|
+
| `--keep FILE` | — | Only for `words`: save the text that texlens gives TeXcount, to check what is counted. |
|
|
328
|
+
| `--full`, `--summary` | — | Only for `notes` and `changes`: print the texts in full, or only the totals per section. |
|
|
329
|
+
| `--config FILE` | — | Read the settings from FILE instead of the `texlens.toml` next to the main file. |
|
|
330
|
+
| `--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"`. |
|
|
331
|
+
|
|
332
|
+
### Which text texlens skips
|
|
333
|
+
|
|
334
|
+
As LaTeX does, texlens skips:
|
|
335
|
+
|
|
336
|
+
- `%` comments;
|
|
337
|
+
- the text inside `\iffalse ... \fi` and `\if 0 ... \fi`, keeping the `\else`
|
|
338
|
+
branch, if any (`\iftrue` does the opposite, and `\unless` reverses
|
|
339
|
+
either);
|
|
340
|
+
- the text under a switch defined with `\newif` and set to false: after
|
|
341
|
+
`\newif\ifdraft` and `\draftfalse`, the text inside `\ifdraft ... \fi`
|
|
342
|
+
(switches defined with `\let\ifdraft\iffalse` work too);
|
|
343
|
+
- the conditionals that you declare with `--false-if` and `--true-if`;
|
|
344
|
+
- the content of `comment` environments, of the environments hidden with the
|
|
345
|
+
comment package's `\excludecomment`, and of those in `hidden_environments`;
|
|
346
|
+
- the files that `\includeonly` leaves out.
|
|
347
|
+
|
|
348
|
+
To find all the text, texlens follows `\input`, `\include`, `\subfile`,
|
|
349
|
+
`\import`, and `\subimport`. Of an included file that is a document of its
|
|
350
|
+
own (with the standalone or subfiles packages), it keeps only the text
|
|
351
|
+
between `\begin{document}` and `\end{document}`. It leaves verbatim text,
|
|
352
|
+
such as `\verb` and the content of `verbatim`, `lstlisting`, `minted`, and
|
|
353
|
+
`filecontents` environments, as it is. texlens warns when a conditional or a
|
|
354
|
+
`comment` environment is still open at the end of a file, and handles it as
|
|
355
|
+
LaTeX does.
|
|
356
|
+
|
|
357
|
+
### What `texlens words` counts
|
|
358
|
+
|
|
359
|
+
- **Range.** texlens counts from the first start marker (by default,
|
|
360
|
+
`\begin{abstract}`, or `\begin{document}` if there is no abstract) to the
|
|
361
|
+
first stop marker after it (by default, the first of the markers listed
|
|
362
|
+
under `stop` in [the settings file](#the-settings-file)). Thus, the title,
|
|
363
|
+
the authors, the references, and the appendices are not counted. Neither
|
|
364
|
+
are keywords and ACM's classification concepts (`\ccsdesc`) and dates
|
|
365
|
+
(`\received`), even when they come after the abstract; ACM's teaser figure
|
|
366
|
+
counts as a figure. The first line of the output shows the markers that
|
|
367
|
+
texlens used.
|
|
368
|
+
- **Counted.** The words in the text, including footnotes, and in headings.
|
|
369
|
+
As in TeXcount, the title of the abstract counts as a heading word, and a
|
|
370
|
+
URL counts as one word if the preamble loads hyperref or url.
|
|
371
|
+
- **Not counted, unless you ask.** Figure and table captions and margin
|
|
372
|
+
notes (`--captions`), and formulas (`--math`, which counts each formula as
|
|
373
|
+
one word).
|
|
374
|
+
- **Never counted.** The content of tables (`tabular`), as in TeXcount; code,
|
|
375
|
+
both inline (`\verb`, `\lstinline`) and in listings; and the ACM
|
|
376
|
+
classification codes (`CCSXML`), which LaTeX does not print.
|
|
377
|
+
- **`%TC:ignore`.** As in TeXcount, the text between `%TC:ignore` and
|
|
378
|
+
`%TC:endignore` is not counted. texlens warns when such a region hides more
|
|
379
|
+
than about 20 words outside figures and tables, which usually means that
|
|
380
|
+
`%TC:endignore` is missing or in the wrong place.
|
|
381
|
+
|
|
382
|
+
For everything else, TeXcount's own rules apply.
|
|
383
|
+
|
|
384
|
+
## Limitations
|
|
385
|
+
|
|
386
|
+
- **Other conditionals.** Some conditionals depend on information that
|
|
387
|
+
texlens does not have: for example, `\ifpdf` depends on the TeX engine, and
|
|
388
|
+
`\ifx\a\b` compares two macros. texlens keeps the text of both branches,
|
|
389
|
+
unless you declare the conditional, as with `--true-if ifpdf` if you
|
|
390
|
+
compile with pdfLaTeX. etoolbox toggles and booleans, such as
|
|
391
|
+
`\iftoggle{draft}{...}{...}`, always keep both texts: they take the texts as
|
|
392
|
+
arguments instead of ending with `\fi`, so they cannot be declared.
|
|
393
|
+
- **Switches set by macros.** texlens follows a `\newif` switch through the
|
|
394
|
+
`\...true` and `\...false` commands written in your files, outside macro
|
|
395
|
+
definitions. If one of your macros sets the switch, as in
|
|
396
|
+
`\newcommand{\finalversion}{\draftfalse}`, texlens cannot know whether or
|
|
397
|
+
when that macro runs, so it ignores the change. The same holds for switches
|
|
398
|
+
set in a class, in a package, or on the command line. In these cases,
|
|
399
|
+
declare the switch with `--true-if` or `--false-if`.
|
|
400
|
+
- **Section numbers.** In the output of `notes` and `changes`, texlens
|
|
401
|
+
numbers the sections by counting `\section`, `\subsection`, and so on, as
|
|
402
|
+
the standard classes do. If your class or preamble numbers them differently
|
|
403
|
+
(for example, IEEEtran uses Roman numerals, and `\setcounter{section}{...}`
|
|
404
|
+
changes the count), these numbers can differ from those in the PDF. File
|
|
405
|
+
names and line numbers are always exact.
|
|
406
|
+
|
|
407
|
+
## Testing
|
|
408
|
+
|
|
409
|
+
The tests use Python's built-in `unittest` module. From the repository, run:
|
|
410
|
+
|
|
411
|
+
```sh
|
|
412
|
+
python -m unittest discover -s tests -t .
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
The tests cover:
|
|
416
|
+
|
|
417
|
+
- **reading a project:** following `\input`, `\include` (with
|
|
418
|
+
`\includeonly`), `\subfile`, `\import`, and `\subimport`; missing,
|
|
419
|
+
self-including, and deeply nested files; line endings and encodings;
|
|
420
|
+
comments and escaped `%` signs; all the conditionals above, nested,
|
|
421
|
+
declared, unclosed, or inside macro definitions, and macros that only look
|
|
422
|
+
like conditionals; hidden and verbatim environments; and finding the main
|
|
423
|
+
file;
|
|
424
|
+
- **listings:** finding macro calls with optional, multiple, and nested
|
|
425
|
+
arguments, outside verbatim text; reading macro definitions; numbering
|
|
426
|
+
sections, including starred sections, appendices, and the abstract;
|
|
427
|
+
skipping notes in hidden text; and the table of macros;
|
|
428
|
+
- **settings:** the defaults, `texlens.toml` files (including invalid or
|
|
429
|
+
contradictory ones), and command-line options;
|
|
430
|
+
- **word counts:** the counted range, the settings and rules given to
|
|
431
|
+
TeXcount, `%TC:ignore` regions, and, with TeXcount, the counts of the test
|
|
432
|
+
paper and of a paper without hidden text, which must equal TeXcount's own;
|
|
433
|
+
- **the command line:** the output of each command, `--summary` and
|
|
434
|
+
`--json`, warnings, and errors such as a missing main file or a missing
|
|
435
|
+
TeXcount.
|
|
436
|
+
|
|
437
|
+
The tests that run TeXcount are skipped if it is not installed; set
|
|
438
|
+
`TEXLENS_REQUIRE_TEXCOUNT=1` to make them fail instead. To use a specific
|
|
439
|
+
copy of TeXcount, set `TEXLENS_TEXCOUNT`, as described under
|
|
440
|
+
[Command-line options](#command-line-options). On Python 3.10, the tests that
|
|
441
|
+
read `texlens.toml` files need the tomli package, which `pip install .`
|
|
442
|
+
installs.
|
|
443
|
+
|
|
444
|
+
All tests pass with TeXcount 3.1.1 on Linux (Ubuntu 24.04), with Python 3.10
|
|
445
|
+
to 3.13, and on macOS 26, with Python 3.11. texlens has not been tested on
|
|
446
|
+
Windows yet.
|
|
447
|
+
|
|
448
|
+
## Contributing
|
|
449
|
+
|
|
450
|
+
Bug reports and pull requests are welcome, including new features that you
|
|
451
|
+
would find useful. A pull request should add tests for what it changes and
|
|
452
|
+
pass the whole test suite (see [Testing](#testing)), which GitHub also runs
|
|
453
|
+
on every pull request.
|
|
454
|
+
|
|
455
|
+
## License
|
|
456
|
+
|
|
457
|
+
Copyright 2026 Roberta De Viti.
|
|
458
|
+
|
|
459
|
+
texlens is released under the
|
|
460
|
+
[Apache License 2.0](https://github.com/rdeviti/texlens/blob/main/LICENSE). You may use,
|
|
461
|
+
modify, and redistribute it, also in proprietary software. If you
|
|
462
|
+
redistribute it, modified or not, include the
|
|
463
|
+
[LICENSE](https://github.com/rdeviti/texlens/blob/main/LICENSE) and
|
|
464
|
+
[NOTICE](https://github.com/rdeviti/texlens/blob/main/NOTICE) files, keep the copyright notices, and mark the files that
|
|
465
|
+
you change. Contributors also grant you a license to any of their patents
|
|
466
|
+
that texlens would otherwise infringe.
|
|
467
|
+
|
|
468
|
+
texlens runs [TeXcount](https://app.uio.no/ifi/texcount/), by Einar Andreas
|
|
469
|
+
Rødland, which is distributed separately under the LaTeX Project Public
|
|
470
|
+
License. texlens is not affiliated with TeXcount.
|