%%
%% This is file `poetry.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% poetry.dtx  (with options: `package')
%% 
%% IMPORTANT NOTICE
%%
%% poetry package -- sophisticated typesetting of poetry
%% Copyright (c) 1996 Mark Wooding
%%
%% This package is not finished, let alone properly tested.  It is being
%% released in the hope that others can contribute ideas and suggestions
%% that the author (who is not an expert on poetry) may have missed.
%%
%% I hope that someone finds this package useful.  However, if it goes
%% wrong, that's your problem.  I may try and fix it, although the author
%% does not guarantee that this is the case.
%%
%% This pre-release version may be distributed under the terms of the GNU
%% General Public Licence, as published by the Free Software Foundation;
%% either version 2 of the Licence, or (at your option) any later version.
%% However, since this is not finished, and I'd like others to benefit
%% from the finished version, the author BEGS and PLEADS you not to spread
%% this pre-release too much.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{poetry}
                [1996/05/28 1.00 Poetry typesetting]
%% \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         \~}
%%
\newcounter{poem@count}
\newcounter{poemline}
\newcount\poemchunksize
\let\c@poemchunksize\poemchunksize
\newcount\poem@linesleft
\poemchunksize=30
\newdimen\poem@width
\newdimen\poem@thiswidth
\newdimen\poem@lastwidth
\newdimen\poem@prevdepth
\newif\ifpoem@long
\newskip\poemleftskip
\poemleftskip\@centering
\def\poem@widths{}
\def\poem@savedwidths{}
\def\poem@getwidth#1{%
  \def\@tempa##1[#1]##2##3\@@{##2}%
  \global\poem@width\expandafter\@tempa\poem@savedwidths[#1]\z@\@@%
  \relax%
}
\def\poem@setwidth#1{%
  \def\@tempb##1[#1]\z@{##1}%
  \def\@tempa##1[#1]##2##3\@@{%
    \xdef\poem@widths{%
      ##1%
      [#1]{\the\poem@thiswidth}%
      \ifdim##2=\z@\else\expandafter\@tempb\fi##3%
    }%
  }%
  \expandafter\@tempa\poem@widths[#1]\z@\@@%
}
\AtEndDocument{%
  \if@filesw%
    \immediate\write\@auxout%
      {\gdef\noexpand\poem@savedwidths{\poem@widths}}%
  \fi%
}
\def\@maybe@unskip{\hskip-\@ne\lastskip\relax}
\def\ifmultipleof#1#2{%
  \count@#2%
  \divide\count@#1%
  \multiply\count@#1%
  \relax%
  \ifnum#2=\count@%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi%
}
\def\poemlineposition{\@ifnextchar[\poem@lp@i{\poem@lp@i[l]}}
\def\poem@lp@i[#1]#2{%
  \if#1r%
    \hfil\kern8\p@#2%
  \else\if#1l%
    \llap{#2\kern8\p@\kern\linewidth}%
  \fi\fi%
}
\providecommand{\poemline}{%
  \ifmultipleof{5}{\value{poemline}}%
    {\poemlineposition[r]{\scriptsize\thepoemline}}%
    {}%
  \refstepcounter{poemline}%
}
\def\xpoem{%
  \global\c@poemline\z@%
  \global\let\poem@printline\poemline%
  \def\nonumber{\global\let\poem@printline\@empty}%
  \let\title\poemtitle%
  \let\author\poemauthor%
  \global\@inlabelfalse%
  \global\@newlistfalse%
  \everycr{}%
  \let\\\poem@cr%
  \def\nl{\poem@nl}%
  \global\let\poem@nl\poem@donl%
  \let\par\@empty%
  \expandafter\poem@getwidth\expandafter{\the\c@poem@count}%
  \global\poem@thiswidth\z@%
  \global\poem@longfalse
  \dimen@\hsize%
  \advance\dimen@-\@totalleftmargin%
  \advance\dimen@-\linewidth%
  \bigskip%
  \stepcounter{poemline}%
  \def\@currentlabel{\p@poemline\thepoemline}%
  \poem@hook%
  \poem@startchunk%
}
\def\endxpoem{%
  \nl%
  \poem@endchunk%
  \ifnum\c@poemline>\poemchunksize\poem@longtrue\fi%
  \ifpoem@long%
    \expandafter\poem@setwidth\expandafter{\the\c@poem@count}%
  \fi%
  \global\advance\c@poem@count\@ne%
  \bigskip%
}
\def\poem@hook{}
\def\poem@addtohook#1{%
  \expandafter\def\expandafter\poem@hook\expandafter{\poem@hook#1}%
}
\providecommand{\poemtitle}[1]{%
  \nl%
  \nonumber%
  \hfill\normalfont\large\bfseries#1\hfill%
  \\*[\bigskipamount]%
}
\providecommand{\poemauthor}[1]{%
  \nl*[\smallskipamount]%
  \nonumber%
  \hfill\normalfont\itshape#1%
  \\%
}
\def\poem@startchunk{%
  \global\poem@linesleft\poemchunksize%
  \skip@\@totalleftmargin%
  \advance\skip@\poemleftskip%
  \tabskip\skip@%
  \halign to\hsize\bgroup%
    \global\let\poem@nl\poem@cr%
    \global\setbox\@ne\hbox{{\ignorespaces##\@maybe@unskip}}\poem@doline%
    \tabskip\@centering&&%
    \poem@rightcolumn\hbox{{##}}\tabskip\dimen@\cr%
}
\def\poem@endchunk{%
  \crcr%
  \noalign{\global\dimen@i\prevdepth\nointerlineskip}%
  \omit\hb@xt@\poem@width{}\cr%
  \egroup%
  \prevdepth\dimen@i%
}
\def\poem@doline{%
  \dimen@\linewidth%
  \global\setbox\@labels\hbox{\poem@printline}%
  \advance\dimen@-\wd\@labels%
  \ifdim\wd\@ne>\dimen@%
    \global\setbox\@ne\vtop{%
      \parshape\tw@ \z@\dimen@ \z@\linewidth%
      \leftskip3em%
      \noindent%
      \kern-3em%
      \unhbox\@ne%
      \@@par%
    }%
    \global\setbox\thr@@\vbox{%
      \unvcopy\@ne%
      \global\setbox\thr@@\lastbox%
      \global\poem@prevdepth\dp\thr@@%
      \global\setbox\thr@@\hbox{\unhbox\thr@@\unskip}%
      \global\poem@lastwidth\wd\thr@@%
    }%
    \box\@ne%
    \global\setbox\thr@@\box\voidb@x%
    \global\poem@width\linewidth%
    \global\poem@thiswidth\linewidth%
  \else%
    \ifdim\wd\@ne>\poem@width\global\poem@width\wd\@ne\fi%
    \ifdim\wd\@ne>\poem@thiswidth\global\poem@thiswidth\wd\@ne\fi%
    \global\poem@lastwidth\wd\@ne%
    \unhbox\@ne\hfil%
    \global\poem@prevdepth\maxdimen%
  \fi%
}
\def\poem@cr{%
  \relax%
  \global\let\poem@nl\poem@donl%
  \iffalse{\fi\ifnum0=`}\fi%
  \@ifstar{\poem@cr@i\@M}{\poem@cr@i\z@}%
}
\def\poem@cr@i#1{\@ifnextchar[{\poem@cr@ii{#1}}{\poem@cr@ii{#1}[\z@]}}
\def\poem@cr@ii#1[#2]{%
  \ifnum0=`{}\fi%
  \global\let\poem@rightcolumn\relax%
  &\relax%
  \llap{\unhbox\@labels}%
  \global\let\poem@printline\poemline%
  \global\let\poem@rightcolumn\poem@@rightcolumn%
  \global\advance\poem@linesleft\m@ne%
  \ifnum\poem@linesleft=\z@%
    \poem@endchunk%
    \expandafter\poem@startchunk%
  \else%
    \expandafter\cr%
  \fi%
  \noalign{%
    \addpenalty{#1}%
    \vskip#2%
    \ifdim\poem@prevdepth=\maxdimen\else\prevdepth\poem@prevdepth\fi%
  }%
}
\def\poem@donl{%
  \noalign{\ifnum0=`}\fi%
  \@ifstar{\poem@donl@i{\addpenalty\@M}}{\poem@donl@i{}}%
}
\def\poem@donl@i#1{%
  \@ifnextchar[{\poem@donl@ii{#1}}{\poem@donl@ii{#1}[\z@]}%
}
\def\poem@donl@ii#1[#2]{%
  #1%
  \addvspace{#2}%
  \ifnum0=`{\fi}%
}
\def\splitline{\nl\nonumber\kern\poem@lastwidth\ }
\newcounter{stanza}
\def\stanza{%
  \nl%
  \noalign{\ifnum0=`}\fi%
  \@ifstar{%
    \stanza@i{}%
  }{%
    \stanza@i{\global\advance\c@stanza\@ne\labelstanza}%
  }%
}
\def\stanza@i#1{\@ifnextchar[{\stanza@ii{#1}}{\stanza@ii{#1}[]}}
\def\stanza@ii#1[#2]{%
  \def\@currentlabel{\p@stanza\thestanza}%
  \sbox\z@{#1}%
  \sbox\tw@{\stanzaname{#2}}%
  \ifdim\wd\tw@>\z@%
    \ifdim\wd\z@>\z@%
      \global\setbox\@ne\hbox{\stanzacombine{\unhbox\z@}{\unhbox\tw@}}%
    \else%
      \global\setbox\@ne\box\tw@%
    \fi%
  \else%
    \global\setbox\@ne\hbox{\unhbox\z@\unhbox\tw@}%
  \fi%
  \ifnum0=`{\fi}%
  \stanzaspace%
  \ifdim\wd\@ne>\z@%
    \nonumber%
    \stanzatitle{\unhbox\@ne}%
  \else
  \fi%
}
\poem@addtohook{\global\c@stanza\z@}
\renewcommand{\thestanza}{\Roman{stanza}}
\providecommand{\labelstanza}{\textsc{\roman{stanza}}}
\providecommand{\stanzaname}[1]{\textsc{#1}}
\providecommand{\stanzacombine}[2]{#1\quad#2}
\providecommand{\stanzaspace}{\nl[\medskipamount]}
\providecommand{\stanzatitle}[1]{%
  \hfill#1\hfill\\%
}
\def\obeypoemlines{%
  \obeycr%
  \bgroup\lccode`\~=`\^^M\lowercase{\egroup\let~\poem@litcr}%
}
\def\poem@litcr{%
  \ifx\poem@nl\poem@cr\poemliteralcr%
  \else\poemliteralstanza%
  \fi%
}
\def\poemliteralcr{\\\@empty}
\def\poemliteralstanza{\stanza*\@empty}
\endinput
%%
%% End of file `poetry.sty'.
