#!/bin/sh

alias echo='/bin/echo -e'

clean() {
	## Not sure if this step is needed, guess latexmk should be able to detect a change
        echo "\t¤ Clean previous build"

        ## Delete temp files from previous build
	echo "\t\t- delete all temporary files (.aux, .bbl, ...)"
        find latex/$1 -regextype posix-extended                                                        \
                      -regex     ".*\.(aux|bbl|blg|dvi|fdb|fls|idx|ilg|ind|log|maf|mtc|out|pdf|toc).*" \
                      -exec      rm {} \;

        ## Remove minted folders
	echo "\t\t- remove pygments input hash files (\"_minted\" folders)"
        find latex/$1 -type d -name '_minted*' -exec rm -r {} \; 2> /dev/null

        ## HTML exports
	#echo '   - possible HTML export'
        #find latex/$1 -type d -name 'html*'    -exec rm -r {} \;

	echo
}

build() {
        echo "\t¤ Generation of the PDF format\n"
        cd latex/$1/main
        latexmk $opts $1'_manual' 1> /dev/null
        [ -f $1'_manual'.pdf ] && mv $1'_manual'.pdf ../../..
        cd - > /dev/null
	echo
}
