7

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 ?

5
  • 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. – Loic Rosnay Aug 2 '12 at 7:58
  • 3
    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
  • 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. – Loic Rosnay Aug 2 '12 at 9:33
  • @nicolasroy As I said below my answer, I think it would be useful to ask a question which explains the entire context here. There may be alternative approaches which make sense if we know what is actually required. – Joseph Wright Aug 2 '12 at 10:12
9

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}
\bye

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.

4
  • 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 ? – Loic Rosnay Aug 2 '12 at 8:02
  • 1
    @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... – Loic Rosnay Aug 2 '12 at 8:11
  • 1
    @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 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.