Last active
November 28, 2021 20:42
-
-
Save iwishiwasaneagle/2f91f63f3cb0107b94b501aa284a18ca to your computer and use it in GitHub Desktop.
🧰 Useful CLI one-liners for LaTex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show all errors, warnings, and undefined messages in log file after compilation with location in log file for further analysis | |
grep -iHEn "error|warning|undefined" *.log | |
# Find all the duplicated labels in a directory | |
grep -ERh "\\\\label\{\w*:\w*\}" --include="*.tex" | tr -d " " | sort | uniq -c | awk '$1>1 {print $0}' | |
# Validate references.bib using https://github.com/Pezmc/BibLatex-Check | |
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) | |
# Find all the unused labels | |
# 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; | |
# Get document (rough) wordcount. Doesn't exclude referencing etc. but accurate enough | |
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 | |
# Spell checker - 2 options (requires `aspell-en`): | |
# 1) Non-interactive - list of misspelled words | |
pdftotext main.pdf - | grep -ohE "\b[a-zA-Z]{2,}\b" | tr '[:upper:]' '[:lower:]' | sort | uniq | aspell list -t | sort | uniq -c | |
# 2) Interactive spell-check - file by file | |
aspell -c -t main.tex # Replace main.tex with whatever tex file you're checking | |
# Pages between start of intro to start of appendix (only useful in my use case for MEng diss) | |
echo $(($(pdfgrep "A. Appendix" main.pdf -n | awk -F: '{print $1}')-$(pdfgrep "1. Introduction" main.pdf -n | awk -F: '{print $1}'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment