You seem to be processing a TeX file ... so why not use TeX for this? Then you will be sure that there will be no problems and side effects, for example,
\word {there a space between \verb=\word= and the curly bracket}
it will work anyway! It will still work for multi-line broadcasting:
\word{this is a multiline stuff \emph{and you can even add more groupings in it,} it'll still work fine!}
In the (La) TeX preamble, simply add:
\newwrite\file \immediate\openout\file=output.txt \def\word#1{\immediate\write\file{#1}}
or use \newcommand if you are using LaTeX and not plainTeX.
You can also put \immediate\write\file{#1} in your \word definition macro. If you do not have access to the \word macro (for example, in a class or style file), you can:
\let\oldword\word \def\word#1{\immediate\write\file{#1}\oldword{#1}}
Hope this helps!
source share