about summary refs log tree commit diff stats
path: root/build/latex/academia/build.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbuild/latex/academia/build.sh27
1 files changed, 25 insertions, 2 deletions
diff --git a/build/latex/academia/build.sh b/build/latex/academia/build.sh
index c67ad52..1ff2b6e 100755
--- a/build/latex/academia/build.sh
+++ b/build/latex/academia/build.sh
@@ -1,6 +1,8 @@
 #!/usr/bin/env sh
 
-file="./%INIT_APPLICATION_NAME.tex"
+root="$(git rev-parse --show-toplevel)"
+
+file="$root/%INIT_APPLICATION_NAME.tex"
 dst=build
 
 clear=false
@@ -21,10 +23,31 @@ for arg in "$@"; do
 done
 
 # find all directories which are not the destination dir or inside it
-find . -type d -not -name "$dst" -not -path "./$dst/*" -printf '%P\n' | while IFS= read -r dir; do
+find "$root" -type d -not -name "$dst" -not -path "./$dst/*" -printf '%P\n' | while IFS= read -r dir; do
     mkdir --parents "$dst/$dir"
 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"