Using LuaLaTeX with TeXlive 2016, although I imagine that this question applies to nearly anything:
I know how to create a file using \immediate\write
on a line-by-line basis. But I would like to do it for multiple lines, where the number of lines is not known in advance (it is the result of gathering text items in a macro). Something like this:
\newwrite\file
\immediate\openout\file=pickafilename.txt
\immediate\write\file{Hello! I am a new file.}
\immediate\write\file{\MacroContainingTextMacros}
\closeout\file
The \MacroContainingTextMacros
has a few small macros within it, which I wish to expand as the file is written. Each of those small macros contains a few lines of plain text. So I cannot use verbatim, or filecontents
.
Any ideas?