A small Typst package for quick and easy in-document word counts.
Basic usage
#import "@preview/wordometer:0.1.6": word-count, total-words
#show: word-count
In this document, there are #total-words words all up.
#word-count(total => [
The number of words in this block is #total.words
and there are #total.characters letters.
])
Excluding elements
You can exclude elements by name (e.g., "caption"), function (e.g., figure.caption), where-selector (e.g., raw.where(block: true)), or label (e.g., <no-wc>).
#show: word-count.with(exclude: (heading.where(level: 1), strike))
= This Heading Doesn't Count
== But I do!
In this document #strike[(excluding me)], there are #total-words words all up.
#word-count(total => [
You can exclude elements by label, too.
#[That was #total.words, excluding this sentence!] <no-wc>
], exclude: <no-wc>)
Development and testing
We use Tytanic for unit tests. Run with
tt run --font-path tests/
to ensure CJK fonts are available.
Changelog
v0.1.6
- Improve CJK word counting support (#10)
- Add support for term list elements (#21)
- Fix crash with labeled footnotes (#20)
v0.1.5
- Count CJK characters as one word each (#9)
- Fix deprecation warning comparing types to strings.
- Put utility functions in
utilssubmodule. Possibly breaking. - Refresh the manual.
v0.1.4
- Fix deprecated use of
locate()for Typst>=0.12.0
v0.1.3
(No changes 🤡)
v0.1.2
- Fix bugs when using labels and where-selectors to exclude elements
v0.1.1
- Allow excluding elements by passing their element functions
- Add basic
element.where(..)selectors - Fix crash for figures without captions
v0.1.0
- Initial version