iditacards/scantex.sh
2024-10-14 17:38:03 -04:00

26 lines
699 B
Bash

#!/bin/bash
echo 'ninja_dyndep_version = 1'
scriptdir="$(dirname -- "${BASH_SOURCE[0]}")"
src="$1"
dst="$2"
tgt="${dst%.*}.pdf"
cd "$scriptdir" || exit 1
temp="$(mktemp -p .)"
trap 'rm -rf ${temp} ${temp}.*' EXIT INT
cp "$src" "$temp.tex"
xelatex -recorder --shell-escape "$temp.tex" >/dev/null
deps="$(awk -v "temp=$temp" -v "repl=${src%%.*}" '/INPUT \./ {gsub(temp,repl,$2); print $2}' < "$temp.fls" | sort | uniq | tr '\n' ' ')"
outs="$(awk -v "temp=${temp#*/}" -v "repl=${dst%.*}" '/OUTPUT / {gsub(temp,repl,$2); print $2}' < "$temp.fls" | sort | uniq | tr '\n' ' ')"
echo -n "build $tgt"
[ -z "$outs" ] || echo -n " | $outs"
echo -n " : dyndep"
[ -z "$deps" ] || echo -n " | $deps"
echo