| 1 | #!/bin/sh |
| 2 | # |
| 3 | # letr - a Unix shell script for printing a letter with an addressed |
| 4 | # envelope, using TeXsis (the TeX macros for physicists). The syntax is: |
| 5 | # |
| 6 | # letr [ -q ][ -Pprinter ] [ dvips flags ] [ filename ] |
| 7 | # |
| 8 | # where "filename" is the name for your TeX job. The TeX instructions |
| 9 | # for creating your letter will be put in the file filename.tex, while |
| 10 | # the instructions for creating the printed envelope will be in the |
| 11 | # file filename.env. If no name is given the default is "TeXletter". |
| 12 | # |
| 13 | # You first edit your letter with your default EDITOR, then it is run |
| 14 | # through TeXsis. You can preview the letter, and then choose whether |
| 15 | # or not to print it, and whether or not to print the addressed envelope. |
| 16 | # |
| 17 | # Use the -q flag to bypass the editor, and -P to specify an alternate |
| 18 | # printer. All other flags are passed to dvips. So, for example, if |
| 19 | # you give the -m flag it will go to dvips and the letter (not just the |
| 20 | # envelope) will be printed in manual feed mode, so you can put your own |
| 21 | # paper in the printer for it. |
| 22 | # |
| 23 | # To get the envelope to print in landscape mode and with manual feed |
| 24 | # we call dvips explicitly. If you need to, change the DVIPS command |
| 25 | # and ENVFLAGS below to match your local site configuration. |
| 26 | # |
| 27 | # Eric Myers <[email protected]> - 27 January 1996 |
| 28 | # Department of Physics, University of Michigan, Ann Arbor |
| 29 | # @(#) $Id: letr,v 1.7 2000/06/01 20:02:30 myers Exp $ |
| 30 | ###################################################################### |
| 31 | # Local Customization: |
| 32 | |
| 33 | EDITOR=${EDITOR-"emacs"} # editor (default to emacs) |
| 34 | DVIVIEW=${DVIVIEW-"xdvi"} # dvi file viewer (dviview is more general) |
| 35 | DVIPS=${DVIPS-"dvips -q"} # general dvips command |
| 36 | ENVLFLAGS="-m -t landscape" # dvips flags for the envelope |
| 37 | |
| 38 | #====================(end of customization)====================* |
| 39 | |
| 40 | ## Parse command line arguments. Unrecognized ones are saved for dvips |
| 41 | |
| 42 | FNAME=${FNAME-"TeXletter"} # name of file to process |
| 43 | FLAGS=" " # flags to pass on to dvips |
| 44 | NOEDIT="" |
| 45 | |
| 46 | while [ $# != 0 ] |
| 47 | do case "$1" in |
| 48 | -P*) PRINTER=`echo $1 | tail +3c` # strip off the -P |
| 49 | LPDEST=$PRINTER ;; |
| 50 | -q) NOEDIT="NOEDIT" ;; |
| 51 | -*) FLAGS="$FLAGS $1" ;; |
| 52 | *) FNAME="$1" ;; |
| 53 | esac |
| 54 | shift |
| 55 | done |
| 56 | |
| 57 | PROG=`basename $0` |
| 58 | |
| 59 | ############### |
| 60 | # Determine which printer we shall use, and how. In NeXTStep the lpr |
| 61 | # command ignores the $PRINTER variable, so we will correct for that |
| 62 | # here by always using `lpr -P$PRINTER`, with "Local_Printer" as the |
| 63 | # default. For other Unix change default printer to 'lp'. For SYSV |
| 64 | # we need to use "lp -d$LPDEST" instead. |
| 65 | |
| 66 | if [ -x /usr/ucb/lpr ]; then |
| 67 | if [ -x /sdmach ]; then # NeXTStep |
| 68 | PRINTER=${PRINTER-"Local_Printer"} |
| 69 | else # other BSD |
| 70 | PRINTER=${PRINTER-"lp"} |
| 71 | fi |
| 72 | # The -h option suppresses the banner page |
| 73 | LPR="/usr/ucb/lpr -h -P$PRINTER" |
| 74 | fi |
| 75 | |
| 76 | if [ -x /usr/bin/lpr ]; then # BSD (Linux, Solaris) |
| 77 | PRINTER=${PRINTER-"lp"} |
| 78 | # The -h option suppresses the banner page |
| 79 | LPR="/usr/bin/lpr -h -P$PRINTER" |
| 80 | fi |
| 81 | |
| 82 | if [ -x /usr/bin/lp ]; then # SYSV (eg. HP-UX) |
| 83 | LPDEST=${LPDEST-"lp"} |
| 84 | # The -onb option suppresses the banner page on HP LaserJet3/4 (and 5?) |
| 85 | LPR="/usr/bin/lp -onb -d${LPDEST} " |
| 86 | fi |
| 87 | |
| 88 | if [ ! $?LPR ]; then |
| 89 | echo "Cannot determine lpr/lp command." |
| 90 | exit 2 |
| 91 | fi |
| 92 | |
| 93 | ## Figure out line end suppression for BSD or SYSV |
| 94 | |
| 95 | if [ "`echo 'EC\c'; echo HO`" = "ECHO" ]; then |
| 96 | SYSVNL="\c"; BSDNL="" # System V line control |
| 97 | else |
| 98 | BSDNL="-n"; SYSVNL="" # BSD line control |
| 99 | fi |
| 100 | |
| 101 | ## the function `ask_def default text` asks a question and returns |
| 102 | ## the user's answer, using the default if just <cr> is pressed. |
| 103 | |
| 104 | ask_def () { |
| 105 | DEFAULT=$1 ; shift |
| 106 | echo ${BSDNL} "$* [${DEFAULT}] ${SYSVNL}" |
| 107 | read ANS |
| 108 | if [ -z "$ANS" ]; then ANS=$DEFAULT ; fi |
| 109 | export ANS; } |
| 110 | |
| 111 | |
| 112 | ## Strip off .tex from the filename, if it is included. |
| 113 | ## Any trailing . is also removed (helps for tcsh filename completion). |
| 114 | |
| 115 | FNAME=`basename $FNAME .tex` # get just the file name, strip .tex |
| 116 | FNAME=`basename $FNAME .` # get just the file name, strip "." |
| 117 | |
| 118 | ## If the named TeX file does not exist, create it with a simple |
| 119 | ## TeXsis \letter template |
| 120 | |
| 121 | if [ ! -f ${FNAME}.tex ]; then |
| 122 | cat >${FNAME}.tex <<End-of-Text |
| 123 | \\texsis |
| 124 | \\letter |
| 125 | \\withEnvelope % if you also want to print an envelope |
| 126 | \\def\\Email{}% <-- set e-mail address if you want it in the letterhead |
| 127 | \\letterhead{}% <-- phone number or extension goes here |
| 128 | \\address |
| 129 | NAME OF ADDRESSEE HERE |
| 130 | ADDRESS GOES HERE |
| 131 | AS MANY LINES AS YOU NEED |
| 132 | |
| 133 | \\body |
| 134 | Dear WHOEVER, |
| 135 | |
| 136 | BODY OF LETTER GOES HERE. |
| 137 | |
| 138 | AS MANY PARAGRAPHS AS YOU WANT. |
| 139 | |
| 140 | \\closing |
| 141 | Sincerely, |
| 142 | YOUR NAME HERE |
| 143 | |
| 144 | \bye |
| 145 | End-of-Text |
| 146 | fi |
| 147 | |
| 148 | |
| 149 | ## Edit the file with EDITOR, unless -q flag was given |
| 150 | |
| 151 | if [ -z "$NOEDIT" ]; then |
| 152 | if $EDITOR ${FNAME}.tex |
| 153 | then echo " " |
| 154 | else |
| 155 | echo "${PROG}: ${EDITOR} editing error ($?). Bailing out..." |
| 156 | exit 1 |
| 157 | fi |
| 158 | fi |
| 159 | |
| 160 | if [ ! -f ${FNAME}.tex ]; then exit 0 ; fi |
| 161 | |
| 162 | ## Process through TeXsis |
| 163 | |
| 164 | if [ -z "$NOEDIT" ]; then |
| 165 | ask_def yes "Process file ${FNAME}.tex through TeXsis? " |
| 166 | else |
| 167 | ANS="yes" |
| 168 | fi |
| 169 | |
| 170 | case $ANS in |
| 171 | yes|Y|y|YES|Yes) |
| 172 | if texsis ${FNAME}.tex |
| 173 | then |
| 174 | echo " " |
| 175 | else |
| 176 | echo "${PROG}: TeXsis error ($?). Bailing out..." |
| 177 | exit 1 |
| 178 | fi ;; |
| 179 | *) exit 0 |
| 180 | esac |
| 181 | |
| 182 | |
| 183 | ## Preview the .dvi file, if desired |
| 184 | |
| 185 | if [ -f ${FNAME}.dvi ]; then |
| 186 | |
| 187 | ask_def yes "Do you want to preview the letter? " |
| 188 | case $ANS in |
| 189 | yes|Y|y|YES|Yes) echo " " |
| 190 | $DVIVIEW ${FNAME} #>/dev/null 2>&1 |
| 191 | sleep 1 ;; |
| 192 | esac |
| 193 | |
| 194 | echo " " |
| 195 | echo "Default printer is '${PRINTER}'." |
| 196 | ask_def yes "Do you want to print this now? " |
| 197 | case $ANS in |
| 198 | yes|Y|y|YES|Yes) |
| 199 | ${DVIPS} ${FLAGS} ${FNAME}.dvi # >/dev/null 2>&1 |
| 200 | echo "Printing the letter..." |
| 201 | ${LPR} ${FNAME}.ps ;; |
| 202 | *);; |
| 203 | esac |
| 204 | |
| 205 | fi |
| 206 | |
| 207 | |
| 208 | ## Process envelope, if desired and it exists |
| 209 | |
| 210 | if [ -f ${FNAME}.env ]; then |
| 211 | |
| 212 | ask_def yes "Do you want to print the envelope? " |
| 213 | case $ANS in |
| 214 | yes|Y|y|YES|Yes) |
| 215 | /bin/rm -rf ${FNAME}.dvi ${FNAME}.ps |
| 216 | texsis ${FNAME}.env |
| 217 | $DVIPS ${FLAGS} ${ENVLFLAGS} ${FNAME}.dvi ## >/dev/null 2>&1 |
| 218 | echo "Printing the envelope... Please feed the printer. " |
| 219 | ${LPR} ${FNAME}.ps |
| 220 | esac |
| 221 | |
| 222 | else |
| 223 | echo "No envelope file ${FNAME}.env was found." |
| 224 | fi |
| 225 | |
| 226 | # Clean up: remove .dvi file, .ps file, and .log file (but keep .env file). |
| 227 | |
| 228 | /bin/rm -f ${FNAME}.dvi ${FNAME}.log ${FNAME}.ps |
| 229 | |
| 230 | exit 0 |