[comp.text.tex] Question on a TeX formletter macro

klinck@cs.odu.edu (Dr. John Klinck) (03/05/90)

     This is a request to TeX wizards to help me solve a puzzle. I am trying
to create a macro to write a form letter.  The arguments to the macro will
be the name and address of the recipient and the salutation. The form letter
uses the letter format that is given in the back of the TeXbook (pp.403-408).

     The macro that I have created (\letterone) has a problem when the
address arguements are read by the \getaddress macro.  The \getaddress macro
looks for carriage returns to delimit arguements, but the \letterone macro
has apparently removed them.  I have tried a number of ways to put them in
explicitly, with no luck.  I anticipate having the same problem with
\closing.  It is apparent that I am missing something fundamental about the
way that TeX macros work or I am looking in the wrong place for the problem
or both.  I have included the .tex file and the .log file hoping that this
is enough information to solve the puzzle.

     I would greatly appreciate if someone would tell me how to create the
formletter macro so that it properly interfaces with the letter format.
Although a working macro is what I want, I would also like to know why this
version has failed so that I can avoid such errors in the future.

Thanks in advance,  John Klinck     klinck@nansen.ocean.odu.edu

p.s.  Yes, I know that it is possible to use LaTeX with the letter style and
a merge substyle.  There are some features of the LaTeX letter that I do not
like and would need to change. I would prefer to use my own letter.tex macros.

-------------------------------- tex file to test letter macro ---------
\input tex/letter.tex

\long\def\letterone#1
#2
#3
#4{
%              macro to create a letter given a name and address.
\obeylines
\blankhead
\relax
\address
#1
#2
#3

\body
Dear {#4},

This will be a short letter.

\closing
Sincerely,
John M. Klinck

\annotations
enclosures

\endletter   }

\tracingmacros=1
\letterone {Mr. P. Student}
{123 Maple Street}
{Anytown, State 22332}
{Mr. Student}

\end
-----------------------------  end of test file -------------------------

------------------ log file from test -----------------------------------
This is TeX, Version 2.1 for Berkeley UNIX (preloaded format=plain 89.7.31)  4 MAR 1990 13:52
**fletter 
(fletter.tex (tex/letter.tex
\longindentation=\dimen16
\theaddress=\box16
\ttglue=\skip18
)
\letterone #1 #2 #3 #4-> \obeylines \blankhead \relax \address #1 #2 #3 \par \b
ody Dear {#4}, \par This will be a short letter. \par \closing Sincerely, John 
M. Klinck \par \annotations enclosures \par \endletter 
#1<-Mr. P. Student
#2<-123 Maple Street
#3<-Anytown, State 22332
#4<-Mr. Student

\obeylines ->\catcode `\^^M\active \let ^^M\par 

\blankhead ->\vbox {\vskip 48pt} \pageno =1 {\leftskip =\longindentation \parsk
ip =0pt \today \bigskip } 

\today ->\ifcase \month \or January\or February\or March\or April\or May\or Jun
e\or July\or August\or September\or October\or November\or December\fi \space \
number \day , \number \year 

\space -> 

\bigskip ->\vskip \bigskipamount 

\address ->\beginlinemode \getaddress 

\beginlinemode ->\endmode \begingroup \noindent \obeylines \def \endmode {\par 
\endgroup }

\obeylines ->\catcode `\^^M\active \let ^^M\par 

\getaddress #1^^M#2^^M->\parskip 0pt\parindent 0pt^^M#1\gdef \addressee {#2}\gl
obal \setbox \theaddress =\vbox \bgroup \raggedright \hsize =\longindentation \
everypar {\hangindent 2em}#2^^M\def \endmode {\egroup \endgroup \copy \theaddre
ss \bigskip }

Runaway argument?
Mr. P. Student 123 Maple Street Anytown, State 22332 
! Paragraph ended before \getaddress was complete.
<to be read again> 
                   \par 
\letterone ...khead \relax \address #1 #2 #3 \par 
                                                  \body Dear {#4}, \par This...
l.34 {Mr. Student}
                  
? x
No pages of output.
-------------------------------  end of log file  ------------------------