#!/bin/bash

if [[ -z $STEX_CONTENT_HOME ]]
then
    echo "STEX_CONTENT_HOME is not set; please set it in your ~/.bashrc"
    exit 1
fi

LIB="$STEX_CONTENT_HOME/slides/lib"
cat <<'EOF'
% this file is automatically generated by allgen
% Note: This hack is needed to make mikoslides and problems work together.
\PassOptionsToPackage{solutions,notes,pts,min}{problems}
EOF

sed -e '/\\begin{document}/ i\
\\usepackage{problems}
' $LIB/pre.tex | \
    grep -v '^\\def\\snippets'

cat <<'EOF'
EOF

for file in *.tex
do
    prefix=${file%.tex}        # file name without .tex suffix
    [[ $prefix != "all" ]] && echo -e "\\subsection{${prefix//_/\\\\_}} \n \\input{$prefix}" # in subsection replace "_" by "\_" 
done

cat $LIB/post.tex
