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?

  • I'd extended the answer at the previous question to handle this case before seeing this question:-) – David Carlisle Sep 6 '17 at 7:18
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.