#!/bin/zsh

# This short script calls texexec to run a conTeXt job
# Richard Koch; September 14, 2001 and May 29, 2006

mygspath="$2"
if [ -x ${mygspath}/ps2pdf ]; then
	export PATH="${mygspath}":$PATH
fi
 
mytexexecpath="$4"
if [ -x ${mytexexecpath}/texexec ]; then
	PATH="${mytexexecpath}":$PATH
fi

pstest="$5"
filename="$6"
basename="${filename%%.*}"
dviname="$basename".dvi

if [ "$1" = "YES" ]; then
	texexec --passon=" --interaction=nonstopmode " "${filename}"
else
	texexec "${filename}"
fi

if [ "$3" = "Panther" ]; then
    
    if [ "$pstest" = "no" ]; then
	simpdftex latex --distiller /usr/bin/pstopdf "$dviname"
    else
	simpdftex latex --distiller /usr/bin/pstopdf --keep-psfile "$dviname"
    fi
    
else

    if [ "$pstest" = "no" ]; then
	simpdftex latex "$dviname"
    else
	simpdftex latex --keep-psfile "$dviname"
    fi

fi

