% \iffalse meta-comment
% Copyright 2010-2015 Louis Paternault
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Louis Paternault
%
% This work consists of the files thalie.dtx and thalie.ins
% and the derived file thalie.sty.
% \fi
% 
% \iffalse
%<*driver>
\ProvidesFile{thalie.dtx}
%</driver>
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{thalie}
%<*package>
    [2015/12/30 v0.8 A package to typeset drama plays]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage{array}
\usepackage{attachfile}
\usepackage{enumerate}
\usepackage{multirow}
\usepackage{hyperref}
\usepackage{thalie}
\usepackage{showexpl}
\lstset{language=[LaTeX]TeX, numbers=left, numberstyle=\tiny}
\usepackage[francais,english]{babel}
\begin{document}
\DocInput{thalie.dtx}
\end{document}
%</driver>
% \fi
% 
% \CheckSum{0}
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \GetFileInfo{thalie.dtx}
%
% \DoNotIndex{\@backslashchar, \@ifnextchar, \@ifundefined, \\, \protect\`, \(, \)}
% \DoNotIndex{\addcontentsline, \addto, \ae, \AND, \arabic}
% \DoNotIndex{\begin, \bfseries, \boolean}
% \DoNotIndex{\captionsenglish, \captionsfrench, \center, \centering, \ClassError, \cleardoublepage, \csname, \csundef}
% \DoNotIndex{\def, \defcharcommand@with, \defcharcommand@without}
% \DoNotIndex{\emph, \end, \endcsname, \equal, \expandafter}
% \DoNotIndex{\framebox}
% \DoNotIndex{\gappto, \gdef, \global}
% \DoNotIndex{\hspace}
% \DoNotIndex{\ifthenelse, \@ifpackageloaded, \indent, \isundefined}
% \DoNotIndex{\LARGE, \Large, \left, \leftskip}
% \DoNotIndex{\medskip, \MakeUppercase, \markboth, \markright}
% \DoNotIndex{
%   \@actlevel,
%   \@actstyle,
%   \@character,
%   \@characterstyle,
%   \@clearpage,
%   \@definecharactercommand,
%   \@displaytitle,
%   \@dramatis@clear,
%   \@dramatis@hook,
%   \@groupname,
%   \@interludelevel,
%   \@label,
%   \@playlevel,
%   \@playstyle,
%   \@scenelevel,
%   \@scenestyle,
%   \@short,
%   \@speaks,
% }
% \DoNotIndex{\newcommand, \newcounter, \newenvironment, \noindent, \noexpand, \NOT}
% \DoNotIndex{\OR}
% \DoNotIndex{\par, \pgfkeys, \ProcessPgfPackageOptions, \protect, \provideboolean, \protected@xappto}
% \DoNotIndex{\refstepcounter, \renewcommand, \RequirePackage, \right, \Roman}
% \DoNotIndex{\section, \setboolean, \setlength, \sffamily}
% \DoNotIndex{\tabularnewline, \textrm, \textsc, \textwidth, \thispagestyle}
% \DoNotIndex{\undef}
% \DoNotIndex{\vspace}
% \DoNotIndex{\WithSuffix}
% \DoNotIndex{\xappto, \xspace}
%
% \newcommand{\bbackslash}{\symbol{92}}
%
% \title{The \textsf{thalie} package\thanks{
%   This document corresponds to \textsf{thalie}~\fileversion, dated \filedate.
%   Home page, bug requests, etc. at \url{http://git.framasoft.org/spalax/thalie}
%   }\\A package to typeset drama plays}
% \author{Louis Paternault\\ \texttt{spalax(at)gresille(dot)org}}
%
% \maketitle
%
% \begin{abstract}
% This package is meant to typeset drama plays using \LaTeX{}. It provides
% commands to introduce characters' lines, to render stage direction, to divide
% a play into acts and scenes, to automatically build the dramatis person\ae{},
% etc.
% \end{abstract}
%
% \setcounter{tocdepth}{2}
% \tableofcontents
%
% \section{Introduction}
% This document introduces the \textsf{thalie} package, used to typeset drama
% plays.
%
% \subsection{Other classes and packages}
% This package is far from being the only one that can be used to render drama
% plays. If you do not like my work, you can use one of the following ones (and
% I guess there exists others):
% |drama| \cite{drama},
% |dramatist| \cite{dramatist},
% |play| \cite{play},
% |screenplay| \cite{screenplay},
% |sides| \cite{sides}.
%
% I began to write this package in 2010, and now, at the end of 2012, I must
% admit that I wonder why I started this\ldots There are already several such
% packages in
% \textsc{ctan}\footnote{\url{http://www.ctan.org/topic/drama-script}}, and the
% |dramatist| package seems really nice (I borrowed some ideas and copied some
% code from it). There are actually a few improvements in my package compared
% to |dramatist|: in my package, plays, acts and scenes appear in the table of
% contents; it is possible to include several plays in a single document; there
% are more options when building the dramatis person\ae{}; headers and footers
% are taken into account, etc. But these improvements are small; it might have
% been smarter to contribute to |dramatist| instead of starting my own package.
% The good part is that I have a package that fits my needs, and I learned how
% to write a \LaTeX{} package.
%
% Oh, yes! I know why I started this: I am a geek\ldots
%
% \subsection{License}
% This work may be distributed and/or modified under the
% conditions of the \LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
%
% Further information can be found in the |.dtx| file used to build this
% document.
%
% In short (but this paragraph has no legal value), you can use this package
% freely to render your drama plays, and modify it almost freely. Nevertheless,
% if you like my work, you can send me smiles, cakes or poetry, or, better, the
% text of the plays you write using my package\footnote{Seriously, it would
% make me \emph{really} happy!}.
%
% \subsection{Acknowledgements}
% I borrowed ideas and lines of code from the \LaTeX{} packages
% |drama|\cite{drama} and |dramatist|\cite{dramatist}.
%
% I used the following guides to package my package: \emph{How to Package Your
% \LaTeX{} Package} \cite{dtxtut}, and \emph{\LaTeXe{} for class and package
% writers} \cite{clsguide}.
%
% \subsection{Examples}
%
% All the examples are taken from Edmond Rostand's \emph{Cyrano de Bergerac}
% \cite{cyrano} or from William Shakespeare's \emph{A Midsummer Night's Dream}
% \cite{midsummer}. The snippets of \emph{Cyrano de Bergerac} are from the
% original (French) version of this play, roughly translated by myself (which
% means that they must be of poor quality).
%
% A part of this play (now in public domain), is
% \textattachfile[mimetype=text/plain,color=0 0 1]{examples/cyrano.tex}{attached to this
% file}, as a working example of this package.
%
% \subsection{Overview}
% Documentation about how to use this package is given in section
% \ref{sec:usage}. In particular, section \ref{sec:sectioning} explains how to
% use acts and scenes, section \ref{sec:characters} explains how to define
% characters, and use these definitions to introduce characters' lines, and
% section \ref{sec:directions} describes commands used to render stage
% directions.
%
% Implementation is given in section \ref{sec:implementation}.
%
% \section{Usage}
% \label{sec:usage}
%
% \subsection{Localization}
% \DescribeMacro{\playname}
% \DescribeMacro{\actname}
% \DescribeMacro{\scenename}
% \DescribeMacro{\interludename}
% \DescribeMacro{\pausename}
% \DescribeMacro{\curtainname}
% Language cannot be defined directly in this package. Instead, the language
% currently used by the |babel| package (i.e. the language returned by
% |babel|'s |\languagename| command) is used to display names.
%
% Package |babel|, and its languages you want to use, must be loaded
% \emph{before} this package, otherwise localization will not be available.
%
% The effect of choosing a language or another is to translate some words. The
% corresponding commands, and the words they correspond to, are listed in table
% \ref{table:l10n}.
%
% \begin{table}
%   \centering
%   \begin{tabular}{ccc}
%   \hline
%   Command & Result (in English) & Result (in French) \\
%   \hline
%   |\playname| & Play & Pi\`ece \\
%   |\actname| & Act & Acte \\
%   |\scenename| & Scene & Sc\`ene \\
%   |\interludename| & Interlude & Interm\`ede \\
%   |\pausename| & Pause & Pause \\
%   |\curtainname| & Curtain & Rideau \\
%   \hline
%   \end{tabular}
%   \caption{Localization commands}
%   \label{table:l10n}
% \end{table}
%
% If the option for your language does not exist\footnote{You can also send me
% the translation for your language, to improve this package.}, or if you want
% to change the default words used here, you can redefine the commands listed
% in table \ref{table:l10n}. For instance use
% |\renewcommand{\curtainname}{Tel\`on}| for Spanish (if I am not wrong).
%
% \subsection{Package options}
% \label{sec:options}
%
% Package options are summed up in table \ref{table:packageoptions}.
%
% \begin{table}
% \centering
% \begin{tabular}{c|c|c}
% Name & Available options & Default \tabularnewline
% \hline
% \hline
% |characterstyle| & |bold| |margin| |center| |simple| |arden| & |simple| \tabularnewline
%                  & |imprimerie-verse| |imprimerie-prose|     &          \tabularnewline
% \hline
% |playstyle| & \multirow{3}{*}{|center| |bigcenter| |box| |custom|} & |box| \tabularnewline
% |actstyle| &  & |bigcenter| \tabularnewline
% |scenestyle| & & |center| \tabularnewline
% \hline
% |playlevel| & \multirow{3}{*}{|part| |chapter| |section| \ldots |subparagraph|} & |chapter| \tabularnewline
% |actlevel| &  & |section| \tabularnewline
% |scenelevel| &  & |subsection| \tabularnewline
% \hline
% |interludelevel| & |play| |act| |scene| & |act| \tabularnewline
% \hline
% |xspace| & |true| |false| & |true|\tabularnewline
% \end{tabular}
% \caption{Package options summary}
% \label{table:packageoptions}
% \end{table}
%
% \subsubsection{Space following character commands}
% \changes{v0.7}{2015/12/28}{New package option \texttt{xspace}.}
% As commands introducing characters' lines and displaying characters' names
% may be frequently used, it might be tempting to omit the following |{}|. For
% instance, one might prefer to write:
% \begin{quote}
% |\cyrano Indeed, \cyranoname is my name!|
% \end{quote}
% instead of:
% \begin{quote}
% |\cyrano{} Indeed, \cyranoname{} is my name!|
% \end{quote}
%
% If package option |xspace| is set (e.g. |xspace=true|), space is automatically
% added after those commands if necessary\footnote{This is easily done with
% the |$\backslash$xspace| command (from the |xspace| package), hence the name.};
% otherwise, it is not.
%
% For historical reasons, the option |xspace| default is |true|, but this might
% change in some later non-backward compatible version.
%
% \subsubsection{Style}
% The way characters' lines are displayed, as well as play, act and scene
% titles, can be set when loading the options.
% To set character style, use option |characterstyle=|\meta{style}. Available
% styles, and indication to use a custom one, are described in section
% \ref{sec:lines}.
%
% Several play, act and scene title styles are defined. Choose it using options
% |playstyle|=\meta{style}, |actstyle|=\meta{style} and
% |scenestyle|=\meta{style}. Description of available styles, and how to define
% your own one, are described in section \ref{sec:sectionstyles}.
%
% \subsubsection{Sectioning levels}
% If you use a table of contents, or if you also use ``usual'' sectioning
% commands (|\chapter|, |\section| and so on), the relative importance of
% plays, acts and scenes is important. You can set this using options
% |playlevel=|\meta{level}, |actlevel=|\meta{level} and
% |scenelevel=|\meta{level}. The argument is the name of the corresponding
% sectioning level, i.e. one of |part|, |chapter|, |section|, |subsection|,
% |subsubsection|, |paragraph| and |subparagraph|.
%
% Setting the interlude level is slightly different. While setting it using
% |interludelevel=|\meta{level}, instead of choosing one of \LaTeX{} vanilla
% sectioning levels as the level, you may choose |play|, |act| or |scene|. It
% defines if an interlude is at the same level as a play, an act or a scene.
%
% \subsection{Sectioning}
% \label{sec:sectioning}
% Here begin the parts explicitly relating to drama.
% \subsubsection{Levels}
% \DescribeMacro{\play}
% \DescribeMacro{\play*}
% \DescribeMacro{\act}
% \DescribeMacro{\act*}
% \DescribeMacro{\scene}
% \DescribeMacro{\scene*}
% To introduce a new play, act or scene, use commands |\play|, |\act| and
% |\scene|. Their behaviour is as close as the ``usual'' sectioning commands
% (|\chapter|, |\section| and so on) as possible, i.e.:
% \begin{itemize}
% \item Their signature is |\play|\oarg{short title}\marg{longtitle} (the
% optional short title is the one used in the table of content, and in headers
% and footers).
% \item A starred version (|\play*|, |\act*| and |\scene*|) is provided, which
% inserts a play (or act, or scene) which is not numbered, and does not insert
% any line in the table of content.
% \item Headers and footers are changed (more information in section \ref{sec:header}).
% \end{itemize}
%
% Both commands |\act| and |\scene| (and their starred versions) are designed to
% deal with empty titles. Indeed, it is common not to give any name to acts and
% scenes.
%
% By default, a play is as deep (regarding to the table of contents) as a
% chapter, an act as a section, and a scene as a subsection. But this can be
% set using package options |playlevel|, |actlevel| and |scenelevel| (see
% packages options, page \pageref{sec:options}). That way, you can use in your
% document plays, acts and scenes as well as chapters, sections and so on. It
% can be useful if you want a foreword, and appendix, etc.
%
% It is not compulsory to use all three commands |\play|, |\act| and |\scene|.
% The rule of thumb is: if only one element exists, skip the corresponding
% command: if your document has a single play, you should ignore |\play|; if
% your document has several single act plays, set
% |playlevel=section,scenelevel=subsection| and ignore |\act|; etc.
%
% \DescribeMacro{\interlude}
% \DescribeMacro{\interlude*}
% You may want to use interludes, which are acts or scenes which are not
% numbered, but which should appear in the table of content. Command
% |\interlude|\oarg{short title}\marg{long title} has this purpose.
%
% You may choose the sectioning level an interlude is equivalent to in the
% package options. If your interludes are acts, use |interludelevel=act|; if
% they are scenes, use |interludelevel=scene|.
%
% \DescribeMacro{\curtain}
% At last, to mark the end of an act or of the play, you can use command
% |\curtain|, which prints the word |\curtainname| in the middle of its own
% line.
%
% \subsubsection{Title styles}
% \label{sec:sectionstyles}
% Several styles are available to render play, act and scene titles. Choose
% them using package options |playstyle|, |actstyle| and |scenestyle|. Default
% is |playstyle=box|, |actstyle=bigcenter|, |scenestyle=center|.
%
% \paragraph{Custom titles}
% Unfortunately, as play, act and scene titles are not considered (by \LaTeX{})
% as usual sections, package
% |titlesec|\footnote{\url{http://www.ctan.org/pkg/titlesec}} cannot be used to
% use alternative section titles. Here is the way to set your own one.
%
% \begin{figure}[p]
% \centering
% \iffalse
%<*example>
% \fi
% \begin{lstlisting}
\newcommand\customact[2]{
  \begin{center}
    \textsc{#1}

    #2
  \end{center}
}
\WithSuffix\newcommand\customact*[1]{\customact{}{#1}}
% \end{lstlisting}
% \iffalse
%</example>
% \fi
% \caption{Example of custom act definition}
% \label{fig:custom}
% \end{figure}
%
% \DescribeMacro{\customplay}
% \DescribeMacro{\customact}
% \DescribeMacro{\customscene}
% When loading the package, use |custom| as the style of the title you want to
% customize (e.g. |actstyle=custom|). Then, commands
% |\customact|\marg{counter}\marg{title} and |\customact*|\marg{title} will be
% called by this package to render titles. You \emph{must} define them. Figure
% \ref{fig:custom} gives the example of the definition of the |center| style.
%
% The first argument of |\customact| is the label of the act being printed
% (that is, |\theact| for an act, |\theplay| for a play, etc.), its second
% argument is its title. Command |\customact*| only has one argument, which is
% the act title.
% 
% \subsubsection{Labels and counters}
%
% \DescribeMacro{\theplay}
% \DescribeMacro{\theact}
% \DescribeMacro{\thescene}
% Using the same tools as |\chapter|, |\section| and so on, it is possible to
% define the way counters of plays, acts and scenes are displayed. You can do
% this by redefining |\theplay|, |\theact| and |\thescene|. For example, to
% have acts numbered using letters, use |\renewcommand{\theact}{\Alph{act}}|.
%
% \subsubsection{Headers and footers}
% \label{sec:header}
%
% \DescribeMacro{\playmark}
% \DescribeMacro{\actmark}
% \DescribeMacro{\scenemark}
% Once again, similar tools as those used by |\section| are provided to deal
% with headers and footers. When introducing, a new play, act or % scene,
% respectively, commands |\playmark|\marg{label}, |\actmark|\marg{label} and
% |\scenemark|\marg{label} are called, so that titles can be used in headers
% and footers. If the default behaviour does not suit you (which should be the
% case if you did not choose the default option for |playlevel|, |actlevel| or
% |scenelevel|), you can redefine them.
%
% \subsection{Characters}
% \label{sec:characters}
% This part explains how to define characters, introduce character's lines, and
% build and display the dramatis person\ae{}.
%
% \subsubsection{Dramatis person\ae{}}
% Definition of characters is done in document body.
% As it is possible to have several plays in a single documents (for a
% collection of plays or sketches), it is possible to define several
% dramatis person\ae{}. A new one disables the character commands
% defined by the previous one.
%
% \DescribeEnv{dramatis}
% Definition of characters is done inside the |dramatis| environment. If the
% |hidden| option is given, the dramatis person\ae{} is not printed (its
% only purpose is then to define the character commands).
% \begin{quote}
% |\begin{dramatis}|\oarg{hidden}
% \end{quote}
% Then, several commands are available to define characters, and organize
% character definitions.
%
% \DescribeMacro{\characterspace}
% Command |\characterspace| put some vertical space into the dramatis
% person\ae{}.
%
% \subsubsection{Character definition}
% \paragraph{Basic definition}
% \label{paragraph:basiccharacter}
% 
% \begin{figure}[p]
% \centering
% \iffalse
%<*example>
% \fi
% \begin{LTXexample}[pos=b]
\begin{dramatis}
  \character[cmd={cyrano}, drama={Cyrano de Bergerac}]{Cyrano}
  \character[cmd={lebret}]{Le Bret}
  \character[cmd={bellerose}]{Bellerose}
\end{dramatis}

\bigskip

\lebret[to \cyranoname, holding his arm]
Let's talk !

\cyrano
Wait for the crowd to leave.  \did{To \bellerosename} Can I stay?
% \end{LTXexample}
% \iffalse
%</example>
% \fi
% \caption{Example of character definition}
% \label{fig:character_example}
% \end{figure}
%
% \DescribeMacro{\character}
% To define a character, use command |\character|.
% \begin{quote}%
% |\character|\oarg{\emph{cmd=}command,\emph{drama=}dramatis,\emph{desc=}description}\marg{name}%
% \end{quote}
% The mandatory argument is the name of the character, as it will appear in each of this character's line. It is later possible to redefine it using command |\setcharactername| (see part \ref{setcharactername}). Optional arguments are:
% \begin{description}
% \item[desc] is a description of your character, appearing in the dramatis person\ae{};
% \item[cmd] is the name of the command that will be used to introduce this character's lines in the remaining part of your document;
% \item[drama] is the name of your character, as it will appear in the dramatis person\ae{}. The name of the character (mandatory argument) is used as a default value.
% \end{description}
%
% If \emph{cmd} is defined, this command creates two new commands: |\|\meta{cmd}
% and |\|\meta{cmd}|name|. The
% first one is used to introduce a character's line. The second one prints the
% character's name. An error is raised if a command with any of these two names
% already exists.
%
% An example of the use of this command is given in figure
% \ref{fig:character_example}.
%
% \paragraph{Special character definition}
%
% Although optional arguments are not mandatory, not defining them, or leaving the mandatory argument blank, have special meaning.  The combination are summed up in table \ref{table:character}.
%
% \begin{table}
%   \centering
%   \begin{tabular}{cc||c|c|c|c|}
%     \multicolumn{2}{c||}{}                            &     \multicolumn{2}{c|}{empty \meta{name}} & \multicolumn{2}{c|}{\meta{name}} \\
%     \multicolumn{2}{c||}{}                            & no \meta{cmd}                 & \meta{cmd} & no \meta{cmd}               & \meta{cmd} \\
%     \hline
%     \hline
%     \multirow{4}{*}{no \meta{drama}} & \multirow{2}{*}{no \meta{desc}} &                               &                          & silent\up{\ref{character:silent}}    & default\up{\ref{character:default}} \\
%                                      &                &                               &                          &                                    & hidden\up{\ref{character:hidden}}\\
%     \cline{2-6}
%                                      & \multirow{2}{*}{   \meta{desc}} & description                        &                          & silent\up{\ref{character:silent}}    & default\up{\ref{character:default}} \\
%                                      &                & only\up{\ref{character:description}} &                          &                                    &                                   \\
%     \hline
%     \multirow{2}{*}{   \meta{drama}} & no \meta{desc} & silent\up{\ref{character:silent}}      &                          &                             & default\up{\ref{character:default}} \\
%     \cline{2-6}
%                                      &    \meta{desc} & silent\up{\ref{character:silent}}      &                          &                             & default\up{\ref{character:default}} \\
%     \hline
%   \end{tabular}
%
%   An empty cell means that the corresponding combination is forbidden. The superscript number refers to the list of special character definitions (page \pageref{specialcharaclist}).
%   \caption{(Not) defining arguments in character definition}
%   \label{table:character}
% \end{table}
%
% \label{specialcharaclist}
% \begin{enumerate}[(i)]
% \item \label{character:default} \textbf{Default definition (\meta{name} and \meta{cmd} are given; \meta{desc} and \meta{drama} may be omitted):} The character is defined as described in \ref{paragraph:basiccharacter}. If \meta{description} is omitted, no description appear in the dramatis person\ae{}; if no \meta{drama} is given, character in the dramatis person\ae{} has the same name as it will have in the document.
% Example:\\|\character[drama={A ghost}, desc={the king's ghost},|\\
%           |           cmd={ghost}]{The ghost}|
% \item \label{character:description} \textbf{Description only (everything omitted but \meta{desc}):} A description is inserted in the dramatis person\ae{}. Useful to add characters such as \emph{The kings' armies}.
% Example:\\|\character[desc={The kings' armies}]{}|
% \item \label{character:hidden} \textbf{Hidden character (\meta{drama} is empty (defined, but empty), \meta{cmd} and \meta{name} are defined, \meta{desc} is omitted)} Definition of a character that does not appear in the dramatis person\ae{}.
% Example:\\|\character[drama={}, cmd={postman}]{The postman}|
% \item \label{character:silent} \textbf{Silent character (one of \meta{name} or \meta{drama} is defined; \meta{desc} may be omitted; \meta{cmd} is omitted):} The character only appear in the dramatis person\ae{}. It will not be used elsewhere in the document. An optional description may also appear in the dramatis person\ae{}.
% Example:\\|\character{A priest}|
% \end{enumerate}
%
% \paragraph{Group of characters}
% \DescribeEnv{charactergroup}
% It is possible to group several characters' definition if they have the same
% description. This is done with environment
% |charactergroup|\marg{description}. For example, one can use code of figure
% \ref{fig:charactergroup} to define the three sons of another character.
% 
% \begin{figure}[p]
% \centering
% \iffalse
%<*example>
% \fi
% \begin{LTXexample}
\begin{dramatis}
\begin{charactergroup}{Two musicians}
  \character[desc={Gaston Henry}]{}
  \character[desc={Damon}]{}
\end{charactergroup}
\end{dramatis}
% \end{LTXexample}
% \iffalse
%</example>
% \fi
% \caption[Defining a group of characters]{Defining a group of characters\footnotemark}
% \label{fig:charactergroup}
% \end{figure}
% \footnotetext{
% I admit I am cheating here. As it was difficult to find a single play that
% illustrates every feature of this package, this snippet, in the original
% \emph{Cyrano de Bergerac}, is used to give the names of the actors playing the
% two musicians, which is a bit different from the purpose of the
% |charactergroup| environment. Still, you can see how it is rendered,
% which is the important part here.
% }
%
% The effect of this code will be, in the dramatis person\ae{}, to have a
% nice brace mapping the three characters to their common description.
%
% \paragraph{Disposable character}
% \DescribeMacro{\disposablecharacter}
% One can need to define characters that are used only once (or a few times).
% Command |\disposablecharacter| is here to help.
% \begin{quote}|\disposablecharacter|\oarg{directions}\marg{name}\end{quote}
% This command, used in the body, introduces a line for character |name|, with optional stage
% directions. It is rendered the same way regular characters are rendered, but
% nothing is added to the dramatis person\ae{}. It is used in figure
% \ref{fig:setcharactername_example}.
%
% \subsubsection{Changing character's name}
% \label{setcharactername}
% \DescribeMacro{\setcharactername}
%
% \begin{figure}[p]
% On the first scenes of Cyrano de Bergerac, the main character (Cyrano) is
% somewhere in a crowd, and only appears as \emph{a voice}. He appears as
% Cyrano in the following verses.
%
% \centering
% \iffalse
%<*example>
% \fi
% \begin{LTXexample}[pos=b]
\begin{dramatis}[hidden]
  \character[desc={Cyrano de Bergerac}, cmd=cyrano]{The voice}
  \character[cmd=montfleury]{Montfleury}
\end{dramatis}

\cyrano Leave!

\disposablecharacter{The crowd} Oh!

\montfleury[losing his voice] ``Happy he who far away from court\ldots''

\setcharactername{cyrano}{Cyrano}

\cyrano[emerging from the crowd, standing up on a chair {[}\ldots{]} with
    a terrible nose] Ah! I am getting angry!\ldots
% \end{LTXexample}
% \iffalse
%</example>
% \fi
% \caption{Example of changing the name of a character}
% \label{fig:setcharactername_example}
% \end{figure}
%
% It is possible to change the name that appears to introduce character's lines
% within the text. This can be used, for example, when a character is first
% refered to as \emph{A voice}, until we learn his real identity, which is
% \emph{Cyrano}. An example is given in figure
% \ref{fig:setcharactername_example}.
% \begin{quote}|\setcharactername|\marg{command}\marg{name}\end{quote}
%
% This command takes two mandatory arguments. The first one, |command|, is the
% command used to introduce this character's line. The second one is the name
% to display for this character.
%
% \subsubsection{Lines}
% \label{sec:lines}
% To introduce characters' lines, use the commands defined in the character
% definition (see the |\character| command, or the example in figure
% \ref{fig:character_example}).
%
% \paragraph{Choose style}
% \changes{v0.6}{2014/06/25}{New character styles \texttt{imprimerie-verse}, \texttt{imprimerie-prose} and \texttt{arden}.}
% Several styles are available, to typeset character's name and lines in
% different ways. Change the style by loading package using option
% |characterstyle=|\marg{style} (available styles are |bold|, |center|,
% |margin|, |simple|, |imprimerie-verse|, |imprimerie-prose|).
% Note that |imprimerie-verse| and |imprimerie-prose| styles are French
% \emph{de facto} standards for typesetting drama plays, respectively in verse
% and in prose, as defined by the \emph{Imprimerie nationale}
% \cite{imprimerienationale}, and |arden| tries to mimick typesetting of the
% Arden Shakespeare series.  Default style is |simple|.
%
% \paragraph{Customize style}
% \DescribeMacro{\speakswithoutdirection}
% \DescribeMacro{\speakswithdirection}
% If available styles does not fit your need, you can also define your own one.
% To do so, you can redefine the following commands.
% \begin{quote}
% |\speakswithoutdirection|\marg{name}\\
% |\speakswithdirection|\marg{name}\marg{direction}
% \end{quote}
% The first one (|\speakswithoutdirection|) is invoked to display a character's name
% to introduce its line. It takes one argument, which is the character's line.
% The second one (|\speakswithdirection|) is also invoked to display a character's
% name to introduce its line, but it takes a second argument, which is stage
% directions to be printed together with character's name.
%
% See also section \ref{sec:directions} to see other ways to print stage
% directions.
%
% \subsection{Stage directions}
% \label{sec:directions}
% Let us begin with a warning: since we could not figure out a nice command
% name made from ``stage directions'', we used the French word
% \emph{(didascalie)} to build up command names.
%
% \DescribeMacro{\did}
% \DescribeEnv{dida}
% We define two ways to render stage directions: a short one, that is printed
% inline, and a long one, printed in its own paragraph. They act a bit like
% |$\formula$| and |\[\formula\]| for formulas.
% The first way is the command |\did|\marg{directions}. The second way is the
% environment |dida|.
%
% \DescribeMacro{\onstage}
% Some stage directions are displayed centered under the scene or act
% definition (I often see it in classical drama, where the list of characters
% appearing in each scene is displayed that way). Command
% |\onstage|\marg{directions} can be used to display such information.
%
% \DescribeMacro{\pause}
% As we often need to mark pauses in theater, we created the command |\pause|,
% which is a shortcut for |\did{\pausename}|.
%
% \subsection{Splitting verses}
% \DescribeMacro{\pauseverse}
% \DescribeMacro{\resumeverse}
% \DescribeMacro{\adjustverse}
%
% When writing verses, it is sometimes useful to split a verse between two
% characters: the first character starts it in its line, and the second one
% finishes it in a second line. Visually, the start of the second line is
% vertically aligned to the end of the first line.
%
% \begin{figure}[p]
% \centering
% \iffalse
%<*example>
% \fi
% \begin{dramatis}[hidden]
%   \character[cmd={hermia}]{Hermia}
%   \character[cmd={theseus}]{Theseus}
% \end{dramatis}
% \begin{LTXexample}[pos=b]
\adjustverse{-7em}

\hermia
So is Lysander.\pauseverse

\theseus
\resumeverse In himself he is.
% \end{LTXexample}
% \iffalse
%</example>
% \fi
% \caption{Example of commands to split verse}
% \label{fig:splitverse}
% \end{figure}
%
% Command |\pauseverse|  is used at the end of the verse to be continued,
% while command |\resumeverse| is used at the beginning of the continuing
% verse.
% Let us face it: these commands are kind of a hack, and sometimes, the lines
% are not aligned the way one would expect them to. To correct this, command
% |\adjustverse|\marg{length} can be used to add an extra (possibly negative)
% space when calling |\resumeverse|, to get a correct alignment.
% See figure \ref{fig:splitverse}, page \pageref{fig:splitverse}, for an
% example of those three commands.
%
% When writing a play in verse, one can use a lot of those commands, which can
% be tedious because of their long names. So, defining ``shortcuts'' of those
% commands can be handy, as in the following example.
%
% \begin{quote}
% \begin{verbatim}
% \newcommand{\pv}{\pauseverse}
% \newcommand{\rv}{\resumeverse}
% \end{verbatim}
% \end{quote}
%
% This is not done by default, because short command names is a scare ressource
% in \LaTeX, so, defining these commands by default might conflict with other
% packages, while most of |thalie| users will not use them.
%
% \section{Implementation}
% \label{sec:implementation}
%
% \subsection{Required packages}
% Loading some packages.
%    \begin{macrocode}
\RequirePackage{ifthen}
% Chapters, sections, etc
\RequirePackage{etoolbox}
\RequirePackage{suffix}
% Dramatis person\ae{} is written using a table. Package "longtable" is used to be
% able to write it on several pages.
\RequirePackage{longtable}
% Handling spaces after having introduced characters' lines.
\RequirePackage{xspace}
%    \end{macrocode}
%
% \subsection{Package options}
% Manage package options.
%    \begin{macrocode}
\RequirePackage{pgfopts}

\pgfkeys{
  % Character style
  /THALIE/.cd,
  characterstyle/.value required,
  characterstyle/.default=simple,
  characterstyle/.is choice,
  characterstyle/bold/.code=\def\@characterstyle{bold},
  characterstyle/center/.code=\def\@characterstyle{center},
  characterstyle/margin/.code=\def\@characterstyle{margin},
  characterstyle/simple/.code=\def\@characterstyle{simple},
  characterstyle/arden/.code=\def\@characterstyle{arden},
  characterstyle/imprimerie-verse/.code=\def\@characterstyle{imprimerie-verse},
  characterstyle/imprimerie-prose/.code=\def\@characterstyle{imprimerie-prose},
  characterstyle,
}

\pgfkeys{
  % play style
  /THALIE/.cd,
  playstyle/.value required,
  playstyle/.default=box,
  playstyle/.is choice,
  playstyle/center/.code=\def\@playstyle{center},
  playstyle/bigcenter/.code=\def\@playstyle{bigcenter},
  playstyle/box/.code=\def\@playstyle{box},
  playstyle/custom/.code=\def\@playstyle{custom},
  playstyle,
}
\pgfkeys{
  % act style
  /THALIE/.cd,
  actstyle/.value required,
  actstyle/.default=bigcenter,
  actstyle/.is choice,
  actstyle/center/.code=\def\@actstyle{center},
  actstyle/bigcenter/.code=\def\@actstyle{bigcenter},
  actstyle/box/.code=\def\@actstyle{box},
  actstyle/custom/.code=\def\@actstyle{custom},
  actstyle,
}
\pgfkeys{
  % scene style
  /THALIE/.cd,
  scenestyle/.value required,
  scenestyle/.default=center,
  scenestyle/.is choice,
  scenestyle/center/.code=\def\@scenestyle{center},
  scenestyle/bigcenter/.code=\def\@scenestyle{bigcenter},
  scenestyle/box/.code=\def\@scenestyle{box},
  scenestyle/custom/.code=\def\@scenestyle{custom},
  scenestyle,
}

\pgfkeys{
  % play level
  /THALIE/.cd,
  playlevel/.value required,
  playlevel/.default=chapter,
  playlevel/.store in=\@playlevel,
  playlevel,
}
\pgfkeys{
  % act level
  /THALIE/.cd,
  actlevel/.value required,
  actlevel/.default=section,
  actlevel/.store in=\@actlevel,
  actlevel,
}
\pgfkeys{
  % scene level
  /THALIE/.cd,
  scenelevel/.value required,
  scenelevel/.default=subsection,
  scenelevel/.store in=\@scenelevel,
  scenelevel,
}
\pgfkeys{
  % interlude level
  /THALIE/.cd,
  interludelevel/.value required,
  interludelevel/.default=act,
  interludelevel/.is choice,
  interludelevel/play/.code=\def\@interludelevel{play},
  interludelevel/act/.code=\def\@interludelevel{act},
  interludelevel/scene/.code=\def\@interludelevel{scene},
  interludelevel,
}
\newif\if@xspace
\pgfkeys{
  % xspace option
  /THALIE/.cd,
  xspace/.value required,
  xspace/.is if=@xspace,
  xspace/.default=true,
  xspace,
}

\ProcessPgfPackageOptions{/THALIE}
%    \end{macrocode}
%
% \subsection{Localization}
% \begin{macro}{\playname}
% \begin{macro}{\actname}
% \begin{macro}{\scenename}
% \begin{macro}{\interludename}
% \begin{macro}{\curtainname}
% \begin{macro}{\pausename}
% Definition of the commands used for localization. The \emph{only} way to
% choose the language to use is by loading the |babel| package before loading
% this one.
%    \begin{macrocode}
\newcommand{\playname}{Play}
\newcommand{\actname}{Act}
\newcommand{\scenename}{Scene}
\newcommand{\interludename}{Interlude}
\newcommand{\curtainname}{Curtain}
\newcommand{\pausename}{Pause}
\@ifpackageloaded{babel}{
    \addto\captionsfrench{%
      \renewcommand{\playname}{Pi\`ece}
      \renewcommand{\actname}{Acte}
      \renewcommand{\scenename}{Sc\`ene}
      \renewcommand{\interludename}{Interm\`ede}
      \renewcommand{\curtainname}{Rideau}
      \renewcommand{\pausename}{Pause}
    }
    \addto\captionsenglish{%
      % Useless: these are the default...
    }
}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Sectioning}
% \subsubsection{Headears, footers, counters, etc.}
% \begin{macro}{playmark}
% \begin{macro}{actmark}
% \begin{macro}{scenemark}
% Define commands |\playmark|, |\actmark| and |\scenemark|, which are involved
% in headers and footers definition.
%    \begin{macrocode}
\newcommand{\playmark}[1]{%
  \markboth{\MakeUppercase{#1}}{}%
}
\newcommand{\actmark}[1]{%
  \markright{\MakeUppercase{#1}}%
}
\newcommand{\scenemark}[1]{%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% 
% \begin{macro}{theplay}
% \begin{macro}{theact}
% \begin{macro}{thescene}
% Defines counters for plays, acts and scenes, and the associated labels
% (|\theplay|, |\theact|, |\thescene|).
%    \begin{macrocode}
\newcounter{play}
\renewcommand{\theplay}{\arabic{play}}
\newcounter{act}[play]
\renewcommand{\theact}{\Roman{act}}
\newcounter{scene}[act]
\renewcommand{\thescene}{\arabic{scene}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% 
% \subsubsection{Styles}
% Style difinition. Command |\@displaytitle| is later used by commands
% |\play|, |\act| and |\scene| (and their starred version) to typeset the
% title.
%    \begin{macrocode}
\newcommand{\@displaytitle}[3]{
  % Arguments:
  % - Style
  % - Label (none = not in toc)
  % - Title
  \ifthenelse{\equal{#1}{center}}{
    \begin{center}
      \textsc{#2}

      #3
    \end{center}
  }{\ifthenelse{\equal{#1}{bigcenter}}{
    \begin{center}
      \Large
      \textsc{#2}

      #3
    \end{center}
  }{\ifthenelse{\equal{#1}{box}}{
    \begin{center}
      \framebox{\begin{minipage}{0.7\textwidth}
      \begin{center}
        \Large \bfseries
      \vspace{0.5em}

      #2
      \ifthenelse{\equal{#3}{} \OR \equal{#2}{}}{}{---}
      #3

      \vspace{0.5em}
    \end{center}
    \end{minipage}}
    \end{center}
    \vspace{1em}
  }{}}}
}
%    \end{macrocode}
% 
% \subsubsection{Sectioning commands}
% 
% Some general commands to handle clearing pages, and table of contents.
%    \begin{macrocode}
\newcommand\@clearpage[1]{%
  % Clear page if necessary
  \ifthenelse{\equal{#1}{part} \OR \equal{#1}{chapter}}{
    \cleardoublepage
    \thispagestyle{empty}
  }{}
}

%    \end{macrocode}
% 
% \begin{macro}{\play}
% \begin{macro}{\play*}
% Define sectioning commands to introduce plays. As for |\section| (and
% other) sectioning command, the starred version does the same, excepted that
% nothing is written in the table of content.
%    \begin{macrocode}
\newcommand{\play}[2][]{%
  \refstepcounter{play}
  \ifthenelse{\equal{#1}{}}{
    \def\@short{#2}
  }{
    \def\@short{#1}
  }
  \@clearpage{\@playlevel}
  \playmark{\@short}
  \addcontentsline{toc}{\@playlevel}{\@short}
  \ifthenelse{\equal{\@playstyle}{custom}}{
    \customplay{\theplay}{#2}
  }{
    \@displaytitle{\@playstyle}{}{#2}
  }
}
\WithSuffix\newcommand\play*[1]{%
  \@clearpage{\@playlevel}
  \ifthenelse{\equal{\@playstyle}{custom}}{
    \customplay*{#1}
  }{
    \@displaytitle{\@playstyle}{}{#1}
  }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% \begin{macro}{\act}
% \begin{macro}{\act*}
% Define commands to introduce acts.
%    \begin{macrocode}
\newcommand{\act}[2][]{%
  \refstepcounter{act}
  \ifthenelse{\equal{#1}{}}{
    \def\@short{#2}
  }{
    \def\@short{#1}
  }
  \ifthenelse{\equal{\@short}{}}{
    \def\@label{\actname{} \theact{}}
  }{
    \def\@label{\actname{} \theact{}\xspace: }
  }
  \@clearpage{\@actlevel}
  \actmark{\@label\@short}
  \addcontentsline{toc}{\@actlevel}{\@label\@short}
  \ifthenelse{\equal{\@actstyle}{custom}}{
    \customact{\theact}{#2}
  }{
    \@displaytitle{\@actstyle}{\actname{} \theact}{#2}
  }
}
\WithSuffix\newcommand\act*[1]{%
  \@clearpage{\@actlevel}
  \ifthenelse{\equal{\@actstyle}{custom}}{
    \customact*{#1}
  }{
    \@displaytitle{\@actstyle}{}{#1}
  }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% \begin{macro}{\scene}
% \begin{macro}{\scene*}
% Define commands to introduce scenes.
%    \begin{macrocode}
\newcommand{\scene}[2][]{%
  \refstepcounter{scene}
  \ifthenelse{\equal{#1}{}}{
    \def\@short{#2}
  }{
    \def\@short{#1}
  }
  \ifthenelse{\equal{\@short}{}}{
    \def\@label{\scenename{} \thescene{}}
  }{
    \def\@label{\scenename{} \thescene{}\xspace: }
  }
  \@clearpage{\@scenelevel}
  \scenemark{\@label\@short}
  \addcontentsline{toc}{\@scenelevel}{\@label\@short}
  \ifthenelse{\equal{\@scenestyle}{custom}}{
    \customscene{\thescene}{#2}
  }{
    \@displaytitle{\@scenestyle}{\scenename{} \thescene}{#2}
  }
}
\WithSuffix\newcommand\scene*[1]{%
  \@clearpage{\@scenelevel}
  \ifthenelse{\equal{\@scenestyle}{custom}}{
    \customscene*{#1}
  }{
    \@displaytitle{\@scenestyle}{}{#1}
  }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% \begin{macro}{\interlude}
% \begin{macro}{\interlude*}
% Define commands to introduce interludes.
%    \begin{macrocode}
\newcommand{\interlude}[2][]{%
  \ifthenelse{\equal{#1}{}}{
    \def\@short{#2}
  }{
    \def\@short{#1}
  }
  \ifthenelse{\equal{\@short}{}}{
    \def\@label{\interludename{}}
  }{
    \def\@label{\interludename{}\xspace: }
  }
  \ifthenelse{\equal{\@interludelevel}{play}}{
    \@clearpage{\@playlevel}
    \playmark{\@label\@short}
    \addcontentsline{toc}{\@playlevel}{\@label\@short}
    \@displaytitle{\@playstyle}{\interludename}{#2}
  }{\ifthenelse{\equal{\@interludelevel}{act}}{
    \@clearpage{\@actlevel}
    \actmark{\@label\@short}
    \addcontentsline{toc}{\@actlevel}{\@label\@short}
    \@displaytitle{\@actstyle}{\interludename}{#2}
  }{% \@interludelevel is scene
    \@clearpage{\@scenelevel}
    \scenemark{\@label\@short}
    \addcontentsline{toc}{\@scenelevel}{\@label\@short}
    \@displaytitle{\@scenestyle}{\interludename}{#2}
  }}
}
\WithSuffix\newcommand\interlude*[1]{%
  \ifthenelse{\equal{\@interludelevel}{play}}{
    \@clearpage{\@playlevel}
    \@displaytitle{\@playstyle}{\interludename}{#1}
  }{\ifthenelse{\equal{\@interludelevel}{act}}{
    \@clearpage{\@actlevel}
    \@displaytitle{\@actstyle}{\interludename}{#1}
  }{% \@interludelevel is scene
    \@clearpage{\@scenelevel}
    \@displaytitle{\@scenestyle}{\interludename}{#1}
  }}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Curtain}
%
% \begin{macro}{\curtain}
% Used to mark the end of an act. Prints ``curtain'' centered in its own line.
%    \begin{macrocode}
% Curtain
\newcommand\curtain{
  \begin{center}
    \sffamily\LARGE\bfseries \textsc{\curtainname}
  \end{center}
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Characters}
%
% \subsubsection{Spacing}
% Add (or not) an |$\backslash$xspace| command at the end of character names,
% depending on the |xspace| package option.
%    \begin{macrocode}
\newcommand{\@maybexspace}{%
  \if@xspace%
    \xspace%
  \fi%
}
%    \end{macrocode}
%
% \subsubsection{Characters' line}
% Define the command |\@speaks|, wich introduce a character's line. It
% is not meant to be used by user, but will be used by further commands.  It
% takes two arguments: the character's name, and optionally, a stage direction.
%    \begin{macrocode}
\newcommand{\@speaks}[2][]{%
  \ifthenelse{\equal{#1}{}}{%
    \speakswithoutdirection{#2}%
  }{%
    \speakswithdirection{#2}{#1}%
  }\@maybexspace%
}
%    \end{macrocode}
% 
% \begin{macro}{\speakswithdirection}
% \begin{macro}{\speakswithoutdirection}
% Definition of styles for introducing characters' lines. These
% commands can be overloaded by user.
%    \begin{macrocode}
\ifthenelse{\equal{\@characterstyle}{bold}}{%
  % Bold style
  \newcommand\speakswithdirection[2]{%
    \noindent%
    {\bfseries\sffamily #1} \emph{(#2)}\xspace:%
  }
  \newcommand\speakswithoutdirection[1]{%
    \noindent%
    {\bfseries\sffamily #1\xspace:}%
  }%
}{}%
\ifthenelse{\equal{\@characterstyle}{center}}{%
  % Center style
  \newcommand\speakswithdirection[2]{%
    \begin{center}%
    \textsc{#1},\\\emph{#2}%
    \end{center}%
  }%
  \newcommand\speakswithoutdirection[1]{%
    \begin{center}%
    \textsc{#1}%
    \end{center}%
  }%
}{}%
\ifthenelse{\equal{\@characterstyle}{imprimerie-verse}}{%
  % Style for verse plays defined by the French Imprimerie nationale
  \newcommand\speakswithdirection[2]{%
    \begin{center}%
    \textsc{#1}, \emph{#2}%
    \end{center}%
  }%
  \newcommand\speakswithoutdirection[1]{%
    \begin{center}%
    \textsc{#1}%
    \end{center}%
  }%
}{}%
\ifthenelse{\equal{\@characterstyle}{imprimerie-prose}}{%
  % Style for prose plays defined by the French Imprimerie nationale
  \newcommand\speakswithdirection[2]{%
    \noindent\hspace*{-\parindent}\textsc{#1}, \emph{#2}\xspace:%
  }%
  \newcommand\speakswithoutdirection[1]{%
    \noindent\hspace*{-\parindent}\textsc{#1}\xspace:%
  }%
}{}%
\ifthenelse{\equal{\@characterstyle}{arden}}{%
  \newcommand\speakswithdirection[2]{%
    \noindent\hspace*{-\parindent}\textsc{\MakeLowercase{#1}} [\emph{#2}]\quad%
  }%
  \newcommand\speakswithoutdirection[1]{%
    \noindent\hspace*{-\parindent}\textsc{\MakeLowercase{#1}}\quad%
  }%
}{}%
\ifthenelse{\equal{\@characterstyle}{simple}}{%
  % Simple style
  \newcommand\speakswithdirection[2]{%
    \indent\textsc{#1}, \emph{#2}\xspace:%
  }%
  \newcommand\speakswithoutdirection[1]{%
    \indent\textsc{#1}\xspace:%
  }%
}{}%
\ifthenelse{\equal{\@characterstyle}{margin}}{%
  % Margin style
  \setlength{\leftskip}{3cm}
  \newcommand\speakswithdirection[2]{%
    \hspace{-3cm} #1 #2
  }
  \newcommand\speakswithoutdirection[1]{%
    \hspace{-3cm} #1
  }%
}{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Dramatis person\ae{}}
% \begin{environment}{dramatis}
% In this environment are defined characters.
%    \begin{macrocode}
\newcommand{\@dramatis@clear}{}
\provideboolean{@dramatis@hidden}
\newenvironment{dramatis}[1][]{
  \@dramatis@clear{}
  \undef{\@dramatis@clear}
  \undef{\@dramatis@hook}
  \newcommand{\@dramatis@hook}{}
  \ifthenelse{\equal{#1}{hidden}}{
    \setboolean{@dramatis@hidden}{true}
  }{\ifthenelse{\equal{#1}{}}{
    \setboolean{@dramatis@hidden}{false}
    \gappto{\@dramatis@hook}{\begin{longtable}{l}}
  }{
    \ClassError{thalie}{%
      Environment dramatis does not accept option #1.%
    }{
    }
  }
  }
}{%
  \ifthenelse{\boolean{@dramatis@hidden}}{%
  }{%
    \gappto{\@dramatis@hook}{\end{longtable}}
    \@dramatis@hook{}%
  }
}
%    \end{macrocode}
% \end{environment}
%
% Generic character output
%    \begin{macrocode}
\newcommand{\@character}[2]{%
  \ifthenelse{\( \equal{#1}{} \) \AND \( \equal{#2}{} \)}{%
    ~%
  }{}%
  \ifthenelse{\( \NOT \equal{#1}{} \) \AND \( \equal{#2}{} \)}{%
    #1%
  }{}%
  \ifthenelse{\( \equal{#1}{} \) \AND \( \NOT \equal{#2}{} \)}{%
    #2%
  }{}%
  \ifthenelse{\( \NOT \equal{#1}{} \) \AND \( \NOT \equal{#2}{} \)}{%
    #1, #2%
  }{}%
  \tabularnewline
}
%    \end{macrocode}
%
% \begin{macro}{\characterspace}
% Add space in the dramatis person\ae{}.
%    \begin{macrocode}
\newcommand{\characterspace}{%
  \gappto{\@dramatis@hook}{\@character{}{~}}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{charactergroup}
% \changes{v0.6}{2013/11/02}{Groups of characters are now aligned with other caracters.}
% Gathers definition of characters that share the same description.
%    \begin{macrocode}
\newenvironment{charactergroup}[1]{%
  \gdef\@groupname{#1}
  \gappto{\@dramatis@hook}{
    \hspace{-7.2pt}\begin{math}\left.
    \begin{tabular}{ll}
  }
}{%
  \gappto{\@dramatis@hook}{
    \end{tabular}
    \right\} \end{math}
  }
  \protected@xappto{\@dramatis@hook}{\@groupname}
  \gappto{\@dramatis@hook}{\tabularnewline}
}
%    \end{macrocode}
% \end{environment}
%
% \subsubsection{Character definitions}
% \begin{macro}{\setcharactername}
% Set (or change) the name used to introduce the lines of a character.
%    \begin{macrocode}
% The tough part of this code is to deal with optional argument.
\newcommand{\setcharactername}[2]{%
    \expandafter\gdef\csname#1name\endcsname{%
      #2\@maybexspace%
    }%
    \expandafter\gdef\csname#1\endcsname{%
      \@ifnextchar[{%
        \defcharcommand@with{#2}%
      }{%
        \defcharcommand@without{#2}%
      }%
    }%
    \xappto{\@dramatis@clear}{%
      \global\noexpand\csundef{#1}%
      \global\noexpand\csundef{#1name}%
    }%
}
%    \end{macrocode}
% \end{macro}
%
% Define the command used to introduce a character's line. It takes two
% arguments: the first one is the name of the command to define, and the second
% one is the name of the character corresponding to this command.
%    \begin{macrocode}
\newcommand{\@definecharactercommand}[2]{%
  \@ifundefined{#1}{%
  }{%
    \ClassError{thalie}{%
      A command named \@backslashchar#1 already exists. We cannot define a new
      one.%
    }{%
      Choose another command name to introduce character #2's lines.%
    }%
  }%
  \@ifundefined{#1name}{%
  }{%
    \ClassError{thalie}{%
      A command named \@backslashchar#1name already exists. We cannot define a
      new one.%
    }{%
      Choose another command name to introduce character #2's lines, such that
      when a new command is defined by adding "name" to it, it does not
      conflict with an existing one.
    }%
  }%
  \setcharactername{#1}{#2}%
}
\def\defcharcommand@with#1[#2]{\@speaks[#2]{#1}}
\def\defcharcommand@without#1{\@speaks{#1}}
%    \end{macrocode}
%
% \begin{macro}{\character}
% Define a character: put it in the dramatis person\ae{}, and define
% corresponding commands.
%   \begin{macrocode}
\pgfkeys{
  % Character definition
  /CHARACTER/.is family, /CHARACTER,
  cmd/.value required,
  cmd/.store in=\@cmd,
  drama/.value required,
  drama/.store in=\@drama,
  desc/.value required,
  desc/.store in=\@desc,
}
\newcommand{\character}[2][]{
  \undef{\@drama}
  \undef{\@cmd}
  \undef{\@desc}
  \pgfkeys{/CHARACTER, #1}%
 % Forbidden combinations
  \ifthenelse{
    \( \( \NOT \isundefined{\@cmd} \) \AND \equal{#2}{} \) \OR
    \( \equal{#2}{} \AND \isundefined{\@cmd} \AND \isundefined{\@desc} \AND \isundefined{\@drama} \) \OR
    \( \isundefined{\@cmd} \AND \( \NOT \equal{#2}{} \) \AND \( \NOT \isundefined{\@drama} \) \)
  }{
    \ClassError{thalie}{Invalid character definition.}{All combination of omitted arguments are not allowed. See the documentation for more information}
  }{
    % Defining character command
    \ifthenelse{\( \NOT \isundefined{\@cmd} \) \AND \( \NOT \equal{#2}{} \)}{
      \@definecharactercommand{\@cmd}{#2}
    }{
    }
    \ifthenelse{
      \( \NOT \equal{#2}{} \) \AND \( \NOT \isundefined{\@cmd} \) \AND \( \NOT \isundefined{\@drama} \) \AND \isundefined{\@desc}
    }{
      \ifthenelse{\equal{\@drama}{}}{
      % Hidden character. Nothing added to dramatis personae
      }{
      % Populating dramatis personae
        \protected@xappto{\@dramatis@hook}{\noexpand\@character{\@drama}{}}
      }
    }{
      % Populating dramatis personae
      \@ifundefined{@desc}{\def\@desc{}}{}
      \@ifundefined{@drama}{\def\@drama{#2}}{}
      \protected@xappto{\@dramatis@hook}{\noexpand\@character{\@drama}{\@desc}}
    }
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\disposablecharacter}
% Disposable character (character used only a few times, defined on-the-fly,
% that does not appear in the dramatis person\ae{}).
%    \begin{macrocode}
\newcommand{\disposablecharacter}[2][]{%
  \@speaks[#1]{#2}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Stage directions}
% \begin{macro}{\onstage}
% Centered stage direction.
%    \begin{macrocode}
\newcommand{\onstage}[1]{{\centering \emph{#1}\par\medskip}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\did}
% Inline stage directions.
%    \begin{macrocode}
\newcommand{\did}[1]{\emph{(#1)} }
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{dida}
% Bigger stage directions, in its own paragraph.
%    \begin{macrocode}
\newenvironment{dida}{%
  \begin{quote}
  \begin{em}
  }{%
  \end{em}
  \end{quote}
}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\pause}
% Shortcut for |\did{\pausename}|.
%    \begin{macrocode}
\newcommand\pause{\did{\pausename}}
%    \end{macrocode}
% \end{macro}

% \subsection{Splitting verses}
% \begin{macro}{\pauseverse}
% \changes{v0.7}{2015/12/28}{New commands \texttt{\bbackslash{}pauseverse}, \texttt{\bbackslash{}resumeverse}, \texttt{\bbackslash{}adjustverse}.}
% \begin{macro}{\resumeverse}
% \begin{macro}{\adjustverse}
% Commands to split a verse between several characters.
%    \begin{macrocode}
% Thanks to Timothy Li for his question, and David Carlisle for his answer:
% https://tex.stackexchange.com/questions/107726/107727#107727

\newlength{\@verseadjust}
\setlength{\@verseadjust}{0pt}

\newcommand{\adjustverse}[1]{\setlength{\@verseadjust}{#1}}

\newcommand{\pauseverse}{{\abovedisplayshortskip\z@\abovedisplayskip\z@
      \belowdisplayshortskip\z@\belowdisplayskip\z@
  $$\global\dimen\@ne\predisplaysize
   \xdef\tmp{%
        \predisplaysize\the\predisplaysize
        \prevgraf\the\prevgraf\relax}%
  $$\vskip\dimexpr-\parskip-\baselineskip\relax}\tmp
}

\newcommand{\resumeverse}{%
  \hspace{\@verseadjust}\hspace{\the\dimen\@ne}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \changes{v0.5}{2013/06/08}{First published version.}
%
% \addcontentsline{toc}{section}{Change History}
% \PrintChanges
%
% \begin{thebibliography}{9}
%   \addcontentsline{toc}{section}{References}
%   \bibitem{imprimerienationale}
%     {Imprimerie nationale},
%     \emph{Lexique des r\`egles typographiques en usage \`a l'Imprimerie nationale},
%     2002,
%     ISBN : 978-2-7433-0482-9
%   \bibitem{cyrano}
%     {Edmond Rostand},
%     \emph{Cyrano de Bergerac},
%     1897
%   \bibitem{midsummer}
%     {William Shakespeare},
%     \emph{A Midsummer Night's Dream},
%     1600
%   \bibitem{dtxtut}
%     {Scott Pakin},
%     \emph{How to Package Your \LaTeX{} Package --- Tutorial on writing .dtx and .ins files},
%     2004,
%     \url{http://www.ctan.org/pkg/dtxtut/}
%   \bibitem{clsguide}
%     {The \LaTeX{} Team},
%     \emph{\LaTeXe{} for class and package writers},
%     2006,
%     \url{http://www.ctan.org/pkg/clsguide}
%   \bibitem{drama}
%     {Matt Swift},
%     \emph{drama --- Production-style stage script in LaTeX},
%     2001,
%     \url{http://www.ctan.org/pkg/drama}
%   \bibitem{dramatist}
%     {Massimiliano Dominici},
%     \emph{dramatist --- Typeset dramas, both in verse and in prose},
%     2005,
%     \url{http://www.ctan.org/pkg/dramatist}
%   \bibitem{play}
%     {James Kilfiger},
%     \emph{play --- Typeset drama using \LaTeX{}},
%     2001,
%     \url{http://www.ctan.org/pkg/play}
%   \bibitem{screenplay}
%     {John Pate},
%     \emph{screenplay --- A class file to typeset screen­plays},
%     2012,
%     \url{http://www.ctan.org/pkg/screenplay}
%   \bibitem{sides}
%     {Wing L Mui},
%     \emph{sides --- A LaTeX class for typesetting stage plays},
%     2005,
%     \url{http://www.ctan.org/pkg/sides}
% \end{thebibliography}
%
% \StopEventually{%
% \addcontentsline{toc}{section}{Index}
% \PrintIndex
% }
% \Finale
\endinput
