%GLETTER.TEX, VERSION 2.0
% January 7, 1989
% Written by Alan Guth

% January 7, 1989 change:
% \labelht set to 1truein (was .985truein) for normal size
%   labels.

% December 13, 1988 changes:
% Simplequote definition moved so that active " could be used in
%   address macros.  Previously was after \def\stretch.
% Quotesave introduced with getline macros.
% Nosimplequotes added to completeaddress macro.

\newif\ifapple  \applefalse

%PERSONALIZATION OF LETTERHEADS:  A SAMPLE GLETPERS.TEX FILE
 %To select the Center for Theoretical Physics as the default
 % division in the letterhead, use
    \def\wdivision{Center for Theoretical Physics}
 %The division can of course be changed if desired.

 %Redefine symbol ":" to allow extra space on each side
    \def\colon{:} \catcode`:=\active \gdef:{$\,$\colon$\,$}

 %Format for personalized letterhead information:
 %  Sample entry for letters from Alan Guth:
 \def\ag{\def\wroom{Room 6-209} \def\wtelephone{(617)-253-6265}
    \def\wemail{GUTH@MITLNS} \def\dsecretary{AHG:cn}}

 %To add new names, duplicate the two lines following this paragraph,
 %  omit the % signs at the start of each line, and replace each @
 %  sign by the desired information.  The first @ is replaced
 %  by the person's initials, or whatever other code is desired
 %  for identification.  The letterhead information will be
 %  automatically input by typing a backslash followed by these
 %  letters.  Each of the other @'s should be replaced by the
 %  appropriate information.  If you want to omit the item, then
 %  delete the @, leaving the rest of the command.

 %\def\@{\def\wroom{Room @} \def\wtelephone{@}
 %   \def\wemail{@} \def\dsecretary{@}}

 %Redefine symbol ":" to normal definition
   \catcode`:=12

%END OF SAMPLE GLETPERS.TEX FILE

%Redefinition of \alloc@ and \newinsert, to avoid writing of
%   counter numbers to output .lis file
% We make @ signs act like letters, temporarily.
\catcode`@=11
\def\alloc@#1#2#3#4#5{\global\advance\count1#1by\@ne
  \ch@ck#1#4#2% make sure there's still room
  \allocationnumber=\count1#1%
  \global#3#5=\allocationnumber
  \writelog{#5}{#2}}
\outer\def\newinsert#1{\global\advance\insc@unt by\m@ne
  \ch@ck0\insc@unt\count
  \ch@ck1\insc@unt\dimen
  \ch@ck2\insc@unt\skip
  \ch@ck4\insc@unt\box
  \allocationnumber=\insc@unt
  \global\chardef#1=\allocationnumber
  \writelog{#1}{\insert}}
\def\writelog#1#2{}
\catcode`@=12 % at signs are no longer letters

%QUOTATION MARKS
%  In order to avoid the need for typing `` and '' for opening
%  and closing quotes, gletter redefines " as an active
%  character.  Alternate occurences are defined as `` and then
%  ''.  These definitions are created by the macro \simplequotes,
%  which is on by default, and can be cancelled by
%  \nosimplequotes.

\def\quote{"}
\catcode`"=\active
\def\simplequotes{\def\openquote{``\def"{\closequote}}
  \def\closequote{''\def"{\openquote}} \def"{\openquote}}
\def\nosimplequotes{\def"{\quote}}
\simplequotes

%\new declarations
\newif\ifstartcc \newdimen\labelwd \newdimen\labelht \newdimen\labelsep
\newdimen\addresslimit \newdimen\raddresslimit
\newskip\addressskip \newskip\sigskip \newdimen\sigindent
\newskip\closingskip \newskip\letterheadskip
\newif\ifsetaddressee \newif\ifsetauthor
\newskip\textbaselineskip \newskip\shortbaselineskip
\newskip\minbaselineskip \newskip\longbaselineskip
\newskip\textparskip \newskip\shortparskip \newskip\minparskip
\newskip\longparskip \newcount\boxnum \newcount\boxstart
\newcount\boxstop \newcount\linecount \newif\ifsaveaddress
\newcount\datestyle \newcount\numa \newcount\numb \newcount\numc
\newif\iflabelsend \newif\iflabeldone \newcount\labelline
\newcount\labelstyle \newcount\labelcopies \newcount\labelpageno
\newdimen\labelvsize \newdimen\labelvoffset \newdimen\labelhsize
\newdimen\labelhoffset \newif\iffullpage \newif\ifpagefit
\newdimen\testht \newif\ifnotest \newif\ifmemo \newcount\columns
\newcount\lcount \newdimen\spacea \newdimen\spaceb
\newdimen\spacec \newdimen\spaced \newdimen\spacee
\newdimen\spacef \newdimen\spaceg \newcount\texttype
\newdimen\topspace \newinsert\topspaceinsert
\skip\topspaceinsert=0pt \count\topspaceinsert=1000
\dimen\topspaceinsert=\maxdimen \newtoks\toksa \newtoks\toksb
\newbox\boxa \newbox\boxb \newbox\boxc \newdimen\digitwidth
\newdimen\commawidth \newif\ifheadwrite \newdimen\letterheadspace
\newdimen\spaceindent \newdimen\labeltop \newdimen\labelbottom
\newbox\raddressbox \boxstart=\count14 \advance\boxstart by 1
\boxnum=\boxstart \boxstop=\boxstart \advance\boxstop by 20
\count14=\boxstop \saveaddressfalse \labelstyle=1 \labelpageno=1
\labelcopies=1 \headwritetrue
%End of \new declarations

%Restore original meaning to \alloc@ and \newinsert
\def\writelog#1#2{\wlog{\string#1=\string#2\the\allocationnumber}}

\ifdim\hsize>0pt \magnification=1200 \fi
\font\tenrmm=cmr10 at 12truept     %Used for 4 line addresses
\font\ninermm=cmr9 at 10.8truept   %Used for 5 line addresses
\font\eightrmm=cmr8 at 9.6truept   %Used for 6 line addresses
\font\sevenrmm=cmr7 at 8.4truept   %Used for 7 line addresses
\font\sixrmm=cmr6   at 7.2truept   %Used for 8 line addresses

\input gfont.tex
%\ifapple \input nuke:[bqs.tex.gletter]gfont.tex \else
%\input nuke:[bqs.tex.gletter]gfont.tex
%\fi

% To print on the Applewriter on the CFA, type the command
%   \applewriter once to reset the offsets.  To undo, type
%   \noapplewriter

\def\applewriter{\advance\hoffset by-1truein\advance\voffset
     by-1truein  \appletrue}
\def\noapplewriter{\advance\hoffset by 1truein\advance\voffset
     by 1truein  \applefalse}
\ifapple \applewriter \fi


%Definitions necessary for \reset of parameters:

%To select \ag (Alan Guth) as the default letterhead, use
%  \ag \def\personalize{\ag}
%For impersonal letterhead,
   \def\impersonal{\def\wroom{} \def\wtelephone{} \def\wemail{}
       \def\dsecretary{}}
%To default to a letterhead with no personalized information, use
   \def\personalize{\impersonal}

\let\finalend=\end
\def\saveaddress{\saveaddresstrue \def\end{\makelabels
  \finalend}}
\def\nosaveaddress{\saveaddressfalse}
\def\pagenumbers{\footline={\hss\normal\folio\hss}}
\def\folio{\ifnum\pageno=1\nopagenumbers\else\number\pageno\fi}

\def\settable{\global\columns=8 \global\spacea=20pt
   \global\spaceb=20pt \global\spacec=20pt \global\spaced=20pt
   \global\spacee=20pt \global\spacef=20pt \global\spaceg=20pt}
\def\minireset{\startcctrue \setaddresseefalse \setauthorfalse}
\def\mit{\def\letterhead{\mitletterhead}
   \letterheadskip=-0.15truein \hsize=6.4truein
   \hoffset=1.0truein \voffset=1.0truein \vsize=8.9truein
   \datestyle=1 \sigindent=3truein \ifapple \advance\hoffset by
   -1truein \advance\voffset by -1truein \fi}
   %See explanation below.
\def\cfa{\def\letterhead{\cfaletterhead}
   \letterheadskip=-0.15truein \hsize=6truein \hoffset=1.25truein
   \voffset=1.0truein \vsize=8.75truein \datestyle=2
   \sigindent=3.5truein \ifapple \advance\hoffset by -1truein
   \advance\voffset by -1truein \fi}
\def\noletterhead{\def\letterhead{\blankletterhead}
   \letterheadskip=-0.15truein \hsize=6.4truein
   \hoffset=1.0truein \voffset=1.0truein \vsize=8.9truein
   \datestyle=4 \sigindent=3truein \ifapple \advance\hoffset by
   -1truein \advance\voffset by -1truein \fi}
%\def\noletterhead{\def\letterhead{\blankletterhead}
%   \letterheadskip=-0.15truein \hsize=16.5truecm
%   \hoffset=2.0truecm \voffset=2.0truecm \vsize=25truecm
%   \datestyle=4 \sigindent=8.25truecm \ifapple \advance\hoffset by
%   -1truein \advance\voffset by -1truein \fi}
\def\telaviv{\noletterhead\letterheadspace=2in}
\def\nodate{\datestyle=0}
%See explanation below.
%End of definition package

%Explanations:
%  This macro package can produce either of two letterheads, and
%  the commands \mit and \cfa determine one or the other.  It can
%  also produce a letter with no letterhead, using \noletterhead.
%  In that case one can set the parameter \letterheadspace = ...
%  to allow room for a letterhead on the stationary.  The
%  parameter \sigindent determines the indentation of the
%  signature (closing) material (e.g., Sincerely yours,), and has
%  different default values for the two letterheads.  The date
%  can be handled in any of four styles, indicated by \datestyle.
%  \datestyle=0 omits date.  \datestyle=1 produces a date flush
%  against the right margin.  \datestyle=2 produces a date
%  indented by \sigindent.  \datestyle=3 is for memos, producing
%  a date in the form:
%    Date:  February 22, 1987
%  beginning at the left margin.  \datestyle=4 includes the date
%  with a return address at the upper right, and defaults to
%  \datestyle=1 when no return address has been entered.
%  \datestyle=1 is the default for the MIT letterhead, while
%  \datestyle=2 is the default for the cfa letterhead.  It is
%  recommended that one use \sigindent=3.5 truein with
%  \datestyle=2.  \datestyle=4 is the default for \noletterhead,
%  or if a return address has been entered.
%
%  The shifts conditioned on \ifapple are included because the
%  applewriter starts with a home position one inch down and one
%  inch in, in contrast to the Imagen which begins right at the
%  corner of the page.
%
%  A change has been made since Version 1.0 concerning vertical
%  positioning.  Any letterhead designed for the earlier version
%  should be modified by adding a \vskip 22.5 pt at the
%  beginning.


%Definitions necessary for headlines:
%  The macro package will normally put a headline on all pages
%  after the first.  The default style, created by
%  \headlinestylea, creates a single headline consisting of the
%  name of the addressee, the date, and page number.
%  \headlinestyleb creates a more unusual headline: on the left is
%  the author's name, followed by a double colon and then the
%  addressee; below this is the date, and the page number is at
%  the right.  To delete the headline, use \noheadline.  To number
%  the pages instead, type \pagenumbers: numbers will appear at
%  the bottom of all pages except the first.  To change the name
%  of the addressee to something other than the first line of the
%  address, type \addressee ..... .  For \headlinestyleb, the name
%  of the author can be changed to something other than the
%  second line of the closing by typing \author ..... .  In
%  addition, the command \superheadline ... will cause the text
%  which appears on the balance of the line to be printed above
%  the letterhead, without affecting the spacing of the letter.
%  Example: \superheadline \bigbf - DRAFT -.  Finally, one can
%  design one's own headlines completely, by using \headline
%  followed by the TeX code for the desired headline, entered as
%  a one-line entry.  The headline will be printed with an \hfil
%  following it.  One can design a two-line headline by adding the
%  command \headlineb, followed by the TeX code for the second
%  line.  Some of these macros are below, and others are included
%  later in the text.

\def\nulltest{}       %Used in comparison tests
\def\headlineactive#1{\let\headlinetextold=\headlinetext
    \gdef\headlinetext{#1}
  \ifx \headlinetextold \nulltest
    \ifx \headlinetext \nulltest \else
       \toks1=\expandafter{\headlinetext}
       \ifheadwrite \immediate\write16{Headline set: \the\toks1}
          \fi
       \global\advance\topspace by 26pt
       \ifnum\pageno>1 \insert\topspaceinsert{\vskip 26pt} \fi
    \fi
  \else
    \ifx \headlinetext \nulltest
       \global\advance\topspace by -26pt
       \ifnum\pageno>1 \insert\topspaceinsert{\vskip -26pt} \fi
       \ifheadwrite \immediate\write16{Headline cancelled.} \fi
    \else \toks1=\expandafter{\headlinetext}
       \ifheadwrite \immediate\write16{Headline changed to:
          \the\toks1} \fi
    \fi
  \fi}
\def\headlinebactive#1{\let\headlinetextbold=\headlinetextb
    \gdef\headlinetextb{#1}
  \ifx \headlinetextbold \nulltest
    \ifx \headlinetextb \nulltest \else
       \toks1=\expandafter{\headlinetextb}
       \ifheadwrite \immediate\write16{Headlineb set: \the\toks1}
          \fi
       \global\advance\topspace by 12pt
       \ifnum\pageno>1 \insert\topspaceinsert{\vskip 12pt} \fi
    \fi
  \else
    \ifx \headlinetextb \nulltest
       \global\advance\topspace by -12pt
       \ifnum\pageno>1 \insert\topspaceinsert{\vskip -12pt} \fi
       \ifheadwrite \immediate\write16{Second headline
          cancelled.} \fi
    \else \toks1=\expandafter{\headlinetextb}
       \ifheadwrite \immediate\write16{Headlineb changed to:
          \the\toks1} \fi
    \fi
  \fi}
\def\noheadline{\headlineactive{} \headlinebactive{}}
\def\headlinestylea{{\headwritefalse \headlineactive{\normal
  \waddressee\hfill--\folio --\hfill\wdate} \headlinebactive{}}}
\def\headlinestyleb{{\headwritefalse \headlineactive{\normal
  \wauthor \raise1pt\hbox{$\,$::$\,$}\waddressee \hfill
  p.~\folio} \headlinebactive{\normal \wdate}}}



% Variable parameters:
\def\reset{
%Clearing of entries:
\def\wcc{} \def\wdate{} \def\waddress{}
  \setbox\raddressbox=\hbox{} \def\wre{} \def\wto{} \def\wfrom{}
  \def\wsubject{} \def\wemailheading{} \def\wdear{}
  \def\wemailbody{} \def\wbody{} \def\wclosing{}
  \def\wannotations{} \def\wps{} \def\wsecretary{}
  \def\waddressee{} \def\wauthor{} \def\wlabeltitle{}
  \def\wsuperheadline{} \def\headlinetext{} \def\headlinetextb{}
  \topspace=0pt \settable \fullpagefalse \notestfalse \memofalse
  \pageno=1

%Setting of default parameters:
\shortbaselineskip=12pt plus 2pt minus 2pt  %Lineskip for text of
                          %  one-page letters --- flexible
\minbaselineskip=10pt     %Minimum possible shortbaselineskip
\longbaselineskip=12pt    %Baselineskip for text of multipage
                          %  letters
\shortparskip=6pt plus 3pt minus 3pt %Extra space between
                          %  paragraphs for one-page letters
\minparskip=3pt           %Minimum possible shortparskip
\longparskip=6pt plus 2pt minus 2pt  %Extra space between
                          %  paragraphs for multi-page letters
\lineskip=0pt             %Plain TeX uses 1pt --- this choice
                          %  prevents overlapping of boxes, but
                          %  inserts no additional space.
\addresslimit=3truein     %Maximum length of line in address--
                          %  longer lines are split.
\raddresslimit=3truein    %Maximum length of line in return
                          %  address-- longer lines are split.
\addressskip=10.5pt plus 1.5pt minus 1pt   %Lineskip in address
                          %  Re.:, and cc.
\sigskip=3\bigskipamount  %Extra space for signature.  36pt.
\closingskip=4pt plus 2pt minus 2pt %Spacing between items in
                 % closing is \textbaselineskip + \closingskip.
                 % Spacing between cc's is \textbaselineskip,
                 % while spacing within a multiline cc is
                 % \addressskip
\raggedbottom            %Allows pages which are not quite filled.
\topskip10pt             %Raggedbottom sets topskip10pt plus 60pt
\interlinepenalty=100    %Tries to avoid splitting paragraphs.
                 %Had been at 1000, as recommended in the TeXbook.
                 %\interlinepenalty is also set to 100 within a ps.
\headlinestylea           %Create standard headline, described above.
\nopagenumbers            %No page numbers.  Alternative is
                          % \pagenumbers, which puts numbers on
                          % all but first page.
\letterheadspace=0pt     %Allow no extra space for letterhead
                         %  with \noletterhead
\minireset               %Defined in package above
\roman                   %Default typeface is Roman
\mit                     %Set default for MIT letterhead
\personalize             %Define \wroom, \wtelephone, and \wemail
}
\reset

%Parameters for label sheet:
\labelvsize=9.2 truein    \labelvoffset=1.0 truein
\labelhsize=7.8 truein    \labelhoffset=0.35 truein
\labelwd=2.25 truein      %Width of column
\labelht=1.0 truein       %Height of each row
\labelsep=0.45 truein     %Separation between columns
\labeltop=8truept         %Space at top of label
\labelbottom=8truept      %Space at bottom of label

\def\largelabels{\ifnum \boxnum>\boxstart
  \immediate\write16{ERROR: You must move the \string\largelabel
  \space instruction so that it precedes the storing of any
  addresses.}  \fi
\labelstyle=2 \advance\boxstop by -17
\labelvsize=10.0 truein   \labelvoffset=.5 truein
\labelhsize=7.5 truein    \labelhoffset=0.5 truein
\labelwd=3.25 truein      %Width of column
\labelht=1.97 truein      %Height of each row
\labelsep=1 truein        %Separation between columns
\labeltop=18truept        %Space at top of label
\labelbottom=18truept     %Space at bottom of label
}

%  The page layout is "ragged" at the bottom.  A rather large
%  \interlinepenalty is used so that page breaks will tend to
%  occur between paragraphs.  \raggedbottom normally inserts a
%  \vfil at the bottom of each page, but in this version
%  \pagecontents is redefined so that a \vfi (to be defined
%  below) in inserted instead.  A \vfitop is used in the
%  letterhead, so that material in between is vertically
%  centered.  \vfitop is set to skip about 2/3 as much as \vfi,
%  so that the text is slightly above center.  We are using \vfi
%  rather than \vfil so that there is some penalty
%  for leaving too much blank space on a page.  For letters more
%  than one page long, we use \vfi=\vskip 0pt plus .85truein.
%  For these letters a \vfil is inserted at the end, so that the
%  material is pushed upward, and no underfull box message is
%  created.  For one page letters, \vfi=\vfil, to avoid underful
%  boxes and associated stretching.  \raggedbottom normally
%  redefines \topskip to be 10pt plus 60pt, but these macros
%  keep the default value of 10pt.

%  This program tests the size of a letter before processing it,
%  which can be time-consuming for large batches.  It is
%  therefore recommended that for large batches, the file should
%  use either the command \fastshort or \fastlong, for one-page
%  or multipage letters, respectively.  To reverse the effect of
%  these commands, type \slow

\def\fastshort{\notesttrue \pagefittrue}
\def\fastlong{\notesttrue \pagefitfalse}
\def\slow{\notestfalse}

%  To use  TeX's normal pagebreak mechanism, type \fullpage.  To
%  restore the raggedbottom format, type \nofullpage

\def\fullpage{\fullpagetrue \normalbottom \interlinepenalty=0}
\def\nofullpage{\fullpagefalse \raggedbottom \topskip10pt
  \interlinepenalty=100}

%Redefinition of \pagecontents and \plainout:
% We make @ signs act like letters, temporarily.
\catcode`@=11
\def\pagecontents{
  \ifvoid\topspaceinsert\else\unvbox\topspaceinsert\fi
    %Line above added to allow space for headline(s).
  \ifvoid\topins\else\unvbox\topins\fi
  \dimen@=\dp\@cclv \unvbox\@cclv % open up \box255
  \ifvoid\footins\else % footnote info is present
    \vskip\skip\footins
    \footnoterule
    \unvbox\footins\fi
  \ifr@ggedbottom \kern-\dimen@ \vfi \fi}
    %In the line above, the standard \vfil was replaced by \vfi
\def\plainoutput{
 \shipout\vbox{\makeheadline\pagebody
  \makefootline}
  \advancepageno
  \ifnum\outputpenalty>-\@MM \insert\topspaceinsert{\vskip\topspace}
  \else\dosupereject\fi}
  %Insert above added to allow space for headline at top of each
    %page.
\catcode`@=12 % at signs are no longer letters
\def\vfi{\vfil}  \def\vfitop{\vskip 0pt plus 0.65fil \relax}
 % The purpose of the \relax in the above macro is to overcome a
 % bug in TeX.  When the 0.65fil is followed by certain commands,
 % including an ifdim statement, then the "fil" is ignored.  I
 % pointed the bug out to Donald Knuth in Aug 1987, and he said
 % that he would fix it.

\overfullrule=0pt  %eliminate black boxes denoting overfull boxes

%  \hangalign#1#2#3 prints #1 at left margin, then prints the
%  material in #3 in paragraph form, starting on the same line as
%  #1 appears, but indented by the width of the text in #2.
%  Continuation lines are hangindented an extra 20 points.
\def\hangalign#1#2#3{{\setbox\boxa=\hbox{#2} \par\noindent
  \hangindent=\wd\boxa \advance \hangindent by 20pt {\hbox to
  \wd\boxa{#1\hfill}#3}\par}}

%  The letterhead macros are given below:

\def\mitletterhead{
\font\sft=cmssq8 at 9.6truept      %San-Serif, magnified 1200
\font\ssft=cmssq8 at 8truept       %San-Serif 8 truept

\def\spc{\hskip 8truept}
%Allow for all possibilities of omitted information
\def\stylea{\def\wlinea{\wdivision,\hskip 5truept \wroom}
  \def\wlineb{\wtelephone \spc \wemail}}
\def\styleb{\def\wlinea{\wdivision} \def\wlineb{\ifx \wroom
  \nulltest \else \wroom \spc \fi \ifx \wtelephone \nulltest
  \else \wtelephone \spc \fi \wemail \unskip}}  %The \unskip
  % will remove the \spc which could occur at the end of the line
  % if \wemail is null.
%stylea is used only if all four items are nonempty.
\ifx \wdivision \nulltest \styleb \else \ifx \wroom \nulltest
  \styleb \else \ifx \wtelephone \nulltest \styleb \else \ifx
  \wemail \nulltest \styleb \else \stylea \fi \fi \fi \fi

%\s is used to spread out letters, matching standard Department
%  of Physics letterhead
\def\s{\hskip 0pt plus 3truept}
\def\mass{\hbox to 1.48 truein{\sft M\s A\s S\s S\s A\s C\s H\s
U\s S\s E\s T\s T\s S}}
\def\inst{{\sft I\hskip 1truept N\hskip 1 truept STITUTE}}
\def\of{{\sft OF}}
\def\tech{\hbox to 1.15 truein{\sft T\s E\s C\s H\s N\s O\s L\s
O\s G\s Y}}

\vbox{\baselineskip 16truept
\centerline{\mass\spc\inst\hskip 9truept\of\spc\tech}
\centerline{\ssft DEPARTMENT OF PHYSICS}
\centerline{\ssft CAMBRIDGE, MASSACHUSETTS \thinspace 02139}
\vskip 5truept
\setbox\boxa=\hbox{\wlinea}
\ifdim \wd\boxa>0pt \centerline{\ssft \wlinea} \fi
\setbox\boxa=\hbox{\wlineb}
\ifdim \wd\boxa>0pt \centerline{\ssft \wlineb} \fi
\vskip 20truept}
}

\def\cfaletterhead{
\ifapple \font\BF=psmtimb at 16 truept
         \font\Ss=psmhlv at 10 truept
  \else  \font\BF=cmbx10 at 16 truept
         \font\Ss=cmssq8 at 9.6 truept
  \fi
\moveleft 0.5truein\vbox{\baselineskip=12truept
      \hbox{\BF Center for Astrophysics}
      \nointerlineskip \vbox to 3pt{}
      \hbox to 6.95truein
          {\vbox{\hbox{\Ss 60 Garden Street}
                \hbox{\Ss Cambridge, Massachusetts 02138}}
          \hfill
          \vbox{\hbox{\Ss Harvard College Observatory}
                \hbox{\Ss Smithsonian Astrophysical Observatory}}}
      \vskip 48truept}
}

\def\blankletterhead{\vskip\letterheadspace}

%  This format depends on using some special techniques of
%  inputting information into macros which are defined as the
%  processing takes place.  Begin by defining a modified version
%  of \obeylines, called \seelines.  This command turns each
%  carriage return into the control sequence \linebreak, which
%  the user can define.  By default, \linebreak is defined as
%  \inactive, which simulates the normal carriage return.
%  \inactive inserts a space, and if the next token is also a
%  carriage return, it inserts a \par.  Apparently TeX's normal
%  mechanism of ignoring blank spaces before and after a carriage
%  return continues to operate in this context.

{\catcode`\^^M=\active %
  \gdef\seelines{\catcode`\^^M=\active \def^^M{\linebreak}}}
{\seelines \gdef\partest{\ifx\next
  \par\fi}}
\def\inactive{ \futurelet\next\partest}
\def\linebreak{\inactive}

% %  It will also be useful to define ``active'' versions of the {
% %  and } symbols, for reasons described below.
%
% \begingroup \catcode`\{=\active \catcode`\}=\active \catcode`\@=1
%   \catcode`\?=2 \global\def{@\bgroup? \global\def}@\egroup?
%   \endgroup

%  One can now define \getbalance and \dobalance so that one can
%  use a definition of the form
%       \def\seqactive#1{...}
%       \def\seq{\let\dobalance=\seqactive \getbalance}
%  so that \seq will become a macro with argument #1 equal to
%  the balance of the line on which it appears.  The replacement
%  text will be {...}.  Definitions made within {...} should
%  be done by using \gdef rather than \def.  If the argument
%  is found not to fit on one line, it can be continued by
%  ending the line with a space followed by %.

% The purpose of
% %  the active { and } involves only a rare complication.  If
% %  this feature were omitted, and if the user put the entire
% %  entry ... within brackets to localize a definition, then TeX
% %  would remove these brackets when identifying the argument.  By
% %  making the brackets active, they are not removed.

{\seelines \gdef\getbalancea #1
  {\dobalance{#1} \endgroup}}
\def\getbalance{\begingroup % \catcode`{=\active \catcode`}=\active
  \seelines \getbalancea}

%  The macro \date defines the macro \wdate to be the text which
%    appears on the balance of the line.  A blank date is
%    replaced at the end by the current date.  \date can be
%    omitted.  To print the letter without a date, use
%    \datestyle=0

\def\dateactive#1{\gdef\wdate{#1}}
\def\date{\let\dobalance=\dateactive \getbalance}

%  The following macro expands to the current date.

\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}

%  \dear defines the macro \wdear to be the text which appears on
%  the balance of the line, with a similar construction for \re
%  and \wre, \annotations and \wannotations, \telephone and
%  \wtelephone, \email and \wemail.  \email includes a
%  mechanism for overriding a possible redefinition of the @
%  symbol.  \room defines \wroom to be "Room" followed by the
%  number which appears on the balance of the line.  \secretary
%  defines \wsecretary to be the text on the balance of the line
%  if there is text, and it defines \wsecretary to be \dsecretary
%  ("d" stands for default) if the balance of the line is blank.
%  The symbol ":" is redefined to allow extra space on each side.

\def\dearactive#1{\gdef\wdear{#1}}
\def\dear{\let\dobalance=\dearactive \getbalance}
\def\reactive#1{\gdef\wre{#1}}
\def\re{\let\dobalance=\reactive \getbalance}
\def\annotationsactive#1{\gdef\wannotations{#1}}
\def\annotations{\let\dobalance=\annotationsactive \getbalance}
\def\secretaryactive#1{\gdef\wsecretary{#1} \ifx \wsecretary
  \nulltest \gdef\wsecretary{\dsecretary} \fi \global\catcode`:=12}
\def\secretary{\catcode`:=\active \let\dobalance=\secretaryactive
  \getbalance}
\def\sec{\secretary}  %Used only for compatibility with earlier
%  version
\def\divisionactive#1{\gdef\wdivision{#1}}
\def\division{\let\dobalance=\divisionactive \getbalance}
\def\roomactive#1{\def\tester{#1} \ifx \tester \nulltest
  \gdef\wroom{} \else \gdef\wroom{Room #1} \fi}
\def\room{\let\dobalance=\roomactive \getbalance}
\def\telephoneactive#1{\gdef\wtelephone{#1}}
\def\telephone{\let\dobalance=\telephoneactive \getbalance}
\def\emailactive#1{\gdef\wemail{#1}}
\def\email{\let\dobalance=\emailactive \begingroup
   \catcode`@=12 \def\linebreak{\endgroup} \seelines %
   \getbalancea}

%  The body of the letter can be read into the macro \wbody by
%  typing
%             \body
%             text of arbitrary length
%             \endbody
%  by using the following definition:

\long\def\body#1\endbody{\gdef\wbody{#1} \texttype=1}

%  P.S. text can be read in the same way, using \ps and \endps

\long\def\ps#1\endps{\gdef\wps{#1} \texttype=2}

%  The variable \texttype has been introduced so that the program
%  can keep track of which type of text (body or ps) has been most
%  recently entered.  Used with \centerblock and \table.

%  We will also find use for a macro that works just like \body
%  (or \ps), but which appends the subsequent text to the
%  definition of \wbody (or \wps).

\long\def\addbody#1\endbody{\toksa=\expandafter{\wbody}
  \toksb={#1} \xdef\wbody{\the\toksa \the\toksb}
  \texttype=1}

\long\def\addps#1\endps{\toksa=\expandafter{\wps}
  \toksb={#1} \xdef\wps{\the\toksa \the\toksb}
  \texttype=2}

%  cc's are more complicated, since we want to allow for more
%  than one.  \ifstartcc is a conditional initialized true and
%  set true by \minreset, which indicates to start a new block of
%  cc's if a cc statement is found.  When starting a new letter
%  after \minireset, cc's can be blanked by \cc on an empty line.

\def\ccactive#1{
  \ifstartcc
    \def\wcca{#1}
    \ifx \wcca \nulltest
      \gdef\wcc{}
    \else \global\startccfalse \gdef\wcc{\nobreak \noindent \hbox
      to 20pt {cc: \hfil}#1 \par}
    \fi
  \else
    \toksa=\expandafter{\wcc} \toksb={#1}
    \xdef\wcc{\the\toksa \nobreak \the\toksb \par}
  \fi}
\def\cc{\let\dobalance=\ccactive \getbalance}

%  To handle the addresses, I define a more complicated input
%  system which allows the following general construction:
%       \def\seqactive#1{...}
%       \def\seqfinish{....}
%       \def\seqafter{...}
%       \def\seq{\let\dotofinish=\seqactive \def\doafterfinish
%           {\seqfinish} \def\doafterall{\seqafter}
%           \def\tofinish{xxx} \gettofinish}.
%  The result will be that all lines following \seq will be
%  processed as arguments to the macro \seqactive.  The
%  processing will cease when a line is encountered that
%  contains exactly the one token xxx.  The token could be a
%  single control sequence, like \finish, or a null line, or a
%  single character.  After the line processing ceases, the
%  macro \seqfinish will be executed.  After the end of a
%  grouping which begins at \gettofinish, the final macro
%  \seqafter is executed.  As an option, one can add \getbalancea
%  to the end of \def\seq, and earlier in \def\seq include the
%  assignment \let\dobalance=\seqbalance.  Elsewhere one defines
%  \def\seqbalance#1{...}, and the result is that the macro
%  \seqbalance is performed with the argument consisting of the
%  balance of the line on which \seq appears.

{\seelines \long\gdef\gettofinisha #1
  {\def\tester{#1} \ifx \tester \tofinish \doafterfinish%
        \endgroup \doafterall%
    \else \dotofinish{#1} \fi
   }}
\def\gettofinish{\begingroup
  % \catcode`{=\active \catcode`}=\active
  \def\linebreak{\par \gettofinisha} \seelines}

%  The \address macro is designed to read in up to ten lines of
%  address.  These are grouped into one macro called \waddress
%  for the letter.  If \ifsaveaddress is true, then the address
%  is also formed into a box for a sheet of mailing labels to be
%  put together at the end.  The boxes are numbered in sequence,
%  from \box\boxstart through \box\boxstop.  The boxes are made
%  at their minimum width, so that later they can be centered on
%  the label.  Overlength lines are broken and indented, with
%  raggedright used to (1) prefer starting a new line to using a
%  hyphen, and (2) to allow TeX to forgo right justification.
%  Labels are printed automatically whenever a page is full, and
%  also when the final \end command is given.  The \returnaddress
%  macro enters an address in the same way as \address, creating
%  the box \raddressbox.  In both \address and \returnaddress, a
%  space at the beginning of a line results in an indentation of
%  the same size as is used for a broken line--- 20pt for an
%  address at the start of the letter, and 12.5pt in a label.

\def\addressactive#1{\ifcase\linecount \gdef\addressa{#1} \or
  \gdef\addressb{#1} \or \gdef\addressc{#1} \or
  \gdef\addressd{#1} \or \gdef\addresse{#1} \or
  \gdef\addressf{#1} \or \gdef\addressg{#1} \or
  \gdef\addressh{#1} \or \gdef\addressi{#1} \or
  \gdef\addressj{#1} \else
  \immediate\write16{Sorry but the address should be no more than
  10 lines long.  Address for \addressa \ is too long.} \fi
  \global\advance \linecount by 1}

\def\address{\blankaddress \let\dotofinish=\addressactive
  \def\doafterfinish{\procaddress} \def\doafterall{\endgroup}
  \def\tofinish{} \begingroup \obeyspaces\gettofinish}

\def\blankaddress{\gdef\addressa{} \gdef\addressb{}
  \gdef\addressc{} \gdef\addressd{} \gdef\addresse{}
  \gdef\addressf{} \gdef\addressg{} \gdef\addressh{}
  \gdef\addressi{} \gdef\addressj{} \linecount=0}

%  In order that a space at the beginning of the line result in
%  an indentation, it is necessary to use active spaces.

{\obeyspaces\gdef\visispace{\futurelet\nexta\nodupspace}
\gdef\nodupspace{\ifx\nexta \else\space\fi}
\gdef {\visispace}}

{\obeyspaces\gdef\maybeskip{\expandafter\skiptest}
\gdef\spacetest{ }
\gdef\skiptest#1{\def\nexta{#1}\ifx\nexta\spacetest\hskip%
\spaceindent\def\skipcont##1{\killspace{##1}}\else\def%
\skipcont{}\nexta\fi\skipcont}
\gdef\killspace#1{\def\nexta{#1}\ifx\nexta\spacetest\def%
\skipcont##1{\killspace{##1}}\else\def\skipcont{}\nexta\fi%
\skipcont}}

\def\procaddress{\long\gdef\waddress{{\maybeskip \addressa \relax
  \par} {\maybeskip \addressb \relax \par} {\maybeskip
  \addressc \relax \par} {\maybeskip \addressd \relax \par}
  {\maybeskip \addresse \relax \par} {\maybeskip \addressf
  \relax \par} {\maybeskip \addressg \relax \par} {\maybeskip
  \addressh \relax \par} {\maybeskip \addressi \relax \par}
  {\maybeskip \addressj \relax \par}}
  \ifsetaddressee \else \global\let\waddressee=\addressa \fi
  \ifsaveaddress \setaddressbox \fi}
%In above macro, \relax is used to serve as argument for
%   \maybeskip when \addressx is void.

\def\raddressactive#1{\ifcase\linecount \gdef\raddressa{#1} \or
  \gdef\raddressb{#1} \or \gdef\raddressc{#1} \or
  \gdef\raddressd{#1} \or \gdef\raddresse{#1} \or
  \gdef\raddressf{#1} \or \gdef\raddressg{#1}
  \gdef\raddressh{#1} \or \gdef\raddressi{#1}
  \gdef\raddressj{#1} \else
  \immediate\write16{Sorry but the return address should be no
  more than 10 lines long.} \fi \global\advance \linecount by 1}

\def\returnaddress{\blankraddress \datestyle=4
  \let\dotofinish=\raddressactive
  \def\doafterfinish{\procraddress} \def\doafterall{\endgroup}
  \def\tofinish{} \begingroup \obeyspaces\gettofinish}

\def\blankraddress{\gdef\raddressa{} \gdef\raddressb{}
  \gdef\raddressc{} \gdef\raddressd{} \gdef\raddresse{}
  \gdef\raddressf{} \gdef\raddressg{} \gdef\raddressh{}
  \gdef\raddressi{} \gdef\raddressj{} \linecount=0}

\def\procraddress{\labelwd=\raddresslimit
   \baselineskip=\addressskip \lineskiplimit=-3.6truept
   \spaceindent=20pt
   \global\setbox\raddressbox=\vbox{
    \getlined{\raddressa}  \getlined{\raddressb}
    \getlined{\raddressc}  \getlined{\raddressd}
    \getlined{\raddresse}  \getlined{\raddressf}
    \getlined{\raddressg}  \getlined{\raddressh}
    \getlined{\raddressi}  \getlined{\raddressj}}}

\def\setaddressbox{{\labeldonefalse
  \tenrmm \baselineskip=13.2truept minus 1.2truept
  \setaddressboxa
  \ifnum\labelline<5 \labeldonetrue \fi
  \ifnum\labelstyle=2 \labeldonetrue \fi
  \iflabeldone \else
    \ninermm \baselineskip=12truept minus 2.4truept
    \setaddressboxa \ifnum\labelline<6 \labeldonetrue \fi \fi
  \iflabeldone \else
    \eightrmm \baselineskip=9.6truept minus 1.6truept
    \setaddressboxa \ifnum\labelline<7 \labeldonetrue \fi \fi
  \iflabeldone \else
    \sevenrmm \baselineskip=8.4truept minus 1.54truept
    \setaddressboxa \ifnum\labelline<8 \labeldonetrue \fi \fi
  \iflabeldone \else
    \sixrmm \baselineskip=7.2truept minus 1.2truept
    \setaddressboxa \ifnum\labelline<9 \labeldonetrue \fi \fi
  \iflabeldone \else
    \setnoaddressbox \fi
  \global\setbox\boxnum=\vbox to \labelht{\unvbox\boxnum}
  \global\advance\boxnum by 1
  \ifnum \boxnum > \boxstop
   \makelabels
  \fi
}}

\def\setaddressboxa{\global\setbox\boxnum=\vbox{
    \vfill \vskip\labeltop \lineskiplimit=-3.6truept
    \global\labelline=0 \spaceindent=12.5pt
    \getlined{\addressa}  \getlined{\addressb}
    \getlined{\addressc}  \getlined{\addressd}
    \getlined{\addresse}  \getlined{\addressf}
    \getlined{\addressg}  \getlined{\addressh}
    \getlined{\addressi}  \getlined{\addressj}
    \vskip\labelbottom \vfill}}

\def\setnoaddressbox{\global\setbox\boxnum=\vbox to \labelht{
    \tenrmm \baselineskip=14truept \vfill \getlined{\addressa}
    \hbox{\bf ADDRESS TOO LONG} \vfill}}

\def\getlinea{\box\boxa \global\advance\labelline by 1}
\def\getlineb{\hsize=\labelwd \rightskip 0pt plus 50pt
   \hyphenpenalty=10000 \exhyphenpenalty=10000 \par \noindent
   \hangindent \spaceindent{\wadline} \par
   \global\advance\labelline by 2}
\def\getlinec{\setbox\boxa=\hbox{\wadline
   \global\let\quotesave="} \ifdim\wd\boxa < \labelwd \getlinea
   \else \getlineb \fi}  %quotesave used to store a possible
                         %  redefinition of " by simplequote system.
\def\getlined#1{\setbox\boxa=\hbox{\def\visispace{}#1}
   \ifdim\wd\boxa=0pt \else \let\wadlinea=#1 \def\wadline{\maybeskip
   \wadlinea \relax} \getlinec \global\let"=\quotesave \fi}

%  The closing is handled in a manner similar to the address,
%  with the format:
%           \closing
%           Sincerely,
%           Seymour T. Jones
%           Professor of Physics
%           \qquad and Everything Else
%
%  Follow the closing with a blank line, as with the address.
%  The title can of course be omitted.  One can also use
%           \sincerely
%           Alan H. Guth
%  or
%           \closing
%           Alan Guth
%  where the latter results in the printing of the name only.
%  Occassionally a letter has more than one author.  To allow for
%  extra authors, enter them as
%           \extraauthor
%           Alan Guth
%  or as
%           \extraauthor
%           Alan Guth
%           Professor of Physics
%  Follow the extraauthor listing by a blank line.  Any number of
%  extra authors are allowed, each entered in the same way.

\def\closing{\begingroup \seelines \closingactive}
{\seelines \gdef\closingactive #1
  #2
  #3
  {\endgroup \messageout{#1} \def\wclosinga{#3} %
  \ifx \wclosinga \nulltest %
     \gdef\wclosing{#2 \par \nobreak} %
     \ifsetauthor \else \gdef\wauthor{#2} \fi %
     \gdef\endclosing{} %
  \else %
     \gdef\wclosing{#2 \par \nobreak \vskip \sigskip #3 \par} %
     \ifsetauthor \else \gdef\wauthor{#3} \fi %
     \gdef\endclosing{\readclosing} %
  \fi \endclosing
  }}
\def\messageout#1{\def\tester{#1} \ifx \tester
  \nulltest \else \immediate\write16{The following material
  appearing in the closing was not processed: #1} \fi}
\def\readclosing{\let\dotofinish=\readclosingactive
  \def\doafterfinish{} \def\doafterall{} \def\tofinish{}
  \gettofinish}
\def\readclosingactive#1{\toksa=\expandafter{\wclosing}
  \toksb={#1} \xdef\wclosing{\the\toksa \nobreak \the\toksb
  \par}}
\def\sincerely{\begingroup \seelines \sincerelyactive}
{\seelines \gdef\sincerelyactive #1
  {\endgroup \messageout{#1} \closing
  Sincerely,
  }}
\def\extraauthor{\toksa=\expandafter{\wclosing} \toksb={\nobreak
  \vskip \sigskip} \xdef\wclosing{\the\toksa \the\toksb}
  \readclosing}

%More macros needed for headlines:

\def\addresseeactive#1{\gdef\waddressee{#1}}
\def\addressee{\setaddresseetrue \let\dobalance=\addresseeactive
  \getbalance}
\def\superheadlineactive#1{\gdef\wsuperheadline{#1}}
\def\superheadline{\let\dobalance=\superheadlineactive \getbalance}
\def\authoractive#1{\gdef\wauthor{#1}}
\def\author{\setauthortrue \let\dobalance=\authoractive
  \getbalance}
\def\headline{\let\dobalance=\headlineactive \getbalance}
\def\headlineb{\let\dobalance=\headlinebactive \getbalance}
\def\topline#1{\setbox\boxa=\line{#1\hfil} \ifdim\ht\boxa<10pt
    \vbox to 10pt{\vfill \box\boxa}
   \else \box\boxa \fi}
\def\makeheadline{\vbox to 0pt{\baselineskip 12pt
    \ifnum\pageno> 1
      \ifx \headlinetext \nulltest \else \topline{\headlinetext}
          \fi
      \ifx \headlinetextb \nulltest \else
          \line{\headlinetextb\hfil} \fi
    \fi \vss} \nointerlineskip}


%  The package is also capable of reading in a list of addresses
%  for an address labelsheet.  Use \addresses to start, the
%  first address should begin on the next line, skip lines
%  between addresses, and terminate with \endaddresses.

\def\addresses{\def\end{\makelabels \finalend} \blankaddress
  \let\dotofinish=\addressesactive
  \def\doafterfinish{\completeaddress}
  \def\doafterall{\endgroup} \def\tofinish{\endaddresses}
  \begingroup \obeyspaces\gettofinish}
\def\addressesactive#1{\def\test{#1}
  \ifx \test \nulltest
    \completeaddress
  \else
    \addressactive{#1} \fi}
\def\completeaddress{\ifnum\linecount>0 {\def\visispace{\space}
  \nosimplequotes \immediate\write16{Address for: \addressa}}
  \setaddressbox \blankaddress \fi}

%  Macros for memo format:
%    A memo can be indicated by using the command \to followed by
%    the addressee, or by using the command \memo.

\def\memo{\memotrue \datestyle=3}
\def\toactive#1{\gdef\wto{#1}
    \ifsetaddressee \else \global\setaddresseetrue
    \gdef\waddressee{#1} \fi}
\def\to{\memo \let\dobalance=\toactive \getbalance}
\def\fromactive#1{\gdef\wfrom{#1}
    \ifsetauthor \else \global\setauthortrue \gdef\wauthor{#1}
    \fi}
\def\from{\let\dobalance=\fromactive \getbalance}
\def\subjectactive#1{\gdef\wsubject{#1}}
\def\subject{\let\dobalance=\subjectactive \getbalance}

\def\makesuperheadline{\ifx \wsuperheadline \nulltest \else \vbox
  to 0pt{\vskip -24 truept \centerline{\wsuperheadline} \vfil}
  \nointerlineskip \fi}

%The following macro is used in \makememoheading to allow for
%  extra space whenever one or more entries requires more than one
%  line.
\def\checkheight{\ifdim \ht\boxb > \baselineskip
  \def\headingskip{\smallskip} \fi}

\def\makememoheading{\ifmemo
  {\baselineskip=\addressskip \parindent=0pt
      \parskip=\textbaselineskip \advance \parskip by
      -\addressskip \lineskiplimit=-2pt \def\headingskip{}
  \ifx \wsubject \nulltest
    \setbox\boxb=\vbox{\hangalign{To:}{From:\quad}{\wto}}
      \checkheight
    \setbox\boxb=\vbox{\hangalign{From:}{From:\quad}{\wfrom}}
      \checkheight
    \ifx \wto \nulltest \else
      \hangalign{To:}{From:\quad}{\wto} \headingskip \fi
    \ifx \wfrom \nulltest \else
      \hangalign{From:}{From:\quad}{\wfrom} \headingskip \fi
    \ifnum\datestyle=3
      \hangalign{Date:}{From:\quad}{\wdate} \headingskip \fi
   \else
    \setbox\boxb=\vbox{\hangalign{To:}{Subject:\quad}{\wto}}
      \checkheight
    \setbox\boxb=\vbox{\hangalign{From:}{Subject:\quad}{\wfrom}}
      \checkheight
    \setbox\boxb=\vbox{\hangalign{Subject:}{Subject:\quad}{\wsubject}}
      \checkheight
    \ifx \wto \nulltest \else
      \hangalign{To:}{Subject:\quad}{\wto} \headingskip  \fi
    \ifx \wfrom \nulltest \else
      \hangalign{From:}{Subject:\quad}{\wfrom} \headingskip \fi
    \hangalign{Subject:}{Subject:\quad}{\wsubject} \headingskip
    \ifnum\datestyle=3
      \hangalign{Date:}{Subject:\quad}{\wdate} \headingskip \fi
  \fi} \smallskip \fi}

\def\makeemailheading{{\parindent=0pt
   \baselineskip=\textbaselineskip \wemailheading}}
\def\makeraddress{
  \ifdim \ht\raddressbox > 0pt
     \line{\hfill \vbox{\copy\raddressbox
     \ifnum \datestyle=4 \medskip \hbox{\wdate} \fi}}
     \ifnum \datestyle=1 \medskip \else
        \ifnum \datestyle=2 \medskip \else
           \bigskip
        \fi
     \fi
  \else
     \ifnum \datestyle=4 \rightline{\wdate} \bigskip \fi
  \fi
}
\def\makedate{\ifnum\datestyle=1 \rightline{\wdate} \bigskip \fi
  \ifnum\datestyle=2 \noindent \hskip \sigindent \wdate \bigskip
     \fi }
\def\makeaddress{\ifx \waddress \nulltest \else
  {\hsize=\addresslimit \baselineskip=\addressskip \parskip=0pt
  \parindent=0pt \lineskiplimit=-2pt \spaceindent=20pt
  \everypar{\hangindent \spaceindent} \rightskip 0pt plus 50pt
  \hyphenpenalty=10000 \exhyphenpenalty=10000 \waddress} \medskip
  \fi}
\def\makere{\ifx \wre \nulltest \else \par\noindent
  {\baselineskip=\addressskip \lineskiplimit=-2pt
  \hangalign{Re.: }{Re.: }{\wre}} \medskip \fi}
\def\makedear{\ifx \wdear \nulltest \else {\baselineskip=
  \textbaselineskip \parskip=\textparskip \noindent Dear \wdear
  \par} \fi}
\def\makeemailbody{{\baselineskip=\textbaselineskip
   \parindent=20pt \parskip=\textparskip \normalperiod
   \wemailbody}}
\def\makebody{{\baselineskip=\textbaselineskip \parindent=20pt
  \parskip=\textparskip \normalperiod \wbody \par}}

%  One wants to avoid page breaks during the ending.  This is
%  accomplished by using a large interlinepenalty, and by using
%  \nobreak before each element of glue.  A page break is allowed
%  within the ps, but there is a penalty of 100 (interlinepenality).

\def\makeending{{\baselineskip=\textbaselineskip
  \interlinepenalty=10000 \parindent=0pt \makeclosing
  \makeannotations \makecc \makeps \makesecretary \ifpagefit
  \iffullpage \vfi \fi \else \vfill \fi \supereject}}
\def\makeclosing{\par \nobreak \bigskip \nobreak \medskip
  {\leftskip=\sigindent \nobreak \wclosing} \bigskip \nobreak
  \vskip -\closingskip}
\def\makeannotations{\ifx \wannotations \nulltest \else \nobreak
  \vskip \closingskip \nobreak \par\hangindent=20pt
  \wannotations \par \fi}
\def\makecc{\ifx \wcc \nulltest \else \nobreak \vskip \closingskip
  {\baselineskip=\addressskip \parskip=\textbaselineskip
  \advance\parskip by -\addressskip \parindent=20pt
  \everypar{\hangindent 40pt} \wcc} \fi}
\def\makeps{\ifx \wps \nulltest \else {\baselineskip=
  \textbaselineskip \interlinepenalty=100 \everypar{\penalty 100}
  \parskip=\closingskip \setbox\boxa=\hbox{P.S.\thinspace :\quad}
  \parindent=\wd\boxa \normalperiod \par \noindent
  P.S.\thinspace :\quad\wps \par} \fi}
\def\makesecretary{\ifx \wsecretary \nulltest \else \nobreak
  \vskip \closingskip \nobreak \par\hangindent=20pt \wsecretary
  \par \fi \ifx \wps \nulltest \ifdim\lastskip=-\closingskip
  \nobreak \vskip \closingskip \nobreak \vskip -\bigskipamount
  \fi \fi}
% In the above macro, the \ifdim\lastskip statement is used to
%   undo the space left after the closing, in the event that no
%   other material follows.  The goal is to improve centering on
%   page.

\def\makelettera{\baselineskip=12pt \shortperiod
  \vbox{\vskip\letterheadskip \makesuperheadline \letterhead}
  \vfitop \makeraddress \makedate \makememoheading
  \makeemailheading \makeaddress \makere \makedear \makeemailbody
  \makebody \makeending \normalperiod \global\pageno=1}
%\pageno is reset at the end in case another letter follows ---
%  the headline reading mechanism needs to know the correct page
%  number.

\def\testletter{{\textbaselineskip=\minbaselineskip
  \textparskip=\minparskip \def\smallskip{\vskip 2pt}
  \def\medskip{\vskip 4pt} \def\bigskip{\vskip 8pt}
  \setbox\boxc=\vbox{\makelettera} \testht=\ht\boxc
  \ifdim\testht<\vsize \global\pagefittrue \else
  \global\pagefitfalse \fi \def\visispace{\space}
  \immediate\write16{Letter from \wauthor \space to \waddressee.}
  \immediate\write16{ Minimum total length = \the\testht.}
  \immediate\write16{ \string\vsize = \the\vsize.  Expecting
  \ifpagefit 1 Page. \else >1 Page. \fi }}}

\def\makeletter{\ifx \wdate \nulltest \def\wdate{\today} \fi
  \ifnotest {\def\visispace{\space} \immediate\write16{Letter
     from \wauthor \space to \waddressee.}}
     \else \testletter \fi
  \ifpagefit \textbaselineskip=\shortbaselineskip
            \textparskip=\shortparskip
     \else \textbaselineskip=\longbaselineskip
            \textparskip=\longparskip \fi
  \iffullpage \makelettera
     \else
        \ifpagefit \makelettera
           \else {\def\vfi{\vskip 0pt plus .85truein}
             \def\vfitop{\vskip 0pt plus .55truein}
             \makelettera}\fi
        \fi \minireset}

%Macros for making labels:

\def\labeltitleactive#1{\gdef\wlabeltitle{#1}}
\def\labeltitle{\let\dobalance=\labeltitleactive \getbalance}
\def\fullbox#1{\hbox to \labelwd{\hfill #1\hfill}}
\def\makerow#1#2#3{\hbox{\fullbox{#1}\hskip \labelsep
  \fullbox{#2}\ifnum\labelstyle=1\hskip \labelsep \fullbox{#3}\fi}}
\def\addressrow{
  \iflabelsend \else
    \ifnum \numa<\boxnum
      \makerow{\copy\numa}
      {\ifnum \numb<\boxnum{\copy\numb}\fi}
      {\ifnum \numc<\boxnum{\copy\numc}\fi}
      \ifnum\labelstyle=1
        \advance\numa by 3 \advance\numb by 3 \advance\numc by 3
      \else
        \advance\numa by 2 \advance\numb by 2
      \fi
    \else \labelsendtrue
    \fi
  \fi}
\def\addresspage{\iflabelsend \else \addressrow \addressrow
  \addressrow \addressrow \addressrow \ifnum\labelstyle=1
%% our paper has only 7 rows!
%% \addressrow \addressrow \addressrow \addressrow \fi \fi}
  \addressrow \addressrow  \fi \fi}

\def\makelabels{{\ifnum \boxnum > \boxstart
  \pageno=100 \vsize=\labelvsize \voffset=\labelvoffset
  \advance\vsize by 22truept \advance\voffset by -22truept
    %Line above places headline 22 truept (18pt mag 1200) above
    %  the one inch line.
  \topspace=0pt
  \hsize=\labelhsize \hoffset=\labelhoffset
  \ifapple \advance\hoffset by-1truein\advance\voffset
          by-1truein \fi
  \parindent=0pt \parskip=0pt
  \def\headlinetext{\tenrmm \hfill \wlabeltitle \hfill \hbox to
    0pt{\hss \number\labelpageno \hskip 0.40truein}}
  \def\headlinetextb{}
  \lcount=0 \loop
     \numa=\boxstart \numb=\boxstart \advance\numb by 1
     \numc=\boxstart \advance\numc by 2 \labelsendfalse
     \vbox to 31truept{} \addresspage \supereject
     \advance\lcount by 1
  \ifnum \lcount < \labelcopies \repeat
  \global\advance\labelpageno by 1
  \global\boxnum=\boxstart  \global\pageno=1
  \fi}}

%Special application macros:

%For purposes of underlining the last line of a column of digits
%  to be added, I define a macro \addline which acts like
%  \underbar, except that it adds some extra space both above and
%  below.

\catcode`@=11
\def\addline#1{\vtop{\hbox{$\setbox\boxa=\hbox{#1} \dp\boxa=1.5pt
  \m@th \underline{\box\boxa}$} \ifdim\lineskip=0pt \vskip 2.5pt
  \else \vskip 1.5pt \fi}} %If clause gives same results for
  %  \lineskip=0pt or 1pt.
\catcode`@=12

%PAGEBREAKS
% In order to force a page break, use \pagebreak.  Within a
% paragraph, it will force a break following the line in which it
% occurs.  Between paragraphs, it will cause a break where it
% occurs.
\def\pagebreak{\ifhmode \vadjust{\break} \else \eject \fi}

%\CENTERBLOCK
%\centerblock is used to insert objects like addresses.  The format
%  for inserting the address is:
%        \endbody\centerblock  [\baselineskip=\textbaselineskip]
%        Technical Printing, Inc.
%        37 Pine Grove Terrace
%        Cambridge, MA 02139
%        \noalign{\smallskip}
%        ATTN: Mr. John Jones
%
%        [Continuation of text ... ]
%  The result will be an address which is centered from left to
%  right, with a line spacing slightly narrower than the rest.
%  The address will be separated from the text above and below by
%  the same separation as between paragraphs.  The continuation
%  of the text will be treated as a new paragraph, so one must
%  begin it with \noindent if it is not really a new paragraph.
%  Within the centerblocked material, periods will not cause extra
%  space to be left.

\def\tstrut{\vrule height8.5pt depth0pt width0pt}
\def\centerblocktext{\startbox
  \global\let\dotofinish=\centerblockactive
  \gdef\doafterfinish{} \gdef\doafterall{\finishbox}
  \gdef\tofinish{} \gettofinish}
\def\startbox{\vskip\parskip \linecount=0 \bgroup
  \lineskip=\baselineskip \advance\lineskip by -\prevdepth
  \advance\lineskip by -8.5pt \line\bgroup \hfill \vbox\bgroup
  \lineskip=0pt \parskip=0pt \baselineskip=\addressskip
  \def\noalign##1{\egroup ##1 \bgroup} \shortperiod}
\def\centerblockactive#1{ \setbox\boxa=\hbox\bgroup
  \ifnum\linecount=0 \tstrut \fi #1\egroup \ifdim\wd\boxa > 0.0pt
  \box\boxa \global\advance \linecount by 1 \fi}
\def\finishbox{\egroup \hfill \egroup \par \egroup}
\def\centerblock{\begingroup \seelines \getcenter}
{\seelines \long\gdef\getcenter#1

{\ifcase\texttype \or %
\toksa=\expandafter{\wbody}%
  \toksb={\centerblocktext #1

}\xdef\wbody{\the\toksa \par %
\the\toksb}\endgroup\let\cont=\addbody\or%
\toksa=\expandafter{\wps}%
  \toksb={\centerblocktext #1

}\xdef\wps{\the\toksa \par \the\toksb}\endgroup\let\cont=\addps %
\fi \cont}}

%TABLE
%\table is used to insert a table, like a list of expenses.  The
%  format for inserting the list is:
%        \endbody\table \columns=3 \spacea=10pt [\baselineskip= %
%             \textbaselineskip]
%        Title1  &Title2    &Title3
%        \noalign{\smallskip}
%        Item1a  &Item2a    &Item3a
%        Item1b  &Item2b    &Item3b
%
%        [Continuation of text ... ]
%  Each line of the table is normally entered as one line of
%  input text, but the line can be continued by ending it with a
%  space followed by %.  The result will be a table with 3
%  columns (1-8 columns are possible), centered from left to
%  right.  The spacing indicated by \spacea will be left between
%  columns 1 and 2, \spaceb will be left between columns 2 and 3,
%  etc. The default values for \spacex is 20pt, and the default
%  value of \columns is 8.  The table will be separated from the
%  text above and below by the same separation as between
%  paragraphs.  The continuation of the text will be treated as a
%  new paragraph, so one must begin it with \noindent if it is
%  not really a new paragraph.  If one wants to narrow the
%  spacing, one should add \baselineskip=\addressskip.

%  Technical note:  This macro works by a method very different
%  from that used in \centerblock.  I believe that this method
%  would also work for \centerblock, but peculiarities of \halign
%  prevent the method used in \centerblock from working here.
%
%  Maximum number of columns changed from 5 to 8 on 5/4/88.

\def\loop#1\repeat{\long\gdef\lbody{#1}\iterate}
\def\iterate{\lbody \let\lnext\iterate \else\let\lnext\relax\fi
  \lnext}
\let\repeat=\fi % this makes \loop...\if...\repeat skippable

\def\tabletext{\global\linecount=20 \let\dotofinish=\tableactive
  \def\doafterfinish{\maketable} \def\doafterall{}
  \def\tofinish{} \gettofinish}
\def\tableactive#1{\global\advance\linecount by 1
  \global\toks\linecount={#1}}
\def\maketable{\vskip\parskip {\lineskip=\baselineskip
  \advance\lineskip by -\prevdepth
  \advance\lineskip by -8.5pt \line{\hfill \vbox{\parskip=0pt
  \lineskip=0pt \shortperiod \digits
  \ifcase\columns \immediate\write16{Error: The parameter
     \string\columns \space must not be zero.} \or
  \halign{##\hfil\cr \insertrows\crcr} \or
  \halign{##\hfil&\hskip\spacea##\hfil\cr
     \insertrows\crcr} \or
  \halign{##\hfil &\hskip\spacea ##\hfil &\hskip\spaceb
     ##\hfil\cr \insertrows\crcr} \or
  \halign{##\hfil &\hskip\spacea ##\hfil &\hskip\spaceb ##\hfil
     &\hskip\spacec ##\hfil\cr \insertrows\crcr} \or
  \halign{##\hfil &\hskip\spacea ##\hfil &\hskip\spaceb ##\hfil
     &\hskip\spacec ##\hfil &\hskip\spaced ##\hfil\cr
     \insertrows\crcr} \or
  \halign{##\hfil &\hskip\spacea ##\hfil &\hskip\spaceb ##\hfil
     &\hskip\spacec ##\hfil &\hskip\spaced ##\hfil &\hskip\spacee
     ##\hfil\cr \insertrows\crcr} \or
  \halign{##\hfil &\hskip\spacea ##\hfil &\hskip\spaceb ##\hfil
     &\hskip\spacec ##\hfil &\hskip\spaced ##\hfil &\hskip\spacee
     ##\hfil &\hskip\spacef ##\hfil\cr \insertrows\crcr} \or
  \halign{##\hfil &\hskip\spacea ##\hfil &\hskip\spaceb ##\hfil
     &\hskip\spacec ##\hfil &\hskip\spaced ##\hfil &\hskip\spacee
     ##\hfil &\hskip\spacef ##\hfil &\hskip\spaceg ##\hfill\cr
     \insertrows\crcr} \else
  \immediate\write16{Error: The parameter \string\columns \space
     must be an integer from 1 to 8.}
  \fi }\hfill}\par}}
%\insertrows modified 11/27/87-- older version could not use
%     \noalign
\def\insertrows{\global\lcount=20\gdef\ins{}%
  \global\advance\linecount by -1 \ifnum\linecount>20%
  \loop\global\advance\lcount by 1\toksa=\expandafter{\ins}%
  \ifnum\lcount=21\toksb={\tstrut\crcr}\else\toksb={\crcr}%
  \fi \xdef\ins{\the\toksa \the\toks\lcount \the\toksb}%
  \ifnum\linecount>\lcount \repeat \fi \advance\lcount by 1%
  \toksa=\expandafter{\ins}\xdef\ins{\the\toksa
  \the\toks\lcount}\ins}
\def\table{\begingroup \seelines \gettable}
{\seelines \long\gdef\gettable#1

{\ifcase\texttype \or %
\toksa=\expandafter{\wbody}%
  \toksb={\tabletext #1

}\xdef\wbody{\the\toksa \par%
\the\toksb}\endgroup\let\cont=\addbody\or%
\toksa=\expandafter{\wps}%
  \toksb={\tabletext #1

}\xdef\wps{\the\toksa \par \the\toksb}\endgroup\let\cont=\addps %
\fi \cont}}

%Special Treatment for Periods:
%  Gletter uses two modes for the handling of the spaces which
%  follow periods.  Within the \body or \ps, the rules are the
%  same as in normal TeX.  Elsewhere the period is not followed
%  by any additional space.  To override these normal procedures,
%  one can use \period to indicate a period followed by extra
%  space, and one can use .\ to denote a period without extra
%  space.

\def\period{{.\spacefactor=3000} }
\def\shortperiod{\sfcode`.=1000}
\def\normalperiod{\sfcode`.=3000}


%SHRINKING AND STRETCHING OF LINESKIPS:
%  The macro \shrink shrinks each of the lineskips by 5%, except
%  that \addressskip is not affected.  The macro \stretch
%  stretches each lineskip other than \addressskip by 5%.
\def\shrink{
  \multiply\shortbaselineskip by 19
  \divide\shortbaselineskip by 20
  \multiply\minbaselineskip by 19
  \divide\minbaselineskip by 20
  \multiply\longbaselineskip by 19
  \divide\longbaselineskip by 20
  \multiply\shortparskip by 19
  \divide\shortparskip by 20
  \multiply\minparskip by 19
  \divide\minparskip by 20
  \multiply\longparskip by 19
  \divide\longparskip by 20
  \multiply\sigskip by 19
  \divide\sigskip by 20
  \multiply\closingskip by 19
  \divide\closingskip by 20}

\def\stretch{
  \multiply\shortbaselineskip by 20
  \divide\shortbaselineskip by 19
  \multiply\minbaselineskip by 20
  \divide\minbaselineskip by 19
  \multiply\longbaselineskip by 20
  \divide\longbaselineskip by 19
  \multiply\shortparskip by 20
  \divide\shortparskip by 19
  \multiply\minparskip by 20
  \divide\minparskip by 19
  \multiply\longparskip by 20
  \divide\longparskip by 19
  \multiply\sigskip by 20
  \divide\sigskip by 19
  \multiply\closingskip by 20
  \divide\closingskip by 19}

%E-MAIL MESSAGE PROCESSING
% To process an incoming E-mail message, put the commands
%   \emailheading and \endemailheading before and after the
%   heading material, to process it verbatim.  The normal
%   letterhead and the date will then be suppressed, unless they
%   are explicitly reinstated.  If the body has been prepared for
%   processing by TeX, then the body of the letter can be
%   processed by \body in the usual way.  If however it was not
%   prepared for TeX, then it can be processed by putting the
%   commands \emailbody and \endemailbody before and after it.
%   The characters which are special to TeX will then just be
%   printed as they are.

\def\lessthan{\hbox{$<$}} \def\greaterthan{\hbox{$>$}}
{\catcode`\<=\active \catcode`\>=\active \gdef<{\lessthan}
   \gdef>{\greaterthan}}  %Define active versions of < and >.
\begingroup \catcode`\{=\active \catcode`\}=\active \catcode`\@=1
  \catcode`\?=2 \global\def{@\bgroup? \global\def}@\egroup?
  \endgroup   %Define active versions of { and }
{\catcode`\_=12 \def\lbar{{\ttfont _}} \catcode`\_=\active
   \global\let_=\lbar} % Define active _
{\catcode`\@=0 \catcode`\\=\active @gdef\{$@backslash$}}%Active \
{\catcode`\@=0 \catcode`\\=\active
   @long@gdef@getemailbody#1\endemailbody{@xdef@wemailbody{#1}
   @endgroup}}  %The problem here was to end the argument with
   %  \endemailbody, with the \ in active mode (so it can be
   %  printed).  The solution was to substitute @ for \.  Using
   %  xdef causes \wemailmode to be expanded immediately, so
   %  that it will not be affected if the active characters are
   %  later redefined.
{\catcode`\@=0 \catcode`\\=\active
@long@gdef@getemailheading#1\endemailheading{@xdef%
@wemailheading{#1} @endgroup}}
\def\emailbody{\font\ttfont=cmtt10 \begingroup
  \setspecials\getemailbody}
\def\emailheading{\noletterhead \nodate \noheadline
  \font\ttfont=cmtt10 \begingroup \seelines \obeyspaces
  \def\visispace{\space} \def\linebreak{\leavevmode\par}
  \setspecials \getemailheading}
  %The leavevmode command causes TeX to leave vertical mode, and
  %   hence allows successive lineskips to be processed.
\def\setspecials{\catcode`\%=12 \catcode`\<=\active
  \catcode`\>=\active \catcode`\$=12 \catcode`\#=12
  \catcode`\^=12 \catcode`\_=\active \catcode`\&=12
  \def\bgroup{\hbox{$\{$}} \def\egroup{\hbox{$\}$}}
  \catcode`\{=\active \catcode`\}=\active \catcode`\\=\active
  \def"{\noexpand"} \catcode`\~=12}
  % Note that earlier the active versions of { and } were defined
  %   to be \bgroup and \egroup.  The above macro defines them to
  %   print properly.  The def for " is required because it will
  %   appear in the argument of an xdef.  xdef does not recognize
  %   \def statements, and so the \openquote definition becomes a
  %   closed loop if xdef expands it.

%Alignment of columns of numbers:
%  The easiest way is to define @ as a blank symbol with the same
%  width as a digit.  The $ seems to have the same width, at
%  least in Roman type, so it can also be substituted by a @ in
%  lines for which the $ is not wanted.  To use this definition,
%  type \digits.  To redefine @ as a normal symbol, type
%  \nodigits.  To use the normal symbol when \digits is in
%  effect, use \at.  Note that @ is always an active symbol.  For
%  a spacer to substitute for a comma, use \cw (comma-width).
%  Within the \table macro, \digits is selected by default.

\def\at{@}
\setbox\boxa=\hbox{\rm0} \digitwidth=\wd\boxa
\def\dw{\kern\digitwidth}
\setbox\boxa=\hbox{\rm,} \commawidth=\wd\boxa
\def\cw{\kern\commawidth}
\catcode`@=\active
\def\digits{\def@{\dw}}
\def\nodigits{\def@{\at}}
\nodigits


%ITEMIZE MACRO: USED TO TURN ALL SUBSEQUENT PARAGRAPHS INTO
%   "ITEM" FORMAT, WITH FIRST WORD AS LABEL.

\long\def\itemize#1{{
   \def\entry ##1 {\hang\llap{##1\enspace}\ignorespaces}
   \everypar={\entry} \par #1\par
}}


% Compatibility with earlier versions:
%  To allow compatibility with files prepared for earlier
%  versions of gletter, the following definitions are included:

\def\heading{\addressee}
\def\superheading{\superheadline}
\def\bitnet{\email}
\def\bitnetbody{\emailbody}
\def\bitnetheading{\emailheading}

% Display of boxes in LIS files:
%  The following macro will cause boxes to be displayed in full.

\def\showall{\showboxdepth=\maxdimen \showboxbreadth=\maxdimen}



