#!/bin/bash

run_lualatex() {
    local jobname=$1
    local texinput=$2

    for i in 1 2 3; do
        lualatex -jobname="$jobname" -shell-escape "$texinput"
    done
}

clean_env() {
	rm -f *.aux *.log *.toc *.out *.lof *.lot *.bbl *.blg *.fls *.fdb_latexmk *.synctex.gz *.nav *.snm
}

current_dir=$(basename "$(pwd)")

run_lualatex "$current_dir" "\PassOptionsToClass{handout}{beamer}\input{main.tex}"
clean_env

run_lualatex "$current_dir-presentation" "main.tex"
clean_env

run_lualatex "$current_dir-print-portrait" "\PassOptionsToClass{handout}{beamer}\def\printportrait{1}\input{main.tex}"
clean_env

run_lualatex "$current_dir-print-landscape" "\PassOptionsToClass{handout}{beamer}\def\printlandscape{1}\input{main.tex}"
clean_env
