forked from nju-lug/modern-nju-thesis
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathword-counter.typ
27 lines (24 loc) · 931 Bytes
/
word-counter.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* word-counter.typ
*
* @project: modern-ecnu-thesis
* @author: Juntong Chen ([email protected])
* @created: 2025-01-11 13:37:30
* @modified: 2025-01-12 16:21:32
*
* Copyright (c) 2025 Juntong Chen. All rights reserved.
*/
#import "@preview/wordometer:0.1.4": *
#let word-count-cjk(content, ..options) = {
let stats = word-count-of(content, exclude: (heading), counter: s => (
characters: s.replace(regex("\s+"), "").clusters().len(),
words: s.matches(regex("\b[\w'’.,\-]+\b")).len(),
words-cjk: s.matches(regex("[\p{Han}]|[\p{Latin}'’.,\-]+")).len(),
), ..options)
state("total-words-cjk").update((prev) => prev + stats.words-cjk)
state("total-words").update((prev) => prev + stats.words)
state("total-characters").update((prev) => prev + stats.characters)
content
}
#let total-words = context state("total-words-cjk").final()
#let total-characters = context state("total-characters").final()