General ⇒ \write curly brace
-
- Posts: 7
- Joined: Tue Jun 23, 2009 10:59 pm
\write curly brace
I know this is a very specific issue but it is important to me, I hope someone knows how to solve it!
I am trying to write a line to a text file (not unlike creating the aux file). I want to write out the line:
PageProps = {
to a file.
I can write:
PageProps =
or:
PageProps = {}
but if I try what I want, I get an error because of unbalanced braces.
Try it out with this
\newwrite\outputstream
\immediate\openout\outputstream=document.pdf.info
\immediate\write\outputstream{PageProps = { }
note that \{ doesn't seem to do it.
I am trying to write a line to a text file (not unlike creating the aux file). I want to write out the line:
PageProps = {
to a file.
I can write:
PageProps =
or:
PageProps = {}
but if I try what I want, I get an error because of unbalanced braces.
Try it out with this
\newwrite\outputstream
\immediate\openout\outputstream=document.pdf.info
\immediate\write\outputstream{PageProps = { }
note that \{ doesn't seem to do it.
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
\write curly brace
Code: Select all
\immediate\write\outputstream{PageProps = \string{ \string} }
Joseph Wright
-
- Posts: 7
- Joined: Tue Jun 23, 2009 10:59 pm
Re: \write curly brace
Thank you for your quick reply, unfortunately this again only makes a pair of braces; I need to write out only a left brace { at the end.
Is there some way of doing this?
Is there some way of doing this?
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
\write curly brace
Use a group, and inside replace { } with, say, [ ], as group begin/end characters:
This is all plain TeX coding, I'm afraid.
Code: Select all
Code, edit and compile here:
\newwrite\outputstream\immediate\openout\outputstream=document.pdf.info\begingroup\catcode`\[ = 1\relax\catcode`\] = 2\relax\catcode`\{ = 12\relax\catcode`\} = 12 \relax\immediate\write\outputstream[PageProperies = { ]\endgroup
Joseph Wright
-
- Posts: 7
- Joined: Tue Jun 23, 2009 10:59 pm
\write curly brace
Excellent, just a little massaging and that is now working.
I have just one more question then. What if I wanted a command to write out a } to the file and close it. I am trying
but it doesn't seem to accept this as a command that I can define. The method works for generating a } without trying to call it as \finalizeinfo.
Thanks again for all the help!
I have just one more question then. What if I wanted a command to write out a } to the file and close it. I am trying
Code: Select all
Code, edit and compile here:
\providecommand{\finalizeinfo}[0]{\begingroup\catcode`\[ = 1\relax\catcode`\] = 2\relax\catcode`\{ = 12\relax\catcode`\} = 12\relax\immediate\write\outputstream[ } ]\endgroup\immediate\closeout\outputstream}
Thanks again for all the help!
-
- Posts: 7
- Joined: Tue Jun 23, 2009 10:59 pm
Re: \write curly brace
One more note. The fix for the first problem works, but still gives an error message. Is there someway to turn that off? Just curious.
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
\write curly brace
A better method:
You can then use \OpenBrace and \CloseBrace wherever you need.
Code: Select all
Code, edit and compile here:
\newwrite\outputstream\immediate\openout\outputstream=document.pdf.info\begingroup\catcode`\[ = 1\relax\catcode`\] = 2\relax\catcode`\{ = 12\relax\catcode`\} = 12 \relax\gdef\OpenBrace[{]\gdef\CloseBrace[}]\endgroup\immediate\write\outputstream{PageProperies = \OpenBrace }\immediate\write\outputstream{\CloseBrace}
Joseph Wright
-
- Posts: 7
- Joined: Tue Jun 23, 2009 10:59 pm
Re: \write curly brace
Thanks so much, that works perfectly!