tags:

views:

89

answers:

3

To enter a bit of dialogue using the screenplay package, I have to use

\begin{dialogue}{Johnny} Some dialogue. \end{dialogue}
\begin{dialogue}{Jane} I see. \end{dialogue}

It gets a bit tedious after a while. Is it possible to specify a custom command so that I can use something like

\dialogue{Johnny} Some dialogue.
\dialogue{Jane} I see.

instead?

+4  A: 

Try this:

\newcommand{\dialogueline}[2]{\begin{dialogue}{#1} #2 \end{dialogue}}

% Usage example:
\dialogueline{Johnny}{Some dialogue.}  
\dialogueline{Jane}{I see.}  
In silico
That works perfectly. Thank you very much!
njt
This is a good answer, but if anybody knows how to replicate the exact format requested by the original poster, it would be nice to see.
Geoff
I think that's about as close as you can get to what the poster wants. There has to be braces around the text so LaTeX knows where to put `\begin{dialogue}` and `\end{dialogue}` properly. Also, I used `\dialogueline` in case there's already another command named `\dialogue`, but if that's not the case, then the poster can replace `\dialogueline` with `\dialogue` instead if it causes no errors.
In silico
+6  A: 
Antal S-Z
Very good answer! (+1)
Patrick
That's rather clever. I didn't know about `\catcode` up until now. While my solution will work for anything put inside the braces, yours will work for one-liners and is closer to the asker's requested syntax.
In silico
The trick is actually less about catcodes and more about pattern-matching in `\def`: you could also do something like `\gdef\dialogueline@EOL#1:#2^^M` to be able to write `\dialogueline Johnny: Some dialogue.`. The catcode switch is so that the end of a line isn't just treated as a space character and ignored, but is instead treated as a matchable character. You're right that this may outlaw some valid strings (though some of these can be permitted by hiding the matched string in curly braces, e.g. `\dialogueline {Alexander: the Great}: Die!`), but it's nice for shortcuts and embedded DSLs.
Antal S-Z
Real nice. Works just as you say. Thanks for the thorough explanation!
njt
Well, actually I got a "use of \dialogueline doesn't match its definition" error when I used \makeatother, but it works just fine with \makeatletter.
njt
Sorry I didn't clarify that---the definition has to come *after* `\makeatletter` and *before* `\makeatother`. (The former changes the catcode of `@` to that of a letter, so it can be part of control sequence names; the latter changes it back.)
Antal S-Z
Got it. It worked just fine sandwiched between two \makeatletter commands, but I guess that's not really the correct syntax. Thanks again.
njt
+2  A: 
Charles Stewart
That's clever, I hadn't seen this technique before.
Antal S-Z