From 0d4c0fb3c9a5b9e57c8653de3e32554c510a3f67 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Fri, 11 Sep 2026 11:26:53 +0200 Subject: [PATCH] Add word counting script + call it in .latexmkrc --- .latexmkrc | 3 +++ wordcount.sh | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100755 wordcount.sh diff --git a/.latexmkrc b/.latexmkrc index bafccc8..723ad7a 100644 --- a/.latexmkrc +++ b/.latexmkrc @@ -6,6 +6,9 @@ $aux_dir = ".aux"; $bibtex = "biber %O %S"; $pdf_previewer = "zathura %O %S"; +# Count words after compiling the full thing +$success_cmd = 'if [ %R = thesis ]; then ./wordcount.sh; fi'; + # Create minted output path use File::Path qw(make_path); make_path("$aux_dir/_minted"); diff --git a/wordcount.sh b/wordcount.sh new file mode 100755 index 0000000..4f200f9 --- /dev/null +++ b/wordcount.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Relative paths +cd -- "$(dirname -- "${BASH_SOURCE[0]}")" + +wordcount=$(pdftotext .out/thesis.pdf - | wc -w) +timestamp=$(date +%FT%T%:z) + +if [[ ! -s wordcounts.csv ]]; then + printf 'date,wordcount\n' >> wordcounts.csv +fi +printf '%s,%s\n' "$timestamp" "${wordcount//[[:space:]]/}" >> wordcounts.csv