%  BELLMAC.TXH; reference in TeXhax.8724

Date:     Wed, 25 Mar 87 21:06 CST
From:     <BELL@UKANVAX.BITNET>
Subject: Form letter/mailing list processing.

        In Vol. 87, Issue 22, Eric Skinner inquires about a set of TeX
        macros which will produce form letters. I developed such a
        procedure here (in plain TeX) at the University of Kansas for use
        by our departmental secretaries, and it has been in use now for
        several months. John Lee in the October 1986 issue of TUGBoat asked
        the same question and the result was a reply which I expect to appear
        in the March 1987 TUGBoat along with another reply in LaTeX. For
        those of you who do not receive TUGBoat (or are impatient) here is
        a copy of it as I sent it. A label formatting procedure utilizing
        the same address file is also available.

                                        Ed Bell
                                        BITnet: BELL@UKANVAX
                                        SPAN:   KUPHSX::BELL

  --------------------------------------------------------------------------

\title AutoLetter: A \TeX\ form letter procedure.
\\Edwin V. Bell, II\cr
        Department of Physics and Astronomy
        University of Kansas
\endx

\pagexref{bell}

The inquiry from John Lee (\TUB, October 1986) concerning form letters was
particularly interesting to me as I had recently completed such a procedure
at the request of our office staff. The procedure (called AutoLetter) is
a ``plain'' \TeX\ procedure which requires two files, one containing a
delimited listing of names and addresses, the other a generic form letter.

Each entry in the address file is followed by a line containing a single
asterisk. The last entry must also be followed by this line, which in turn
{\it must} be followed by the end-of-file mark. Each individual entry consists
of six lines for the addressee's title, name, etc., followed by as many
address lines as desired. The lines for the addressee's name are:

\item{(1)}Title (Prof., Mr., Ms., etc.)
\item{(2)}First name/initial
\item{(3)}Name to be used as a familiar form of address.
\item{(4)}Middle name(s)/initial(s)
\item{(5)}Last/family name
\item{(6)}Additional name information (Jr., II, Esq., etc.)

\noindent
These lines are then used to reconstruct the persons name for various forms
of address (including for the address block) and to address the person formally
(Sir, Madam, Sir or Madam), familiarly (by item (3) above or, if (3) is
blank, by first name), or by title and last name. If any of these lines
are left blank, AutoLetter doesn't mind, but if the entry is irrelevant
or absent from the persons name, {\it it must still be left blank}. An example
of an address entry might be:
\begintt
Mr.
Edwin
Ed
V.
Bell
II
Department of Physics \& Astronomy
University of Kansas
Lawrence, KS\ \ \ 66045
*
\endtt

The letter file is quite simple and used macros that are the same as or
slight variations of those listed in Appendix E of {\sl The \TeX book}.
AutoLetter takes care of the placement of the date and address block (and
could as well the letterhead, although I have not yet implemented that here
as yet), so the letter file might appear as:
\begintt
\letterbody
Dear \person--

...text...

\closing
Sincerely,
...

\annotations...
\ps...

\endletter
\endtt

AutoLetter consists of two files, on the \TeX\ procedure itself, the other
containing the letter-formatting macros (and local macros, if desired).
The AutoLetter procedure looks like:
\begintt
\input letter_format

\message{+------------------------------------------+}
\message{| AutoLetter Version 1.1 -- 9 October 1986 |}
\message{+------------------------------------------+}

\newread\addressfile

\message{Enter name of file containing the addresses:}
\read-1 to\addfile
\openin\addressfile=\addfile

\message{Enter name of file containing the body of the letter:}
\read-1 to\letfile

%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%       Now read in an entry containing the person to whom to send the letter
%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

\endlinechar=-1
\read\addressfile to\text \let\title=\text

\loop
    \read\addressfile to\text \let\firstname=\text
    \read\addressfile to\text \let\nickname=\text
    \read\addressfile to\text \let\middlename=\text
    \read\addressfile to\text \let\lastname=\text
    \read\addressfile to\text
        \ifx\text\blank\def\jr{}\else\def\jr{, \text}\fi
        \endlinechar='015
    \message{Now processing letter to \addressee.}
    \getaddress
    \doletter
      \endlinechar=-1
    \read\addressfile to\text \let\title=\text
    \ifeof\addressfile\endfalse\else\endtrue\fi
    \ifend
\repeat

\bye
\endtt

\noindent
Our local letter-formatting macros are:
\begintt
\input whatever local macro package you wish here

\twelvept    % 12-point size is so much easier to read

\hsize=6.5truein
\vsize=8.0truein
\hoffset=1.0truein
\voffset=1.5truein

\raggedbottom
\interlinepenalty=1000
\parindent=0pt
\parskip=0pt

\nopagenumbers

%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%      Define some stuff so that the headlines will come out the way
%      we want them to be.
%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

\newbox\headbox
\headline={\ifnum\pageno>1
   {\twelverm
      \global\setbox\headbox=\vbox\bgroup%
         \leftline{\addressee}
         \leftline{\today}
         \leftline{Page \folio}\egroup}\copy\headbox
   \else\hfil\fi}

\def\makeheadline{\vbox to 0pt{\vskip-70.6pt
   \line{\vbox to30.6pt{}\the\headline}\vss}
   \nointerlineskip}

\newif\ifend

%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%       Macros for reading in the address from the file.
%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

\def\blank{}

\def\endletter{\endmode\vfill\eject\pageno=1}

\newdimen\longindentation \longindentation=10truecm
\newbox\theaddress
\newif\ifast
\def\aster{* }
\def\getaddress{{\global\setbox\theaddress=\vbox\bgroup\raggedright%
   \hsize=\longindentation
   \everypar{\hangindent2em}
      \line{\vbox to10.2pt{}\addressee\hss}\egroup%
   {\loop{\read\addressfile to\text
      \ifx\text\aster\astfalse\else\asttrue\fi
      \ifast\global\setbox\theaddress=\vbox\bgroup\unvbox\theaddress
         \line{\vbox to 10.2pt{}\text\hss}\egroup}\repeat}}}

%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%       Macros for formatting the letter.
%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

\def\letterbody{\beginparmode}
\def\closing{\beginlinemode\getclosing}
{\obeylines\gdef\getclosing #1
   #2
      {#1\nobreak\bigskip \leftskip=\longindentation #2
      \nobreak\bigskip\bigskip\bigskip\bigskip % space for signature
      \def
      {\endgraf\nobreak}}}
\def\annotations{\beginlinemode\def\par{\endgraf\nobreak}\obeylines\par}
\def\ps{\beginparmode\nobreak
   \interlinepenalty5000\def\par{\endgraf\penalty5000}
   P.cS.\ }

\def\address{\beginlinemode \copy\theaddress \endgroup}
\def\doletter{{\leftskip=\longindentation%
      \rm\today\bigskip\address\bigskip}
   \input \letfile}

%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%       Macros for setting up forms of salutation.
%::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

\def\mr{Mr.}
\def\ms{Ms.}
\def\mrs{Mrs.}
\def\miss{Miss}

\def\addressee{\ifx\blank\title\else\title\space\fi%
   \firstname\space\ifx\blank\middlename\else\middlename\space\fi%
   \lastname\jr}
\def\person{\ifx\blank\title Sir or Madam\else\title\space\lastname\fi}
\def\familiar{\ifx\blank\nickname \firstname\else\nickname\fi}
\def\formal{\ifx\mr\title Sir\else{\ifx\ms\title Madam\else%
   {\ifx\mrs\title Madam\else{\ifx\miss\title Madam\else{\person}\fi}%
   \fi}\fi}\fi}
\endtt

The AutoLetter procedure prompts the user for the names of the address and
letter files and then goes to work. A similar procedure (called {\smc Labels})
can also be used with the address file to produce 33 labels/page (3 columns
of 11 labels). This enables us to produce form letters with or without labels
or to maintain mailing lists without requiring letters (for abstract mailings,
for example).

If anyone is interested in having these procedures, drop me a line. If response
is high, I would be more than willing to provide them to the \TeX\ community
at large. Mail may be sent to:

\leftline{Bitnet: Bell@UKANVAX}
\leftline{SPAN: KUPHSX::Bell}

-------