diff options
Diffstat (limited to '')
-rwxr-xr-x | build/latex/presentation/build.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/build/latex/presentation/build.sh b/build/latex/presentation/build.sh new file mode 100755 index 0000000..1ff2b6e --- /dev/null +++ b/build/latex/presentation/build.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env sh + +root="$(git rev-parse --show-toplevel)" + +file="$root/%INIT_APPLICATION_NAME.tex" +dst=build + +clear=false + +for arg in "$@"; do + case "$arg" in + "--clear") + clear=true + ;; + --*) + echo "No such option: '$arg'" + exit 2 + ;; + *) + file="$arg" + ;; + esac +done + +# find all directories which are not the destination dir or inside it +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" |