12

I was trying to make my own customization letter class and searching for the definition of the \toname command, I found this.

some LaTeX definitions

A triple at several times, but I wasn't able to find information so I decided to ask.

2 Answers 2

9

When you do

\begin{letter}{
  M. Y. Friend \\
  42 Some Rd \\
  Someplace
}

LaTeX does

\@processto{\leavevmode\ignorespaces #1}}

which in the example case becomes

\@processto{\leavevmode\ignorespaces M. Y. Friend \\ 42 Some Rd \\ Someplace }

This will first execute

\@xproc \leavevmode\ignorespaces M. Y. Friend \\ 42 Some Rd \\ Someplace \\@@@

According to the definition of \@xproc, LaTeX will take as #1 everything up to the first \\ and #2 everything up to \\@@@ and so it will do

\def\toname{\leavevmode\ignorespaces M. Y. Friend }
\def\toadddress{ 42 Some Rd \\ Someplace \\}

Suppose instead you do

\begin{letter}{M. Y. Friend}

The same process will lead to the call

\@xproc \leavevmode\ignorespaces M. Y. Friend \\@@@

In this case #1 is again everything up to the first (and unique) \\, and #2 is everything from \\ (excluded) up to @@@, so it's empty.

The interesting case is therefore when \toaddress is not empty: a call to \@yproc is necessary in order to remove the trailing \\ and indeed the call is

\@yproc #1@@@

which will become

\@yproc  \leavevmode\ignorespaces M. Y. Friend \\ 42 Some Rd \\ Someplace @@@

so it will end up in

\def\toaddress{ 42 Some Rd \\ Someplace }

Note that leading and trailing spaces are not omitted. They will “disappear” when \opening is executed, because \toname and \toaddress are typeset in the scope of \raggedright, precisely (line 192)

{\raggedright \toname \expandafter\\\toaddress \par}%

so in the example case we'll get

{\raggedright \leavevmode\ignorespaces M. Y. Friend \\ 42 Some Rd \\ Someplace \par}

Since \\ also does \par, in this context, trailing spaces are suppressed by the implicit \unskip.

Why the strange \expandafter? Because a user might like some separation between the addressee's name and the address, so typing in something like

\begin{letter}{
  M. Y. Friend \\[1ex]
  42 Some Rd \\
  Someplace
}

Apply the same reasoning as above to see that in this case LaTeX does

\def\toaddress{[1ex] 42 Some Rd \\ Someplace }

and without the \expandafter the following \\ would not see [1ex].

The documentation indeed says

A better fix would be to do a proper parsing but…

9

Look at the next line where \@xproc is defined.

\long\def\@xproc #1\\#2@@@{\def\toname{#1}\def\toaddress{#2}}
\long\def\@yproc #1\\#2@@@{\def\toaddress{#2}}

There are #1 separated by \\ and #2 separated by @@@. So @@@ is simply separetor of the second parameter. The usage of \@xproc text\\@@@ (used in \@processto) does following: if text includes \\ then #2 is nonempty because #2 includes the rest of text followed by \\. If text does not include \\ then #2 is empty because #1 is whole text and we see nothing between \\ and @@@. This behavior can be broken if someone write a text including \\@@@ but macro programmer supposed that this has less probability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.