#!/usr/bin/env bash

LOGO="images/logo"
FOOTER="images/footer"
DPI=600

clean() {
	rm -rf *.aux *.nav *.toc *.log *.snm *.out *.vrb _minted*
}

convert_images() {
	if [ ! -f "${LOGO}.png" ]; then
		convert -density ${DPI} ${LOGO}.svg ${LOGO}.png
	fi

	if [ ! -f "${FOOTER}.png" ]; then
		convert -density ${DPI} ${FOOTER}.svg ${FOOTER}.png
	fi
}

main() {
	clean
	convert_images
	xelatex --shell-escape "${1}"
	xelatex --shell-escape "${1}"
	clean
	echo "Done, output is ${1%.*}.pdf"
}

main "${1}"

