#! /bin/sh
# ----------------------------------------------------------------------------
# - aleph-latex                                                              -
# - run latex, bibtext and mkindex on a particular latex file                -
# ----------------------------------------------------------------------------
# - This program is  free software;  you can  redistribute it and/or  modify -
# - it provided that this copyright notice is kept intact.                   -
# -                                                                          -
# - This  program  is  distributed in the hope  that it  will be useful, but -
# - without  any   warranty;  without  even   the   implied    warranty   of -
# - merchantability  or fitness for a particular purpose. In not event shall -
# - the copyright holder be  liable for  any direct, indirect, incidental or -
# - special damages arising in any way out of the use of this software.      -
# ----------------------------------------------------------------------------
# - copyright (c) 1999-2003 amaury darsch                                    -
# ----------------------------------------------------------------------------

# the input files
srctex=$1-$2.tex
bibtex=$1-$2.bib
idxtex=$1-$2.idx

# extra files
export TEXINPUTS=$3

# check for file
if test ! -f $srctex; then
    echo "aleph-latex: no input file"
    exit 1
fi

# latex pass 1
latex $srctex
if test $? != 0; then
    exit 1
fi

# bibtex pass
if test -f $1.bib; then
    bibtex $1-$2
    if test $? != 0; then
	exit 1
    fi
fi

# latex pass 2
latex $srctex
if test $? != 0; then
    exit 1
fi

# makeindex pass
if test -f $idxtex; then
  makeindex $idxtex
  if test $? != 0; then
      exit 1
  fi
fi

# latex pass 3
latex $srctex
if test $? != 0; then
    exit 1
fi

# normal exit
exit 0
