#!/bin/bash

COURSE=$1
INPUT="$COURSE".tex
TOC="$COURSE".toc
OUTLINE="$COURSE"-appendix-outline.html

COURSE=$COURSE 
VERSION=$(grep '\\newcommand{\\version}' $INPUT \
    | sed -e s/'\\newcommand{\\version}{'//g | sed -e s/'}'//g) \

TITLE="$(grep 'coursetitle' $INPUT \
	| sed -e s/'\\newcommand{\\coursetitle}{'//g | sed -e s/'}'//g)" \
TITLE="$TITLE: Appendices"

cat <<EOF > $OUTLINE
<HTML>
<HEAD>
<TITLE>
$COURSE $TITLE
</TITLE>
</HEAD>
<BODY>
<H1>$COURSE $TITLE</H1>
<OL>
EOF

grep appendix $TOC \
    | sed -e s/'\\contentsline {chapter}{\\numberline {.}'/'<LI>'/g \
    | sed 's/}.*/<\/LI>/'  >> $OUTLINE

cat <<EOF >> $OUTLINE
</OL>
</BODY>
</HTML>
EOF
echo I made: "$OUTLINE"

