April 19, 2023 LaTex CLI Tools ☕️ buy me a coffee
Some useful LaTex one-liners that I’ve accumulated over the years. You can also find these tools here
Very basic but useful to analyse a log file after compilation with location in log file for further analysis
grep -iHEn "error|warning|undefined" *.log
Useful if referencing a figure results in warnings/errors
grep -ERh "\\\\label\{\w*:\w*\}" --include="*.tex" \
| tr -d " " | sort | uniq -c | awk '$1>1 {print $0}'
We use Pezmc/BibLatex-Check for this one.
curl https://raw.githubusercontent.com/Pezmc/BibLatex-Check/master/biblatex_check.py \
2>/dev/null | python - \
-b $(find ./ -maxdepth 1 -name "*.bib" | head -n1) \
-a $(find ./ -maxdepth 1 -name "*.aux" | head -n1)
Calling this one a “one-liner” is pushing it, but it’s very useful nonetheless so it’s being included.
REF=($(IFS=;grep -ERoh "\\\\\w*ref\{\w*:\w*\}" . | sort | uniq | awk -F{ '{print $2}' | tr -d '}'))
LABEL=($(IFS=;grep -ERoh "\\\\label\{\w*:\w*\}" . | sort | uniq | awk -F{ '{print $2}' | tr -d '}'))
for i in $LABEL
do
echo $REF | grep -iq " $i "
if [[ $? -eq 1 ]]
then
printf "\033[0;31mUNUSED LABEL: \033[0;32m$i\033[0m\n"
fi
done
This doesn’t exclude referencing etc. but accurate enough for rough estimates.
pdftotext main.pdf - | \
grep -ohE "\b[a-zA-Z]{2,}\b" | \
tr '[:upper:]' '[:lower:]' | \
sort | uniq > /tmp/words.txt; pdftotext main.pdf - | \
grep -ohFf /tmp/words.txt | wc -w
Requires aspell-en
.
pdftotext main.pdf - | grep -ohE "\b[a-zA-Z]{2,}\b" | tr '[:upper:]' '[:lower:]' | sort | uniq | aspell list -t | sort | uniq -c
aspell -c -t main.tex # Replace main.tex with whatever tex file you're checking