TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

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

Obviously the following does not work:

share|improve this question
up vote 23 down vote accepted

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`!=`\}


share|improve this answer

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).

% ...

share|improve this answer

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.

share|improve this answer

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.