Created
May 22, 2021 21:52
-
-
Save SteVwonder/bb3e4ad170dcaa4e0d18aeb2970c2775 to your computer and use it in GitHub Desktop.
Quick script to take a multi-file tex document and make it more human-readable for software like Grammarly or other grammar checkers
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
#!/bin/bash | |
USAGE="Usage: $0 mainfile.tex outputfile.tex" | |
function usage { | |
echo $USAGE | |
exit 1 | |
} | |
if [[ -z "$1" || -z "$2" ]]; then | |
usage | |
elif [[ ! -f "$1" ]]; then | |
echo "Main tex file is not a file" | |
usage | |
elif [[ -e "$2" ]]; then | |
echo "Output tex file exists, cowardly refusing to overwrite" | |
usage | |
fi | |
if type "gsed" &> /dev/null; then | |
echo "Using gsed" | |
SED_CMD=gsed | |
else | |
echo "Using sed" | |
SED_CMD=sed | |
fi | |
cd $(dirname $1) | |
#detex -rl $1 | awk '// {print ""} {gsub(ORS,FS)}1' RS= | sed 's/^[ ]+//' > $2 | |
latexpand $1 2> /dev/null | awk '/\\(section|chapter|subsection)/ {print "\n Section: " $0 "\n"; next} {print $0}' | $SED_CMD -E -e 's/~?\\ref\{[A-Za-z:_-]+\}/ 1/g' -e 's/\.\\@ ?/. /g' | detex -rl | awk '// {print ""} {gsub(ORS,FS)}1' RS= | $SED_CMD -E -e 's/^[ ]+//; s/ ([,.])/\1/g; s/[ ]+/ /g' -e 's/I\/O/IO/g'> $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment