#!/bin/sh # ======================================================================== # == dotex : a simple shell script to allow "direct" == # == transformation of a TeX/LaTeX/grLaTeX file == # == to postcript file == # == usage : dotex [-cvp] [-d flags] filename[.tex] == # == -c : toggle output debugging messages == # == -v : toggle view dvi after end == # == -p : toggle print after mode == # == -h : output help message == # == -l : view logging info == # == -i : interactive (allow terminal input) == # == -d flag : pass flags to dvi to ps == # == -2 : ps2up == # == -P name : printer name == # == -F fmt : Force format fmt == # == -n : Do compilation on the spot (no tmp) == # == == # == $Id: dotex,v 1.12 1995/10/17 12:14:03 kd Exp kd $ == # ======================================================================== # == Copyright (C) 1993-94 By K J Dryllerakis (kd@doc.ic.ac.uk) == # == All Rights Reserved == # == == # == Using or storing this program in your system means that you == # == have read and agreed to the following terms: == # == == # == You may freely distribute and use this script as long as the == # == copyright message remains intact and any changes are clearly == # == mentioned in the file. == # == I accept no responsibility for the proper functioning of the == # == script which may or may not prove to do what you expect it to == # == do. I will accept all comments and bug reports but do not == # == guarantee that they will materialise to a new script == # == (nevertheless I will put all possible effort to do so). == # == New in version 1.1 : Accept grlatex style if a line exists == # == of the form %% TeX: grlatex == # == [regexp search ^\%\%.*TeX\:.*grlatex] == # == New in version 1.2 : Accept the -L to force latex compilation == # == New in version 1.3 : Added support for LaTeX2e == # == and -P option == # == no more -L but -F introduced == # == New in version 1.4 : Automatic indexing support == # == New in version 1.5 : Allow for dvi previewing of the file == # == New in version 1.6 : Fixed bug of included ISO files == # == New in version 1.7 : greektex support was added == # == New in version 1.8 : compilation on the spot == # ======================================================================== # # ======================================================================== # == Executables - Changes these values to suit == # == your system == # ======================================================================== # TEX=tex LATEX=latex LATEX2E=latex2e GRLATEX=grlatex GREEKTEX=greektex NFSSLATEX=nfsslatex BIBTEX=bibtex SLITEX=slitex DVITOPS=dvips MAKEINDEX="makeindex" TEXTPREVIEW=less PRINTCMND=lpr DVIPREVIEWER=ghostview TWOUPFILTER="psnup -2 -q" DVITOPSFLAGS="" PTSTUPIDTEX=NO GREP="/usr/bin/grep" SGREP="/usr/bin/grep -s" # -s for silent SunOS grep -q for gnu GREEK2ASCII="/usr/local/tex/bin/ascii2grtex" XDVI=xdvi # # ======================================================================== # == Startup Options Changes these values to suit == # == your requirements (yes/no) == # ======================================================================== # CHECK=no DOPREVIEW=no DOPRINT=no SEELOG=no TWOUP=no ONLYDVI=no DOTMP=yes # # End of User Configurable Section # # Startup values do NOT change # # ======================================================================== # == END OF USER CONFIGURABLE PART == # ======================================================================== # VERSION="$Id: dotex,v 1.12 1995/10/17 12:14:03 kd Exp kd $" SEPERATEBIB=no INDEXNEEDED=no NEEDBIBTEX="" EXEC=$TEX ENCODED=no FORCEFORMAT=no FFORMAT="" INSTREAM="/dev/null" USEBIB=yes # By default use bibtex if necessary FORCEBIB=no # By default do not run bibtex if unnecessary # # ======================================================================== # == Useful Routines == # ======================================================================== # usage() { WEARE=`basename $0` echo "DoTeX Version $VERSION" 1>&2 echo "(C) 1993-95 K J Dryllerakis -- All Rights Reserved" 1>&2 echo "Usage: $WEARE [-hcvpi2l] [-P printer] [-d flags] [-F fmt] filename[.tex]" 1>&2 echo " where: " 1>&2 echo " -h : help screen" 1>&2 echo " -c : toggle output debugging messages " 1>&2 echo " -v : toggle view ps output after TeXing mode" 1>&2 echo " -p : toggle print ps output after TeXing " 1>&2 echo " -l : toggle log file viewing " 1>&2 echo " -i : allow terminal interaction " 1>&2 echo " -d flags: pass flags to the dvi to ps converter " 1>&2 echo " -2 : print two pages in one " 1>&2 echo " -F fmt : force compilation with fmt " 1>&2 echo " -P name : name of printer for output " 1>&2 echo " -n : run TeX on current directory " 1>&2 echo " -B[b] : suppress [force] use of bibtex " 1>&2 echo " Recognised Input: tex, latex, latex2e, grlatex, greektex, slitex, nfsslatex" 1>&2 exit 1 } nosuchfile() { echo "$FNAME : No such file" 1>&2 exit 1 } typerror(){ echo "" 1>&2 echo "Error in $1 Stage" 1>&2 cleanup exit 1 } typerrorwithlog(){ echo "" 1>&2 echo "Error in $1 Stage" 1>&2 cat $OURTMP/$FNAME.log | awk '/^\!/, /^End of file on the terminal/' | $TEXTPREVIEW cleanup exit 1 } cleanup(){ if [ "$DOTMP" = "yes" ] ; then rm -rf $OURTMP fi } checkrerun(){ if $GREP -i 'rerun' $FNAME.log ; then return 0 else return 1 fi } isencoded(){ if $SGREP -i '8859\-7' $FNAME.tex ; then return 0 else return 1 fi } indexneeded(){ if $SGREP -i '\\makeindex' $FNAME.tex ; then return 0 else return 1 fi } findincludedfiles(){ $GREP '\\\include[^ ^\{]*{[^ ]*}' | \ $GREP -v '^.*%.*\\\include' | \ sed -n -e 's/\\\include[^ ]*{\([^ ]*\)}/\1/p' | \ while read a do bb=`echo $a | sed 's/\.tex//'` echo -n "$bb " done } # Find if option $1 is specified in file $2 latexoption(){ $SGREP "^[^%]*\\\documentstyle\[[^,]*,*$1[],]" $2 } latexstyle(){ $SGREP "^[^%]*\\\documentstyle[^ ]*{$1}" $2 } nfsslatexstyle(){ latexoption Times $1 || latexoption Palatino $1 || latexoption palatino $1 || latexoption times $1 } copyright(){ # echo "dotex v$VERSION Copyright (C)1993-94 K J Dryllerakis. All Rights Reserved" echo -n "" } # # ======================================================================== # == Reference Pass macro == # ======================================================================== # # This should be a while loop RunAgainIfNeeded(){ if $SGREP -i 'rerun' $FNAME.log ; then if [ "$CHECK" = "yes" ] ; then echo -n "Reruning..." ; fi if $EXEC $FNAME.tex <$INSTREAM >$SEEFILE ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerrorwithlog "Reruning $EXEC" fi elif [ -f $OURTMP/$FNAME.toc ] ; then if [ "$CHECK" = "yes" ] ; then echo -n "TableOfC..." ; fi if $EXEC $FNAME.tex <$INSTREAM >$SEEFILE ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerrorwithlog "Building TOC in $EXEC" fi fi } # # # ======================================================================== # == Indexing Pass macro == # ======================================================================== # indexingStage(){ if [ "$NEEDINDEX" = "yes" ] ; then if [ "$CHECK" = "yes" ] ; then echo -n "Indexing..." ; fi if $MAKEINDEX $FNAME <$INSTREAM >$SEEFILE; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerror "Executing $MAKEINDEX" fi if [ "$CHECK" = "yes" ] ; then echo -n "Reruning..." ; fi if $EXEC $FNAME.tex <$INSTREAM >$SEEFILE ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerrorwithlog "Reruning $EXEC" fi fi } # # ======================================================================== # == Startup Message == # ======================================================================== # copyright # # ======================================================================== # == Parse arguments == # ======================================================================== # if [ $# -eq 0 ] ; then usage fi while getopts cvnBbp2hlid:P:F: x do case $x in b) FORCEBIB=yes;; B) USEBIB=no;; c) if [ "x$CHECK" = "xno" ] ; then CHECK=yes else CHECK=no fi;; n) if [ "x$DOTMP" = "xno" ] ; then DOTMP=yes else DOTMP=no fi;; v) if [ "x$DOPREVIEW" = "xno" ] ; then DOPREVIEW=yes else DOPREVIEW=no fi;; p) if [ "x$DOPRINT" = "xno" ] ; then DOPRINT=yes else DOPRINT=no fi;; F) if [ "x$FORCEFORMAT" = "xno" ] ; then FORCEFORMAT=yes FFORMAT="$OPTARG" else FORCEFORMAT=no fi ;; l) if [ "x$SEELOG" = "xno" ] ; then SEELOG=yes else SEELOG=no fi;; i) INSTREAM="/dev/tty" SEELOG=yes ;; P) PRINTER="$OPTARG"; export PRINTER ;; d) DVITOPSOPTS="$DVITOPSOPTS $OPTARG" ;; 2) if [ "x$TWOUP" = "xno" ] ; then TWOUP=yes else TWOUP=no fi;; h) usage;; \?) usage;; esac done shift `expr $OPTIND - 1` # # ======================================================================== # == Locate the file to use == # ======================================================================== # if [ $# -eq 0 ] ; then usage fi FNAME=$1 if [ ! -f $FNAME.tex ] ; then TT=`echo $FNAME | sed 's/\.tex//'` if [ ! -f $TT.tex ] ; then nosuchfile else FNAME=$TT fi fi if [ "$CHECK" = "yes" ] ; then echo "File $FNAME.tex located" ; fi # Set the output file if [ "x$SEELOG" = "xyes" ] ; then SEEFILE="/dev/tty" else SEEFILE="/dev/null" fi # # ======================================================================== # == Check encoding of file == # ======================================================================== # if isencoded ; then ENCODED=yes if [ "$CHECK" = "yes" ] ; then echo "File $FNAME.tex is greek encoded" ; fi else ENCODED=no fi # # ======================================================================== # == Verify TeX Format File == # ======================================================================== # if $SGREP '^[^%]*\\documentclass' $FNAME.tex ; then EXEC=$LATEX2E elif $SGREP '^[^%]*\\documentstyle' $FNAME.tex ; then if latexstyle gr.* $FNAME.tex \ || latexoption greek $FNAME.tex \ || $SGREP '^\%\%.*TeX\:.*grlatex' $FNAME.tex ; then EXEC=$GRLATEX elif latexstyle slides $FNAME.tex ; then EXEC=$SLITEX elif nfsslatexstyle $FNAME.tex ; then EXEC=$NFSSLATEX else EXEC=$LATEX fi elif $SGREP '^\\input greektex' $FNAME.tex \ || $SGREP -i '^%.*Use: GreekTeX' $FNAME.tex ; then EXEC=$GREEKTEX else EXEC=$TEX fi if [ "$FORCEFORMAT" = "yes" ] ; then EXEC=$FFORMAT if [ "$CHECK" = "yes" ] ; then echo "Format accepted as $EXEC" ; fi else if [ "$CHECK" = "yes" ] ; then echo "Format Verified as $EXEC" ; fi fi # # ======================================================================== # == Check For BibTeX calls == # ======================================================================== # if $SGREP '^[^%]*\\bibliography{' $FNAME.tex ; then NEEDBIB=$BIBTEX else NEEDBIB=no fi if [ "$USEBIB" = "no" ] ; then if [ "$CHECK" = "yes" -a $NEEDBIB = $BIBTEX ] ; then echo "Need for Bibtex suppresed" ; fi NEEDBIB=no else if [ "$CHECK" = "yes" -a $NEEDBIB = $BIBTEX ] ; then echo "Need for Bibtex verified" ; fi fi if latexoption chapterbib $FNAME.tex || latexstyle phd $FNAME.tex \ || latexoption specialbib $FNAME.tex ;then SEPERATEBIB=yes NEEDBIB=$BIBTEX else SEPERATEBIB=no fi if [ "$FORCEBIB" = "yes" -a $NEEDBIB != $BIBTEX ] ; then NEEDBIB=$BIBTEX SEPERATEBIB=no if [ "$CHECK" = "yes" ] ; then echo "Need for Bibtex accepted" fi else if [ "$CHECK" = "yes" -a "$SEPERATEBIB" = "yes" ] ; then echo "Need for Seperate Bibtex verified" ; fi fi # # ======================================================================== # == Check For index need == # ======================================================================== # if indexneeded ; then NEEDINDEX=yes else NEEDINDEX=no fi if [ "$CHECK" = "yes" -a "$NEEDINDEX" = "yes" ] ; then echo "Need for indexing verified" ; fi # # ======================================================================== # == Create tmp dir and start work == # ======================================================================== # HERE=`pwd` if [ "$DOTMP" = "yes" ] ; then OURTMP=/tmp/typeset.$$ if [ "$PTSTUPIDTEX" = "YES" ]; then MYTEXINPUTS=".:$HERE:$MYTEXINPUTS"; export MYTEXINPUTS BIBINPUTS=".:$HERE:$BIBINPUTS" ; export BIBINPUTS else TEXINPUTS=".:$HERE:$TEXINPUTS"; export TEXINPUTS BIBINPUTS=".:$HERE:$BIBINPUTS" ; export BIBINPUTS fi mkdir $OURTMP cd $OURTMP else OURTMP=`pwd` fi trap 'cleanup;exit' 1 2 3 6 9 # # ======================================================================== # == Change to ascii == # ======================================================================== # if [ "$ENCODED" = "yes" ] ; then $GREEK2ASCII <$HERE/$FNAME.tex >$FNAME.tex ALLIN=`cat $FNAME.tex | findincludedfiles ` for ff in $ALLIN do $GREEK2ASCII <$HERE/$ff.tex >$ff.tex done if [ "$CHECK" = "yes" ] ; then echo "File un-encoded" ; fi fi # # ======================================================================== # == Create stupid index file first == # ======================================================================== # # this is needed to keep include command in latex happy even when # file is not there! # if [ "$NEEDINDEX" = "yes" ] ; then cat /dev/null >$FNAME.ind fi # # ======================================================================== # == First Pass -- TeXing == # ======================================================================== # if [ "$CHECK" = "yes" ] ; then echo -n "First Pass..." ; fi if $EXEC $FNAME.tex <$INSTREAM >$SEEFILE ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerrorwithlog "Executing first $EXEC" fi # # ======================================================================== # == BibTeX Pass & Second TeXing Pass == # ======================================================================== # if [ "$NEEDBIB" != "no" ] ; then STAGE=1 if [ "$SEPERATEBIB" = "no" ] ; then if [ "$CHECK" = "yes" ] ; then echo -n "Bibtex..."; fi if $BIBTEX $FNAME <$INSTREAM >$SEEFILE; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi STAGE=2 else typerror "Executing $BIBTEX" fi else if [ "$CHECK" = "yes" ] ; then echo -n "Bibtex..."; fi FILEOOO=`cat $HERE/$FNAME.tex | findincludedfiles` if [ "$CHECK" = "yes" ] ; then echo Seperate Bibliography Files: $FILEOOO fi for ff in $FILEOOO do if $BIBTEX $ff <$INSTREAM >$SEEFILE; then STAGE=2 else typerrorwithlog "Executing Seperate Bibtex" fi done fi if [ "$STAGE" = "2" ]; then if [ "$CHECK" = "yes" ] ; then echo -n "Second Pass..." ; fi if $EXEC $FNAME.tex <$INSTREAM >$SEEFILE ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerrorwithlog "Executing second $EXEC" fi fi fi # # if the log file indicates so do another pass # RunAgainIfNeeded # # if we need indexing do it # indexingStage # # if we still have cross-references or TOC re-run # RunAgainIfNeeded # if [ "$ONLYDVI" = "yes" ] ; then if [ "x$DOPREVIEW" = "xyes" ] ; then $XDVI $OURTMP/$FNAME.dvi if [ "$CHECK" = "yes" ] ; then echo "Cleaning up" ; fi fi if [ "x$DOPRINT" != "xyes" -a "$DOTMP" = "yes" ] ; then mv $OURTMP/$FNAME.dvi $HERE fi cleanup exit fi # # ======================================================================== # == Convert to PS File == # ======================================================================== # cd $HERE if [ "$CHECK" = "yes" ] ; then echo -n "Converting to ps..." ; fi if $DVITOPS $OURTMP/$FNAME -q -o $OURTMP/$FNAME.ps $DVITOPSOPTS <$INSTREAM >$SEEFILE ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerror "Converting to PS" fi if [ "$TWOUP" = "yes" ] ; then if [ "$CHECK" = "yes" ] ; then echo -n "Converting to 2up..." ; fi mv $OURTMP/$FNAME.ps $OURTMP/$FNAME.ps.1 if $TWOUPFILTER $OURTMP/$FNAME.ps.1 >$OURTMP/$FNAME.ps ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi rm $OURTMP/$FNAME.ps.1 else mv $OURTMP/$FNAME.ps.1 $OURTMP/$FNAME.ps typerror "Converting to 2up" fi fi # # ======================================================================== # == What to Do with the PS file == # ======================================================================== # if [ "x$DOPREVIEW" = "xyes" ] ; then $DVIPREVIEWER $OURTMP/$FNAME.ps else if [ "x$DOPRINT" = "xyes" ] ; then if [ "$CHECK" = "yes" ] ; then echo -n "Sending PS to printer..." fi if $PRINTCMND $OURTMP/$FNAME.ps ; then if [ "$CHECK" = "yes" ] ; then echo "done" ; fi else typerror "running $PRINTCMND" fi else if [ "$DOTMP" = "yes" ] ; then mv $OURTMP/$FNAME.ps . fi fi fi # # ======================================================================== # == Finished - Clean Up and Exit == # ======================================================================== # if [ "$CHECK" = "yes" ] ; then echo "Cleaning up" ; fi cleanup # ======================================================================== # == END - OF - FILE == # ========================================================================