3

On the question How to make \meaningbody say the command is undefined? the \meaningbody command from Equivalent of \show to display the LaTeX code in the document was fixed to correctly display undefined commands. But after @egreg commented on the @David Carlisle answer saying: What about \meaningbody\box? Then I tried this:

\documentclass{article}

\makeatletter
\newcommand{\meaningbody}[1]
{%
    {\ttfamily
    \ifdefined#1
        \expandafter\strip@prefix\meaning#1
    \else
        `The command \string#1 is undefined.'
    \fi}%
}
\makeatother

\begin{document}

\meaningbody\box

\meaning\box

\end{document}

And it does the strange error:

! Argument of \strip@prefix has an extra }.
<inserted text> 
                \par 
l.17 \meaningbody\box

When I just do \meaning\box it outputs “box on the PDF:

enter image description here

Why would be \box is different?

Werner
  • 603,163
user
  • 4,745

1 Answers1

8

It cannot work because the definition of \strip@prefix is actually

\def\strip@prefix#1>{}

That means, that it strips everything before the >. That works perfect in case of a macro like \mbox. If we look at \meaning\mbox we find

\long macro:#1->\leavevmode \hbox {#1}

So if we snip that at the > as we can do with \expandafter\strip@prefix\meaning\mbox we get the rest: \leavevmode \hbox {#1}.

Now \box is a primitive and therefore \meaning\box is just

\box

So where should \strip@prefix snip now? It just keeps absorbing tokens, looking for >, until in your case something invalid is encountered and then it throws an error.

Henri Menke
  • 109,596