% \iffalse    meta-comment
%
% 
%                   COPYRIGHT NOTICE AND LICENSE
% 
% 
% COPYRIGHT
% =========
% 
%    Copyright Gianfranco Boggio-Togna 2006
% 
% 
% DEFINITIONS
% ===========
% 
% In this document the following terms are used:
% 
%    `Work'
%     The files TEXNIKA.dtx, poetry.dtx, drama.dtx, technica.ins and
%     the derived files TEXNIKA.sty, poetry.sty, drama.sty
%     
%     'Copyright Holder'
%     Gianfranco Boggio-Togna
% 
%    `Derived Work'
%     Any work that under any applicable law is derived from the Work.
% 
%    `Modification' 
%     Any procedure that produces a Derived Work under any applicable
%     law -- for example, the production of a file containing an
%     original file associated with the Work or a significant portion of
%     such a file, either verbatim or with modifications and/or
%     translated into another language.
% 
%    `Modify'
%     To apply any procedure that produces a Derived Work under any
%     applicable law.
%     
%    `Distribution'
%     Making copies of the Work available from one person to another, in
%     whole or in part.  Distribution includes (but is not limited to)
%     making any electronic components of the Work accessible by
%     file transfer protocols such as FTP or HTTP or by shared file
%     systems such as Sun's Network File System (NFS).
% 
% 
% CONDITIONS ON DISTRIBUTION AND MODIFICATION
% ===========================================
% 
% 1.  You may distribute a complete, unmodified copy of the Work as you
% received it.  Distribution of only part of the Work is considered
% modification of the Work, and no right to distribute such a Derived
% Work may be assumed under the terms of this clause.
% 
% 2. The Copyright Holder may, without restriction, modify the Work,
% thus creating a Derived Work. The Copyright Holder may also distribute
% the Derived Work without restriction. Derived Works distributed in
% this manner by the Copyright Holder are considered to be updated
% versions of the Work.
% 
% 3.  If you are not the Copyright Holder, you are not allowed
% to modify the Work.
% 
% 4.  The conditions above are not intended to prohibit, and hence do
% not apply to, the modification, by any method, of any component so that it
% becomes identical to an  updated version of that component of the Work as
% it is distributed by the Copyright Holder under Clause 2, above.
% 
% 5. Distribution of the Work in an alternative format, where the Work
% is then produced by applying some process to that format, does not
% relax or nullify any sections of this license as they pertain to the
% results of applying that process.
% 
% 6. This license places no restrictions on works that are unrelated to
% the Work, nor does this license place any restrictions on aggregating
% such works with the Work by any means.
% 
% 7.  Nothing in this license is intended to, or may be used to, prevent
% complete compliance by all parties with all applicable laws.
% 
% 
% CONDITIONS ON USE
% =================
% 
% The Work may be used without charge for non-commercial private
% or academic purposes. Use of the Work for commercial purposes is
% prohibited. To use the Work for commercial purposes you must obtain a
% license for commercial use from the Copyright Holder.
% 
% 
% NO WARRANTY
% ===========
% 
% There is no warranty for the Work.  Except when otherwise stated in
% writing, the Copyright Holder provides the Work `as is', without
% warranty of any kind, either expressed or implied, including, but not
% limited to, the implied warranties of merchantability and fitness for
% a particular purpose.  The entire risk as to the quality and performance
% of the Work is with you.  Should the Work prove defective, you
% assume the cost of all necessary servicing, repair, or correction.
% 
% In no event unless agreed to in writing will the Copyright Holder or
% any other party who may distribute the Work as permitted above, be
% liable to you for damages, including any general, special, incidental
% or consequential damages arising out of any use of the Work or out
% of inability to use the Work (including, but not limited to, loss of
% data, data being rendered inaccurate, or losses sustained by anyone
% as a result of any failure of the Work to operate with any other
% programs), even if the Copyright Holder or said other party has been
% advised of the possibility of such damages.
% 
%<*driver>
\documentclass{ltxdoc}
\setlength{\parindent}{0pt}
\setlength{\textwidth}{5.5in}
\setlength{\textheight}{8.5in}
\setlength{\parskip}{\smallskipamount}
\usepackage[ibycus,english]{babel}
\usepackage[pagestyles]{titlesec}
\newpagestyle {DRAMA@page} {

  \sethead   {}
             {\large {\itshape The} \texttt{drama} {\itshape package}} 
             {\textup{\thepage}}
  \setfoot   {}
             {Copyright \copyright\  Gianfranco Boggio--Togna 2006}
             {}%
  \setmarks  {section}{subsection}
}
\MakeShortVerb{|}
\AlsoImplementation
\begin{document}
\DocInput{drama.dtx}
\end{document}
%</driver>
%
% \fi
%
% \iftrue \CheckSum{2530} \fi
%
% \def\fileversion{0.9}
% \def\filedate{2006/11/11}
%
\def\TEXNIKA {%
  \expandafter
  \ifx \csname l@polutonikogreek\endcsname \relax
    \expandafter
    \ifx \csname l@ibycus\endcsname \relax
       $\tau\kern-.05em\epsilon\chi\nu\kern-.05em\iota
       \kappa\kern.04em\acute\alpha$%
    \else
      \foreignlanguage{ibycus}{texnika'}%
    \fi
  \else
      \foreignlanguage{polutonikogreek}{teqnik'a}%
  \fi
}
\def \TXN@cmd#1{\texttt{\protect\bslash #1}}%
%
% \thispagestyle{empty}
% \begin{centering}
% {\large \textsc{Gianfranco Boggio\,--Togna}}\par
% \vspace*{1in}
% {\Huge \TEXNIKA}\par 
% \vspace*{.15in}
% {\LARGE Typesetting for the Humanities}\par
% \vspace*{.5in}
% {\Large The \textbf{drama} package}\par
% \vfill
% {\Large Version 0.9}\par
% \end{centering}
% \newpage
% \thispagestyle{empty}
% \vspace{6ex}
% \section*{Copyright notice}
% \noindent Copyright \copyright\ Gianfranco Boggio--Togna 2006\par
%        Author's address: C.P. 14021, I-20140 Milano\\
%                  Email: \textsl{gbt\kern .08em @\kern .1em acm.org}
% \vspace{6ex}
% \section*{License}
% \noindent This program is distributed under the terms of the license
% that appears at the start of the file \texttt{drama.dtx} (this file)
% and in file \texttt{license.txt} 
%  
% This program consists of the files \texttt{drama.dtx} and 
% \texttt{technica.ins} 
%  
% \newpage
% \pagenumbering{roman}
% \tableofcontents
% \newpage
% \pagenumbering{arabic}
% \pagestyle {DRAMA@page}
% 
% \StopEventually{}
% \newpage
%
% \section{External dependencies} 
%
%    \begin{macrocode}
\def \TXN@temp {LaTeX2e}
\def \TXN@temp@bis {2003/12/01}
\@tempswafalse
\ifx \fmtname \TXN@temp
  \ifx \fmtversion \TXN@temp@bis
  \else
    \def \TXN@temp@bis {2005/12/01}
    \ifx \fmtversion \TXN@temp@bis
    \else
      \@tempswatrue
    \fi
  \fi
\else
    \@tempswatrue
\fi
\if@tempswa
   \PackageError {DRAMA}
     {The Technica suite requires the LaTex\MessageBreak
      release dated `2003/12/01' or `2005/12/01'}
     {}
   \def\recurse{(\recurse)}\recurse
\fi
%
\ProvidesPackage {drama} [2006/11/11 v. 0.9 A package for typesetting drama]
\RequirePackageWithOptions {TEXNIKA}
%    \end{macrocode}
% \section{Initialization} 
%    \begin{macrocode}
\newbox \DRM@vbox
\newbox \DRM@hbox
%    \end{macrocode}
% Most internal variables are initialized to |\empty|, for easier testing.
%    \begin{macrocode}
\def \DRM@persona@side         {}
\def \DRM@persona@flags        {}
\edef \DRM@persona@position    {\TXN@o@PersonaNormal}
\def \DRM@persona@field        {}
\def \DRM@FaciesPersonae       {}
\def \DRM@FormaPersonae        {}
\def \DRM@SpatiumAntePersonam  {}
\def \DRM@SpatiumSupraPersonam {}
\def \DRM@SpatiumInfraPersonam {}
\def \DRM@speech@lines         {0}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@FaciesBracketSD       {}
\def \DRM@FormaBracketSD        {}
\def \DRM@SpatiumAnteBracketSD  {}
\def \DRM@SpatiumPostBracketSD  {}
\def \DRM@SpatiumSupraBracketSD {}
\def \DRM@SpatiumInfraBracketSD {}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@FaciesParenthesisSD       {}
\def \DRM@FormaParenthesisSD        {}
\def \DRM@SpatiumSupraParenthesisSD {}
\def \DRM@SpatiumInfraParenthesisSD {}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@resume@par {}
%    \end{macrocode}
% 
% \section{Entering and leaving the domain}
%
% A switch used to avoid a spurious |\par| before the first speech.
%    \begin{macrocode}
\newif \ifDRM@first@speech
%    \end{macrocode}
%
%    \begin{macrocode}
\def \Drama {\TXN@withinDramatrue  \DRM@first@speechtrue}
\let \drama = \Drama
%    \end{macrocode}
%
%    \begin{macrocode}
\def \endDrama {\TXN@withinDramafalse} 
\let \enddrama = \endDrama
%    \end{macrocode}
% \section{Speech-headings}
%
%
% True for the starred form of |\persona|.
%    \begin{macrocode}
\newif \ifDRM@starred
%    \end{macrocode}
% True if the |\persona| is followed by a b-SD.
%    \begin{macrocode}
\newif \ifDRM@persona@bracketSD
%    \end{macrocode}
% True if |\Facies \personae| contains |#2|.
%    \begin{macrocode}
\newif \ifDRM@bracketSD@in@persona
%    \end{macrocode}
% True is |\persona| is preceded by |\aparte|.
%    \begin{macrocode}
\newif \ifDRM@aparte@persona
%    \end{macrocode}
% True if b-SD starts a line (no |\StatiumAnte|).
%    \begin{macrocode}
\newif \ifDRM@initial@bracketSD
%    \end{macrocode}
% \subsection{The \TXN@cmd{persona} command}
%    \begin{macrocode}
\newcommand {\persona}{%
  \@ifstar {\DRM@starredtrue  \DRM@persona@switch}
           {\DRM@starredfalse \DRM@persona@switch}}
\let \personae = \persona
\let \personam = \persona
%    \end{macrocode}
% 
%    \begin{macrocode}
\def \DRM@persona@switch {%
  \ifx \empty \TXN@attribute@name 
    \expandafter \DRM@persona
  \else
    \def \TXN@subclass@name {persona}%
    \def \TXN@subclass@number {}%
    \def \TXN@temp {DRM}%
    \expandafter \TXN@attribute@set
  \fi
} 
%    \end{macrocode}
% \subsection{Processing the \TXN@cmd{persona} command}
%    \begin{macrocode}
\newcommand {\DRM@persona} [2][]{%
%<debug>  \TXN@trace \DRM@persona
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifTXN@withinDrama
  \else
    \ifDRM@starred
    \else
      \PackageError {DRAMA}
        {\protect\persona\space may be used\MessageBreak
         only within the `drama' domain}
        {}%
    \fi
  \fi
%    \end{macrocode}
% First define the abbreviation, if present.
%    \begin{macrocode}
   \TXN@counter@a = \z@
   \TXN@counter@b = \z@
   \DRM@check@abbreviation #1\TXN@nil
%    \end{macrocode}
% There is an abbreviation.
%    \begin{macrocode}
   \ifnum \TXN@counter@a > \z@
     \TXN@gdef {DRM@#1}{\persona{#2}}%
   \fi
   \ifDRM@starred
%    \end{macrocode}
% If \textasteriskcentered-form, nothing else to do.
%    \begin{macrocode}
   \else
     \DRM@getPersona {#2}%
     \expandafter \DRM@process@persona
   \fi
}
%    \end{macrocode}
% Get the argument.
%    \begin{macrocode}
\def \DRM@getPersona #1{%
  \let \DRM@esc@esc = \\%
  \def \\{\relax}%
  \DRM@splitPersona #1\\\\%
  \let \\= \DRM@esc@esc 
}
%    \end{macrocode}
% Split the argument into the two sub-arguments.
%    \begin{macrocode}
\def \DRM@splitPersona #1\\#2\\{%
%<debug>  \TXN@trace \DRM@splitPersona
  \TXN@trim {#1}%
  \ifDRM@aparte@persona
    \DRM@aparte@personafalse
    \ifx \DRM@FaciesAparte \relax
      \edef \DRM@persona@first {\the\TXN@trimmed}%
    \else
      \edef \DRM@persona@first
        {\noexpand\DRM@FaciesAparte\the\TXN@trimmed}%
    \fi
  \else
    \edef \DRM@persona@first {\the\TXN@trimmed}%
  \fi
  \@ifmtarg{#2} {\relax} {\TXN@trim {#2}}%
  \edef \DRM@persona@second {\the\TXN@trimmed}%
}
%    \end{macrocode}
% Check for an abbreviation in the optional parameter.
%    \begin{macrocode}
\def \DRM@check@abbreviation #1{%
  \ifx \TXN@nil #1\relax
    \ifnum \TXN@counter@a > \tw@
      \PackageError {DRAMA}
        {The \protect\persona\space abbreviation has more than 2 digits}
        {An abbreviation must be in the range 01-99}%
    \fi
    \ifnum \TXN@counter@b = \z@
      \ifnum \TXN@counter@a > \z@
        \PackageError{DRAMA}%
          {The \protect\persona\space abbreviation cannot be zero}
          {The control sequences \@backslashchar0 and \@backslashchar00
           are reserved \MessageBreak (see the User Manual)}%
      \fi
    \fi
  \else
    \advance \TXN@counter@a by \@ne
    \TXN@check@start@of@number {#1}%
    \ifTXN@isdigit
      \advance \TXN@counter@b by #1\relax
    \else
      \PackageError {DRAMA}%
        {A \protect\persona\space abbreviation contains\MessageBreak
         a character that is not a digit}
        {An abbreviation must be a number in the range 01-99}%
    \fi
    \expandafter \DRM@check@abbreviation
  \fi
}
%    \end{macrocode}
% \subsection{Setting the \TXN@cmd{persona} attributes}
% \paragraph{Facies}
%    \begin{macrocode}
\def \DRM@setFacies@persona #1{%
  \let \DRM@esc@esc = \\%
  \let \\= \relax
  \DRM@splitFaciesPersonae #1\\\\%
  \let \\= \DRM@esc@esc 
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@splitFaciesPersonae #1\\#2\\{%
  \def \DRM@FaciesPersonae@first ##1##2{%
    \begingroup
      \TXN@withinPersonatrue
      \DRM@ifthenelse
      #1%
    \endgroup
  }%
  \@ifmtarg{#2}%
    {\def \DRM@FaciesPersonae@second ##1##2{%
       \begingroup
         \DRM@ifthenelse
         \ignorespaces
         #1%
       \endgroup
     }%
    }
    {\def \DRM@FaciesPersonae@second ##1##2{%
      \begingroup
        \DRM@ifthenelse
        \ignorespaces
        #2%
      \endgroup
     }%
    }%
  \DRM@bracketSD@in@personafalse
  \TXN@check@parm 2\DRM@FaciesPersonae@first\TXN@nil
  \ifTXN@sw
    \DRM@bracketSD@in@personatrue 
  \fi
}
%    \end{macrocode}
% \paragraph{Forma}
%    \begin{macrocode}
\def \DRM@setForma@persona #1{%
  \def \DRM@FormaPersonae {#1\relax}%
}
%    \end{macrocode}
% \paragraph{Locus}
%    \begin{macrocode}
\def \DRM@setLocus@persona #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \edef \DRM@persona@side {}%
  \else
    \TXN@counter = \z@
    \def \TXN@entity@code {p}%
    \TXN@setLocus {#1}%
  \fi
}
%    \end{macrocode}
% \paragraph{Modus}
%    \begin{macrocode}
\def \DRM@setModus@persona #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \edef \DRM@persona@flags {}%
    \edef \DRM@persona@field {}%
  \else
    \TXN@counter = \z@
    \def \TXN@entity@code {p}%
    \TXN@setModus {#1}%
  \fi
}
%    \end{macrocode}
% \paragraph{Spacing}
%    \begin{macrocode}
\def \DRM@setSpatiumAnte@persona #1{%
  \TXN@build@spatium@horizontal {#1}%
  \toks@ = \expandafter {\TXN@temp}%
  \edef \DRM@SpatiumAntePersonam {\the\toks@}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@setSpatiumSupra@persona #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \def \DRM@SpatiumSupraPersonam {}%
  \else
    \TXN@build@spatium@list {#1}%
    \edef \DRM@SpatiumSupraPersonam {\TXN@L@spatium}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@setSpatiumInfra@persona #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \def \DRM@SpatiumInfraPersonam {}%
  \else
    \TXN@build@spatium@list {#1}%
    \edef \DRM@SpatiumInfraPersonam {\TXN@L@spatium}%
  \fi
}
%    \end{macrocode}
% \subsection{Processing an abbreviation}
%
% |\nn| is associated with the \textbf{cs} |\DRM@nn|.
%    \begin{macrocode}
\def \0{\DRM@persona@number 0}
\def \1{\DRM@persona@number 1}
\def \2{\DRM@persona@number 2}
\def \3{\DRM@persona@number 3}
\def \4{\DRM@persona@number 4}
\def \5{\DRM@persona@number 5}
\def \6{\DRM@persona@number 6}
\def \7{\DRM@persona@number 7}
\def \8{\DRM@persona@number 8}
\def \9{\DRM@persona@number 9}
%    \end{macrocode}
% |\0| and |\00| are reserved and are set to special values.
%    \begin{macrocode}
\TXN@def {DRM@0}{\persona{\kern0cc}}
\TXN@def {DRM@00}{\persona{\kern0dd}}
\def \DRM@persona@zero {\kern0cc}
\def \DRM@persona@zero@zero {\kern0dd}
%    \end{macrocode}
% Get the first digit.
%    \begin{macrocode}
\def \DRM@persona@number #1{%
  \ifTXN@withinSD
  \else
    \ifTXN@withinPersona
      \PackageError {DRAMA}
        {You cannot use a \protect\persona\space abbreviation \MessageBreak
         within the argument of \protect\persona}
        {}%
    \fi
  \fi
  \gdef \DRM@@ {#1}%
  \futurelet \DRM@token \DRM@persona@number@bis
}
%    \end{macrocode}
% Check for a second digit.
%    \begin{macrocode}
\def \DRM@persona@number@bis {%
  \TXN@check@start@of@number {\DRM@token}%
  \ifTXN@isdigit
    \expandafter \DRM@persona@number@ter
  \else
    \expandafter \DRM@persona@number@quater
  \fi
}
%    \end{macrocode}
% Attach the second digit.
%    \begin{macrocode}
\def \DRM@persona@number@ter #1{%
  \xdef \DRM@@ {\DRM@@#1}%
  \DRM@persona@number@quater
}
%    \end{macrocode}
% Check whether the abbreviation exists.
%    \begin{macrocode}
\def \DRM@persona@number@quater {%
  \if \TXN@relax {DRM@\DRM@@}%
    \PackageError {DRAMA}%
      {The \protect\persona\space abbreviation is undefined}{}%
  \else
    \expandafter \DRM@persona@number@quinquies
  \fi
}
%    \end{macrocode}
% Expand the abbreviation.
%    \begin{macrocode}
\def \DRM@persona@number@quinquies{\@nameuse {DRM@\DRM@@}}
%    \end{macrocode}
% 
% \subsection{Processing the speech-heading}
%    \begin{macrocode}
\def \DRM@process@persona {%
%<debug>  \TXN@trace \DRM@process@persona
  \def \DRM@options@SD {}%
  \let \next = \DRM@process@persona@bis
%    \end{macrocode}
% Within a SD, generate the second sub-argument.
%    \begin{macrocode}
  \ifTXN@withinSD
    \let \next = \relax
    \DRM@FaciesPersonae@second \DRM@persona@second \DRM@persona@first
  \else
%    \end{macrocode}
% Within another |\persona|, generate the first sub-argument.
%    \begin{macrocode}
    \ifTXN@withinPersona
      \let \next = \relax
      \DRM@persona@first
    \else
      \xdef \DRM@speech@lines {\ifTXN@withinVersus 1\else 2\fi}%
      \ifhmode
        \ifTXN@withinVersus
%    \end{macrocode}
% Check for more than one |\persona| in the heading.
%    \begin{macrocode}
          \ifnum \PTR@box@ind > \PTR@box@line 
            \if\TXN@num {PTR@box@type\number\PTR@box@line}
                        = \PTR@box@persona
              \let \next = \DRM@process@persona@within@line 
            \fi
          \fi
        \else
          \ifDRM@first@speech
          \else
            \par
          \fi
        \fi
      \fi
    \fi
    \DRM@first@speechfalse
  \fi
  \next
}
%    \end{macrocode}
%
% If no text has yet been found on the line, join the |\persona|
% to the speech-heading; otherwise, generate the usual box for
% a |\persona| but flag it as `text'.
%    \begin{macrocode}
\def \DRM@process@persona@within@line {%
  \xdef \TXN@gtemp {\DRM@persona@first}%
  \xdef \TXN@gtemp@bis {\DRM@persona@second}%
  \PTR@close@box \PTR@box@text \empty
  \edef \DRM@persona@first {\TXN@gtemp}%
  \edef \DRM@persona@second {\TXN@gtemp@bis}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifdim \wd\PTR@box@ind = \z@
    \count@ = \PTR@box@ind
    \advance \count@ by \m@ne
    \setbox \count@ = \hbox {%
      \unhbox \count@ 
      \unhbox \PTR@box@ind \unskip
      \DRM@FaciesPersonae@first {\DRM@persona@first}\empty
    }%
    \gdef \PTR@ignorespaces {\ignorespaces}%
    \advance \PTR@box@ind by \m@ne
  \else
    \advance \PTR@box@ind by \@ne
    \setbox \PTR@box@ind = \hbox {%
      \DRM@SpatiumAntePersonam
      \DRM@FaciesPersonae@first {\DRM@persona@first}\empty
    }%
    \TXN@edef {PTR@box@type\the\PTR@box@ind}{\PTR@box@text}%
  \fi
  \PTR@next@box
}
%    \end{macrocode}
% Record the position of the speech-heading.
%    \begin{macrocode}
\def \DRM@process@persona@bis {%
%<debug>  \TXN@trace \DRM@process@persona@bis
  \ifx \empty \DRM@persona@side 
    \edef \DRM@persona@position {\TXN@o@PersonaNormal}%
  \else
    \ifnum \DRM@persona@side = \TXN@centre \TXN@safe
      \edef \DRM@persona@position {\TXN@o@PersonaCentre}%
    \else
      \edef \DRM@persona@position {\TXN@o@PersonaLeft}%
    \fi
  \fi
  \futurelet \DRM@token \DRM@process@persona@checknonspace
}
%    \end{macrocode}
%  First check for a comma immediately following the persona, and then
%  (if the |\Facies| |\personae| includes |#2|) for a SD starting
%  with |\[|
%    \begin{macrocode}
\def \DRM@process@persona@checknonspace {%
%<debug>  \TXN@trace \DRM@process@persona@checknonspace
  \ifx ,\DRM@token 
    \expandafter \DRM@process@persona@checknonspace@bis
  \else
    \expandafter \DRM@process@persona@checknonspace@ter
  \fi
}
%    \end{macrocode}
% Attach the comma to the |\persona| string.
%    \begin{macrocode}
\def \DRM@process@persona@checknonspace@bis #1{%
  \edef \DRM@persona@first {\DRM@persona@first #1}%
  \futurenonspacelet \DRM@token \DRM@process@persona@checkbracketSD
}
%    \end{macrocode}
% Fetch the next token.
%    \begin{macrocode}
\def \DRM@process@persona@checknonspace@ter {%
 \futurenonspacelet \DRM@token \DRM@process@persona@checkbracketSD
}
%    \end{macrocode}
%
% Check for a b-SD. 
%
%    \begin{macrocode}
\def \DRM@process@persona@checkbracketSD {%
%<debug>  \TXN@trace \DRM@process@persona@checkbracketSD
%    \end{macrocode}
% If a b-SD follows, the |\persona| string will be processed after the
% b-SD has been read.
%    \begin{macrocode}
  \let \next = \DRM@process@persona@check@position
  \DRM@initial@bracketSDfalse
  \ifx \[\DRM@token
    \ifDRM@bracketSD@in@persona
      \setbox \z@ = \hbox {\DRM@persona@first}%
      \ifdim \wd\z@ = \z@
%    \end{macrocode}
% |\0| and |\00| get special treatment.
%    \begin{macrocode}
        \global \TXN@blank@linefalse
        \DRM@initial@bracketSDtrue
      \else
        \global \DRM@persona@bracketSDtrue
        \let \next = \relax
      \fi
    \else
      \DRM@initial@bracketSDtrue
    \fi
  \fi
  \next
}
%    \end{macrocode}
%
% Check for a special position of |\persona|. If it is |\centre|,
% we can typeset the speech-heading here; it is |\left|, we can do
% this only if we are not in the \textit{Versus} domain (the speech-heading
% may end up at the start of a fragment of a split line).
%
%    \begin{macrocode}
\def \DRM@process@persona@check@position {%
%<debug>  \TXN@trace \DRM@process@persona@check@position
  \ifTXN@withinVersus
    \let \next = \DRM@start@speech@versus
    \if \TXN@o@PersonaCentre \DRM@persona@position
      \let \next = \DRM@process@persona@position@centre
    \fi
  \else
    \let \next = \DRM@start@speech@prose
    \if \TXN@o@PersonaLeft\DRM@persona@position
       \DRM@process@persona@position@left
    \else
      \if \TXN@o@PersonaCentre\DRM@persona@position
        \DRM@process@persona@position@centre
      \fi
    \fi
  \fi
  \next
}
%    \end{macrocode}
%
% Special position: |\centre|.
%
%    \begin{macrocode}
\def \DRM@process@persona@position@centre {%
%<debug>  \TXN@trace \DRM@process@persona@position@centre
  \skip@ = \DRM@persona@offset
  \advance \skip@ by \skip@
  \skip@@ = \z@skip
  \ifdim \skip@ < \z@
    \skip@@ = -\skip@
    \skip@ = \z@skip
  \fi
  \setbox \DRM@hbox = \hbox to \TXN@measure {%
    \hfill
    \hskip \skip@ 
    \DRM@FaciesPersonae@first {\DRM@persona@first}\empty
    \hskip \skip@@
    \hfill
   }%
  \ifTXN@withinVersus
    \TXN@was@withinVersustrue
    \global \PTR@par@startedfalse
    \global \TXN@after@Spatiumtrue
  \else
     \TXN@was@withinVersusfalse
  \fi
  \if \TXN@option p\TXN@numbered@classes
    \ifTXN@withinVersus
      \TXN@exxxpandafter \prosa
    \fi
  \fi
  \TXN@spatium@vertical \DRM@SpatiumSupraPersonam
  \def \TXN@line@class {p}%
  \if \TXN@option p\TXN@numbered@classes
    \leavevmode \box \DRM@hbox \par
  \else
    \box \DRM@hbox 
  \fi
  \def \TXN@line@class {}%
  \TXN@spatium@vertical \DRM@SpatiumInfraPersonam
  \if \TXN@option p\TXN@numbered@classes
    \ifTXN@was@withinVersus
      \TXN@exxxpandafter \endprosa
    \fi
  \fi
}
%    \end{macrocode}
%
% Special position: |\left|.
%
%    \begin{macrocode}
\def \DRM@process@persona@position@left {%
%<debug>  \TXN@trace \DRM@process@persona@position@left
  \ifx \DRM@persona@first \DRM@persona@zero@zero
  \else
    \setbox \z@ = \vbox {%
      \hbox to \TXN@measure {%
        \DRM@FaciesPersonae@first {\DRM@persona@first} \empty
        \hfil
      }%
    }%
    \TXN@spatium@vertical \DRM@SpatiumSupraPersonam
    \box \z@ 
    \TXN@spatium@vertical \DRM@SpatiumInfraPersonam
  \fi
}
%    \end{macrocode}
%
% We are the start a speech within \textit{Versus}. Fill a box
% with the speech-heading and continue fetching text from the line. 
%
%    \begin{macrocode}
\def \DRM@start@speech@versus {%
%<debug>  \TXN@trace \DRM@start@speech@versus
  \ifx \DRM@persona@first \DRM@persona@zero@zero
    \gdef \DRM@speech@lines {2}%
  \else
    \ifx \DRM@persona@first \DRM@persona@zero
      \gdef \DRM@speech@lines {1}%
    \else
      \expandafter 
      \let \expandafter \DRM@save@textus@zero 
        \csname TXN@textus[\TXN@theTextus]Facies\endcsname
      \expandafter
      \let \csname TXN@textus[\TXN@theTextus]Facies\endcsname = \relax
      \PTR@start@box
      \DRM@FaciesPersonae@first {\DRM@persona@first} \empty
      \PTR@close@box \PTR@box@persona \DRM@persona@position
      \expandafter
      \let \csname TXN@textus[\TXN@theTextus]Facies\endcsname 
        = \DRM@save@textus@zero
      \ifx \empty \DRM@persona@field 
      \else
        \DRM@persona@inside@field
      \fi
      \expandafter \PTR@next@box
    \fi
  \fi
}
%    \end{macrocode}
% The |\persona| box is unpacked and re-packed inside the field. 
%    \begin{macrocode}
\def \DRM@persona@inside@field {%
%<debug>  \TXN@trace \DRM@persona@inside@field
  \dimen@ = \DRM@persona@field
  \advance \dimen@ by -\wd\PTR@box@ind 
  \ifdim \dimen@ > \z@
    \dimen@@ = \dimen@ 
    \divide \dimen@@ by \tw@
    \def \TXN@glue@left {}%
    \def \TXN@glue@right {}%
    \if \TXN@option \TXN@o@RangedLeft \DRM@persona@flags
      \edef \TXN@glue@right {\kern \the\dimen@@\relax}%
      \if \TXN@option \TXN@o@RangedRight \DRM@persona@flags
        \edef \TXN@glue@left {\kern \the\dimen@@\relax}%
      \else
        \edef \TXN@glue@right {\kern \the\dimen@\relax}%
      \fi
    \else
      \edef \TXN@glue@left {\kern \dimen@\relax}%
    \fi
    \setbox \PTR@box@ind = \hbox {%
      \TXN@glue@left \unhbox \PTR@box@ind \TXN@glue@right}%
  \fi
}
%    \end{macrocode}
%
% We are at the start of a speech outside \textit{Versus}. Typeset
% the speech-heading (possibly packing it inside a field) and
% set the formatting parameters for the speech.
%
%    \begin{macrocode}
\def \DRM@start@speech@prose {%
%<debug>  \TXN@trace \DRM@start@speech@prose
  \ifx \empty \DRM@persona@side 
    \TXN@spatium@vertical \DRM@SpatiumSupraPersonam
    \def \TXN@glue@left {}%
    \def \TXN@glue@right {}%
    \ifx \empty \DRM@persona@field 
      \setbox \DRM@hbox = \hbox \bgroup
    \else
      \if \TXN@option \TXN@o@RangedRight \DRM@persona@flags
        \def \TXN@glue@left {\hfil}%
      \fi
      \if \TXN@option \TXN@o@RangedLeft \DRM@persona@flags
        \def \TXN@glue@right {\hfil}%
      \fi
      \setbox \DRM@hbox = \hbox to \DRM@persona@field \bgroup
    \fi
    \TXN@glue@left
    \setbox \z@ = \hbox {\DRM@persona@first}%
    \ifdim \wd\z@ = \z@
    \else
      \def \TXN@parm@i {\DRM@persona@first}% 
      \DRM@FaciesPersonae@first \TXN@parm@i \empty
    \fi
    \TXN@glue@right
    \egroup
  \fi
  \everypar = {}%
  \DRM@FormaPersonae 
  \ifx \DRM@persona@first \DRM@persona@zero@zero
    \DRM@set@resume@par 
    \DRM@resume@par  
  \else
    \leavevmode
    \DRM@set@resume@par 
  \fi
  \ifx \empty \DRM@persona@field \unhbox \else \box \fi \DRM@hbox  
  \everypar = {\DRM@resume@par}%
  \ignorespaces
}
%    \end{macrocode}
% A speech may be interrupted (for instance, by a SD) and, on
% resumption, we must set the appropriate formatting parameters.
%    \begin{macrocode}
\def \DRM@set@resume@par {%
  \def \DRM@resume@par {}% 
  \ifdim \parindent > \z@
    \parindent = \z@
  \else
    \ifnum \hangafter > \z@
      \edef \DRM@resume@par {\hangindent = \the\hangindent \hangafter = \z@}%
    \fi
    \ifnum \hangafter < \z@
      \edef \DRM@resume@par {\hangindent = \z@ \hangafter = \z@}%
    \fi
  \fi
  \ifdim \leftskip = \z@
  \else
    \edef \DRM@resume@par {\leftskip \the\leftskip \DRM@resume@par}%
  \fi
  \ifdim \rightskip = \z@
  \else
    \edef \DRM@resume@par {\rightskip \the\rightskip \DRM@resume@par}%
  \fi
  \ifx \DRM@persona@first \DRM@persona@zero@zero
    \ifnum \hangafter > \z@
      \hangafter = \z@    
    \fi
    \ifnum \hangafter < \z@
      \hangafter = \z@    
      \hangindent = \z@    
    \fi
    \ifdim \parindent > \z@
      \parindent = \z@
    \fi
  \fi
}
%    \end{macrocode}
% \subsection{Processing the \TXN@cmd{aparte} command}
%    \begin{macrocode}
\newcommand {\aparte} {%
  \ifx \empty \TXN@attribute@name 
    \expandafter \DRM@aparte
  \else
    \def \TXN@subclass@name {aparte}%
    \def \TXN@subclass@number {}%
    \def \TXN@temp {DRM}%
    \expandafter \TXN@attribute@set
  \fi
}
%    \end{macrocode}
% 
% We just set a switch, which is tested in |\DRM@splitPersona|.
% 
%    \begin{macrocode}
\def \DRM@aparte {\DRM@aparte@personatrue}
\def \DRM@setFacies@aparte #1{%
  \def \DRM@FaciesAparte {#1\relax}%
}
%    \end{macrocode}
% 
% \section{Bracketed stage directions (b-SD)}
% \subsection{Processing a b-SD}
% 
% A b-SD is saved in this token register because it may have to be
% typeset again.
% 
%    \begin{macrocode}
\newtoks \DRM@toks@SD
%    \end{macrocode}
%
%    \begin{macrocode}
\def \[{\DRM@inner@bracketSD}%
\def \]{}
\def \DRM@inner@bracketSD {%
  \ifx \empty \TXN@attribute@name 
    \expandafter \DRM@bracketSD
  \else
    \def \TXN@subclass@name {bracketSD}%
    \def \TXN@subclass@number {}%
    \def \TXN@temp {DRM}%
    \expandafter \TXN@attribute@set
  \fi
}
%    \end{macrocode}
%
% Check for options.
%
%    \begin{macrocode}
\def \DRM@bracketSD {%
%<debug>  \TXN@trace \DRM@bracketSD
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifTXN@drive@out
    \global \TXN@drive@outfalse
    \endgroup
  \fi
%    \end{macrocode}
% If we are within |\versus|, close the current box, if any, and
% restore the usual meaning of CR while the argument is read.
%    \begin{macrocode}
  \ifTXN@withinVersus
    \DRM@bracketSD@versus 
  \fi
%    \end{macrocode}
% Redefine the delimiters in order to trap errors.
%    \begin{macrocode}
  \outer \def \[{\relax}%
  \outer \def \({\relax}%
  \outer \def \){\relax}%
  \edef \DRM@opening@delimiter@line {\the\inputlineno}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \def \DRM@delimiter {]}%
  \let \DRM@cs = \DRM@bracketSD@bis
  \DRM@check@options
}
%    \end{macrocode}
% The test is placed in a macro because |\ifPTR@par@started| may be undefined
% and cause an error when TeX is skipping over conditional text.
%    \begin{macrocode}
\def \DRM@bracketSD@versus {%
  \ifPTR@par@started
    \egroup
    \ifdim \wd\PTR@box@ind > \z@
      \advance \PTR@box@ind by \@ne
    \fi
  \fi
  \TXN@normalCR
}
%    \end{macrocode}
% On return from checking the options (if any) we come here.
%    \begin{macrocode}
\def \DRM@bracketSD@bis {\DRM@bracketSDSD}
\long \def \DRM@bracketSDSD #1\]{%
%<debug>  \TXN@trace \DRM@bracketSDSD
%    \end{macrocode}
% First, re-insert any tokens gobbled up while searching for options.
%    \begin{macrocode}
  \DRM@toks@SD = \expandafter {\the\DRM@toks@SD#1}%
  \edef \DRM@options@SD {[\DRM@options@SD\DRM@optionsBracketSD}%
  \if \TXN@option  n\DRM@options@SD
    \if \TXN@option  t\DRM@options@SD
    \else
      \edef \DRM@options@SD {t\DRM@options@SD}%
    \fi
  \fi
  \ifDRM@initial@bracketSD
    \DRM@initial@bracketSDfalse
    \edef \DRM@options@SD {a\DRM@options@SD}%
  \fi
  \def \[{\DRM@inner@bracketSD}%
  \def \({\DRM@inner@parenthesisSD}%
  \def \){\DRM@standalone@post}%
%    \end{macrocode}
% Restore the normal environment.
%    \begin{macrocode}
  \let \next = \relax
  \ifTXN@withinVersus
    \TXN@activeCR
  \fi
%    \end{macrocode}
% Check the b-SD type.
%    \begin{macrocode}
  \ifDRM@persona@bracketSD
    \let \next = \DRM@process@persona@and@bracketSD 
  \else
    \let \next = \DRM@process@normal@bracketSD
    \ifTXN@withinVersus
    \else
      \ifvmode
        \if \TXN@option \TXN@o@EmbeddedSD \DRM@options@SD
        \else
          \let \next = \DRM@process@standalone@bracketSD 
        \fi
      \fi
    \fi 
  \fi
  \next
}
%    \end{macrocode}
% A b-SD appearing immediately after |\persona|.
%    \begin{macrocode}
\def \DRM@process@persona@and@bracketSD {% 
%<debug>  \TXN@trace \DRM@process@persona@and@bracketSD
  \edef \DRM@options@SD {\TXN@o@EmbeddedSD\TXN@o@InitialSD\DRM@options@SD}%    
  \if \TXN@o@PersonaLeft \DRM@persona@position
    \edef \DRM@options@SD {\TXN@o@PersonaLeft\DRM@options@SD}% 
  \fi
  \if \TXN@o@PersonaCentre\DRM@persona@position
    \edef \DRM@options@SD {\TXN@o@PersonaCentre\DRM@options@SD}%
  \fi
  \global \DRM@persona@bracketSDfalse
%    \end{macrocode}
%
%    \begin{macrocode}
  \setbox \z@ = \hbox {\DRM@persona@first}%
  \ifdim \wd \z@ = \z@
    \def \TXN@parm@i {}% 
    \def \TXN@parm@ii {\DRM@FaciesBracketSD{\the\DRM@toks@SD}}% 
  \else
    \def \TXN@parm@i {\DRM@persona@first}% 
    \edef \TXN@temp {\the\DRM@toks@SD}%
    \ifx \empty \TXN@temp
       \def \TXN@parm@ii {}%
    \else
      \if \TXN@option \TXN@o@NoSpatiumAnte \DRM@options@SD
        \def \TXN@parm@ii {\DRM@FaciesBracketSD{\the\DRM@toks@SD}}% 
      \else
        \def \TXN@parm@ii {\DRM@SpatiumAnteBracketSD%
                           \DRM@FaciesBracketSD{\the\DRM@toks@SD}}% 
      \fi
    \fi
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \let \next = \DRM@process@persona@and@bracketSD@normal
  \ifTXN@withinVersus
    \if \TXN@o@PersonaCentre \DRM@persona@position
      \let \next = \DRM@process@persona@and@bracketSD@special
    \fi
  \else
    \if \TXN@o@PersonaNormal \DRM@persona@position
    \else
      \let \next = \DRM@process@persona@and@bracketSD@special
    \fi
  \fi
  \next
}
%    \end{macrocode}
% A b-SD appearing immediately after |\persona|, with the default
% speech-heading style.
%    \begin{macrocode}
\def \DRM@process@persona@and@bracketSD@normal {%
  \ifTXN@withinVersus
    \PTR@start@box 
  \else
    \endgraf
    \DRM@FormaPersonae
    \ifx \DRM@persona@first \DRM@persona@zero@zero
      \DRM@set@resume@par 
      \DRM@resume@par  
    \fi
%    \DRM@SpatiumAntePersonam
  \fi
  \begingroup
    \def \\{}%
    \DRM@FaciesPersonae@first {\TXN@parm@i}{\TXN@parm@ii}%
  \endgroup
  \ifTXN@withinVersus
    \PTR@close@box \PTR@box@persona@bracketSD \DRM@options@SD 
    \TXN@edef {PTR@box@toks\the\PTR@box@ind}{\the\DRM@toks@SD}%
    \def \DRM@options@SD {}%
    \gdef \PTR@ignorespaces {\ignorespaces}%
    \expandafter \PTR@next@box
  \else
    \def \DRM@options@SD {}%
    \expandafter \DRM@process@persona@and@bracketSD@resume 
  \fi
}
%    \end{macrocode}
%
% A b-SD appearing immediately after |\persona|, with a special
% speech-heading style.
%    \begin{macrocode}
\def \DRM@process@persona@and@bracketSD@special {%
    \def \TXN@entity@code {p}%
    \DRM@standalone@pre
    \if \TXN@o@PersonaCentre \DRM@persona@position
      \ifdim \DRM@persona@offset = \z@
      \else
        \dimen@ = \DRM@persona@offset 
        \advance \leftskip by 2\dimen@
      \fi
    \fi
    \DRM@FaciesPersonae@first \TXN@parm@i \TXN@parm@ii
    \DRM@standalone@post 
    \def \DRM@options@SD {}%
    \ifTXN@withinVersus
    \else
      \gdef \PTR@ignorespaces {\ignorespaces}%
      \expandafter \DRM@process@persona@and@bracketSD@resume 
    \fi
}
\def \DRM@process@persona@and@bracketSD@resume {%
  \DRM@set@resume@par 
  \everypar = {\DRM@resume@par}%
  \ignorespaces
}
%    \end{macrocode}
% A detached b-SD: use the same code as for a p-SD.
%    \begin{macrocode}
\def \DRM@process@standalone@bracketSD {% 
%<debug>  \TXN@trace \DRM@process@standalone@bracketSD
  \edef \DRM@options@SD {\TXN@o@DetachedSD\DRM@options@SD}%
  \def \TXN@entity@code {[}%
  \DRM@standalone@pre
  \DRM@FaciesBracketSD{\the\DRM@toks@SD}%
  \DRM@standalone@post
  \def \DRM@options@SD {}%
}
%    \end{macrocode}
% A normal bracket, occurring within the speech.
%
%    \begin{macrocode}
\def \DRM@process@normal@bracketSD {% 
%<debug>  \TXN@trace \DRM@process@normal@bracketSD
  \ifTXN@withinVersus
    \ifTXN@blank@line
      \if \TXN@option \TXN@o@EmbeddedSD \DRM@options@SD
      \else
        \edef \DRM@options@SD {\TXN@o@DetachedSD\DRM@options@SD}%
      \fi
    \else
      \if \TXN@option \TXN@o@DetachedSD \DRM@options@SD
        \global \TXN@blank@linetrue
      \else
        \edef \DRM@options@SD {\TXN@o@EmbeddedSD\DRM@options@SD}%
      \fi
    \fi
    \PTR@start@box
  \else
    \leavevmode
    \edef \DRM@options@SD {\TXN@o@EmbeddedSD\DRM@options@SD}%
    \begingroup
    \if \TXN@option \TXN@o@RightSD \DRM@options@SD
%    \end{macrocode}
% A b-SD that is to be `rangedright' in prose needs a special trick
% to place it at the end of the final line of the paragraph.
% The trick is straight from the \textit{The \TeX{}book} (page 106).
% Here is the first part:
%    \begin{macrocode}
       \unskip \nobreak \hfil \penalty50 \DRM@SpatiumAnteBracketSD
       \hbox {}\nobreak \hfil
    \else
      \if \TXN@option \TXN@o@NoSpatiumAnte \DRM@options@SD
      \else
        \ifx \empty \DRM@persona@field 
          \unskip \DRM@SpatiumAnteBracketSD
        \else
          \if \TXN@option \TXN@o@FieldAutoWidth \DRM@options@SD
          \else
            \unskip \DRM@SpatiumAnteBracketSD
          \fi
        \fi
      \fi
    \fi
  \fi
  \def \\{}%
  \DRM@FaciesBracketSD {\the\DRM@toks@SD}%
  \ifTXN@withinVersus
    \PTR@close@box \PTR@box@bracketSD \DRM@options@SD 
    \TXN@edef {PTR@box@toks\the\PTR@box@ind}{\the\DRM@toks@SD}%
    \gdef \PTR@ignorespaces {\ignorespaces}%
    \def \DRM@options@SD {}%
    \expandafter \PTR@next@box
  \else
    \if \TXN@option \TXN@o@NoSpatiumPost \DRM@options@SD
    \else
      \if \TXN@option \TXN@o@RightSD \DRM@options@SD
%    \end{macrocode}
% The second part of the trick for a `rangedright' b-SD.
%    \begin{macrocode}
        \parfillskip= \z@skip
        \finalhyphendemerits = \z@
        \par
      \else
        \DRM@SpatiumPostBracketSD 
      \fi
    \fi
    \endgroup
    \def \DRM@options@SD {}%
    \expandafter \ignorespaces
  \fi
}
%    \end{macrocode}
% \subsection{Setting the b-SD attributes}
% \paragraph{Facies}
%    \begin{macrocode}
\def \DRM@setFacies@bracketSD #1{%
  \def \DRM@FaciesBracketSD ##1{%
    \begingroup
      \TXN@withinSDtrue
      \DRM@ifthenelse
      #1\relax
    \endgroup
  }%
}
%    \end{macrocode}
% \paragraph{Forma}
%    \begin{macrocode}
\def \DRM@setForma@bracketSD #1{%
  \def \TXN@temp ##1{#1}%
  \TXN@check@parm 1\TXN@temp
  \ifTXN@sw
     \PackageError {DRAMA}
       {You cannot use a parameter within \MessageBreak 
        the argument of \protect\Forma\protect\[}%
       {See the User Manual}%
  \fi
  \def \DRM@FormaBracketSD {%
    \global \TXN@centrefinalfalse
    #1\relax
  }%
}
%    \end{macrocode}
% \paragraph{Modus}
%    \begin{macrocode}
\def \DRM@optionsBracketSD {}
\def \DRM@setModus@bracketSD #1{%
  \gdef \TXN@gtemp {}%
  \begingroup
    \def \options ##1{\xdef\TXN@gtemp{##1\TXN@gtemp}}%
    \let \option = \options
    \let \linenumbers = \TXN@setModus@numbered
    \TXN@toks@a = {}%
    #1\relax
    \xdef\TXN@gtemp{\TXN@gtemp\the\TXN@toks@a}%
  \endgroup
  \edef \DRM@optionsBracketSD {\TXN@gtemp}%
}
%    \end{macrocode}
% \paragraph{Spacing}
%    \begin{macrocode}
\def \DRM@setSpatiumAnte@bracketSD #1{%
%<debug>  \TXN@trace \DRM@setSpatiumAnte@bracketSD
  \TXN@build@spatium@horizontal {#1}%
  \toks@ = \expandafter {\TXN@temp}%
  \edef \DRM@SpatiumAnteBracketSD {\the\toks@}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@setSpatiumPost@bracketSD #1{%
%<debug>  \TXN@trace \DRM@setSpatiumPost@bracketSD
  \TXN@build@spatium@horizontal {#1}%
  \toks@ = \expandafter {\TXN@temp}%
  \edef \DRM@SpatiumPostBracketSD {\the\toks@}%
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@setSpatiumSupra@bracketSD #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \def \DRM@SpatiumSupraBracketSD {}%
  \else
    \TXN@build@spatium@list {#1}%
    \edef \DRM@SpatiumSupraBracketSD {\TXN@L@spatium}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@setSpatiumInfra@bracketSD #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \def \DRM@SpatiumInfraBracketSD {}%
  \else
    \TXN@build@spatium@list {#1}%
    \edef \DRM@SpatiumInfraBracketSD {\TXN@L@spatium}%
  \fi
}
%    \end{macrocode}
% 
% \section{Parenthesized stage directions (p-SD)}
% \subsection{Processing a p-SD}
%    \begin{macrocode}
\def \({\DRM@inner@parenthesisSD}
\def \){}
%    \end{macrocode}
%    \begin{macrocode}
\def \DRM@inner@parenthesisSD {%
  \ifx \empty \TXN@attribute@name 
    \expandafter \DRM@parenthesisSD
  \else
    \def \TXN@subclass@name {parenthesisSD}%
    \def \TXN@subclass@number {}%
    \def \TXN@temp {DRM}%
    \expandafter \TXN@attribute@set
  \fi
}
%    \end{macrocode}
% \subsection{Setting the p-SD attributes}
% \paragraph{Facies}
%    \begin{macrocode}
\def \DRM@setFacies@parenthesisSD #1{%
  \def \TXN@temp ##1{#1}%
  \TXN@check@parm 1\TXN@temp
  \ifTXN@sw
     \PackageError {DRAMA}%
       {You cannot use a parameter within \MessageBreak
        the argument of \protect\Facies\space\protect\(}%
       {See the User Manual}%
  \fi
  \def \DRM@FaciesParenthesisSD {%
     \TXN@withinSDtrue
     \DRM@ifthenelse
     #1\relax
  }%
}
%    \end{macrocode}
% \paragraph{Forma}
%    \begin{macrocode}
\def \DRM@setForma@parenthesisSD #1{%
  \def \DRM@FormaParenthesisSD {%
    \TXN@withinSDtrue
    \global \TXN@centrefinalfalse
    \DRM@ifthenelse
    #1\relax
  }%
}
%    \end{macrocode}
% \paragraph{Modus}
%    \begin{macrocode}
\def \DRM@optionsParenthesisSD {}
\def \DRM@setModus@parenthesisSD #1{%
  \gdef \TXN@gtemp {}%
  \begingroup
    \def \options ##1{\xdef\TXN@gtemp{##1\TXN@gtemp}}%
    \let \option = \options
    \TXN@toks@a = {}%
    #1\relax
    \xdef\TXN@gtemp{\TXN@gtemp\the\TXN@toks@a}%
  \endgroup
  \edef \DRM@optionsParenthesisSD {\TXN@gtemp}%
}
%    \end{macrocode}
% \paragraph{Spacing}
%    \begin{macrocode}
\def \DRM@setSpatiumSupra@parenthesisSD #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \def \DRM@SpatiumSupraParenthesisSD {}%
  \else
    \TXN@build@spatium@list {#1}%
    \edef \DRM@SpatiumSupraParenthesisSD {\TXN@L@spatium}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@setSpatiumInfra@parenthesisSD #1{%
  \def \TXN@parameter {#1}%
  \ifx \empty \TXN@parameter
    \def \DRM@SpatiumInfraParenthesisSD {}%
  \else
    \TXN@build@spatium@list {#1}%
    \edef \DRM@SpatiumInfraParenthesisSD {\TXN@L@spatium}%
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@parenthesisSD {%
%<debug>  \TXN@trace \DRM@parenthesisSD
  \endgraf
  \def \DRM@delimiter {)}%
  \let \DRM@cs = \DRM@parenthesisSD@bis
  \DRM@check@options
}
%    \end{macrocode}
% On return from checking the options (if any) we come here.
%    \begin{macrocode}
\def \DRM@parenthesisSD@bis {%
%<debug>  \TXN@trace \DRM@parenthesisSD@bis
  \edef \DRM@options@SD {(\DRM@options@SD\DRM@optionsParenthesisSD}%
  \if \TXN@option  n\DRM@options@SD
    \if \TXN@option  t\DRM@options@SD
    \else
      \edef \DRM@options@SD {t\DRM@options@SD}%
    \fi
  \fi
  \def \TXN@entity@code {(}%
  \DRM@standalone@pre
  \edef \DRM@opening@delimiter@line {\the\inputlineno}%
  \def \[{\DRM@missing@delimiter}%
  \def \({\DRM@missing@delimiter}%
%    \end{macrocode}
% We re-inject any tokens that may have been gobbled while
% loking for options.
%    \begin{macrocode}
  \strut \hskip \z@ 
  \expandafter \ignorespaces \the\DRM@toks@SD 
}
%    \end{macrocode}
% The text of the SD is processed directly (it cannot be read as
% a parameter as there is no a priori limit on its length).
%    \begin{macrocode}
   \def \){\DRM@standalone@post}
%    \end{macrocode}
% The SD delimiters are not properly nested.
%    \begin{macrocode}
\def \DRM@missing@delimiter {%
    \PackageError {DRAMA}
      {No matching \protect\) found for the \protect\(\space
       command on line \number \DRM@opening@delimiter@line}%
      {You probably forgot to type \protect\)\space
       at the end of the SD}%
}
%    \end{macrocode}
% 
% \section{Common code for both forms of stage directions}
%
%  \subsection{Getting the options (if any).}
%
%  On entry: |\DRM@delimiter| is the closing character ] or ); 
%  |\DRM@cs| is the control sequence to be invoked after checking.
%
%  On exit: |\DRM@options@SD|: the options; 
%  |\DRM@toks@SD|: contains any tokens read while looking 
%  for (non-existent) options, which must be re-injected into the input. 
%    \begin{macrocode}
\def \DRM@check@options {%
  \DRM@toks@SD = {}%
  \def \DRM@options@SD {}%
  \count@ = \z@
  \DRM@check@options@bis
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@check@options@bis {%
  \futurelet \TXN@token \DRM@check@options@ter}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@check@options@ter {%
  \let \next = \DRM@cs
  \expandafter
  \ifx \DRM@delimiter \TXN@token
    \DRM@toks@SD = {}%
    \let \next = \DRM@check@options@quinquies
  \else
    \ifx \TXN@token \relax
      \def \DRM@options@SD {}%
    \else
      \ifcat a\TXN@token\TXN@safe
        \advance \count@ by \@ne
        \ifnum \count@ > \sixt@@n
          \def \DRM@options@SD {}%
        \else
          \let \next = \DRM@check@options@quater
        \fi
      \else
        \def \DRM@options@SD {}%
      \fi
    \fi
  \fi
  \next
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@check@options@quater #1{%
  \edef \DRM@options@SD {\DRM@options@SD#1}%
  \DRM@toks@SD = \expandafter {\the\DRM@toks@SD#1}%
  \DRM@check@options@bis
}
\def \DRM@check@options@quinquies #1{\DRM@cs}
%    \end{macrocode}
% 
%  \subsection{Making the options available to the user}
%    \begin{macrocode}
\def \DRM@ifthenelse {\DRM@set@options}
\def \DRM@isopt #1{%
  \if \TXN@empty {DRM@optSD@#1}%
    \z@ = \z@
  \else
    \z@ = \@ne
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@set@options {%
  \let \DRM@save@isopt = \isopt
  \let \isopt = \DRM@isopt
  \expandafter \DRM@set@option@bis \DRM@options@SD \TXN@nil
}
\def \DRM@set@option@bis #1{%
  \ifx \TXN@nil #1\relax
  \else
    \TXN@def {DRM@optSD@#1}{}%
    \expandafter \DRM@set@option@bis
  \fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def \DRM@reset@options {%
  \let \isopt = \DRM@save@isopt 
  \expandafter \DRM@reset@option@bis \DRM@options@SD \TXN@nil
}
\def \DRM@reset@option@bis #1{%
  \ifx \TXN@nil #1\relax
  \else
    \TXN@def {DRM@optSD@#1}{\relax}%
    \expandafter \DRM@reset@option@bis
  \fi
}
%    \end{macrocode}
% 
%  \subsection{Typesetting a detached SD (also used for a speech)}
%    \begin{macrocode}
\newif \ifDRM@suspended@prosa
\newif \ifDRM@first@paragraph
\newif \ifDRM@not@first@indent
\newif \ifTXN@was@lineating
\newtoks \DRM@save@everypar
%    \end{macrocode}
% The code preceding the text.
%    \begin{macrocode}
\def \DRM@standalone@pre {%
%<debug>  \TXN@trace \DRM@standalone@pre
  \global \DRM@save@everypar = \everypar
  \TXN@was@lineatingfalse
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifTXN@withinVersus
    \TXN@was@withinVersustrue
    \if \TXN@option \TXN@entity@code\TXN@numbered@classes
      \global \PTR@par@startedfalse
      \prosa
    \else
      \PTR@par@startedfalse
      \endVersus
      \ifTXNl@lineating
        \TXN@was@lineatingtrue
        \TXNl@lineate \relax
      \fi
    \fi
  \else
    \TXN@was@withinVersusfalse
    \ifTXNl@lineating
      \TXN@was@lineatingtrue
      \TXNl@lineate \relax
    \fi
    \dimen@ = \baselineskip
    \advance \dimen@ by -\prevdepth
    \advance \dimen@ by -\ht\strutbox
    \vskip \dimen@
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \if p\TXN@entity@code
    \def \TXN@entity {Personam}%
  \else
    \if [\TXN@entity@code
      \def \TXN@entity {BracketSD}%
    \else
      \def \TXN@entity {ParenthesisSD}%
    \fi
  \fi
  \def \[{\DRM@inner@bracketSD}%
  \def \({\DRM@inner@parenthesisSD}%
%    \end{macrocode}
% Set SpatiumSupra
%    \begin{macrocode}
  \if \TXN@option \TXN@o@NoSpatiumSupra \DRM@options@SD
  \else
    \expandafter
    \TXN@spatium@vertical \csname DRM@SpatiumSupra\TXN@entity\endcsname
  \fi
%    \end{macrocode}
% Determine the paragraph shape
%    \begin{macrocode}
  \begingroup
  \let \DRM@Forma = \relax
  \TXN@nostyletrue
  \if \TXN@option \TXN@o@Justified \DRM@options@SD
  \else
    \if \TXN@option \TXN@o@RangedRight \DRM@options@SD
      \let \DRM@Forma = \rangedright
    \else
      \if \TXN@option \TXN@o@RangedLeft \DRM@options@SD
        \let \DRM@Forma = \rangedleft
      \else
        \if \TXN@option \TXN@o@Centred \DRM@options@SD
          \let \DRM@Forma = \centered
        \else
          \if \TXN@option \TXN@o@CentredFinal \DRM@options@SD
            \let \DRM@Forma = \centeredfinal
          \else
            \TXN@nostylefalse
          \fi
        \fi
      \fi
    \fi
  \fi
  \if p\TXN@entity@code
  \else
    \@nameuse {DRM@Forma\TXN@entity}%
  \fi
  \TXN@nostylefalse
  \DRM@Forma
  \edef \TXN@line@class {\TXN@entity@code}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifTXN@centrefinal
    \global \setbox \DRM@vbox = \vbox \bgroup 
    \let \\= \TXN@esc@esc@break@noop
  \else
    \let \\= \TXN@esc@esc@break
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \hsize = \TXN@measure
  \parindent = \z@
  \everypar = {}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \if [\TXN@entity@code
    \ifTXN@was@withinVersus
      \PTR@get@speech@indent \empty   
      \TXN@assign \dimen@ = {TXN@textus[\TXN@theTextus]offset@\TXN@folio}%
      \global \advance \PTR@speech@indent by \dimen@
      \advance \leftskip by \PTR@speech@indent 
      \if \TXN@option \TXN@o@FullWidth \DRM@options@SD
      \else
        \TXN@assign \dimen@ = {TXN@textus[\TXN@theTextus]shift}%
        \advance \leftskip by \dimen@
      \fi
    \fi
  \fi
  \if (\TXN@entity@code
    \if \TXN@option \TXN@o@FullWidth \DRM@options@SD
      \skip@ = \leftskip
      \dimen@ = \skip@
      \advance \skip@ by -\dimen@
      \leftskip = \skip@
      \skip@ = \rightskip
      \dimen@ = \skip@
      \advance \skip@ by -\dimen@
      \rightskip = \skip@
      \hsize = \textwidth
    \fi
  \fi
  \if (\TXN@entity@code
    \DRM@FaciesParenthesisSD 
  \fi
  \if \TXN@option \TXN@o@NoHangindent \DRM@options@SD
    \hangindent = \z@
    \hangafter = \@ne
  \fi
  \if \TXN@option \TXN@o@NoFirstIndent \DRM@options@SD
    \global \DRM@not@first@indenttrue
  \else
    \global \DRM@not@first@indentfalse
  \fi
  \TXN@leftskip   = \leftskip
  \TXN@rightskip  = \rightskip
  \TXN@hangindent = \hangindent
  \TXN@hangafter  = \hangafter sp \TXN@safe
%    \end{macrocode}
% Allow |\textus| objects (typically act/scene) to be attached to
% p-SD, even if not numbered.
%    \begin{macrocode}
  \if \TXN@option \TXN@entity@code\TXN@numbered@classes
  \else
    \if (\TXN@entity@code
      \setbox \TXN@marginalia = \null
      \TXN@SimpleList \TXN@line@fields \z@
      \edef \TXN@temp {\z@,\z@}%
      \TXN@SimpleList@append \TXN@line@fields \TXN@temp
      \TXN@attach@textus {\z@}% 
      \ifdim \wd\TXN@object@textus > \z@
        \box \TXN@marginalia 
        {\par}%    in braces to preserve the paragraph shape
        \vskip -\baselineskip
      \fi
    \fi
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \global \DRM@first@paragraphtrue
  \everypar = {%
    \prevgraf = \the\prevgraf
    \leftskip = \TXN@leftskip
    \rightskip = \TXN@rightskip
    \hangindent = \TXN@hangindent
    \hangafter =  \ifDRM@first@paragraph \TXN@hangafter\else \z@\fi
    \ifDRM@first@paragraph 
      \ifDRM@not@first@indent
         \setbox\z@ = \lastbox
      \fi
    \fi
    \global \DRM@first@paragraphfalse
  }%
  \widowpenalty = \z@
  \clubpenalty = \z@
  \strut
}
%    \end{macrocode}
% The code following the text.
%    \begin{macrocode}
\def \DRM@standalone@post {%
%<debug>  \TXN@trace \DRM@standalone@post
  \global \TXN@baselineskip = \baselineskip
  \strut
  \xdef \TXN@badness {\the\badness}%
  \par
  \xdef \TXN@prevgraf {\the\prevgraf}%
  \ifnum \TXN@badness < \badness
    \xdef \TXN@badness {\the\badness}%
  \fi
  \ifTXN@centrefinal
    \egroup
  \fi
  \endgroup
  \ifnum \TXN@badness < \@M
    \ifTXN@centrefinal
      \edef \TXN@line@class {\TXN@entity@code}
      \global \TXN@centrefinalfalse
      \TXN@dim@a = \wd\DRM@vbox
      \loop
      \ifvbox \DRM@vbox 
        \setbox \tw@ = \vbox{%
          \vbadness = \@M
          \splittopskip = \z@
          \global \setbox \@ne = \vsplit \DRM@vbox to \TXN@baselineskip
          \global \setbox \DRM@vbox = \box \DRM@vbox
          \unvbox \@ne \global \setbox \@ne = \lastbox
        }%
        \setbox \DRM@hbox = \box \@ne
        \TXN@sw@false
        \ifvbox \DRM@vbox
          \ifnum \TXN@prevgraf = \tw@
            \TXN@sw@true
          \fi
        \else
          \TXN@sw@true
        \fi
        \ifTXN@sw
          \setbox \z@ = \hbox {\unhbox \DRM@hbox \unskip \unskip \unpenalty}%
          \dimen@ = \TXN@dim@a
          \advance \dimen@ by -\leftskip
          \advance \dimen@ by -\rightskip
          \advance \dimen@ by -\wd\z@
          \divide \dimen@ by \tw@
          \dimen@@ = \dimen@
          \advance \dimen@@ by -\leftskip
          \advance \dimen@ by -\rightskip
          \setbox \DRM@hbox = \hbox {\kern \dimen@@ \box \z@ \kern \dimen@}%
        \fi
        \leavevmode \box \DRM@hbox \par 
      \repeat
    \fi
  \else
    \def \TXN@temp {speech}%
    \if [\TXN@entity@code
      \def \TXN@temp {b-SD}%
    \else
      \def \TXN@temp {p-SD}%
    \fi
    \TXN@Warning* {The \TXN@temp\space cannot be typeset properly}%
  \fi
  \def \TXN@line@class{}%
  \TXN@sw@true
  \if p\TXN@entity@code
  \else
    \if \TXN@option \TXN@o@NoSpatiumInfra \DRM@options@SD
      \TXN@sw@false
    \fi
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \ifTXN@sw
    \expandafter 
    \TXN@spatium@vertical \csname DRM@SpatiumInfra\TXN@entity\endcsname
  \fi
%    \end{macrocode}
%
%    \begin{macrocode}
  \if (\TXN@entity@code
    \DRM@reset@options
    \def \DRM@options@SD {}%
  \fi
%    \end{macrocode}
% Restore the initial conditions
%    \begin{macrocode}
  \everypar = \DRM@save@everypar 
  \ifTXN@was@lineating
    \TXNl@lineate \TXN@process@line
  \fi
  \ifTXN@was@withinVersus
    \endgraf
    \global \TXN@after@Spatiumtrue
    \if [\TXN@entity@code
      \endgraf
    \fi
    \if \TXN@option \TXN@entity@code\TXN@numbered@classes
      \TXN@exxxpandafter \endprosa
    \else
      \TXN@exxxpandafter \versus
    \fi
  \fi
}
%    \end{macrocode}
%% \Finale
%
\endinput
