#!/bin/sh -e
## http://www.nefkom.net/georg.drenkhahn/prosper/

if [ _"$1" = _"" ] ; then
    echo "What?"
    exit
fi

file=`basename $1 .tex`

if [ "$file" = "$1" ] ; then
    echo "Ups $1 seems to be no LaTeX file."
    exit
fi

if ! grep -q '\\note' "$1" ; then
    echo "File $1 does not contain any notes."
    exit
fi

article=${file}_notes
# sed "s/\(\\mode<\)presentation/\1handout/" ${file}.tex > ${article}.tex
# sed -e "s/\(\\documentclass.*{\)beamer}/\1article}\\
# \\\\usepackage{beamerarticle}/" \
#     ${file}.tex > ${article}.tex
sed -e "s#\\\\setbeameroption{hide notes}#\\\\setbeameroption{show only notes}#" \
    ${file}.tex > ${article}.tex

#cp -a ${file}.tex ${article}.tex

export TEXINPUTS=".:../inputs:../img:$TEXINPUTS"
pdflatex --shell-escape ${article}.tex
pdflatex --shell-escape ${article}.tex
#latex ${article}.tex
#latex ${article}.tex
#dvips -P pdf ${article}.dvi
cleantex
#rm -f  ${file}.ps 

rm -f ${article}.tex
