I'm trying to create a screenplay-like class that uses a very simple syntax to create the dialogue, and dumps it as a plain text file for use in subtitles. To divide the subtitle sections I use &, ^ sets a new speaker, like that:
\documentclass{article} \catcode`\^=13 \def^#1: {\par \textbf{#1:}} \catcode`\&=13 \def&{\par \hspace{10pt}} \begin{document} ^Alice: &Hello Bob. &What's up? ^Bob: &Nothing, really. &Goodbye. \end{document} Now I would like to get at the text between &...& (i.e. from & to just before the next &, so &a&b&c should expand to \foo{a}\foo{b}\foo{c}) to save it with a running index to my text file. So I tried \bgroup/egroup as in:
\documentclass{article} \usepackage{color} \def\testcommand{\textcolor{blue}} \catcode`\^=13 \def^#1: {\egroup \par \textbf{#1:} \bgroup} \catcode`\&=13 \def&{\egroup \par \hspace{10pt} \testcommand\bgroup} \begin{document} \bgroup ^Alice: &Hello Bob. &What's up? ^Bob: &Nothing, really. &Goodbye. \egroup \end{document} And it seems to work, since \textcolor doesn't just colorize the next letter but the whole line, but when I use \def\testcommand#1{(#1)} it is called with an empty argument (produces () Hello Bob. () What…).
I guess this has something to do with the fact that when I use \begingroup/\endgroup with my \testcommand nothing changes but \textcolor breaks with Extra }, or forgotten \endgroup on the first &.
In color.sty they use \def\textcolor#1# which I have never seen before (and when I use it with my testcommand it breaks with \begin{document} ended by \end{)}. What magic is that? Very difficult to google…
My other attempt \def&{ \testcommand{#1} } doesn't work either because it eats the next &… (is there some kind of lookahead? So I could use \def& and eat tokens until the next one would be & or ^?)
Any pointers appreciated!