From 993a42f4327b64248980a92d8f06d1eb44866d1a Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sun, 14 Mar 2021 20:40:07 +0100
Subject: added support for 'patverse'. started documenting poetry

---
 ekdosis.dtx | 168 ++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 101 insertions(+), 67 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 1c35edb..bd95000 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -3657,19 +3657,45 @@ argument of the
 %
 % \section{Poetry}
 % \label{sec:poetry}
+% For typesetting verse texts or poems, \LaTeX\ provides the standard
+% \env{verse} environment. Usually, within this environment, |\\| is
+% used to end lines, with the exception of the last line. Likewise,
+% stanzas are separated from one another by a blank line. However,
+% \pkg{ekdosis} deviates a little from this usage for it needs all
+% lines of poetry to be ended by |\\| as a distinct marker, like
+% so:---
 % 
+% \iffalse
+%<*example>
+% \fi
+\begin{minted}{latex}
+\begin{verse}
+  It is an ancient Mariner,\\
+  And he stoppeth one of three.\\
+  ‘By thy long grey beard and glittering eye,\\
+  Now wherefore stopp'st thou me?\\[\parskip]
+  %
+  The Bridegroom's doors are opened wide,\\
+  And I am next of kin;\\
+  The guests are met, the feast is set:\\
+  May'st hear the merry din.’
+\end{verse}
+\end{minted}
+% \iffalse
+%</example>
+% \fi
+%
 % \begingroup
 % \setcolumnwidth{0.6\textwidth}
 % \setlength{\leftmargini}{0em}
 % \needspace{7\baselineskip}
-% \resetlinenumber
+% \resetlinenumber\resetvlinenumber
 % \begin{alignment}[flush,
 %   lcols=2,
 %   texts=homer[xml:lang="grc"];murray,
 %   apparatus=homer]
 %   \AtBeginEnvironment{homer}{\selectlanguage{greek}}
 %   \setlength{\vrightskip}{0.25em}
-%   \setverselinenums{1}{0}
 %   \begin{homer}
 %     \begin{ekdverse}
 %        Ἄνδρα μοι ἔννεπε, Μοῦσα, πολύτροπον, ὃς μάλα πολλὰ \\
@@ -3706,74 +3732,76 @@ argument of the
 % substantiall fewell,}
 % \FormatDiv{1}{\begin{ekdcenter}}{\end{ekdcenter}}
 % \needspace{7\baselineskip}
-% \resetlinenumber
+% \resetlinenumber\resetvlinenumber
 % \begin{alignment}[flush,
 %   tcols=1,
 %   texts=shakespeare[xml:lang="en"],
 %   apparatus=shakespeare]
-%   \setverselinenums{1}{0}
 %   \setlength{\vrightskip}{-0.75in}
 %   \begin{shakespeare}
 %    \ekddiv{type=sonnets, n=1, head=1}
 %    \begin{ekdverse}[type=sonnet, width=\versewidth]
-%      \begin{ekdstanza}[type=quatrain]
-%        \ekdlettrine{F}{r}om fairest creatures we desire
-%        increase,\\[-1.875ex] 
-%        \vin That thereby beauties \emph{Rose}
-%          \app{
-%            \lem{might}
-%            \rdg[source={shGildon1710, shSewell1725, shEwing1771}]{may}
-%         } neuer die,\\
-%        But as the riper should by time
-%          \app{
-%            \lem{decease}
-%            \rdg[source=shHudson1856]{decrease}
-%          },\\
-%        His tender heire might beare his memory:\\
-%      \end{ekdstanza}
-%      \begin{ekdstanza}[type=quatrain]
-%        But thou contracted to thine owne bright eyes,\\
-%        Feed'st thy
-%          \app{
-%            \lem{lights}
-%            \rdg[source={shButler1899, shWalsh1908}]{life's}
-%          } flame with
-%          \app{
-%            \lem{selfe substantiall}
-%            \rdg[source=shGildon1714,
-%                 alt={\textnormal{Hyphened by}}]{selfe-substantiall}
-%            \note{etc.}} fewell,\\
-%        Making a famine where aboundance lies,\\
-%        Thy selfe thy foe,to thy sweet selfe too cruell:\\
-%      \end{ekdstanza}
-%      \begin{ekdstanza}[type=quatrain]
-%        Thou that art now the worlds fresh ornament,\\
-%        And
-%          \app{
-%            \lem{only}
-%            \rdg[resp=shGod, type=conjecture]{early}
-%            \note{conj.}
-%          } herauld to the gaudy spring,\\
-%        Within thine owne bud buriest thy content,\\
-%        And tender
-%          \app{
-%            \lem{chorle}
-%            \rdg[source=shGildon1710]{churl}
-%            \note{etc.}
-%          } makst wast in niggarding:\\
-%      \end{ekdstanza}
-%      \begin{ekdstanza}[type=couplet]
-%        \vin Pitty the world,or else this glutton be,\\
-%        \vin To eate the worlds due,\app{
+%      \indentpattern{00000000000011}
+%      \begin{patverse}
+%        \begin{ekdstanza}[type=quatrain]
+%          \ekdlettrine{F}{r}om fairest creatures we desire
+%          increase,\\[-1.875ex] 
+%          \vin That thereby beauties \emph{Rose}
+%            \app{
+%              \lem{might}
+%              \rdg[source={shGildon1710, shSewell1725, shEwing1771}]{may}
+%           } neuer die,\\
+%          But as the riper should by time
+%            \app{
+%              \lem{decease}
+%              \rdg[source=shHudson1856]{decrease}
+%            },\\
+%          His tender heire might beare his memory:\\
+%        \end{ekdstanza}
+%        \begin{ekdstanza}[type=quatrain]
+%          But thou contracted to thine owne bright eyes,\\
+%          Feed'st thy
+%            \app{
+%              \lem{lights}
+%              \rdg[source={shButler1899, shWalsh1908}]{life's}
+%            } flame with
+%            \app{
+%              \lem{selfe substantiall}
+%              \rdg[source=shGildon1714,
+%                   alt={\textnormal{Hyphened by}}]{selfe-substantiall}
+%              \note{etc.}} fewell,\\
+%          Making a famine where aboundance lies,\\
+%          Thy selfe thy foe,to thy sweet selfe too cruell:\\
+%        \end{ekdstanza}
+%        \begin{ekdstanza}[type=quatrain]
+%          Thou that art now the worlds fresh ornament,\\
+%          And
+%            \app{
+%              \lem{only}
+%              \rdg[resp=shGod, type=conjecture]{early}
+%              \note{conj.}
+%            } herauld to the gaudy spring,\\
+%          Within thine owne bud buriest thy content,\\
+%          And tender
+%            \app{
+%              \lem{chorle}
+%              \rdg[source=shGildon1710]{churl}
+%              \note{etc.}
+%            } makst wast in niggarding:\\
+%        \end{ekdstanza}
+%        \begin{ekdstanza}[type=couplet]
+%          Pitty the world,or else this glutton be,\\
+%          To eate the worlds due,\app{
 %            \lem{by the}
 %            \rdg[resp=shStee, postwit=conj., type=conjecture]{be thy}
 %            \rdg[resp=shGod, postwit=conj., type=conjecture]{by thy}
-%          } graue
-%            \app{
-%              \lem{and}
-%              \rdg[resp=shGod, postwit=conj., type=conjecture]{as}
-%            } thee.\\!
-%      \end{ekdstanza}
+%            } graue
+%              \app{
+%                \lem{and}
+%                \rdg[resp=shGod, postwit=conj., type=conjecture]{as}
+%              } thee.\\!
+%        \end{ekdstanza}
+%      \end{patverse}
 %    \end{ekdverse}
 %   \end{shakespeare}
 % \end{alignment}
@@ -5479,7 +5507,7 @@ Sample text with a \textcolor{red}{word} in red.
 %
 % \needspace{7\baselineskip}
 % \begin{alignment}[flush,tcols=1,texts=specimen,apparatus=specimen]
-% \setverselinenums{30}{0}
+% \resetlinenumber\resetvlinenumber[30]
 % \setlength{\vrightskip}{-1.5in}
 %   \begin{specimen}
 %     \begin{ekdverse}
@@ -8238,7 +8266,7 @@ Sample text with a \textcolor{red}{word} in red.
 }
 \verselinenumfont{\normalfont\footnotesize}
 \setcounter{poemline}{1}
-\NewDocumentEnvironment{ekdverse}{O{}}{%
+\NewDocumentEnvironment{ekdverse}{!O{}}{%
   \ekvset{ekd@verse}{#1}%
   \if@continuous@vnum\setverselinenums{\thelinenumber}{0}\fi
   \nolinenumbers
@@ -8270,7 +8298,7 @@ Sample text with a \textcolor{red}{word} in red.
 \else
 \newlength{\ekdverseindentlength}
 \setlength{\ekdverseindentlength}{\parindent}
-\NewDocumentEnvironment{ekdverse}{O{\ekdverseindentlength}}{
+\NewDocumentEnvironment{ekdverse}{!O{\ekdverseindentlength}}{
   \begin{list}{}{%
       \setlength{\leftmargin}{#1}
       \setlength{\itemsep}{0pt}
@@ -8299,10 +8327,12 @@ Sample text with a \textcolor{red}{word} in red.
 %   \changes{v1.2}{2021/03/08}{new environment for stanzas}
 %    \begin{macrocode}
 \ekvdefinekeys{ekd@stanza}{
-  code type = \def\type@value{#1}  
+  code type = \def\type@value{#1}
 }
-\NewDocumentEnvironment{ekdstanza}{O{}}{%
+\NewDocumentEnvironment{ekdstanza}{!O{}}{%
+  \leavevmode\unskip
   \ekvset{ekd@stanza}{#1}%
+  \ignorespaces
 }{}
 %    \end{macrocode}
 % \end{environment}
@@ -8712,6 +8742,7 @@ local texpatttotags = {
    {a="\\resetvlinenumber%s+", b=""},
    {a="\\resetlinenumber%s+%[(.-)%]", b=""},
    {a="\\resetlinenumber%s+", b=""},
+   {a="\\indentpattern%s+{(.-)}", b=""},
    {a="\\poemlines%s+{(.-)}", b=""},
    {a="\\pagebreak%s+%[[1-4]%]", b=""},
    {a="\\pagebreak%s+", b=""},
@@ -8958,9 +8989,9 @@ local function linestotei(str)
    then
       str = "\n<l>"..str
    end
-   str = gsub(str, poemline * spcenc^-1 * bclinegroup, "</l>\n%2")
-   str = gsub(str, linegroup * -(spcenc^-1 * bclinegroup), "%1\n<l>")
-   str = gsub(str, lpeg.Cs("</lg>") * -(spcenc^-1 * (bclinegroup + -1)), "%1\n<l>")
+   str = gsub(str, poemline * spcenc^0 * bclinegroup, "</l>\n%2")
+   str = gsub(str, linegroup * -(spcenc^0 * bclinegroup), "%1\n<l>a")
+   str = gsub(str, lpeg.Cs("</lg>") * -(spcenc^0 * (bclinegroup + -1)), "%1\n<l>")
    -- str = gsub(str, poemline * spcenc^-1 * -1, "</l>\n")
    str = gsub(str, poemlinebreak, "<lb/> ")
    -- str = gsub(str, poemline * spcenc^-1 * lpeg.Cs("<lg"), "</l>%2")
@@ -8991,6 +9022,9 @@ end
 
 -- better use lpeg: look into this later
 local function versetotei(str)
+   str = string.gsub(str, "\\begin%s?%{patverse%}", "")
+   str = string.gsub(str, "\\end%s?%{patverse%}", "")
+   str = string.gsub(str, "\\indentpattern%s?%b{}", "")
    str = string.gsub(str, "\\begin%s?%{ekdverse%}(%b[])(.-)\\end%s?%{ekdverse%}", function(opt, arg)
 			arg = string.gsub(arg, "\\par%s?", "")
 			opt = string.sub(opt, 2, -2)
-- 
cgit v1.2.3

