LATEX=pdflatex
BIBTEX=bibtex
BIB=
RERUN='(There is undefined reference|Rerun to get (cross-references|the bars) right)'

%.pdf:%.tex
	${LATEX} $<
	@if [ -e $*.bbl ]; then ${BIBTEX} $* && ${LATEX} $< && ${LATEX} $< ; fi
	@if egrep -q $(RERUN) $*.log ; then ${LATEX} $< ; fi

%.aux %.log: %.tex
	${LATEX} $<
	while grep -e 'Rerun to get' -e 'run LaTeX again' *.log ; do ${LATEX} $< ; done

%.idx %.toc: %.tex
	${LATEX} $<

%.bbl %.blg: %.aux $(BIB)
	bibtex $< && ${LATEX} $*.tex

%.ind: %.idx
	makeindex $< && ${LATEX} $*.tex

indent: *tex
    for i in *.tex; do latexindent -w -y="defaultIndent:'    '" $$i ; done

clean:
	rm -fv *.log *.aux *.dvi *.toc *.lot *.lof *.snm *.nav *.out *.tns *.bak?
