In most cases, by the time output gets to your screen, arguments are fully expanded and my question is moot. But sometimes (verbatim being a common example), one wishes to operate on arguments with different levels of expandedness. My question concerns how to preserve a level of expandedness, or conversely, how to do a partial expansion.

Here's an MWE which demonstrates how the level of expandedness of the argument affects the result:

\display{\large word}\par
\def\x{\large word}

enter image description here

In the first case, I pass actual text to my macro \display and get the top line. But if I stuff the same text into \x and pass it to the macro \display, it produces a different output, because the the two different invocations supplies the macro with an argument at different levels of expansion.

To the MWE, how does one reconcile the output in either direction (i.e., if the first output was what I actually sought from the second instance and, alternately, if the second output was what I actually sought from the first instance)?

Related to this MWE would be to know if there is something like a \verbatim{\x} which prints out the verbatim of the first level expansion of \x, for the example of the MWE, producing \large word (space included).

More generally, what are the LaTeX techniques for controlling the expansion of an argument, when what your macro gets may be far removed from the original "plain" text.

  • Are we allowed to use e-TeX? If so, you seem to be looking for \detokenize\expandafter{\x} and so on.
    – Joseph Wright
    May 23, 2013 at 13:43
  • @JosephWright e-TeX is OK to use. May 23, 2013 at 13:56

2 Answers 2


With e-TeX available, the \detokenize primtive does what you want: it turns all of the material into catcode-12 tokens, apart from spaces which are catcode 10. It also inserts spaces after control words. \detokenize has toks-like syntax, so can be used in the form


The \detokenize primitive is expandable, so you can for example \edef this.

A non-expandable version without e-TeX can be implemented as


in LaTeX and with the appropriate definition of \strip@prefix in plain TeX.

(The e-TeX manual describes the action of \detokenize in terms of conceptually saving to a toks and writing this to a file, then reading back with verbatim-like catcodes. The use of \meaning is rather clearer and avoids the file, and in any case both are not expandable.)


Perhaps what you are looking for is


which gives the verbatim-ish rendering of the first level expansion of #1 but similarly to your example it doesn't really make sense to pas in more than a single token as #1.

Any later tokens in either your example or this one are just typeset as normal.

But note that the output of \meaning isn't the first level expansion really as it's all catcode 12, so can not be further expanded.


You must log in to answer this question.

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