# Plain TeX macros with \obeylines and no delimiters.

How can I define a macro, say \address, so that I can use it like this:

\address
27/7 Montague Street
Edinburgh


and it would put the lines following it into another macro, say \addrinfo ? What I'm ultimately trying to do, is modify Knuth's letter macros so that I can specify the address once in the letter, and then produce an address in a different font. Currently I've got

\newbox\theiraddressbox
\hsize=\longindentation \everypar{\hangindent1cm}


but this means the address label is set in the same font.

-
Is there a reason you want to use plain tex instead of, say, koma-script’s nice letter (scrlttr2) class? – Caramdir Oct 6 '10 at 22:31
Personal preference for plain TeX, born from a frustration with LaTeX not giving me enough freedom. I'm also aware that my understanding of plain TeX is less that I want it to be. – Harry Newton Oct 10 '10 at 11:02

What you can do is to put each line into a separate definition as part of the definition of \address. In Knuth's letter format, he puts the first line of the address in the definition of \addressee.

The idea is to do this for the whole address. Then you'll have the definitions of \ToName, \ToStreet etc to use afterwards in any way you like.

A minimal example to illustrate the idea is as follows:

\def\beginlinemode{\endmode\begingroup\obeylines\def\endmode{\par\endgroup}}
\let\endmode=\par

% Populates the \To* definitions.
#2
#3
#4
{\gdef\ToName{#2\unskip}%
\gdef\ToStreet{#3\unskip}%
\gdef\ToCity{#4\unskip}%
\def\beginletter{\endgroup\bigskip}}}

Some Name
27/7 Montague Street
Edinburgh

\beginletter

And now you can use the different fields as you wish. For example:

\bigskip
\moveright2cm\vbox{\hbox{\ToName}\hbox{\ToStreet}\hbox{\ToCity}}
\bigskip

This letter is addressed to {\bf \ToName}.

\bye


You can also have a \FromAddress macro similar to \address, but whose ending markup is \address instead of \beginletter. So you'd start your letter like:

\FromAddress
My Name
My Street
My City

To Name
To Street
To City

\beginletter

etc

-

In effect, your \address macro is not undelimited: Somehow, the \endmode macro has to get called afterwards. In Knuth's letter macros, this job is done by the \body macro. So, what you can do is delimit the \address macro like this:

\def\address{\beginlinemode\getaddress}

Then the macro \theaddress will contain the unformatted address. Hope you can work out the missing details.
@Harry Newton: Unfortunately, you can't use \bgroup and \egroup in this way. As you can read in the TeXbook in the bottom of page 275, \def needs explicit left and right braces. – Hendrik Vogt Oct 16 '10 at 12:38