#!/bin/sh

cleanup () {
	rm -f *.log *.aux *.toc
	exit $1
}

compile () {
	tectonic $1 || echo 
}

trap cleanup HUP TERM INT

SRC=hip2022.tex

echo -ne "\e[;1H\e[2J"
while true; do
	compile $SRC
	FILES=$(echo *.tex)
	while inotifywait $FILES ; do
		echo -ne "\e[;1H\e[2J"
		compile $SRC
	done
done
