TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use other delimiters than {} for the argument of \detokenize. E.g. something like

\detokenize\begingroup a lot of stuff \com \mycom \endgroup

but it does not work. Am I really obliged to use curly braces ?

share|improve this question
Why do you want to do this? – Joseph Wright Aug 2 '12 at 7:55
because i would like to start the capture (\detokenize\begingroup) at some point, initiated by some command, and make it stop (\endgroup) in another command. – nicolas roy Aug 2 '12 at 7:58
once you start \detokenize commands are not expanded until the closing brace is seen so even if \egroup worked you would not be able to have the \egroup inside another definition. You indicate in comments that you want to write to a file in which case you don't need detokenize at all just something like filecontents package to write the contents of an environment verbatim – David Carlisle Aug 2 '12 at 8:46
ok, thanks for the explanation. – nicolas roy Aug 2 '12 at 8:55
I think filecontents packages is not suitable for me, because I need to do several things on my content before i \write it to the file. – nicolas roy Aug 2 '12 at 9:33
up vote 8 down vote accepted

TeX will allow you to use implicit { and } tokens in some places: these are available as \bgroup and \egroup. The \detokenize primitive is toks-like, and so will accept an implicit begin-group token

\detokenize\bgroup stuff}

but requires an explicit end-group token (as shown).

\begingroup/\endgroup forms a 'semi-simple' group, which is not the same group type as formed by {/}. The two types are thus not interchangeable.

share|improve this answer
ok, thanks for the info. But it does help for my problem, since I can't use \detokenize\bgroup stuff \egroup, because the end } is mandatory, if I understood correctly. Right ? – nicolas roy Aug 2 '12 at 8:02
@nicolasroy As I've indicated, you do need an explicit }, in the same way you do with a toks assignment (and in contrast to boxes, which do allow an implicit end-group token). You probably will need to do a verbatim-like grab. – Joseph Wright Aug 2 '12 at 8:06
Yes, I will look at verbatim. But I want to \write the result of this grab into a file, and need therefore an "expandable verbatim", if it exists... – nicolas roy Aug 2 '12 at 8:11
@nicolasroy I think a question which actually explains what you need to do would be helpful: it's difficult to give more information with the bits-and-pieces here! – Joseph Wright Aug 2 '12 at 8:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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