diff options
Diffstat (limited to '')
-rwxr-xr-x | build/latex/academia/build.sh | 4 | ||||
-rw-r--r-- | build/latex/academia/headers/preamble.tex | 1 | ||||
-rw-r--r-- | build/latex/academia/headers/preamble/academia/index.tex (renamed from build/latex/academia/headers/preamble/core/index.tex) | 0 | ||||
-rw-r--r-- | build/latex/academia/headers/preamble/academia/mod.tex | 1 | ||||
-rw-r--r-- | build/latex/academia/headers/preamble/core/mod.tex | 1 | ||||
-rw-r--r-- | build/latex/academia/headers/preamble/mod.tex | 3 | ||||
-rwxr-xr-x | build/latex/academia/scripts/extract_text_from_all.sh | 8 | ||||
-rwxr-xr-x | build/latex/academia/scripts/optimize_images.sh | 123 |
8 files changed, 128 insertions, 13 deletions
diff --git a/build/latex/academia/build.sh b/build/latex/academia/build.sh index 1ff2b6e..80ecc57 100755 --- a/build/latex/academia/build.sh +++ b/build/latex/academia/build.sh @@ -46,8 +46,8 @@ fd . "$root/figures" --type file --extension tex | while read -r figure; do echo " -> Didn't change, not re-compiling." else echo "$figure_hash" >"$dst/figures/$figure_name/$figure_name.sha256sum_hash" - pdflatex -output-directory="$dst" -file-line-error -jobname="figures/$figure_name/$figure_name" "$figure" + pdflatex -output-directory="$dst" -file-line-error -jobname="figures/$figure_name/$figure_name" "$figure" || exit 1 fi -done +done || exit 1 latexmk -outdir="$dst" -file-line-error -pdflatex -recorder "$file" diff --git a/build/latex/academia/headers/preamble.tex b/build/latex/academia/headers/preamble.tex index d45262a..d10a02e 100644 --- a/build/latex/academia/headers/preamble.tex +++ b/build/latex/academia/headers/preamble.tex @@ -1,2 +1 @@ \input{headers/preamble/mod.tex} -\input{headers/preamble_local.tex} diff --git a/build/latex/academia/headers/preamble/core/index.tex b/build/latex/academia/headers/preamble/academia/index.tex index 3efbfc4..3efbfc4 100644 --- a/build/latex/academia/headers/preamble/core/index.tex +++ b/build/latex/academia/headers/preamble/academia/index.tex diff --git a/build/latex/academia/headers/preamble/academia/mod.tex b/build/latex/academia/headers/preamble/academia/mod.tex index 39b9230..1f2cd71 100644 --- a/build/latex/academia/headers/preamble/academia/mod.tex +++ b/build/latex/academia/headers/preamble/academia/mod.tex @@ -1,4 +1,5 @@ % derived from: % https://github.com/gillescastel/lecture-notes/blob/929672a96abc27eaeb6fa58b1d277b3582d28532/group-theory/preamble.tex +\input{headers/preamble/academia/index.tex} \input{headers/preamble/academia/theorems/mod.tex} \input{headers/preamble/academia/visuals.tex} diff --git a/build/latex/academia/headers/preamble/core/mod.tex b/build/latex/academia/headers/preamble/core/mod.tex index 403ce58..7eaa1c0 100644 --- a/build/latex/academia/headers/preamble/core/mod.tex +++ b/build/latex/academia/headers/preamble/core/mod.tex @@ -7,7 +7,6 @@ \input{headers/preamble/core/date_and_time.tex} \input{headers/preamble/core/encoding.tex} \input{headers/preamble/core/graphics_and_floats.tex} -\input{headers/preamble/core/index.tex} \input{headers/preamble/core/linting.tex} \input{headers/preamble/core/margindate.tex} \input{headers/preamble/core/math.tex} diff --git a/build/latex/academia/headers/preamble/mod.tex b/build/latex/academia/headers/preamble/mod.tex index 91ae2d7..dcdd92a 100644 --- a/build/latex/academia/headers/preamble/mod.tex +++ b/build/latex/academia/headers/preamble/mod.tex @@ -1,2 +1,3 @@ -\input{headers/preamble/academia/mod.tex} \input{headers/preamble/core/mod.tex} + +\input{headers/preamble/academia/mod.tex} diff --git a/build/latex/academia/scripts/extract_text_from_all.sh b/build/latex/academia/scripts/extract_text_from_all.sh deleted file mode 100755 index 11b2ac4..0000000 --- a/build/latex/academia/scripts/extract_text_from_all.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env sh - -grep 'INPUT ./' ./build/main.fls | uniq | sed 's/INPUT //' | while read -r file; do - if ! [ "$(basename "$file")" = preamble.tex ] && ! [ "$(basename "$file")" = gymnasium.png ]; then - printf "\n%% Filename: %s\n" "$file" - grep -v '^\s*%' "$file" - fi -done diff --git a/build/latex/academia/scripts/optimize_images.sh b/build/latex/academia/scripts/optimize_images.sh new file mode 100755 index 0000000..0f48e4b --- /dev/null +++ b/build/latex/academia/scripts/optimize_images.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env nix +#! nix shell nixpkgs#optipng nixpkgs#jpegoptim nixpkgs#nodePackages.svgo nixpkgs#dash --command dash +# shellcheck shell=dash + +# source: https://github.com/stride-tasks/stride/blob/148d513297c8ae66d79fc287769adfe5e711c93c/scripts/optimize-images + +PROJECT_DIR="$(git rev-parse --show-toplevel)" + +cd "$PROJECT_DIR" || { + echo "No '$PROJECT_DIR' ?!" + exit 1 +} + +PNG_OPITMIZE_COMMAND='optipng --quiet -o7 -preserve' +JPG_OPITMIZE_COMMAND='jpegoptim --quiet --strip-all -m76' +SVG_OPITMIZE_COMMAND='svgo --multipass --quiet --input' + +# The extension is the part after the first dot in the filename: +# +# For example: +# file.png => png +# file.tar.gz => tar.gz +find_files_by_extension() { + wanted_extension="$1" + tmp="$(mktemp)" + + git ls-files --cached --modified --other --exclude-standard --deduplicate | while IFS= read -r file; do + extension="${file#*.}" + if [ "$extension" = "$wanted_extension" ]; then + echo "$file" + else + : + # echo "'$file' with extension: '$extension' does not match filter: '$wanted_extension'" 1>&2 + fi + done >"$tmp" + + echo "$tmp" +} + +size_of() { + du -b "$1" | cut -f1 +} + +bytes_human() { + number="$1" + + numfmt --to=iec-i --suffix=B --format="%9.2f" "$number" +} + +# https://stackoverflow.com/questions/44695878/how-to-calculate-percentage-in-shell-script +# Native POSIX solution using string manipulation (assumes integer inputs). +percent() { + DP="$1" + SDC="$2" + + # Special case when DP is zero. + [ "$DP" = "0" ] && echo "0.00" && return + + # # e.g. round down e.g. round up + # # DP=1 SDC=3 DP=2 SDC=3 + Percent=$((DP * 100000 / SDC + 5)) # Percent=33338 Percent=66671 + Whole=${Percent%???} # Whole=33 Whole=66 + Percent=${Percent#"$Whole"} # Percent=338 Percent=671 + Percent=$Whole.${Percent%?} # Percent=33.33 Percent=66.67 + echo "$Percent" +} + +TOTAL=0 +TOTAL_SAVED=0 + +optimize_files() { + FILTER="$1" + PROGRAM="$2" + + printf "%s" "Processing $FILTER files:" + + FILES="$(find_files_by_extension "$FILTER")" + COUNT=$(wc -l <"$FILES") + + if [ "$COUNT" -eq 0 ]; then + echo " no files found!" + return + fi + + echo "" + + I=1 + + TOTAL_INNER=0 + TOTAL_SAVED_INNER=0 + + while IFS= read -r f; do + printf "%-2s/${COUNT} $f ... " "$I" + + SIZE="$(size_of "$f")" + + $PROGRAM "$f" + + NEW_SIZE="$(size_of "$f")" + DIFF=$((SIZE - NEW_SIZE)) + + echo "saved: $(bytes_human "$DIFF") ($(percent $DIFF "$SIZE")%)" + + TOTAL_INNER=$((TOTAL_INNER + SIZE)) + TOTAL_SAVED_INNER=$((TOTAL_SAVED_INNER + DIFF)) + + I=$((I + 1)) + done <"$FILES" + rm "$FILES" + + echo "Total saved for $FILTER: $(bytes_human "$TOTAL_SAVED_INNER") ($(percent $TOTAL_SAVED_INNER $TOTAL_INNER)%)" + echo "" + + TOTAL=$((TOTAL + TOTAL_INNER)) + TOTAL_SAVED=$((TOTAL_SAVED + TOTAL_SAVED_INNER)) +} + +optimize_files 'png' "$PNG_OPITMIZE_COMMAND" +optimize_files 'jpg' "$JPG_OPITMIZE_COMMAND" +optimize_files 'jpeg' "$JPG_OPITMIZE_COMMAND" +optimize_files 'svg' "$SVG_OPITMIZE_COMMAND" + +echo "Total saved: $(bytes_human "$TOTAL_SAVED") ($(percent $TOTAL_SAVED $TOTAL)%)" |