#!/bin/sh
libdir=$1
file=$2
shift 1
if grep "\\tableofcontents" $file.tex > /tmp/grepout; then
    echo "Processing file body"
    echo "%%tth:\begin{html}<title>$file-body</title>\end{html}" > /tmp/title
    cat /tmp/title $file.tex | 
    sed /\\tableofcontents/d | 
    tth >$file-body.html -L$file -p$libdir/ -e2
    echo "Processing table of contents"
    echo "%%tth:\begin{html}<title>$file-toc</title>\end{html}" > /tmp/title
    cat /tmp/title $file.toc | 
    tth -L$file -p$libdir/ |
    sed 's/href=\"#tth_/target=\"$$-body\"href=\"$$-body.html#tth_/g' |
    sed s/[$][$]/$file/g >$file-toc.html  
    echo '<HTML>
<HEAD>
<TITLE>'$file'</TITLE>
</HEAD>
<FRAMESET COLS="23%,77%" border=4>
<FRAME SRC="'$file'-toc.html" NAME="'$file'-toc" border=1>
<FRAME SRC="'$file'-body.html" NAME="'$file'-body" border=1>
<NOFRAMES>
<BODY>
    Pour afficher cette page, vous avez besoin dun navigateur
    pouvant afficher des panneaux. 
</BODY>
</NOFRAMES>
</FRAMESET>
</HTML>' >  $file.html
    echo "done."
else 
    echo "No table of contents. Processing file body"
    tth  -L$file -p$libdir/ <$file.tex >$file.html ${*}
    echo "done."
fi
