Skip to content

Commit ab93a44

Browse files
authored
word count powershell script
A powershell script for windows user
1 parent ca43be6 commit ab93a44

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

script/utils/word_count.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# check not existance of out\zjuthesis.fls
2+
if (!(Test-Path -Path "out\zjuthesis.fls")) {
3+
Write-Host "Cannot find file 'out/zjuthesis.fls', which is generated by latexmk"
4+
Write-Host "Please use 'latexmk' command to compile zjuthesis first, then run"
5+
Write-Host "this script under the project root dir to count words"
6+
exit 1
7+
}
8+
9+
# basename list of files to be excluded
10+
$excluded="thanksto.tex", "acknowledgement.tex", "review.tex", "original.tex", "cv.tex"
11+
12+
# a function to get file basename with UNIX path separator
13+
function Get-Basename {
14+
param (
15+
[string]$path
16+
)
17+
$basename = $path -replace "^.+/", ""
18+
return $basename
19+
}
20+
21+
# get unique file list ending with .tex existed in 'body/' dir
22+
# exclude files whose basename in $excluded list from zjuthesis.fls
23+
Get-Content -Path "out\zjuthesis.fls" `
24+
| Where-Object { $_ -match "INPUT" } `
25+
| ForEach-Object { $_.split(" ")[1] } `
26+
| Where-Object { $_ -match "body/.+\.tex$" } `
27+
| Where-Object { (Get-Basename $_) -notin $excluded } `
28+
| Select-Object -Unique `
29+
| ForEach-Object { "\input{$_}" } `
30+
| Out-File -FilePath "out\zjuthesis.wordcnt" -Encoding UTF8
31+
32+
# count words by texcount
33+
texcount out/zjuthesis.wordcnt -inc
34+
35+

0 commit comments

Comments
 (0)