#!/bin/sh
# Date: 04-04-04 (04-April 2004)
# Last Changed: 04-04-04 (04-April 2004)
# Author: Nico Schottelius <Nico-linux AT Schottelius DOT Org>
# Description: Convert latex to pdf with support for tableofcontents
#
   

if [ $# -lt 1 ]; then
   echo `basename $0`': file(s) (may ommit .tex extension)'
   echo 'Hey, hey guy, what to convert ?'
   exit 1
fi   
   
for mfile in $@; do

   # .texfile
   if [ -f "$mfile" ]; then
      texfile="$mfile"
      dvifile="${mfile%.tex}"
   else 
      if [ -f "$mfile".tex ]; then
         texfile="$mfile".tex
         dvifile="$mfile"
      fi
   fi

   if [ -z "$texfile" ]; then
      echo "No such file: $mfile. Skip."
      break
   fi

   # use three times (table of contents problem)
   latex "$texfile" && latex "$texfile" && latex "$texfile" && dvipdfm -p a4 "$dvifile"
done