%%
%% This is file `poetry.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% poetry.dtx  (with options: `package')
%% This is a generated file.
%% 
%% This document is copyright 2014 by Donald P. Goodman, and is
%% released publicly under the LaTeX Project Public License.  The
%% distribution and modification of this work is constrained by the
%% conditions of that license.  See
%% http://www.latex-project.org/lppl.txt
%% for the text of the license.  This document is released
%% under version 1.3c of that license, and this work may be distributed
%% or modified under the terms of that license or, at your option, any
%% later version.
%% 
%% This work has the LPPL maintenance status 'maintained'.
%% 
%% The Current Maintainer of this work is Donald P. Goodman
%% (dgoodmaniii@gmail.com).
%% 
%% This work consists of poetry.dtx, poetry.ins, and
%% derived files poetry.sty and poetry.pdf.

\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{poetry}[2019/05/02 v2.1 support for typesetting poetry]

\RequirePackage{modulus}%
\newcounter{poemline}%
\newcount\poemlineno%
\newcounter{poemrtline}%
\newcount\poemrtlineno%
\renewcommand\thepoemrtline{}%
\newcounter{verseline}%
\newcount\vslineno%
\newcounter{stanzacount}%
\newcount\stanzano%
\newcounter{abspoemno}%
\newcount\poem@abspoemno%
\newcounter{poemno}%
\newcount\poem@poemno%
\newcounter{poemgroupno}\setcounter{poemgroupno}{0}%
\newcount\poem@groupno\poem@groupno=0%
\newcounter{poemlinenumsevery}\setcounter{poemlinenumsevery}{1}%
\newcount\poem@linenumsevery\poem@linenumsevery=\value{poemlinenumsevery}%
\newcounter{poemrtlinenumsevery}\setcounter{poemrtlinenumsevery}{1}%
\newcount\poem@rt@linenumsevery\poem@rt@linenumsevery=\value{poemrtlinenumsevery}%
\newlength{\poemindent}\setlength{\poemindent}{0pt}%
\newlength{\poemtopskip}\setlength{\poemtopskip}{1em}%
\newlength{\poembotskip}\setlength{\poembotskip}{1em}%
\newdimen\poem@topskip\newdimen\poem@botskip%
\newdimen\poem@defleftskip\poem@defleftskip=\the\poemindent%
\newdimen\poem@maxlinewd%
\newlength{\poemmaxlinewd}\setlength{\poemmaxlinewd}{\textwidth}%
\newdimen\poem@rt@maxlinewd%
\newlength{\poemrtmaxlinewd}\setlength{\poemrtmaxlinewd}{\textwidth}%
\newdimen\poem@hinwd\poem@hinwd=1em%
\newlength{\poemhinwd}\setlength{\poemhinwd}{1em}%
\newif\ifpoemlinenums\poemlinenumstrue%
\newif\ifpoemrtlinenums\poemrtlinenumstrue%
\def\poemlinenumright{%
\renewcommand{\thepoemrtline}{\arabic{poemline}}%
\renewcommand{\thepoemline}{}%
}%
\def\poemlinenumrighttrue{%
\renewcommand{\thepoemrtline}{\arabic{poemline}}%
\renewcommand{\thepoemline}{}%
}%
\def\poemlinenumrightfalse{%
\renewcommand{\thepoemline}{\arabic{poemline}}%
\renewcommand{\thepoemrtline}{}%
}%
\newdimen\poem@linenumboxwd\poem@linenumboxwd=2em%
\newlength{\poemlinenumboxwd}\setlength{\poemlinenumboxwd}{2em}%
\newdimen\poem@rt@linenumboxwd\poem@rt@linenumboxwd=2em%
\newlength{\poemrtlinenumboxwd}\setlength{\poemrtlinenumboxwd}{2em}%
\newdimen\poem@linenumboxgap\poem@linenumboxgap=0pt%
\newlength{\poemlinenumboxgap}\setlength{\poemlinenumboxgap}{0pt}%
\newdimen\poem@rt@linenumboxgap\poem@rt@linenumboxgap=0pt%
\newlength{\poemrtlinenumboxgap}\setlength{\poemrtlinenumboxgap}{0pt}%
\def\poemlinenumstyle{}%
\def\poemrtlinenumstyle{}%
\newdimen\poem@hangindent\poem@hangindent=1em%
\newlength{\poemhangindent}\setlength{\poemhangindent}{1em}%
\newcount\poem@indentevery\poem@indentevery=0%
\newcounter{poemindentevery}\setcounter{poemindentevery}{0}%
\newdimen\poem@verseskip\poem@verseskip=\baselineskip%
\newlength{\poemverseskip}\setlength{\poemverseskip}{\baselineskip}%
\newdimen\poem@buff%
\newcount\poem@tmp%
\def\loopcommand{\hin}%
\def\poem@expandvsloop#1{\poem@xvsloop#1\relax}%
\def\poem@xvsloop#1{%
\ifx\relax#1\else%
\ifnum#1=\the\vslineno%
\loopcommand\relax%
\fi%
\expandafter\poem@xvsloop%
\fi%
}%
\newcommand{\poem@ifbang}[1]{\@ifnextchar !{\@firstoftwo{#1}}}
\newcommand{\poem@ifhyph}[1]{\@ifnextchar -{\@firstoftwo{#1}}}
\newcommand{\poem@ifstar}[1]{\@ifnextchar *{\@firstoftwo{#1}}}
\newcommand{\poem@ifques}[1]{\@ifnextchar ?{\@firstoftwo{#1}}}
\def\poemvsindentlines{}%
\def\poemnumlines{}%
\def\poemrtnumlines{}%
\def\tlap#1{\vbox to0pt{\vss\hbox{#1}}}%
\def\blap#1{\vbox to0pt{\hbox{#1}\vss}}%
\def\placelineno{%
\setcounter{verseline}{\the\vslineno}%
\setcounter{poemline}{\the\poemlineno}%
\setcounter{stanzacount}{\the\stanzano}%
\setcounter{poemrtline}{\the\poemrtlineno}%
\poem@linenumsevery=\value{poemlinenumsevery}%
\poem@rt@linenumsevery=\value{poemrtlinenumsevery}%
\poem@indentevery=\value{poemindentevery}%
\poem@linenumboxgap=\the\poemlinenumboxgap%
\poem@linenumboxwd=\the\poemlinenumboxwd%
\poem@rt@linenumboxgap=\the\poemrtlinenumboxgap%
\poem@rt@linenumboxwd=\the\poemrtlinenumboxwd%
\ifpoemlinenums%
\def\loopcommand{\poem@putlineno}%
\expandafter\poem@expandvsloop\expandafter{\poemnumlines}%
\def\loopcommand{\poem@rt@putlineno}%
\expandafter\poem@expandvsloop\expandafter{\poemrtnumlines}%
\ifnum\poem@linenumsevery=0\relax\else%
\modulo{\the\vslineno}{\the\poem@linenumsevery}%
\ifnum\remainder=0\poem@putlineno\fi%
\fi%
\ifnum\poem@rt@linenumsevery=0\relax\else%
\modulo{\the\vslineno}{\the\poem@rt@linenumsevery}%
\ifnum\remainder=0\poem@rt@putlineno\fi%
\fi%
\fi%
\ifnum\poem@indentevery=0\relax\else%
\modulo{\the\vslineno}{\the\poem@indentevery}%
\ifnum\remainder=0\hin\fi%
\fi%
\def\loopcommand{\hin}%
\expandafter\poem@expandvsloop\expandafter{\poemvsindentlines}%
\def\@currentlabel{\thepoemline}%
\phantomsection%
}%
\def\poem@putlineno{%
\hskip-\poem@linenumboxgap%
\llap{%
\tlap{%
\hbox to\poem@linenumboxwd{%
\poemlinenumstyle\thepoemline%
\hfil%
}\penalty10000%
}%
}%
\ifnum\poemlineno=1\relax\else%
\ifnum\vslineno=1%
\vskip-\baselineskip%
\fi%
\fi%
\penalty10000%
}%
\def\poem@rt@putlineno{%
\hskip0pt\tlap{%
\rlap{%
\hskip\poem@maxlinewd%
\hskip\poem@rt@linenumboxgap%
\hbox to\poem@rt@linenumboxwd{%
\hfil%
\poemrtlinenumstyle\thepoemrtline%
}%
}%
}%
\vskip-\baselineskip%
}%
\def\poem@endline{%
\par%
\advance\poemlineno by1%
\advance\vslineno by1%
\poem@defaultpars%
\leftskip=\poem@defleftskip%
\placelineno%
}%
\def\poem@endpart{%
\par%
\advance\poemlineno by1%
\advance\vslineno by1%
\poem@defaultpars%
\leftskip=\poem@defleftskip%
}%
\def\poem@resume{%
\placelineno%
}%
\def\*{%
\poem@resume%
}%
\def\poem@endverse{%
\par%
\vslineno=1%
\advance\poemlineno by1%
\advance\stanzano by1%
\poem@verseskip=\the\poemverseskip%
\vskip\poem@verseskip%
\leftskip=\poem@defleftskip%
\placelineno%
}
\def\poem@endversepart{%
\par%
\advance\poemlineno by1%
\vslineno=1%
\poem@defaultpars%
\leftskip=\poem@defleftskip%
}
\def\poem@defaultpars{%
\poem@hangindent=\the\poemhangindent%
\everypar={%
\parindent=0pt%
\hangindent=\poem@hangindent%
\hangafter=1%
}%
}%
\def\hin{%
\poem@hinwd=\the\poemhinwd%
\advance\leftskip by\the\poem@hinwd%
\penalty10000%
}%
\def\poemnew{%
\advance\poem@poemno by1\stepcounter{poemno}%
\advance\poem@abspoemno by1\stepcounter{abspoemno}%
}%
\def\poem{%
\widowpenalty=0\clubpenalty=0%
\def\\{%
\poem@ifbang{\poem@endverse}{%
\poem@ifhyph{\par\vskip\poem@botskip\relax}{%
\poem@ifstar{\poem@endpart}{%
\poem@ifques{\poem@endversepart}{\poem@endline}%
}%
}%
}%
}%
\poem@defleftskip=\the\poemindent%
\leftskip=\poem@defleftskip%
\poem@maxlinewd=\the\poemmaxlinewd%
\hsize=\the\poem@defleftskip%
\advance\hsize by\the\poem@maxlinewd%
\poemlineno=1%
\vslineno=1%
\stanzano=1%
\poem@topskip=\the\poemtopskip%
\poem@botskip=\the\poembotskip%
\vskip\poem@topskip%
\poem@defaultpars%
\noindent%
\poem@ifstar{}{\placelineno}%
}%
\def\endpoem{%
}%
\newdimen\poem@centlinewd
\def\centerpoemon#1{%
\settowidth{\poem@centlinewd}{#1}%
\ifdim\poem@centlinewd>\linewidth\poem@defleftskip=0pt%
\else
\poem@buff=\linewidth%
\advance\poem@buff by-\poem@centlinewd%
\divide\poem@buff by2%
\poem@defleftskip=\the\poem@buff%
\poemindent=\the\poem@buff%
\poem@maxlinewd=\the\poem@centlinewd%
\setlength{\poemmaxlinewd}{\poem@maxlinewd}%
\fi
}%
\def\centerpoemoff{%
\poem@defleftskip=0pt\setlength{\poemindent}{0pt}%
\poem@maxlinewd=\the\linewidth%
\setlength{\poemmaxlinewd}{\linewidth}%
}%
\def\thepoemtitle{\poemblanktitle}%
\def\thepoemauthor{\poemblankauthor}%
\def\thepoemlicense{Public Domain}%
\def\poemdefaultlicense{Public Domain}%
\def\thepoempubdate{\today}%
\def\poemblanktitle{Untitled}%
\def\poemblankauthor{Anonymous}%
\def\poemtitlestyle{\LARGE\bfseries}%
\def\poemauthorstyle{\Large}%
\def\poemtitleprehook{%
\begin{center}%
}%
\def\poemtitleposthook{%
\end{center}%
}%
\def\poemauthorprehook{%
\begin{center}%
}%
\def\poemauthorposthook{%
\end{center}%
}%
\def\titlepoem#1{%
\advance\poem@poemno by1\stepcounter{poemno}%
\advance\poem@abspoemno by1\stepcounter{abspoemno}%
\def\thepoemtitle{#1}\def\thepoemauthor{\poemblankauthor}%
\begingroup%
\poemtitleprehook%
\poemtitlestyle #1%
\poemtitleposthook%
\endgroup%
}%
\def\titleauthorpoem#1#2{%
\advance\poem@poemno by1\stepcounter{poemno}%
\advance\poem@abspoemno by1\stepcounter{abspoemno}%
\def\thepoemtitle{#1}\def\thepoemauthor{#2}%
\begingroup%
\poemtitleprehook%
\poemtitlestyle #1%
\poemtitleposthook%
\endgroup%
\begingroup%
\poemauthorprehook%
\poemauthorstyle #2%
\poemauthorposthook%
\endgroup%
}%
\def\poemgroup{%
\advance\poem@groupno by1%
\stepcounter{poemgroupno}%
\poem@poemno=0\setcounter{poemno}{0}%
\def\thepoemgroupname{\poemgroupblankname}%
}%
\def\endpoemgroup{%
}%
\def\poemgrouptitleprehook{}%
\def\poemgrouptitleposthook{}%
\def\poemgroupotherprehook{}%
\def\poemgroupotherposthook{}%
\def\poemgrouptitlestyle{\Huge}%
\def\poemgroupotherstyle{\LARGE}%
\def\poemgroupblankname{Untitled Group}%
\def\poemgroupname{\poemgroupblankname}%
\def\poemgroupheading#1#2{%
\def\thepoemgroupname{#1}%
\begingroup%
\poemgrouptitleprehook%
\poemgrouptitlestyle #1%
\poemgrouptitleposthook%
\endgroup%
\begingroup%
\poemgroupotherprehook%
\poemgroupotherstyle #2%
\poemgroupotherposthook%
\endgroup%
}%
\def\poemlopformat{%
\@dottedtocline{1}{0em}{2.3em}%
}%
\def\l@poem{\poemlopformat}%
\def\addtolop#1{%
\addcontentsline{lop}{poem}{#1}%
}%
\def\addgrouptolop#1{%
\addcontentsline{lop}{poemgroup}{#1}%
}%
\def\lopname{List of Poems}%
\def\listofpoems{%
\@starttoc{lop}%
}%
\def\poemgrouplopformat#1#2{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi%
}%
\def\l@poemgroup{\poemgrouplopformat}%
\ifcsname phantomsection\endcsname%
\else%
\def\phantomsection{\relax}%
\fi%
\ifx\theindex\@undefined\else%
\RequirePackage{imakeidx}
\makeindex[intoc,columns=1,name={\jobname-iofl},title={\poemioflname}]
\def\poemioflname{Index of First Lines}%
\def\poemfirstline#1{%
\index[\jobname-iofl]{#1}%
}%
\def\iofl#1{%
\index[\jobname-iofl]{#1}%
#1%
}%
\def\printiofl{%
\printindex[\jobname-iofl]%
}%
\fi%
\endinput
%%
%% End of file `poetry.sty'.
