What is the meaning of \meaning?

~ $ tex
This is TeX, Version 3.14159265 (TeX Live 2016) (preloaded format=tex)
**\relax

*\def\test#1{This is a test #1 macro}

*\show\test
> \test=macro:
#1->This is a test #1 macro.
<*> \show\test

\show gives the meaning (definition) of a macro (or a primitive) in the log file and the terminal. \meaning shows the same but puts it in the document instead. In the example above it is written to the notes file.


If you process the document

\documentclass{article}
\usepackage{endnotes}

\begin{document}

x\endnote{Recall that $\sqrt{2}$ is irrational}

\end{document}

you'll get a file with extension .ent containing

\@doanenote {1}
macro:->Recall
that
$\sqrt
{2}$
is
irrational
\@endanenote 

This is a consequence of the definition

\long\def\@endnotetext#1{%
     \if@enotesopen \else \@openenotes \fi
     \immediate\write\@enotes{\@doanenote{\@theenmark}}%
     \begingroup
        \def\next{#1}%
        \newlinechar='40
        \immediate\write\@enotes{\meaning\next}%
     \endgroup
     \immediate\write\@enotes{\@endanenote}}

and of

\let\@doanenote=0
\let\@endanenote=0

which make the two control sequences into unexpandable tokens.

The \meaning primitive takes as argument a single token and expands to a string representation of the token: all characters will have category code 12, except for space tokens that are normalized to character code 32 (space) with category code 10. If the token is a macro (that is, it has been defined with \def, \edef, \gdef or \xdef), the representation will be of the form

macro:〈parameter text〉->〈replacement text〉

Thus, in the endnotes case above, \meaning\next will expand to

macro:->Recall that $\sqrt {2}$ is irrational

because the parameter text is empty. By rule, each control word in the string representation will be followed by a space.

The macro \@endnotetext does three \write operations. In the first, \@doanote {1} is written out, because \@doanote is not expandable so it is written out as is (with a trailing space), whereas \@theenmark will be expanded. Also { and } are unexpandable, so we get the first line in the example.

Then the expansion of \meaning\next is written, under the setting \newlinechar='40 which means that spaces (character code decimal 32, octal '40) will be transformed into newline characters. I guess this is done for avoiding overlong lines, in case of long endnotes.

Finally \@endanenote is written (on a new line).

When the .ent file is read in by the \theendnotes command, \@doanenote is given a new meaning; basically it reads until > is found, emits \begingroup, sets the mark to the tokens in braces and starts typesetting the note text; \@endanenote is redefined to issue \par\endgroup.


What does \meaning return in other cases? Here are a few examples; I use plain TeX, but it would be the same in all flavors of TeX.

\let\foo=0 % like in endnote.sty
\def\next{Recall that $\sqrt{2}$ is irrational}
\def\macro#1{Something with #1}

\tt % typewriter type

\meaning\relax

\meaning a

\meaning 0

\meaning\alpha

\meaning\foo

\meaning\next

\meaning\macro

\meaning ~

\meaning\&

\meaning\pageno % plain tex

\bye

enter image description here

A control sequence \let to a character will display the same as if the character was used. A control sequence defined with \chardef (like \&) gives \char" followed by the hexadecimal number of the character; similarly for \mathchardef (like \alpha).

The macros \next and \macro show the difference when there is a parameter text; finally, primitives represent themselves (like \relax). There are a few other cases, I showed \pageno that's defined with \countdef.

Tags:

Tex Core