%%
%% This is file `poetrytex.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% poetrytex.dtx  (with options: `poetrytex')
%% 
%%   Copyright 2012 Samuel Whited
%% 
%%   This file may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either
%%   version 1.3c 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.3c or later is part of all distributions of
%%   LaTeX version 2008/05/04 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{poetrytex}[2013/08/17]
\RequirePackage{expl3}
\RequirePackage{tocloft}
\AtEndOfPackage{\RequirePackage{hyperref}}
\DeclareOption{verse}{\usepackage{verse}}
\DeclareOption{poemsintoc}{\listpoemsintoc}
\DeclareOption{numbertop}{\numbertop}
\DeclareOption{numbertoc}{\numbertoc}
\DeclareOption{resetnumongroup}{\resetnumongroup}
\DeclareOption{numberpoems}{\numberpoems}
\DeclareOption{usedefaulttitles}{\ptusedefaulttitles}
\DeclareOption{useincipits}{\ptuseincipits}
\DeclareOption{clearpageafterpoem}{\clearpageafterpoem}
\DeclareOption{clearpageafterpoems}{\clearpageafterpoem}
\DeclareOption*{%
  \PassOptionsToPackage{\CurrentOption}{hyperref}%
}
\newcommand*{\pttitle}{Title}
\newcommand*{\ptsubtitle}{Subtitle}
\newcommand*{\ptauthor}{Author}
\newcommand*{\ptdate}{\today}
\title{%
  \beforetitle\pttitle\aftertitle%
  \ifx\ptsubtitle\@ptundefined%
    \relax%
  \else%
    \\*\beforesubtitle\ptsubtitle\aftersubtitle%
  \fi%
}
\author{\beforeauthor\ptauthor\afterauthor}
\date{\beforedate\ptdate\afterdate}
\newcommand*{\@ptpoemlabeltext}{poetrytexpoem:}
\newcounter{poemnum}
\newcounter{absolutepoemnum}
\newcounter{untitledpoemnum}
\newcounter{absoluteuntitledpoemnum}
\newcounter{titledpoemnum}
\newcounter{absolutetitledpoemnum}
\newcounter{poemgroupnum}
\newlength{\poemvspace}
\setlength{\poemvspace}{0em}
\newlength{\pttitleleftspace}
\setlength{\pttitleleftspace}{0em}
\newlength{\pttitlerightspace}
\setlength{\pttitlerightspace}{0em}
\newlength{\ptsubtitleleftspace}
\setlength{\ptsubtitleleftspace}{0em}
\newlength{\ptsubtitlerightspace}
\setlength{\ptsubtitlerightspace}{0em}
\newcommand*{\ptusedefaulttitles}{\newcommand*{\@ptusedefaulttitles}{}}
\newcommand*{\ptdefaulttitle}{%
  Untitled No. \arabic{absoluteuntitledpoemnum}%
}
\newcommand*{\ptuseincipits}{\newcommand*{\@ptuseincipits}{}}
\newcommand*{\ptdefaultenv}{verse}
\newcommand*{\pttitleenv}{center}
\newcommand*{\ptdefaultgroupenv}{center}
\newcommand*{\grouppagestyle}{empty}
\newlength{\pregroupvspace}
\newlength{\postgroupvspace}
\setlength{\pregroupvspace}{\fill}
\setlength{\postgroupvspace}{\fill}
\newcounter{annotationnum}
\newcounter{absoluteannotationnum}
\newcommand*{\ptannotationenv}{flushleft}
\newcommand*{\ptdedication}{Renew \textsf{\textbackslash ptdedication}}
\newcommand*{\makededication}[1][flushright]{%
  \thispagestyle{empty}
  \vspace*{\prededicationvspace}
  \begin{#1}
    \beforededication{\dedicationformat\ptdedication}\afterdedication
  \end{#1}
  \vspace*{\postdedicationvspace}
}
\newcommand*{\resetnumon}{}
\newlistof[\resetnumon]{poem}{top}{\topname}
\newcommand*{\listofpoems}{\listofpoem}
\newcommand*{\topname}{List of Poems}
\newcommand*{\topentrytype}{subsection}
\newcommand*{\toptocentrytype}{section}
\newcommand*{\listpoemsintoc}{\newcommand*{\@ptlistpoemsintoc}{}}
\newcommand*{\tocentrytype}{\topentrytype}
\setcounter{secnumdepth}{-1}
\setcounter{tocdepth}{2}
\renewcommand*{\listtablename}{\topname}
\newcommand*{\maketoc}{%
  \beforetoc
  \tableofcontents
  \pagestyle{plain}
  \aftertoc
  \clearpage
  \thispagestyle{empty}
}
\newcommand*{\maketop}{\@ifstar{\@ptmaketopStar}{\@ptmaketopNoStar}}
\newcommand*{\@ptmaketopStar}{%
  \cleardoublepage
  \beforetop
  \listofpoems
  \pagestyle{plain}
  \aftertop
  \clearpage
}
\newcommand*{\@ptmaketopNoStar}{%
  \cleardoublepage
  \beforetop
  \phantomsection
  \addcontentsline{toc}{\toptocentrytype}{\topname}
  \listofpoems
  \pagestyle{plain}
  \aftertop
  \clearpage
}
\newcommand*{\numbertop}{\newcommand*{\@ptnumbertop}{}}
\newcommand*{\numbertoc}{\newcommand*{\@ptnumbertoc}{}}
\newcommand*{\beforetitle}{}
\newcommand*{\aftertitle}{}
\newcommand*{\beforesubtitle}{}
\newcommand*{\aftersubtitle}{}
\newcommand*{\beforeauthor}{}
\newcommand*{\afterauthor}{}
\newcommand*{\beforedate}{}
\newcommand*{\afterdate}{}
\newcommand*{\dedicationformat}{\normalfont\itshape}
\newlength{\prededicationvspace}
\newlength{\postdedicationvspace}
\setlength{\prededicationvspace}{\fill}
\setlength{\postdedicationvspace}{\fill}
\newcommand*{\beforededication}{}
\newcommand*{\afterdedication}{}
\newcommand{\beforetoc}{}
\newcommand{\aftertoc}{}
\newcommand{\beforetop}{}
\newcommand{\aftertop}{}
\newcommand*{\beforepoemgroup}{\cleardoublepage}
\newcommand*{\afterpoemgroup}{\clearpage}
\newenvironment{poem}[3][\ptdefaultenv]{%
  \newcommand*{\@ptwrapenvironment}{#1}
\newcommand*{\incipit}{%
  \@ifstar{%
    \@ptincipitStar
  }{%
    \@ptincipitNoStar
  }
}
\newcommand*{\@ptincipitNoStar}[1]{%
  \global\expandafter\def%
    \csname%
      @poem\arabic{absolutepoemnum} incipit%
    \endcsname{##1}%
  ##1%
}
\newcommand*{\@ptincipitStar}[1]{%
  \global\expandafter\def%
    \csname%
      @poem\arabic{absolutepoemnum} incipit%
    \endcsname{##1}%
}

\newcommand*{\theincipit}{%
  \csname @poem\arabic{absolutepoemnum} incipit\endcsname%
}
  \addtocounter{poemnum}{1}
  \addtocounter{absolutepoemnum}{1}
  \poetryheadings
  \ifx&#2&%
    \addtocounter{untitledpoemnum}{1}
    \addtocounter{absoluteuntitledpoemnum}{1}
  \else
    \addtocounter{titledpoemnum}{1}
    \addtocounter{absolutetitledpoemnum}{1}
  \fi
  \vspace*{\poemvspace}
  \begin{\pttitleenv}
    \refstepcounter{poem}%
    \phantomsection%
    \addcontentsline{top}{\topentrytype}{%
      \ifx\@ptnumbertop\@ptundefined%
        \relax%
      \else%
        \toppoemnum%
      \fi%
      \ifx&#2&%
        \ifx\@ptuseincipits\@ptundefined%
          \ptdefaulttitle%
        \else%
          {\incipittopformat \theincipit}%
        \fi%
      \else%
        #2%
      \fi%
    }%
    \ifx\@ptlistpoemsintoc\@ptundefined%
      \relax%
    \else%
      \addcontentsline{toc}{\tocentrytype}{%
        \ifx\@ptnumbertoc\@ptundefined%
          \relax%
        \else%
          \tocpoemnum%
        \fi%
        \ifx&#2&%
          \ifx\@ptuseincipits\@ptundefined%
            \ptdefaulttitle%
          \else%
            {\incipittocformat \theincipit}%
          \fi%
        \else%
          #2%
        \fi%
      }%
    \fi%
    \hypertarget{\@ptpoemlabeltext\arabic{absolutepoemnum}}{}
    {\poemtitleformat%
      \ifx\@ptnumberpoems\@ptundefined
        \relax
      \else
        \titlepoemnum
      \fi%
      \ifx&#2&%
        \ifx\@ptusedefaulttitles\@ptundefined%
          \relax%
        \else%
          \hspace*{\pttitleleftspace}\ptdefaulttitle%
          \hspace*{\pttitlerightspace}\\*%
        \fi%
      \else
        \hspace*{\pttitleleftspace}#2\hspace*{\pttitlerightspace}\\*%
      \fi%
    }%
    \hspace*{\ptsubtitleleftspace}#3\hspace*{\ptsubtitlerightspace}
  \end{\pttitleenv}
  \nopagebreak
  \begin{\@ptwrapenvironment}
    \begingroup\setlength{\parskip}{\stanzaparskip}%
}{%
    \endgroup
  \end{\@ptwrapenvironment}
  \ifx\@ptclearpageafterpoem\@ptundefined
    \relax
  \else
    \clearpage
  \fi
}
\newcommand*{\poetryheadings}[0]{%
  \pagestyle{myheadings}
  \markboth{\ |\ \textsc{\pttitle}\hfill }
           {\hfill\textsc{\ptgroup}\ |\ }
}
\newcommand*{\resetnumongroup}{%
  \newcommand*{\@ptresetnumongroup}{}%
  \renewcommand*{\resetnumon}{poemgroupnum}%
}
\newcommand*{\numberpoems}{\newcommand*{\@ptnumberpoems}{}}
\newcommand*{\titlepoemnum}{\arabic{poemnum}\\*}
\newcommand*{\toppoemnum}{\arabic{poemnum}.\ }
\newcommand*{\tocpoemnum}{\toppoemnum}
\newlength{\stanzaparskip}
\setlength{\stanzaparskip}{0.7em}
\newcommand*{\clearpageafterpoem}{\newcommand*{\@ptclearpageafterpoem}{}}
\newlength{\ptgap}
\setlength{\ptgap}{2em}
\newcommand*{\ptind}{%
  \@ifstar{%
    \@ptindStar
  }{%
    \@ptindNoStar
  }
}
\newcommand*{\@ptindStar}{\hspace*{\ptgap}}
\newcommand*{\@ptindNoStar}{\hspace{\ptgap}}
\newcommand*{\poemtitleformat}{\normalfont\bfseries\large}
\newcommand*{\incipittopformat}{\itshape}
\newcommand*{\incipittocformat}{\incipittopformat}
\newlength{\ptspacergap}
\setlength{\ptspacergap}{4em}
\newcommand*{\ptspacerchar}{\S}
\newcommand*{\ptspacernum}{3}
\newcommand*{\ptspacer}{%
  \@ifstar{%
    \@ptspacerStar
  }{%
    \@ptspacerNoStar
  }
}
\newcommand*{\@ptspacerStar}{%
  \hspace*{\ptspacergap}%
  \@ptrepeat{\ptspacernum}{\ptspacerchar}%
}
\newcommand*{\@ptspacerNoStar}{%
  \hspace{\ptspacergap}%
  \@ptrepeat{\ptspacernum}{\ptspacerchar}%
}
\ExplSyntaxOn
\cs_new_eq:NN \@ptrepeat \prg_replicate:nn
\ExplSyntaxOff
\newcommand*{\linktopoem}[2][ptnull]{%
  \ifx{#1}{ptnull}
    \hyperlink{\@ptpoemlabeltext#2}{#2}\relax
  \else
    \hyperlink{\@ptpoemlabeltext#1}{#2}\relax
  \fi
}
\newcommand*{\ptgroup}{}
\newcommand*{\poemgroup}[1]{%
  \addtocounter{poemgroupnum}{1}
  \ifx\@ptresetnumongroup\@ptundefined
    \relax
  \else
    \setcounter{poemnum}{0}
    \setcounter{untitledpoemnum}{0}
    \setcounter{titledpoemnum}{0}
    \setcounter{annotationnum}{0}
  \fi
  \beforepoemgroup
  \vspace*{\pregroupvspace}
  \renewcommand*{\ptgroup}{#1}
  \pagestyle{\grouppagestyle}
  \begin{\ptdefaultgroupenv}
    \@ifstar{%
      \@ptpoemgroupStar{#1}
    }{%
      \@ptpoemgroupNoStar{#1}
    }
  \end{\ptdefaultgroupenv}
  \vspace*{\postgroupvspace}
  \afterpoemgroup
}
\newcommand*{\@ptpoemgroupStar}[1]{%
  \section*{#1}
}
\newcommand*{\@ptpoemgroupNoStar}[1]{%
  \section{#1}
  \addcontentsline{top}{section}{#1}
}
\newenvironment{annotation}[2][\ptannotationenv]{%
  \newcommand*{\@ptwrapenvironment}{#1}
  \cleardoublepage
  \addtocounter{annotationnum}{1}
  \addtocounter{absoluteannotationnum}{1}
  \annotationheadings
  \begin{\@ptwrapenvironment}
  \subsection{#2}
  \nopagebreak
}{%

  \end{\@ptwrapenvironment}
  \clearpage
}
\newcommand*{\annotationheadings}[0]{\poetryheadings}
\ProcessOptions\relax
%% 
%%   ___________
%%   Maintainer: Sam Whited
%%   Website:    https://samwhited.com
%%   Contact:    sam@samwhited.com
%%   Public key: 0xEC2C9934
%% 
%%   This work consists of this file poetrytex.dtx
%%             and the derived files poetrytex.sty
%%                               and poetrytex.pdf
%% 
%%
%% End of file `poetrytex.sty'.
