about summary refs log tree commit diff stats
path: root/common
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-03 16:07:01 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-03 16:07:01 +0200
commit8a93963378883b0b9980750ecd7660f345d53799 (patch)
treebb73da5090de34d5d62af24ef10032b2dab0a9d1 /common
parentfix(common/scripts/latex/build.sh): Don't depend on the current PWD (diff)
downloadflake-templates-8a93963378883b0b9980750ecd7660f345d53799.tar.gz
flake-templates-8a93963378883b0b9980750ecd7660f345d53799.zip
feat(common/scripts/latex/build.sh): Support standalone figures as generated by `lpm`
Diffstat (limited to 'common')
-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"