#!/bin/csh -f
#
# Convert Hyperlatex documents to dvi, html, or gif's
#
# Debian Gnu/Linux 
#setenv HYPERLATEX_DIR "~/Hyperlatex"
setenv HYPERLATEX_DIR "/usr/lib/emacs/site-lisp/hyperlatex"
# Debian Gnu/Linux
#setenv HYPERLATEX_ICON_URL "http://graphics.postech.ac.kr/\~{}otfried/img"
setenv HYPERLATEX_ICON_URL "."
#

if ($#argv < 1) then
 echo "usage: hyperlatex [ -html | -dvi | -gif ] file"
 exit(1)
endif

set run_latex = 0

switch ( $argv[1] )
case "-html" :
  shift
  breaksw
case "-dvi" :
  set run_latex = 1
  set latex_flag = ""
  set make_gifs = 0
  shift
  breaksw
case "-gif" :
  set run_latex = 1
  set latex_flag = "\def\makegifs{}"
  set make_gifs = 1
  shift
  breaksw
endsw

if ($#argv < 1) then
  echo "hyperlatex: no file specified"
  exit(2)
endif

set name = $argv[1]
if (! -e $name) then
  set name = $name.tex
  if (! -e $name) then
    echo "hyperlatex: Cannot find file "\"$name\"
    exit(2)
  endif
endif

if ( $run_latex ) then

  latex "$latex_flag\input{$name}"
  if ( ! $status && $make_gifs ) then
    /bin/csh $name:r.makegif
  endif

else

  emacs -batch -no-init-file -no-site-file \
    -l $HYPERLATEX_DIR/hyperlatex-1.4.elc -funcall batch-hyperlatex-format \
    $name

endif
