#!/bin/sh


## Default options for GNU find (Linux OS)
find_pre=''; find_suf='-regextype posix-extended'

## Test OS to tweak the options in find command for working in extended mode everywhere
[ '$( uname )' = 'Darwin' ] && { find_pre='-E'; find_suf=''; }

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

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

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

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

    echo
}

build() {
    printf "\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
}
