#
LETTERHEAD=/usr/TeX/lib/tex/macros/LaTeX/letterhead.tex
if [ "$1" = "-ps" ]; then
	POSTSCRIPT=1
	shift
fi
if [ $# = 1 ]; then
	if [ ! -f $LETTERHEAD ]; then
		echo "$LETTERHEAD not found";
		exit 1
	fi
	sed "s/FILE/$1/" < $LETTERHEAD > texfile.tex || exit
	latex texfile.tex || exit
	echo -n "Do you wish to view $1 (y/n): "
	read ans
	if [ "$ans" = "y" ]; then
		if [ "" = "$DISPLAY" ]; then
				dvi2tty -w132 -q texfile | less
		else
			if [ "$POSTSCRIPT" != "" ]; then
				dvips -o texfile.ps texfile.dvi
				gs texfile.ps
			else
				xdvi texfile
			fi
		fi
	fi
	echo -n "Do you wish to print $1 (y/n): ";
	read ans
	if [ "$ans" = "y" ]; then
		if [ "$POSTSCRIPT" != "" ]; then
#			if [ ! -e texfile.ps -a texfile.dvi -nt texfile.ps ]; then
				dvips -o texfile.ps texfile.dvi
#			fi
			gsprint texfile.ps
			/bin/rm texfile.ps > /dev/null
		else
			dvilj2p -e- texfile > /dev/lp
		fi
		/bin/rm texfile.lj > /dev/null
	fi
	/bin/rm texfile.tex > /dev/null
	/bin/rm texfile.dvi > /dev/null
	/bin/rm texfile.log > /dev/null
	
fi
