home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / textools / part01 / TEX < prev    next >
Encoding:
Text File  |  1986-11-30  |  4.5 KB  |  228 lines

  1. #! /bin/csh -f
  2. #
  3. # Usage: TEX [-flags ...] filename
  4. #
  5. # The various flags are described below, but only one filename should
  6. # be given; stdin is not used. File types are indicated by the filename
  7. # suffix. Input files may have one of the following suffixes:
  8. #    .tex -- a file with tex commands, equations.
  9. #    .dvi -- device independent format.
  10. #    .ver -- output of verser1 (for the varian or AED)
  11. #    .imp -- output of dvi-imagen (or dviimp)
  12. # Anything else is assumed to be in .tex format.
  13. # If TEX sees a .dvi, .ver, or .imp suffix, it will skip ahead to the right
  14. # point in the processing sequence. Specifically,
  15. #    texeqn    accepts .tex, outputs .tex
  16. #    tex    accepts .tex, outputs .dvi and .log
  17. #    latex    accepts .tex, outputs .dvi and .log
  18. #    verser1    accepts .dvi, outputs .ver (for the varian or AED, not on hanuma).
  19. #    lpr    accepts .ver, outputs raster
  20. #    ipr    accepts    .imp, outputs raster
  21. #
  22. # Flags:
  23. # -latex uses LaTeX.
  24. # -log     saves a log file from the tex run in filename.log.
  25. # -d     quits once the .dvi file has been made.
  26. # -x     makes two passes on the (latex) input, so cross-references
  27. #     are resolved.
  28. # -v     output device is the varian (imagen is the default)
  29. # -q     quits once the .imp file has been made if the imagen is the target printer
  30. #     or after the .ver file    (i.e. after verser1 stage) if the AED or the varian
  31. #     is the target printer.
  32. # -eqn     strips out the equations with texeqn and typeset them.
  33. #
  34. # Authors: Kamal Al-Yahya, Jeff Thorson, and Chuck Sword, Stanfor University
  35. #
  36. umask 0
  37. onintr removal
  38. set name=() host=()
  39. set destdir = /usr/local
  40. set tmp = TEX$$
  41. set device = imagen
  42. set st = 0
  43. unset latex x d q eqn log
  44.  
  45. if ($#argv == 0) then
  46.     echo "usage: TEX [-latex] [-eqn] [-log] [-d] [-q] [-x] filename"
  47.     exit(-1)
  48. endif
  49.  
  50. while ($#argv > 0 && !($?inf))
  51.     switch ($argv[1])
  52.         case -latex:
  53.             set latex
  54.             breaksw
  55.  
  56.         case -x:
  57.             set x
  58.             breaksw
  59.  
  60.         case -q:
  61.             set q
  62.             breaksw
  63.  
  64.         case -d:
  65.             set d
  66.             breaksw
  67.  
  68.         case -v:
  69.             set device = varian
  70.             breaksw
  71.  
  72.         case -eqn:
  73.             set eqn
  74.             breaksw
  75.  
  76.         case -log:
  77.             set log
  78.             breaksw
  79.  
  80.         case -*:
  81.             echo unknown flag $argv[1], ignored
  82.             breaksw
  83.                 default:
  84.             set inf = $argv[1]
  85.             if !(-e $inf) then
  86.  
  87. #  filename not found, try with .tex ending
  88.  
  89.                 if !(-e $inf.tex) then 
  90.                     echo $0 'cannot find file' $inf.
  91.                     exit(-1)
  92.                 else
  93.                     set inf = ($inf.tex)
  94.                 endif
  95.             endif
  96.             breaksw
  97.         endsw
  98.     shift argv
  99. end
  100.  
  101. set name = $inf:t
  102. set sname = $name:r
  103. set name = $cwd/$name
  104. set suffix = $name:e
  105.  
  106. if ($suffix == dvi) then
  107.     echo TEX: starting with .dvi file
  108.     set name = $name:r
  109.     set dvifile = $inf
  110.     goto dvi
  111. endif
  112.  
  113. if ($suffix == ver) then
  114.     echo TEX: starting with .ver file
  115.     set name = $name:r
  116.     set verfile = $inf
  117.     goto ver
  118. endif
  119.  
  120. if ($suffix == imp) then
  121.     echo TEX: starting with .imp file
  122.     set name = $name:r
  123.     set impfile = $inf
  124.     goto imp
  125. endif
  126.  
  127. if ($suffix == tex || $suffix == eqn) then
  128.     set name = $name:r
  129. endif
  130.  
  131. echo "\batchmode" > $tmp.tex
  132.  
  133. if ($?eqn) then
  134.     $destdir/texeqn < $inf >> $tmp.tex
  135. else
  136.     cat $inf >> $tmp.tex
  137. endif
  138.  
  139. echo "\bye" >> $tmp.tex
  140.  
  141. # Choose tex or latex
  142.  
  143. if ($?latex) then
  144.     if (-e $name.aux) then
  145.         cp $name.aux $tmp.aux
  146.     endif
  147.     $destdir/latex $tmp:t
  148.     if ($status != 0) then
  149.         goto oops
  150.     else
  151.         if (-e $tmp.aux) then
  152.             cp $tmp.aux $name.aux
  153.         endif
  154.     endif
  155.  
  156.     if ($?x) then
  157.         echo "Starting second pass"
  158.         $destdir/latex $tmp
  159.         if ($status != 0) then
  160.             goto oops
  161.         endif
  162.         if (-e $tmp.aux) then
  163.             cp $tmp.aux $name.aux
  164.         endif
  165.     endif
  166.  
  167. else    $destdir/tex $tmp
  168.     if ($status != 0) then
  169. oops:
  170.         echo TEX could not process your file.
  171.         echo Error messages are in $name.log
  172.         mv -f $tmp.log $name.log
  173.         set st = -1
  174.         goto removal
  175.     endif
  176. endif
  177.  
  178. if ($?log) then
  179.     mv -f $tmp.log $name.log
  180.     if (-e $tmp.aux) then
  181.         mv -f $tmp.aux $name.aux
  182.     endif
  183. endif
  184.  
  185. set dvifile = $tmp.dvi
  186.  
  187. if ($?d) then
  188.     mv -f $dvifile $name.dvi
  189.     goto removal
  190. endif
  191.  
  192. dvi:
  193.  
  194. if($device == imagen) then
  195.     $destdir/dvi-imagen -s $dvifile > $tmp.imp
  196.     if ($?q) then
  197.         mv -f $tmp.imp $name.imp
  198.         goto removal
  199.     endif
  200.     set impfile = $tmp.imp
  201. imp:
  202.     (echo -n \@document\(owner \"$user\", site \"$host\", spooldate \
  203.     \"`date`\", language \"imPress\", jobheader off, \
  204.     jamresistance on\) ; cat $impfile ) | $destdir/ipr
  205.     goto removal
  206. endif
  207.  
  208. if($device == varian) then
  209.     $destdir/verser1 < $dvifile > $tmp.ver
  210.     if ($status != 0) then
  211.         echo TEX bombed out on verser1.
  212.         set st = -1
  213.         goto removal
  214.     endif
  215.     set verfile = $tmp.ver
  216.  
  217.     if ($?q) then
  218.         mv -f $verfile $name.ver
  219.         goto removal
  220.     endif
  221. ver:
  222.     lpr -d -s -Pvarian $tmp.ver
  223. endif
  224.  
  225. removal:
  226. /bin/rm -f $tmp.tex $tmp.log $tmp.dvi $tmp.ver $tmp.imp $tmp.aux
  227. exit($st)
  228.