#!/bin/sh
#
# "checktex"	K. J. Turner	28/07/92
#  
# This script uses "chktex" to check that begin-end pairs of
# LaTeX commands do in fact match.
#
# Source files without a ".tex" extension are automatically given
# one. If no parameters are given, the script reads from the
# standard input. If multiple parameters are given, the script
# prefixes the report on each with its name.

ext=".tex"

if [ $# -eq 0 ]
  then chktex
fi

if [ $# -gt 1 ]
  then many=1
  else many=0
fi

while [ "$1" != "" ]; do
  name="`expr Z$1 : Z'\(.*\)\'$ext`"
  if [ "$name" = "" ]
    then name=$1; filename="$name$ext"
    else filename=$1
  fi
  if [ -f $filename ]
    then :
    else echo "$filename does not exist"; shift; continue
  fi
  if [ $many -eq 1 ]
    then echo; echo "Check of $filename:"; echo
  fi
  checktex <$filename
  shift
done

exit 0
