tags:

views:

30

answers:

1

I have a latex document that I want to use to write text to a plain text file. I want macros to be expanded, so I can't use \filecontents (which just saves input verbatim to a file)

So far I have

\newwrite\metadatafile
\immediate\openout\metadatafile=\jobname-meta.txt
\immediate\write\metadatafile{Title: \jobname\string

Tags: \coursecode.\secnum.\termcode, \coursecode.\termcode, ...

Description:
...}
\immediate\closeout\metadatafile

What comes out in the text file inserts \par tokens instead of my double-newlines, and doesn't have any newlines in it at all. How can I get newlines and have a regular plain text file?

+1  A: 

There are two answers: One is to just use a lot of \write statements, one for each line you want written. That is, \write writes a line to the file, including the newline character. So a blank line can be done with just

\write\metadatafile{}

Or you can use the primitive \newlinechar. In plain tex the double-carat macro ^^J is aliased to \newlinechar so you can use that as well. See pages 228 and 348 of The TeXBook.

While I have that book open, I looked up the importance of the \immediate primitive before \write. All usages of \write cited also use \immediate. I've tried without the \immediate and without it things don't get written.

Matthew Leingang