summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/texsis/base/letr
blob: ad4697fc80e90b7f4aea4c9f8d6c9a66a5a0c82f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/sh 
#
# letr -  a Unix shell script for printing a letter with an addressed
# envelope, using TeXsis (the TeX macros for physicists).  The syntax is: 
#
#  	letr [ -q ][ -Pprinter ] [ dvips flags ] [ filename ]
#
# where "filename" is the name for your TeX job.  The TeX instructions
# for creating your letter will be put in the file filename.tex, while
# the instructions for creating the printed envelope will be in the
# file filename.env.   If no name is given the default is "TeXletter".
#
# You first edit your letter with your default EDITOR, then it is run
# through TeXsis.  You can preview the letter, and then choose whether
# or not to print it, and whether or not to print the addressed envelope.
#
# Use the -q flag to bypass the editor, and -P to specify an alternate
# printer.  All other flags are passed to dvips.  So, for example, if
# you give the -m flag it will go to dvips and the letter (not just the
# envelope) will be printed in manual feed mode, so you can put your own
# paper in the printer for it.
#
# To get the envelope to print in landscape mode and with manual feed
# we call dvips explicitly.  If you need to, change the DVIPS command 
# and ENVFLAGS below to match your local site configuration.
#
# Eric Myers <myers@umich.edu> 	- 27 January 1996
# Department of Physics, University of Michigan, Ann Arbor
# @(#) $Id: letr,v 1.7 2000/06/01 20:02:30 myers Exp $
######################################################################
# Local Customization: 

EDITOR=${EDITOR-"emacs"}   	# editor (default to emacs)
DVIVIEW=${DVIVIEW-"xdvi"}	# dvi file viewer (dviview is more general)
DVIPS=${DVIPS-"dvips -q"}	# general dvips command
ENVLFLAGS="-m -t landscape"	# dvips flags for the envelope

#====================(end of customization)====================*

##  Parse command line arguments.  Unrecognized ones are saved for dvips 

FNAME=${FNAME-"TeXletter"}   	# name of file to process
FLAGS=" "                  	# flags to pass on to dvips
NOEDIT=""

while [ $# != 0 ]
do      case "$1" in
	-P*)    PRINTER=`echo $1 | tail +3c`    # strip off the -P
		LPDEST=$PRINTER		;; 
	-q)	NOEDIT="NOEDIT" 	;;
        -*)     FLAGS="$FLAGS $1" 	;;
         *)     FNAME="$1" 		;;
        esac
        shift
done

PROG=`basename $0` 

###############
# Determine which printer we shall use, and how.  In NeXTStep the lpr
# command ignores the $PRINTER variable, so we will correct for that
# here by always using `lpr -P$PRINTER`, with "Local_Printer" as the
# default.  For other Unix change default printer to 'lp'.  For SYSV
# we need to use "lp -d$LPDEST" instead.

if [ -x /usr/ucb/lpr ]; then
  if [ -x /sdmach ]; then		# NeXTStep
    PRINTER=${PRINTER-"Local_Printer"}	
  else					# other BSD 
    PRINTER=${PRINTER-"lp"}
  fi
  # The -h option suppresses the banner page
  LPR="/usr/ucb/lpr -h -P$PRINTER"
fi
  
if [ -x /usr/bin/lpr ]; then		# BSD (Linux, Solaris)
    PRINTER=${PRINTER-"lp"}
    # The -h option suppresses the banner page
    LPR="/usr/bin/lpr -h -P$PRINTER"
fi

if [ -x /usr/bin/lp ]; then		# SYSV (eg. HP-UX)
  LPDEST=${LPDEST-"lp"}			
  # The -onb option suppresses the banner page on HP LaserJet3/4 (and 5?)
  LPR="/usr/bin/lp -onb -d${LPDEST} "	
fi

if [ ! $?LPR ]; then
  echo "Cannot determine lpr/lp command."
  exit 2
fi

## Figure out line end suppression for BSD or SYSV

if [ "`echo 'EC\c'; echo HO`"  =  "ECHO" ]; then
  SYSVNL="\c"; BSDNL="" # System V line control
else
  BSDNL="-n"; SYSVNL="" # BSD line control
fi

##  the function `ask_def default text` asks a question and returns 
##    the user's answer, using the default if just <cr> is pressed.

ask_def () {
    DEFAULT=$1 ;     shift
    echo ${BSDNL} "$* [${DEFAULT}] ${SYSVNL}" 
    read ANS
    if [ -z "$ANS" ]; then ANS=$DEFAULT ; fi
    export ANS; }


##  Strip off .tex from the filename, if it is included. 
##    Any trailing . is also removed (helps for tcsh filename completion).

FNAME=`basename $FNAME .tex`           # get just the file name, strip .tex
FNAME=`basename $FNAME .`              # get just the file name, strip "."

##  If the named TeX file does not exist, create it with a simple
##  TeXsis \letter template 

if [ ! -f ${FNAME}.tex ]; then 
cat >${FNAME}.tex <<End-of-Text
\\texsis
\\letter
\\withEnvelope	% if you also want to print an envelope
\\def\\Email{}% <-- set e-mail address if you want it in the letterhead
\\letterhead{}% <-- phone number or extension goes here
\\address
NAME OF ADDRESSEE HERE
ADDRESS GOES HERE
AS MANY LINES AS YOU NEED
   
\\body
Dear WHOEVER,

BODY OF LETTER GOES HERE.

AS MANY PARAGRAPHS AS YOU WANT.

\\closing
Sincerely,
YOUR NAME HERE

\bye
End-of-Text
fi


##  Edit the file with EDITOR, unless -q flag was given

if [ -z "$NOEDIT" ]; then
  if $EDITOR ${FNAME}.tex 
  then   echo " "
  else
    echo "${PROG}: ${EDITOR} editing error ($?).  Bailing out..."
    exit 1
  fi
fi

if [ ! -f ${FNAME}.tex ]; then exit 0 ; fi

##  Process through TeXsis 

if [ -z "$NOEDIT" ]; then
  ask_def yes "Process file ${FNAME}.tex through TeXsis? "
else
  ANS="yes"
fi

case $ANS in
  yes|Y|y|YES|Yes) 
     if texsis ${FNAME}.tex  
     then   
        echo " "
     else
       echo "${PROG}: TeXsis error ($?).  Bailing out..."
       exit 1
     fi ;;
  *) exit 0
esac


##  Preview the .dvi file, if desired 

if [ -f ${FNAME}.dvi ]; then

  ask_def yes "Do you want to preview the letter? "
  case $ANS in
      yes|Y|y|YES|Yes)	echo " " 
	$DVIVIEW ${FNAME} #>/dev/null 2>&1   
	sleep 1 ;;
  esac

  echo " "
  echo "Default printer is '${PRINTER}'."
  ask_def yes "Do you want to print this now? "
  case $ANS in
      yes|Y|y|YES|Yes) 
	${DVIPS} ${FLAGS} ${FNAME}.dvi	# >/dev/null 2>&1   
	echo "Printing the letter..."
        ${LPR} ${FNAME}.ps ;;
      *);;
  esac

fi


##  Process envelope, if desired and it exists 

if [ -f ${FNAME}.env ]; then

  ask_def yes "Do you want to print the envelope? "
  case $ANS in
      yes|Y|y|YES|Yes) 
        /bin/rm -rf ${FNAME}.dvi ${FNAME}.ps
	texsis ${FNAME}.env 	
        $DVIPS ${FLAGS} ${ENVLFLAGS}  ${FNAME}.dvi	## >/dev/null 2>&1   
	echo "Printing the envelope...   Please feed the printer. " 
        ${LPR}  ${FNAME}.ps 
  esac

else
  echo "No envelope file ${FNAME}.env was found."
fi
 
# Clean up: remove .dvi file, .ps file, and .log file (but keep .env file).

/bin/rm -f ${FNAME}.dvi ${FNAME}.log ${FNAME}.ps

exit 0