The link to Lisp is quite true (it's mentioned somewhere in the sources, but I can't put my finger on it just now). The way this works is very simple. The definitions are
\def\@car#1#2\@nil{#1}
\def\@cdr#1#2\@nil{#2}
In this context, \@nil
is being used as a delimiter, so what it expands to does not matter at all. This is a classic 'delimited argument' situation in TeX. (The only thing that is important is that TeX finds the appropriate token in the input stream, in this case before any \par
tokens.) TeX will allow us one blank the last item of this type of delimited macro to be empty. As a result, both \@cdr
and \@car
need to have at least one token supplied: something like
\expandafter\@cdr\@empty\@nil
will give an error.
Notice that these are TeX functions, not Lisp ones, and so we get the first <balanced text> separated off from the rest.
\makeatletter %% access private macros
L%% print an L
\kern -.36em%% add a negative kern
{%% open a group
\sbox \z@ T%% load box 0 with a T
\vbox to\ht \z@ {%% start a vertical box as high as box 0
\hbox {% start a horizontal box
\check@mathfonts%% ensure the math fonts sizes are set up at the current font size
\fontsize \sf@size \z@%% use the established font size for sub/superscripts
\math@fontsfalse%% don't bother setting up all the math fonts for the new current size
\selectfont%% select the font
A%% print an A
}%% finish the horizontal box
\vss%% fill up the stated height
}%% finish the \vbox
}%% end the group
\kern -.15em%% add a negative kern
\TeX%% print the TeX logo
\makeatother%% no more private macros allowed
Some notes.
\sbox\z@ T
is completely equivalent to \sbox{0}{T}
; the code is reduced to the minimum number of tokens because at the time LaTeX2e was being developed, computer memory was very scarce. The code stored in the definition of \LaTeX
is three tokens, whereas \sbox{0}{T}
has seven.
What a \vbox
and an \hbox
are can be found in TeX by Topic (freely available in any TeX distribution as texdoc texbytopic
or on CTAN).
\check@mathfonts
ensures that the math fonts are set up for the current size; normally this is only done when a math formula is started. This command, in particular, defines \sf@size
as the font size for first level sub/superscripts. The macro \selectfont
sets up the current font; with \math@fontsfalse
we tell it not to do the necessary work for setting up also the math fonts, because we just want to print an A at the requested size, not to typeset arbitrary text with math.
\vss
is the same as \vspace{0pt plus 1fil minus 1fil}
, so it is an infinitely stretchable and shrinkable space, which will push the \hbox
containing the A flush with the top of the \vbox
. Thus, the top of the A will be at the same height as the top bar of the T (and probably also the top of the L).
A \kern
is something like \hspace
, but not stretchable nor shrinkable. In these places it ia preferred because it cannot be used as a line break point (unless it is followed by a skip).
The definition of \TeX
is simpler: the E is shifted down and some kerns are applied.
As Barbara notes in comments, this definition is very carefully studied for the Computer Modern fonts. Other fonts may give a not so good result. The metalogo
package tries to “abstract” the spacings, so the logo can be adapted to other fonts with minimum hassle (but some tries are needed to get the parameters right).
Best Answer
Here is an attempt at creating something that stretches with the font size:
In the above MWE,
\cMaTeX
stores a\normalsize
version of MaTeX in a box, and resizes the box based on the height ofM
in the prevailing font. Resizing (while maintaining aspect ratio) is done using\resizebox{!}{<height>}{<stuff>}
from thegraphicx
package.