about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xcommon/scripts/latex/build.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/scripts/latex/build.sh b/common/scripts/latex/build.sh
index 616a09d..1ff2b6e 100755
--- a/common/scripts/latex/build.sh
+++ b/common/scripts/latex/build.sh
@@ -29,4 +29,25 @@ done
 
 test "$clear" = true && rm "$dst/${file%tex}out"
 
+fd . "$root/figures" --type file --extension tex | while read -r figure; do
+    figure_name_full="$(basename "$figure")"
+    figure_name="${figure_name_full%.tex}"
+
+    figure_hash="$(sha256sum "$figure")"
+    figure_cache_hash="$(
+        [ -e "$dst/figures/$figure_name/$figure_name.sha256sum_hash" ] &&
+            cat "$dst/figures/$figure_name/$figure_name.sha256sum_hash"
+    )"
+
+    echo "Compiling figure: '$figure_name'.."
+    mkdir --parents "$dst/figures/$figure_name"
+
+    if [ "$figure_hash" = "$figure_cache_hash" ]; then
+        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"
+    fi
+done
+
 latexmk -outdir="$dst" -file-line-error -pdflatex -recorder "$file"