about summary refs log tree commit diff stats
path: root/build/latex/presentation/build.sh
blob: 1ff2b6ea9d63fb0ad86e7ba3cbb6beb9d13220f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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"