What is the result from \string{} and why can't we use it in place of \detokenize to check if a macro argument is empty as explained here?

  • \string stringifies the next token, in that case {, and the result is an unbalanced closing brace. – egreg Nov 18 '14 at 10:17
  • 1
    String doesn't take one argument but one token. So \string{} is converted to \string{ (that prints the {) and a closing brace }. – Manuel Nov 18 '14 at 10:17

From the TeXbook, page 213:

\string⟨token⟩. TeX first reads the ⟨token⟩ without expansion. If a control sequence token appears, its \string expansion consists of the control sequence name (including \escapechar as an escape character, if the control sequence isn’t simply an active character). Otherwise the ⟨token⟩ is a character token, and its character code is retained as the expanded result.

Thus the argument to \string can't be included in braces: with


the { is “stringified”, returning a {12 character token and the following } remains untouched.

On the contrary, \detokenize takes as argument a ⟨general text⟩. Here's the excerpt from the manual of ε-TeX

\detokenize⟨general text⟩.
The expansion is a list of character tokens representing the token list ⟨balanced text⟩. As with the lists of character tokens produced by TeX’s \the and ε-TeX’s \readline, these tokens have category 12 (‘other’), except that the character code 32 gets category 10 (‘space’).

So \detokenize must be followed by a { (after a possible ⟨filler⟩) and its argument is whatever follows until the matching ⟨right brace⟩ (that is an explicit character token with category code 2). As with all instances of ⟨general text⟩, TeX will expand tokens in order to find {.

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.