I have a file like this:
This \word{is} some text.
This is some \word{more text}.
\word{This} is \word{yet} some more \word{text}.
I need to create a list of all of the text that appears between \word{
and the matching closing brace, }
, e.g.:
is
more text
This
yet
text
\word{}
.How can I print a list of all of the text appearing in \word{}
?
It seems you're handling a TeX file... so why not use TeX to do this directly? Then you'll be sure there won't be any problems and side effects, e.g.,
\word {there's a space between \verb=\word= and the curly bracket}
this would still work! It will still work for multi-line stuff:
\word{this is
a multiline stuff \emph{and you can even add more groupings in it,}
it'll still work fine!}
In your (La)TeX preamble, just add:
\newwrite\file
\immediate\openout\file=output.txt
\def\word#1{\immediate\write\file{#1}}
or use \newcommand
if you're using LaTeX and not plainTeX.
You can also put the \immediate\write\file{#1}
inside your \word
definition macro. If you don't have access to the \word
macro (e.g., it's in a class or style file) you can:
\let\oldword\word
\def\word#1{\immediate\write\file{#1}\oldword{#1}}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With