I always thought TeX's macros are very Lispy like and stumbling across the definition of the LaTeXe logo confirmed it. The macro is defined as follows:
%\LaTeXe The LATEX2" logo as proposed by A-W designers.
\def\LaTeXe{%
\mbox{\m@th%
\if b\expandafter\@car\f@series\@nil\boldmath\fi
\LaTeX\kern.15em2$_{\textstyle\varepsilon}$}}
So what does the \@car
do?
Introduced in the Lisp programming language, car
and cdr
are primitive operations upon linked lists composed of cons cells
.
When cons
cells are used to implement singly-linked lists (rather than trees and other more complicated structures), the car
operation returns the first element of the list, while cdr
returns the rest of the list.
How does the @car
work and what is @nil
? As far as I can see, it is undefined, but does not give an error. It does not even give an error even if I define it as \def\@nil{illdefined!}
, as shown in the code below.
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{verbatim}
\begin{document}
\bigskip
\makeatletter
\def\@nil{illdefined!}
\scalebox{5}{\LaTeXe}
\makeatother
\end{document}
More on CAR and CDR at the wikipedia
Best Answer
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
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 likewill 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.