7

Today I came across these three commands:

\@nil
\@cdr
\@car

Some are mentioned here and here, but I didn't get the idea of it. It seems to have to do with the macro character.

I haven't seen any description about it on google and TeX.SX.

4
  • I retagged from tex-core to latex-base as these are latex macros Commented Feb 13, 2017 at 22:01
  • 3
    This question explains them quite well: Lisp relics in LaTeXe logo
    – Alan Munn
    Commented Feb 13, 2017 at 22:02
  • @AlanMunn ooh it does but this one has a better title Commented Feb 13, 2017 at 22:03
  • That's probably the reason I haven't found it Commented Feb 13, 2017 at 22:04

1 Answer 1

10

the names come from lisp.

In lisp, car returns the head of a list, cdr returns the tail of a list and nil is an empty list.


in latex

\def\@car#1#2\@nil{#1}
\def\@cdr#1#2\@nil{#2}

(\@nil is not defined at all)

so

\@car abc\@nil

expands to a

and

\@cdr abc\@nil

expands to bc

9
  • In expl3 lingo, \tl_head:n {abc} and \tl_tail:n {abc}
    – egreg
    Commented Feb 13, 2017 at 22:02
  • But how does this work, if \@nil is undefined. Why is there no undefined error? Commented Feb 13, 2017 at 22:02
  • 6
    @MaestroGlanz tokens only make an undefined error if you try to expand them. tokens used to delimit a macro argument are not expanded, try \def\foo#1\wibblethingy{hello #1}...\foo Maestro\wibblethingy Commented Feb 13, 2017 at 22:06
  • 2
    @egreg we should put in a change request \tl_car:n and tl_cdr:n to honour the cultural heritage Commented Feb 13, 2017 at 22:08
  • Aaaaah. Good to know. Commented Feb 13, 2017 at 22:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .