#MAKE-HPF-CHAPTER
#!/bin/csh

#Version of Sept. 2, 1992 - David Loveman, Digital Equipment Corporation

#  MAKE-HPF-CHAPTER - a script similar to MAKE-HPF-REPORT. It takes 
#     one argument, the filename of the chapter to be produced.  It 
#     uses the file chapter-head.tex and a set of 
#     temporary files named temp.*

#set TEXroot=/usr/local/bin
#alias latex $TEXroot/latex
#alias dvips $TEXroot/dvips
#alias xdvi $TEXroot/xdvi

set thedate = `date`
echo "  "
echo BEGIN JOB ON: $thedate

echo "this script assumes that latex, dvips, and xdvi"
echo "are on your search path"

if $#argv != 1 then
  echo -n "type the chapter's filename:"
  set f = "$<"
else
  set f = $1
endif

if ( ! (-e $f) ) then
  echo "file $f does not exist"
  exit 1
else if ( ! (-r $f) ) then
  echo "file $f is not readable"
  exit 1
else
  echo "file $f exists and is readable"
endif

cat chapter-head.tex $f > temp.tex
echo "\end{document}" >> temp.tex

echo "  "
which latex

##################################################
#        Run LATEX the first time
##################################################
echo "  "
echo "latex $f the first time"
latex temp < /dev/null
if($status != 0) then
   echo "first LATEX run fails, quit"
   exit(1)
endif

##################################################
#        Run LATEX the second time
##################################################
echo "  "
echo "latex $f the second time"
latex temp < /dev/null
if($status != 0) then
   echo "second LATEX run fails, quit"
   exit(1)
endif

##################################################
#        Run dvips to produce a ps file
##################################################
echo "  "
echo "dvips $f"
dvips temp -o temp.ps
if($status != 0) then
   echo "DVIPS fails, quit"
   exit(1)
endif

##################################################
#        Run xdvi to view the ps file
##################################################
echo "  "
echo "xdvi $f"
xdvi temp

set fbase = `basename $f '\..*'`
mv temp.ps $fbase.ps
mv temp.dvi $fbase.dvi
echo "  "
echo "files $fbase.ps and $fbase.dvi have been created"

##################################################
#        Print the ps file
##################################################
echo "  "
echo "now print the postscript file (this script doesn't)"
echo "the HPF Report is meant to be two-sided"
echo "the following command works on a Digital PrintServer"
echo "lpr -Oportrait -Dpostscript -K2 $fbase.ps"
echo "you may not need the -Oportrait -Dpostscript -K2 options"
#lpr -Oportrait -Dpostscript -K2 $fbase.ps

rm temp.*
echo "done"
echo "  "
