How can the special characters { and } be written literally to an external file in LaTeX, without being balanced?

Obviously the following does not work:


3 Answers 3


Writing balanced braces doesn't require anything special, as the following transcript of an interactive TeX session shows:

$ tex
This is TeX, Version 3.1415926 (TeX Live 2011)
No pages of output.
Transcript written on texput.log.
$ cat temp.dat

If you want to write unbalanced braces you can do with

\catcode`<=1 \catcode`>=2
\catcode`{=12 \catcode`}=12




that is, using \wbgroup and \wegroup for writing open and close brace respectively. The contents of temp.dat will be


Notice that LaTeX already has equivalents of \wbgroup and \wegroup that are called \@charlb and \@charrb, which actually expand to category code 11 characters.

Alternative definitions for \wbgroup and \wegroup that expand to category code 12 characters are

\begingroup\lccode`?=`\{ \lccode`!=`\}



In order to write unbalanced braces you should use macros which hold them as verbatim characters instead. These will be expanded when written to the file. LaTeX2e defines \@charlb (left brace) and \@charrb (right brace) which require \makeatletter .. \makeatother of course. You can find these listed in source2e or better macros2e.


You can also define you own macro easily with \Verbdef from my newverbs package (not to be confused with \verbdef from the verbdef package). Macros define this way are usable to be written to an external file (in contrast to \verbdef which macros them typsetable).

% ...

  • The \Verbdef-Methode doesn't seem to work any more: "\protected" is inserted into the output (it worked well with TL2020 but not after I switched to TL2021). Edit: \@charlb also doesn't seem to work. egreg's anwers works well.
    – lAtExFaN
    May 25, 2021 at 12:17

Depends what you want to do, you can try escaping it


This will write \delimiter "5267309 in the temp.dat file or you can write \string\}, which will write \} in the file.

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.