From c10daf3695c4eb889c3831e0687aef2acf09db76 Mon Sep 17 00:00:00 2001
From: Robert Alessi <alessi@robertalessi.net>
Date: Sat, 15 Jan 2022 16:52:45 +0100
Subject: Many improvements, commands and functions for lacunae, including
 \ilabel.

New option Nolem. New commands \getTEIxmlid, \teidirectE.
---
 ekdosis.dtx | 690 ++++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 552 insertions(+), 138 deletions(-)

(limited to 'ekdosis.dtx')

diff --git a/ekdosis.dtx b/ekdosis.dtx
index 5f7b313..c8f3850 100644
--- a/ekdosis.dtx
+++ b/ekdosis.dtx
@@ -61,7 +61,7 @@ along with this program.  If not, see
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{ekdosis}
 %<*package>
-    [2022/01/05 v1.5-dev Typesetting TEI xml-compliant critical editions]
+    [2022/01/15 v1.5-dev Typesetting TEI xml-compliant critical editions]
 %</package>
 %<*driver>
 \begin{filecontents}[noheader,overwrite]{bibdata.xml}
@@ -227,6 +227,7 @@ along with this program.  If not, see
   editor =	 {Constans, L.-A.},
   volume =	 2,
   pagination =	 {none},
+  entrysubtype = {primary},
   series =	 {Collection des Universités de France},
   publisher =	 {Les Belles Lettres},
   location =	 {Paris}
@@ -238,14 +239,39 @@ along with this program.  If not, see
   date =	 1869,
   editor =	 {McDevitte, W. A., and Bohn, W. S.},
   edition =	 1,
+  entrysubtype = {primary},
   series =	 {Harper's New Classical Library},
   publisher =	 {Harper \& Brothers},
   location =	 {New York}}
 
+@Book{CiceroAtt,
+  author =	 {Cicero},
+  title =	 {Ad Atticum epistularum libri sedecim},
+  date =	 1916,
+  entrysubtype = {primary},
+  editor =	 {Sjögren, H.},
+  editortype =	 {recensuit},
+  series =	 {Collectio scriptorum ueterum Vpsaliensis},
+  publisher =	 {Eranos' Förlag}
+}
+
+@Book{CiceroAttTr,
+  author =	 {Cicero},
+  title =	 {Letters to Atticus},
+  date =	 1919,
+  entrysubtype = {primary},
+  editor =	 {Winstedt, E.O.},
+  series =	 {The Loeb Classical Library},
+  number =	 2,
+  publisher =	 {William Heinemann \& The MacMillan Co.},
+  location =	 {London -- New York}
+}
+
 @MVBook{HomerMurray,
   author =	 {{Homer}},
   title =	 {The Odyssey},
   date =	 1919,
+  entrysubtype = {primary},
   editor =	 {Murray, A. T.},
   volumes =	 2,
   publisher =	 {Harvard University Press -- William Heinemann},
@@ -253,15 +279,16 @@ along with this program.  If not, see
 }
 
 @Book{McDonald1916,
+  author =	 {Shakespeare},
   editor =	 {MacDonald Alden, Raymond},
   shorteditor =	 {MacDonald},
-  title =	 {The Sonnets of Shakespeare},
+  title =	 {The Sonnets},
   date =	 1916,
+  entrysubtype = {primary},
   titleaddon =	 {From the Quarto of 1609 with Variorum Readings and
                   Commentary},
   organization = {Houghton Mifflin Co.},
   publisher =	 {The Riverside Press Cambridge},
-  options =	 {useauthor=false, useeditor=true},
   location =	 {Boston \& New York}
 }
 
@@ -412,6 +439,14 @@ along with this program.  If not, see
   version =	 {2.4b}
 }
 
+@Software{xparse,
+  title =	 {The Xparse package},
+  titleaddon =	 {A generic document command parser},
+  author =	 {{The LaTeX Team}},
+  url =		 {https://ctan.org/pkg/xparse},
+  date =	 {2022-01-12},
+}
+
 @Software{arabluatex,
   title =	 {The Arabluatex package},
   titleaddon =	 {ArabTeX for LuaLaTeX},
@@ -451,10 +486,6 @@ along with this program.  If not, see
 }
 \end{filecontents}
 \begin{filecontents}[overwrite]{\jobname-ekd.cfg}
-%% fixfoot:---
-\DeclareFixedFootnote{\seeekdsep}{See below
-  \vpageref{ref:ekdsep-subsep} for more information and
-  \vref{lst:emend-coni-corr}, ll.~23--5 for an illustrative example.}
 %% ekdosis:---
 \footnotelayout{m}
 \SetCritSymbols{suppbegin = ⟨,suppend = ⟩}
@@ -562,12 +593,22 @@ along with this program.  If not, see
 \DeclareSource{shWalsh1908}{Wa}
 \DeclareScholar{shGod}{Godwin}[rawname=Godwin]
 \DeclareScholar{shStee}{Stee}[rawname=Steevens, note=Notes in Malone]
+% Cicero, ad Atticum, VII.9.4
+\DeclareWitness{cicC}{C}{Lectiones quas Cratander in margine editionis,
+  quae a. 1528 Basileae prodiit, adscripsit}
+\DeclareWitness{cicΩ}{Ω}{Consensus codicum Σ et Δ uel archetypum
+  codicum Italicorum}
 \end{filecontents}
 \documentclass{ltxdoc}
  %\usepackage[letterpaper,margin=25mm,left=50mm,nohead]{geometry}
 \usepackage[letterpaper,margin=1.25in,left=50mm,nohead]{geometry}
-\usepackage{dox}
-\doxitem{Option}{option}{options}
+%^^A dox does not work with the latest latex-dev:
+\ifdefined\SpecialMacroIndex
+  \NewDocElement{Option}{option}
+\else
+  \usepackage{dox}
+  \doxitem{Option}{option}{options}
+\fi
 \usepackage{fontspec}
 \defaultfontfeatures{Renderer=Harfbuzz}
 \usepackage{microtype}
@@ -585,14 +626,23 @@ along with this program.  If not, see
 \babeltags{ancientgreek = greek}
 \def\sg#1{\textancientgreek{#1}}
 \usepackage[biblatex=true]{embrac}
-\usepackage{chifoot}
-\usepackage{fixfoot}
 \usepackage[nospace,american]{varioref}
 \usepackage{addlines}
 \newcommand\phts{\phantomsection}
+\usepackage{chifoot}
+\usepackage{savefnmark}
 \usepackage{nameref}
 \usepackage{arabluatex}
 \usepackage[parnotes=roman, teiexport=tidy, poetry=verse]{ekdosis}
+\makeatletter
+\NewDocumentCommand{\ekdelide}{m}{%
+  \IfSubStr{#1}{--}{%
+    \StrBefore{#1}{--}[\@before]%
+    \StrBehind{#1}{--}[\@behind]%
+    \luadirect{tex.sprint(ekdosis.numrange(
+      \luastring{\@before},
+      \luastring{\@behind}))}}{#1}}
+\makeatother
 \AddxmlBibResource{bibdata.xml}
 \usepackage{booktabs}
 \usepackage{xltabular}
@@ -628,7 +678,6 @@ along with this program.  If not, see
   \colorlet{cinnamon}{black}}{}
 \definecolor{gainsboro}{RGB}{222,222,222}
 \PassOptionsToPackage{bookmarks=true}{hyperref}
-\usepackage[obeyspaces]{url}
 \usepackage[numbered]{hypdoc}
 \usepackage[titlematter,loadlang=en|de|fr|es]{metastr}
 \hypersetup{
@@ -637,7 +686,6 @@ along with this program.  If not, see
   linktocpage=true,
   pdftype={Text}
 }
-\usepackage{uri}
 \labelformat{section}{sect.~#1}
 \labelformat{subsection}{sect.~#1}
 \labelformat{subsubsection}{sect.~#1}
@@ -645,10 +693,10 @@ along with this program.  If not, see
 \usepackage[defaultindex=none,citecmd=autocite]{icite}
 \bibinput{ekdosis}
 \newcommand\vnref[1]{\vref{#1}, \enquote{\nameref{#1}}}
+\newcommand\lnref[1]{\getrefnumber{#1}}
 \usepackage[style=oxnotes-inote,dashed]{biblatex}
-\setcounter{biburllcpenalty}{100}
-\setcounter{biburlucpenalty}{200}
-\setcounter{biburlnumpenalty}{100}
+\usepackage{uri}
+\usepackage[obeyspaces]{xurl}
 \DefineBibliographyStrings{english}{
   seenote={cf\adddotspace n\adddotspace}}
 \DeclareSourcemap{
@@ -1119,15 +1167,15 @@ along with this program.  If not, see
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}{latex}
-\begin{ekdosis}
+\begin{minted}[escapeinside=++]{latex}
+\begin{ekdosis} +\label{ln:pj1:1}+
   I 
-  \app{
+  \app{ +\label{ln:pj1:3}+
     \lem{saw}
-    \rdg{met}
+    \rdg{met} +\label{ln:pj1:5}+
   }
-  my friend \app{\lem{Peter}\rdg{John}} at the station yesterday.
-\end{ekdosis}
+  my friend \app{\lem{Peter}\rdg{John}} at the station yesterday. +\label{ln:pj1:7}+
+\end{ekdosis} +\label{ln:pj1:8}+
 \end{minted}
 % \iffalse
 %</example>
@@ -1173,14 +1221,16 @@ along with this program.  If not, see
 % \fi
 %
 % As can be seen from \vref{lst:pj1}, the edition text is inserted in
-% the \env{ekdosis} environment (l.~1 to 8). Then two
-% \cs{app}\marg{apparatus entry} commands (ll.~3 and 7) contain the
-% lemma (\cs{lem}\marg{lemma}), namely the reading that is accepted by
-% the editor, and at least one variant reading
-% (\cs{rdg}\marg{reading}, ll.~5 and 7). As the listing shows, the
-% editor is free to lay out the code in a legible manner to the eye:
-% the first lemma above spans several lines whereas the second one is
-% written in sequence without spaces.
+% the \env{ekdosis} environment (ll.~\lnref{ln:pj1:1} to
+% \lnref{ln:pj1:8}). Then two \cs{app}\marg{apparatus entry}
+% commands (ll.~\lnref{ln:pj1:3} and \lnref{ln:pj1:7})
+% contain the lemma (\cs{lem}\marg{lemma}), namely the reading that is
+% accepted by the editor, and at least one variant reading
+% (\cs{rdg}\marg{reading}, ll.~\lnref{ln:pj1:5} and
+% \lnref{ln:pj1:7}). As the listing shows, the editor is free
+% to lay out the code in a legible manner to the eye: the first lemma
+% above spans several lines whereas the second one is written in
+% sequence without spaces.
 %
 % In the PDF output, the edition text is printed in the upper part of
 % the page, above the line, and naturally shows the accepted
@@ -1712,22 +1762,23 @@ along with this program.  If not, see
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}{latex}
+\begin{minted}[escapeinside=++]{latex}
 \DeclareScholar{ego}{ego}[
      forename=John,
      surname=Smith,
      note=Main editor of the text]
-\DeclareShorthand{egoscr}{\emph{scripsi}}{ego}
+\DeclareShorthand{egoscr}{\emph{scripsi}}{ego}+\label{ln:egoscr}+
 \end{minted}
 % \iffalse
 %</example>
 % \fi
 %
-% Then, the shorthand |egoscr| (l.~5) can be used to print in the
-% apparatus criticus the technical term \emph{scripsi} and use at the
-% same time the pointer |#ego| that is expected in the \texttt{TEI
-% xml} output file. Detailed examples of this technique will be
-% provided below in \vref{sec:emendations-conjectures}.
+% Then, the shorthand |egoscr| (l.~\lnref{ln:egoscr}) can be
+% used to print in the apparatus criticus the technical term
+% \emph{scripsi} and use at the same time the pointer |#ego| that is
+% expected in the \texttt{TEI xml} output file. Detailed examples of
+% this technique will be provided below in
+% \vref{sec:emendations-conjectures}.
 %
 % \subsubsection{Printing Formatted Witnesses
 % --- Conspectus Siglorum}
@@ -1922,10 +1973,19 @@ yesterday.
 % the related entry of the apparatus criticus. This mechanism is
 % useful in more than one respect. For instance, it can be used to
 % insert abbreviated lemmata in the apparatus criticus, or to
-% \addlines[-1]
 % introduce an alternate way of writing entries with Latin technical
 % terms in the apparatus criticus as will be demonstrated below in the
 % example provided by \vref{lst:pj2}.\\
+% \DescribeOption{ilabel}\phts\label{ref:ilabel-opt}
+% |ilabel|$=$\meta{indexed label}\\
+% \newfeature[v1.5] If used, |ilabel| instructs \pkg{ekdosis} not to
+% set a label at the place where \meta{lemma text} ends. Instead, the
+% label is indexed as \meta{indexed label} and only used to compute
+% the ending line number at the place where the index is recalled by
+% \cs{ilabel}\meta{indexed label}.\footnote{See below
+% \vpageref{ref:ilabel-opt}.} This allows for abbreviated lemmas
+% corresponding to spans of texts that cross verse, paragraph or
+% section boundaries as described below in \vnref{sec:lacunae}.\\
 % \DescribeOption{nodelim} |nodelim|$=$\verb+true|false+\\
 % \newfeature[v1.5] This named argument does not need a value as it
 % defaults to |true| if used. |nodelim| removes the delimiter that is
@@ -1943,16 +2003,23 @@ yesterday.
 % if used. |nosep| removes the separator mentioned above. Obviously,
 % |nosep| must be used when for some reason no \cs{rdg} command
 % follows a \cs{lem} command that has just been used, as shown below
-% in \vref{lst:emend-coni-corr}, l.~7.  \danger If |nosep| be used so
-% as to insert an explanatory note after the lemma text with the
+% in \vref{lst:emend-coni-corr},
+% l.~\lnref{ln:emend:nosep}. \danger If |nosep| be used so as
+% to insert an explanatory note after the lemma text with the
 % \cs{note} command described below \vpageref{ref:editorial-notes},
 % then the |sep| optional argument of \cs{note} can be used to put
 % back in the separator. This technique is demonstrated below in
-% \vref{lst:emend-coni-corr}, ll.~23--5.\\
+% \vref{lst:emend-coni-corr},
+% ll.~\ekdelide{\lnref{ln:emend:sep:b}%^^A
+% --\lnref{ln:emend:sep:e}}.\\
 % \DescribeOption{nolem} |nolem|$=$\verb+true|false+\\
 % This named argument does not need a value as it defaults to |true|
 % if used. |nolem| completely removes the lemma text from the related
 % entry in the apparatus criticus.\\
+% \DescribeOption{Nolem} (no-value argument)\\
+% \newfeature[v1.5] |Nolem| takes no value and is equivalent to
+% |nodelim,| |nolem,| |nonum|. For an example of its usage, see
+% \vnref{sec:lacunae} and \vref{lst:cic-att}.\\
 % \DescribeOption{type} |type|$=$\meta{value}\\
 % This named argument has no effect on the apparatus criticus of the
 % edition in print, but it is used in the \texttt{TEI xml} output to
@@ -2057,9 +2124,13 @@ yesterday.
 % \DescribeOption{post} |post|$=$\meta{words}\\
 % |post| inserts \meta{words} immediately after the note.\\
 % \DescribeOption{sep} This argument-less option is equivalent to
-% |post=\ekdsep|.\seeekdsep\\
+% |post=\ekdsep|.\footnote{See below
+%  \vpageref{ref:ekdsep-subsep} for more information and
+%  \vref{lst:emend-coni-corr}, ll.~%^^A
+%  \ekdelide{\lnref{ln:emend:sep:b}--\lnref{ln:emend:sep:e}}
+%  for an illustrative example.}\saveFN\fnEmend\\
 % \DescribeOption{subsep} This argument-less option is equivalent to
-% |pre=\ekdsubsep|.\seeekdsep\\
+% |pre=\ekdsubsep|.\useFN\fnEmend\\
 %
 % \danger Under no circumstances is it permitted to insert this
 % command \cs{note} or \cs{note*} inside the argument of \cs{lem} or
@@ -2079,7 +2150,7 @@ yesterday.
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}{latex}
+\begin{minted}[escapeinside=++]{latex}
 \begin{ekdosis}
   I 
   \app{
@@ -2096,16 +2167,16 @@ yesterday.
     \rdg[wit=B]{good}}
   mood.
   \app{
-    \lem[wit=A, alt={How nice... said}]{\enquote{How nice to find
-        you here!} he said.}
-    \note*{There are no quotation marks in the mss.}
+    \lem[wit=A, alt={How nice... said}]{\enquote{How nice to find+\label{ln:pj2:alt:b}+
+        you here!} he said.}+\label{ln:pj2:alt:e}+
+    \note*{There are no quotation marks in the mss.}+\label{ln:pj2:note1}+
     \rdg[wit=B, alt=\emph{om.}]{}}
   I chuckled to myself, recalling the last time we
   \app{
-    \lem[wit=A,nolem]{met}
-    \rdg[wit=B, alt={\emph{post} met \emph{add.} there}]{met
+    \lem[wit=A,nolem]{met}+\label{ln:pj2:nolem}+
+    \rdg[wit=B, alt={\emph{post} met \emph{add.} there}]{met+\label{ln:pj2:alt2}+
       there}
-    \note*{Ms. \getsiglum{B} provides other additions of this kind.}}.
+    \note*{Ms. \getsiglum{B} provides other additions of this kind.}}.+\label{ln:pj2:note2}+
 \end{ekdosis}
 \end{minted}
 % \iffalse
@@ -2141,18 +2212,22 @@ yesterday.
 % \end{alignment}
 %
 % \begin{remarks}
-% \item Close examination of lines~17--8 from \vref{lst:pj2} shows how
-%   |alt| has been used to insert an abridged lemma text in the
-%   apparatus criticus in print while keeping safe what is to be found
-%   in the \texttt{TEI xml} output.
-% \item The same technique has been used at line~24 to insert
-%   alternate words, including Latin technical terms, in place of the
-%   variant reading. Hence the use of |nolem| at line~23 to remove the
-%   lemma text from the apparatus criticus in print.
+% \item Close examination of lines~\ekdelide{%^^A
+%   \lnref{ln:pj2:alt:b}--\lnref{ln:pj2:alt:e}} from
+%   \vref{lst:pj2} shows how |alt| has been used to insert an abridged
+%   lemma text in the apparatus criticus in print while keeping safe
+%   what is to be found in the \texttt{TEI xml} output.
+% \item The same technique has been used at
+%   line~\lnref{ln:pj2:alt2} to insert alternate words,
+%   including Latin technical terms, in place of the variant
+%   reading. Hence the use of |nolem| at
+%   line~\lnref{ln:pj2:nolem} to remove the lemma text from the
+%   apparatus criticus in print.
 % \item \cs{note*} has been used to insert short annotations in two
-%   places (ll.~19 and 26).
+%   places (ll.~\lnref{ln:pj2:note1} and
+%   \lnref{ln:pj2:note2}).
 % \item For an example of the use of |nordg|, see below
-% \vref{lst:caesar-bg}, l.~11.
+% \vref{lst:caesar-bg}, l.~\lnref{ln:caes:nordg}.
 % \end{remarks}
 %
 % The corresponding \texttt{TEI xml} output produced by \pkg{ekdosis}
@@ -2404,46 +2479,53 @@ friend
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}{latex}
+\begin{minted}[escapeinside=++]{latex}
 % Witnesses:
-\DeclareWitness{V}{V}{\emph{Vaticanus Gr.} 276}
-\DeclareWitness{I}{I}{\emph{Parisinus Gr.} 2140}
+\DeclareWitness{V}{V}{\emph{Vaticanus Gr.} 276}+\label{ln:wsc:wit1}+
+\DeclareWitness{I}{I}{\emph{Parisinus Gr.} 2140}+\label{ln:wsc:wit2}+
 \DeclareHand{Iac}{I}{I\textsuperscript{ac}}[Lectio ante correctionem]
 \DeclareHand{Ipc}{I}{I\textsuperscript{pc}}[Lectio post correctionem]
-\DeclareWitness{R}{R}{\emph{Vaticanus Gr.} 277}
-\DeclareWitness{H}{H}{\emph{Parisinus Gr.} 2142}
+\DeclareWitness{R}{R}{\emph{Vaticanus Gr.} 277}+\label{ln:wsc:wit3}+
+\DeclareWitness{H}{H}{\emph{Parisinus Gr.} 2142}+\label{ln:wsc:wit4}+
 % Sources (the first arguments below must refer to biblatex labels and
 % an xml bibliographical database must be supplied):
-\DeclareSource{Lit}{Littré}
+\DeclareSource{Lit}{Littré}+\label{ln:wsc:src1}+
 \DeclareSource{Erm}{Ermerins}
-\DeclareSource{Sm}{Smith}
+\DeclareSource{Sm}{Smith}+\label{ln:wsc:src2}+
 % Persons:
 \DeclareScholar{ego}{ego}[
                 forename=Robert,
                 surname=Alessi]
 % Useful shorthands:
-\DeclareShorthand{codd}{codd.}{V,I,R,H}
+\DeclareShorthand{codd}{codd.}{V,I,R,H}+\label{ln:wsc:short1}+
 \DeclareShorthand{edd}{edd.}{Lit,Erm,Sm}
-\DeclareShorthand{egoscr}{\emph{scripsi}}{ego}
+\DeclareShorthand{egoscr}{\emph{scripsi}}{ego}+\label{ln:wsc:short2}+
 \end{minted}
 % \iffalse
 %</example>
 % \fi
 %
-% As can be seen from lines~18--20, three useful shorthands have been
-% defined: |codd| prints \enquote{codd.} for Latin pl.\ \emph{codices}
-% viz.\ \enquote{all manuscripts} and refers to the three \texttt{xml}
-% identifiers |V|, |I|, |R| and |H| declared at ll.~2--3 and 6--7;
+% As can be seen from lines~\ekdelide{%^^A
+% \lnref{ln:wsc:short1}--\lnref{ln:wsc:short2}},
+% three useful shorthands have been defined: |codd| prints
+% \enquote{codd.} for Latin pl.\ \emph{codices} viz.\ \enquote{all
+% manuscripts} and refers to the three \texttt{xml} identifiers |V|,
+% |I|, |R| and |H| declared at
+% ll.~\ekdelide{%^^A
+% \lnref{ln:wsc:wit1}--\lnref{ln:wsc:wit2}} and
+% \ekdelide{\lnref{ln:wsc:wit3}--\lnref{ln:wsc:wit4}};
 % |edd| prints \enquote{edd.} for Latin pl.\ \emph{editores} viz.\
 % \enquote{all editors} and refers to the three \texttt{xml}
 % identifiers |Lit|, |Erm| and |Sm| declared at
-% ll.~10--12;\footnote{For detailed information on how to use
-% \cs{DeclareSource} and insert references to cited works, the reader
-% is invited to refer to \vref{sec:references-cited-works}.} finally,
-% |egoscr| (l.~20) is used to print the technical Latin term
-% \enquote{\emph{scripsi}}, \enquote{I wrote}, to denote a personal
-% conjecture. Then, the |.tex| source file can be structured as
-% follows:---
+% ll.~\ekdelide{%^^A
+% \lnref{ln:wsc:src1}--\lnref{ln:wsc:src2}};%^^A
+% \footnote{For detailed information on how to use \cs{DeclareSource}
+% and insert references to cited works, the reader is invited to refer
+% to \vref{sec:references-cited-works}.} finally, |egoscr|
+% (l.~\lnref{ln:wsc:short2}) is used to print the technical
+% Latin term \enquote{\emph{scripsi}}, \enquote{I wrote}, to denote a
+% personal conjecture. Then, the |.tex| source file can be structured
+% as follows:---
 %
 % \iffalse
 %<*example>
@@ -2670,22 +2752,22 @@ friend
 % |type=emendation| to indicate that the lacuna has been accepted by
 % the editor.
 %
-% Examples follow:\footnote{On the use of \texttt{egomute} (l.~2), see
-% above \vref{it:egomute}.}---
+% Examples follow:\footnote{On the use of \texttt{egomute}
+% (l.~\lnref{ln:emend:egomute}), see above \vref{it:egomute}.}---
 %
 % \captof{Emendations, conjectures and
 % corrections}[\label{lst:emend-coni-corr}]
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}{latex}
+\begin{minted}[escapeinside=++]{latex}
 % Preamble:
-\DeclareShorthand{egomute}{\unskip}{ego}
+\DeclareShorthand{egomute}{\unskip}{ego}+\label{ln:emend:egomute}+
 
 % Document:
 \begin{ekdosis}
   σχεδὸν \app{
-    \lem[resp=egomute, nosep, post={post σχεδὸν quattuor uerba
+    \lem[resp=egomute, nosep, post={post σχεδὸν quattuor uerba+\label{ln:emend:nosep}+
       excidisse uid.}, type=emendation]{\supplied{\gap{reason=lost,
           unit=word, quantity=4}}}
   } οὗτοι
@@ -2701,9 +2783,9 @@ friend
   } ὑπογίνονται
 
   Πάντων δὲ \app{
-    \lem[resp=egomute, type=emendation, nosep]{\supplied{τῶν πυρετῶν}}
+    \lem[resp=egomute, type=emendation, nosep]{\supplied{τῶν πυρετῶν}}+\label{ln:emend:sep:b}+
     \note[sep]{addidi (\arb{^gamI`a 'l-.hummayAti}
-      \getsiglum{Gal})}
+      \getsiglum{Gal})}+\label{ln:emend:sep:e}+
     \rdg[nordg, source=Gal]{\arb{al-.hummayAti}}
     \rdg[wit=codd, source=edd, alt=om.]{}
   },
@@ -2792,6 +2874,145 @@ friend
 %</example>
 % \fi
 %
+% \section[Lacunae]{\newfeature[v1.5]Lacunae}
+% \label{sec:lacunae}
+% The term \enquote{lacuna} is used here to indicate a series of words
+% or phrases that are missing from one or more witnesses in the
+% manuscript tradition. When the lacuna is limited to just a few
+% words, it may fill an entire entry of the apparatus criticus,
+% especially when the other witnesses do not provide variants on this
+% span of text.
+%
+% On the other hand, when the lacuna is longer, or includes variants,
+% or crosses a verse, paragraph or section boundary, it is usually not
+% desirable to break it into pieces. The recommended method of
+% encoding is therefore to record explicitly where the lacuna begins
+% and where it ends. However, in well-written apparatus criticus,
+% these two items of information must be provided only in the first
+% entry. Moreover, the line numbering of this entry and the
+% abbreviated lemma must make clear where the lacuna ends. As a
+% consequence, the apparatus in print is silent at the place where the
+% lacuna ends, unlike the \texttt{TEI xml} code which must be explicit
+% at both places.
+%
+% \DescribeMacro{\lacunaStart}\DescribeMacro{\lacunaEnd}
+% \cs{lacunaStart}\oarg{opt} and \cs{lacunaEnd}\oarg{opt} are used in
+% the mandatory argument of the \cs{rdg} command to indicate the
+% beginning and the end of the lacuna. The optional argument of these
+% commands can be used to specify which witnesses are affected by the
+% lacuna, as follows:---\\
+% \DescribeOption{wit} |wit|$=$\meta{csv list of witnesses}\\
+% This option is described above \vpageref{ref:lem-wit}. Of course, it
+% is unnecessary to use it in the case where only one witness in
+% involved in the variant reading that supply the information on the
+% lacuna.
+%
+% \DescribeMacro{\ilabel} \phts\label{ref:ilabel-cmd}
+% \cs{ilabel}\marg{indexed label} is used to recall the indexed label
+% set by means of the |ilabel| optional argument of the \cs{lem}
+% command as described above \vpageref{ref:ilabel-opt}. This command
+% is used to compute the line number where the lacuna ends and must be
+% inserted precisely at this place, supposedly outside the group
+% formed by the \cs{app} command used to print the information on the
+% lacuna in the apparatus criticus.
+%
+% This technique is demonstrated by the following example taken from
+% Cicero's \emph{Letters to Atticus}, VII,
+% 9.4:\footnote{\cite[121.13--15]{CiceroAtt}. English translation:
+% \cite[51]{CiceroAttTr}.}---
+%
+% \captof{Cicero, \emph{ad Atticum epistulae}, VII,
+% 9.4}[\label{lst:cic-att}]
+% \iffalse
+%<*example>
+% \fi
+\begin{minted}[linenos,escapeinside=++]{latex}
+\begin{alignment}
+  \begin{edition}
+    Praeteriit tempus non legis, \app{
+      \lem[wit={C}, ilabel={sed7.9.4.14}, alt={sed\===legis}]{sed}+\label{ln:lac:ilabel:opt}+
+      \rdg[wit={Ω}, alt=\emph{om.}]{\lacunaStart}+\label{ln:lac:lstart}+
+    } libidinis tuae, fac tamen \app{
+      \lem[Nolem, wit={C}]{legis\ilabel{sed7.9.4.14}}+\label{ln:lac:ilabel:cmd}+
+      \rdg[nordg, wit={Ω}]{\lacunaEnd}}; ut succedatur+\label{ln:lac:lend}+
+    decernitur; impedis et ais: \enquote{habe meam rationem.}
+  \end{edition}
+  \begin{translation}
+    This term, not a legal term, but a term of your own will and
+    pleasure\===or say, this legal term\===comes to an end. The House
+    passes a decree for the appointment of a successor. You object and
+    cry, \enquote{Consider my candidature.}
+  \end{translation}
+\end{alignment}
+\end{minted}
+% \iffalse
+%</example>
+% \fi
+%
+% \begin{remarks}
+% \item At line~\lnref{ln:lac:ilabel:opt}, from the |ilabel| optional
+%   argument, \pkg{ekdosis} knows that the span of text affected by
+%   the lacuna does not end after \emph{sed}, but after \emph{legis}
+%   (l.~\lnref{ln:lac:ilabel:cmd}), at the place where the indexed label
+%   is recalled by \cs{ilabel}. So line numbers are computed
+%   accordingly in the apparatus criticus.
+% \item The starting and ending points of the lacuna from which the
+%   \sg{Ω} family suffers have been marked by \cs{lacunaStart} and
+%   \cs{lacunaEnd} respectively (ll.~\lnref{ln:lac:lstart} and
+%   \lnref{ln:lac:lend}).
+% \item Line~\lnref{ln:lac:lend} shows that \emph{legis}
+%   (l.~\lnref{ln:lac:ilabel:cmd}) does not appear in the \sg{Ω}
+%   family. This is where the lacuna ends. Furthermore, as no other
+%   witnesses are mentioned in the \cs{rdg} command
+%   (l.~\lnref{ln:lac:lend}), using the |wit| optional argument of
+%   \cs{lacunaEnd} would introduce an unnecessary redundancy.
+% \end{remarks}
+%
+% PDF output:---\nobreak\medskip
+% \resetlinenumber
+% \begin{alignment}[flush,lcols=2]
+%   \begin{edition}
+%     Praeteriit tempus non legis, \app{
+%     \lem[wit={cicC}, ilabel={sed7.9.4.14}, alt={sed\===legis}]{sed}
+%     \rdg[wit={cicΩ}, alt=\emph{om.}]{\lacunaStart}
+%   } libidinis tuae, fac tamen \app{
+%     \lem[Nolem, wit={cicC}]{legis\ilabel{sed7.9.4.14}}
+%     \rdg[nordg, wit={cicΩ}]{\lacunaEnd}}; ut succedatur
+%     decernitur; impedis et ais: \enquote{habe meam rationem.}
+%   \end{edition}
+%   \begin{translation}
+%     This term, not a legal term, but a term of your own will and
+%     pleasure\===or say, this legal term\===comes to an end. The
+%     House passes a decree for the appointment of a successor. You
+%     object and cry, \enquote{Consider my candidature.}
+%   \end{translation}
+% \end{alignment}
+%
+% \medskip
+% \nobreak \texttt{TEI xml} output (Latin only):---
+% \iffalse
+%<*example>
+% \fi
+\begin{minted}[linenos]{xml}
+<p>Praeteriit tempus non legis, 
+<app>
+  <lem wit="#C">sed</lem>
+  <rdg wit="#Ω">
+    <lacunaStart />
+  </rdg>
+</app>libidinis tuae, fac tamen 
+<app>
+  <lem wit="#C">legis</lem>
+  <rdg wit="#Ω">
+    <lacunaEnd />
+  </rdg>
+</app>; ut succedatur decernitur; impedis et ais: 
+<quote>habe meam rationem.</quote></p>
+\end{minted}
+% \iffalse
+%</example>
+% \fi
+%
 % \section{Alignment of Parallel Texts}
 % \label{sec:alignment-basic}
 % As already said above,\footnote{See point
@@ -2874,17 +3095,17 @@ friend
 % \vref{sec:caesar-gw-tex} and \texttt{TEI xml} output in
 % \vref{sec:caesar-gw-tei}. The corresponding PDF output is available
 % in \href{samples/Caesar_BG-6-13-1.pdf}{a separate file}:\footnote{On
-% the use of \cs{ekddiv} (ll.~3 and 20), see below
-% \vref{sec:ekddiv}.}---
+% the use of \cs{ekddiv} (ll.~\lnref{ln:caes:div1} and
+% \lnref{ln:caes:div2}), see below \vref{sec:ekddiv}.}---
 %
 % \captof{Caesar's \emph{Gallic War}, VI, 13.1}[\label{lst:caesar-bg}]
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}{latex}
+\begin{minted}[escapeinside=++]{latex}
 \begin{alignment}
   \begin{edition}
-    \ekddiv{head=XIII, depth=2, n=6.13, type=section}
+    \ekddiv{head=XIII, depth=2, n=6.13, type=section}+\label{ln:caes:div1}+
     In omni Gallia eorum hominum qui \app{
       \lem[wit=a]{aliquo}
       \rdg[wit=b, alt=in al-]{in aliquo}}
@@ -2892,7 +3113,7 @@ friend
     seruorum habetur loco, quae \app{
       \lem[wit={A,M}, alt={nihil audet (aut et \getsiglum{A1})
         per se}]{nihil audet per se}
-      \rdg[wit=A1,nordg]{nihil aut et per se}
+      \rdg[wit=A1,nordg]{nihil aut et per se}+\label{ln:caes:nordg}+
       \rdg[wit={R,S,L,N}]{nihil habet per se}
       \rdg[wit=b]{per se nihil audet}}, \app{
       \lem[wit=a]{nullo}
@@ -2901,7 +3122,7 @@ friend
       \rdg[wit={T, U}, alt=conc-]{concilio}}.
   \end{edition}
   \begin{translation}
-    \ekddiv{head=XIII, depth=2, n=6.13, type=section}
+    \ekddiv{head=XIII, depth=2, n=6.13, type=section}+\label{ln:caes:div2}+
       Throughout all Gaul there are two orders of those men who are of
       any rank and dignity: for the commonality is held almost in the
       condition of slaves, and dares to undertake nothing of itself,
@@ -3715,7 +3936,7 @@ texts=latin[xml:lang="la"]+\textcolor{red}{;}+
 % \iffalse
 %<*example>
 % \fi
-\begin{minted}[numbersep=6pt]{latex}
+\begin{minted}[numbersep=-.5\linewidth]{latex}
 \SetHooks{
   refnumstyle=\normalfont,
   initialrule=\rule{0.7in}{0.4pt}
@@ -3748,7 +3969,7 @@ texts=latin[xml:lang="la"]+\textcolor{red}{;}+
 %
 % \paragraph{Limiting the Number of Entries per Page}
 % \phts\label{ref:maxentries}
-% In some instances, it can be useful to set a limit to the number of
+% In some instances, it may be useful to set a limit to the number of
 % entries per page that a given layer of critical notes may accept,
 % notably when entries are so abundant in number that \pkg{ekdosis}
 % may oscillate indefinitely between different sets of page decisions
@@ -6449,6 +6670,45 @@ Sample text with a \textcolor{red}{word} in red.
 %</example>
 % \fi
 %
+% \paragraph{Inserting \texttt{xml:id}\emph{s} in \texttt{TEI} Patterns}
+% \DescribeMacro{\getTEIxmlid} \newfeature[v1.5] In some instances, it
+% may be useful to retrieve the |xml| formatted pointers corresponding
+% to unique identifiers declared in commands such as
+% \cs{DeclareWitness}\footnote{See above
+% \vpageref{ref:declarewitness}.} and the like so as to insert them in
+% the second argument\===\meta{TEI pattern}\===of \cs{TeXtoTEIPat}. As
+% an illustration, what follows creates a new \LaTeX\ command
+% \cs{witStart} which prints nothing in the PDF ouput but inserts
+% |<witStart/>| elements in the \texttt{TEI xml} file. This commands
+% accepts an optional argument to make clear which are the fragmentary
+% witnesses involved:---
+%
+% \iffalse
+%<*example>
+% \fi
+\begin{minted}[escapeinside=++]{latex}
+\NewDocumentCommand{\witStart}{O{}}{\ignorespaces}
+\TeXtoTEIPat{\witStart [wit=@b1]}{<witStart wit="\getTEIxmlid{@b1}"/>}+\label{ln:getxml:a}+
+\TeXtoTEI{witStart}{witStart}
+\end{minted}
+% \iffalse
+%</example>
+% \fi
+%
+% \begin{remarks}
+% \item On the use of \cs{NewDocumentCommand} to create new commands,
+% the reader is invited to refer to the documentation of the
+% \pkg{xparse} package.\footcite{xparse}
+% \item As can be seen from l.~\lnref{ln:getxml:a}, \cs{getTEIxmlid}
+%   is used to process the csv-list of unique identifiers that matches
+%   the string captured between the braces after |wit=|, as implied by
+%   |@b1|. As a consequence, \cs{witStart}|[]| is expected as follows:
+%   \mintinline{latex}|\witStart[wit={X,Y}]|. Braces must exist for
+%   pattern matching.
+% \item Finally, |\TeXtoTEI{witStart}{witStart}| is used so that the
+%   argument-less form of the command can be processed as well.
+% \end{remarks}
+% 
 % \subsection{Inserting Code in the \texttt{TEI xml} Ouput File}
 % \label{sec:inserting-code-tei}
 % It may be needed to insert code in the \texttt{TEI xml} output file
@@ -6464,8 +6724,17 @@ Sample text with a \textcolor{red}{word} in red.
 % \texttt{TEI xml} element followed by the contents to be found in the
 % ouput file between the opening and closing tags. Additionally,
 % attribute-value pairs to be found inside the start-tag of the
-% element can be specified in the optional argument of the command. An
-% example follows:
+% element can be specified in the optional argument of the command.
+%
+% \DescribeMacro{\teidirectE} \newfeature[v1.5]
+% \cs{teidirectE}\oarg{xml attributes}\marg{xml element}\\
+% \cs{teidirectE}\===where |E| stands for \enquote{\underLine{e}mpty
+% element}\===is strictly equivalent to
+% \cs{teidirect}\allowbreak\oarg{xml attributes}\marg{xml
+% element}|{}|. Compared to the latter command, it only eliminates the
+% need to insert the ending pair of empty braces.
+%
+% An example follows:
 % 
 % \iffalse
 %<*example>
@@ -7605,7 +7874,10 @@ Sample text with a \textcolor{red}{word} in red.
 %
 % \section{References}
 % \label{sec:references}
-% \printbibliography[heading=none]
+% \subsection*{Texts Used}
+% \printbibliography[heading=none, subtype=primary]
+% \subsection*{References}
+% \printbibliography[heading=none, notsubtype=primary]
 %
 % \section{Sample: C. J. Caesar, \emph{Gallic War},
 %           VI, XIII.1}
@@ -7791,7 +8063,7 @@ Sample text with a \textcolor{red}{word} in red.
 %    \end{macrocode}
 % \paragraph{\textsf{ekdosis} Symbol}
 % \begin{macro}{\eKd}
-% \changes{v1.5}{2022/01/05}{Prints \textsf{ekdosis} indentifying
+% \changes{v1.5}{2022/01/15}{Prints \textsf{ekdosis} indentifying
 % symbol} As of v1.5, \pkg{ekdosis} has its own identifying
 % symbol. It is produced by \cs{eKd} and best printed with the Old
 % Standard Greek font.
@@ -8049,13 +8321,33 @@ Sample text with a \textcolor{red}{word} in red.
 %    \end{macrocode}
 % \end{macro}
 % \begin{macro}{\teidirect}
+% \begin{macro}{\teidirectE}
 % \changes{v1.3}{2021/08/18}{direct insertion of elements in the
 % \texttt{TEI xml} file}
+% \changes{v1.5}{2022/01/15}{direct insertion of empty elements in the
+% \texttt{TEI xml} file}
 % \cs{teidirect}\oarg{xml attributes}\marg{xml element}\marg{code}
-% does nothing in \LaTeX. Its only use is to insert elements in the
-% \texttt{TEI xml} output file.
+% does nothing in \LaTeX. It is only used to insert elements in the
+% \texttt{TEI xml} output file. \cs{teidirectE}\oarg{xml
+% attributes}\marg{xml element} is strictly equivalent to
+% \cs{teidirect}\oarg{xml attributes}\marg{xml element}|{}| and can be
+% used to insert empty \texttt{TEI} elements.
+%    \begin{macrocode}
+\NewDocumentCommand{\teidirect}{O{} m m}{\ignorespaces}
+\NewDocumentCommand{\teidirectE}{O{} m}{\ignorespaces}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\getTEIxmlid}
+% \changes{v1.5}{2022/01/15}{returns \texttt{TEI xml:ids} from a
+% csv-list of ids} This command returns from a csv-list of unique
+% identifiers declared in commands such as \cs{DeclareWitness} and the
+% like a space-separated list of their corresponding |xml:id|s, each
+% preceded by the octothorpe (the |#| sign). 
 %    \begin{macrocode}
-\NewDocumentCommand{\teidirect}{O{}mm}{\ignorespaces}
+\NewDocumentCommand{\getTEIxmlid}{m}{%
+  \luadirect{tex.sprint(ekdosis.getsiglum(\luastringN{#1}, "TEI"))}%
+}
 %    \end{macrocode}
 % \end{macro}
 % \begin{macro}{\EnvtoTEI}
@@ -8612,11 +8904,21 @@ Sample text with a \textcolor{red}{word} in red.
 % while \cs{append@ln@app} inserts a (sub)entry possibly preceded by a
 % line number.
 %    \begin{macrocode}
-\NewDocumentCommand{\append@ln@app}{o +m}{%
-  \IfNoValueTF{#1}
-  {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#2}))}}
-  {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#2},
-      \luastringO{#1}))}}}
+\NewDocumentCommand{\append@ln@app}{o o +m}{%
+  \IfNoValueTF{#2}
+  {\IfNoValueTF{#1}
+    {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#3}))}}
+    {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#3},
+        \luastringO{#1}))}}%
+  }
+  {\IfNoValueTF{#1}
+    {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#3}, nil,
+      \luastringO{#2}))}}
+  {\luadirect{tex.sprint(ekdosis.mdvappend(\luastringO{#3},
+      \luastringO{#1},
+      \luastringO{#2}))}}%
+  }%
+}
 %    \end{macrocode}
 % \paragraph{Lineation Settings}
 % \begin{macro}{\outerlinenumbers}
@@ -8980,6 +9282,7 @@ Sample text with a \textcolor{red}{word} in red.
 %    \begin{macrocode}
 \newif\ifekdl@forcenum
 \newif\ifekdl@nonum
+\newif\ifekdl@ilabel
 \ekvdefinekeys{lem}{
   code wit = \def\ekdlr@wit{#1},
   code source = \def\ekdlr@source{#1},
@@ -8989,12 +9292,14 @@ Sample text with a \textcolor{red}{word} in red.
   code post = \def\ekdlr@post{#1},
   code prewit = \def\ekdlr@prewit{#1},
   code postwit = \def\ekdlr@postwit{#1},
+  code ilabel = \ekdl@ilabeltrue\def\ilabel@val{#1},
   store type = \ekdlr@type,
   store sep = \ekdl@sep,
   noval nonum = \ekdl@nonumtrue,
   noval num = \ekdl@forcenumtrue,
   bool nodelim = \ifekdl@nodelim,
   bool nolem = \ifekdl@nolem,
+  nmeta Nolem = {nodelim, nonum, nolem},
   bool nosep = \ifekdl@nosep,
   initial sep = \ekdsep
 }
@@ -9059,12 +9364,18 @@ Sample text with a \textcolor{red}{word} in red.
 %    \begin{macrocode}
 \NewDocumentCommand{\lem}{O{} m}{%
   \ekd@isinlemtrue
-  \luadirect{ekdosis.dolnlab(\luastringN{#2})}%
-  \null
-  \bgroup%
+  \bgroup
   \ekdl@forcenumfalse
   \ekdl@nonumfalse
+  \ekdl@ilabelfalse
   \ekvset{lem}{#1}%
+  \ifekdl@ilabel
+  \luadirect{ekdosis.dolnlab(\luastringN{#2},
+    \luastringO{\ilabel@val})}%
+  \else
+  \luadirect{ekdosis.dolnlab(\luastringN{#2})}%
+  \fi
+  \null
   \ekd@test@lang
   \ifekd@mapps%
     \ifnum%
@@ -9176,11 +9487,19 @@ Sample text with a \textcolor{red}{word} in red.
       \ifekdl@nosep\else\unexpanded\expandafter{\ekdl@sep}\fi
     }%
   }%
-  \fi%
-  \ifekd@mapps%
-  \append@ln@app[\ekdan@type]{\lem@app}%
-  \else%
-  \append@ln@app{\lem@app}%
+  \fi
+  \ifekd@mapps
+    \ifekdl@ilabel
+      \append@ln@app[\ekdan@type][\ilabel@val]{\lem@app}%
+    \else
+      \append@ln@app[\ekdan@type]{\lem@app}%
+    \fi
+  \else
+    \ifekdl@ilabel
+      \append@ln@app[][\ilabel@val]{\lem@app}
+    \else
+      \append@ln@app{\lem@app}%
+    \fi
   \fi%
   \egroup%
   \ekd@isinlemfalse%
@@ -9594,6 +9913,30 @@ Sample text with a \textcolor{red}{word} in red.
 }
 %    \end{macrocode}
 % \end{macro}
+% \paragraph{Lacunae}
+% \begin{macro}{\ilabel}
+% \changes{v1.5}{2022/01/15}{recalls and sets the ending label of
+% lemmas used to mark lacunae in witnesses} When \cs{lem} has been
+% used with the optional argument |ilabel=<label>|,
+% \cs{ilabel}\marg{label} must be used to mark the point where the
+% span of text corresponding to the abbreviated lemma ends. This
+% command is used to set the ending line number of physical lacunae in
+% the apparatus criticus.
+%    \begin{macrocode}
+\NewDocumentCommand{\ilabel}{m}{%
+  \luadirect{tex.sprint(ekdosis.getindexedlab(\luastringN{#1}))}%
+}
+%    \end{macrocode}
+% \end{macro}
+% \begin{macro}{\lacunaStart}
+% \begin{macro}{\lacunaEnd}
+%    \begin{macrocode}
+\NewDocumentCommand{\lacunaStart}{O{}}{\ignorespaces}
+\NewDocumentCommand{\lacunaEnd}{O{}}{\ignorespaces}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \paragraph{Apparatus Criticus}
 % \cs{apparatus} is used internally by \pkg{ekdosis} to print the
 % apparatus at the bottom of pages. Therefore, it is not documented,
 % but this may change in the future for it will be possible to have
@@ -10157,6 +10500,14 @@ Sample text with a \textcolor{red}{word} in red.
 \def\ekdunspace{\hskip-\ekdspace}
 %    \end{macrocode}
 % \end{macro}
+% \subsection*{Errors and Warnings}
+%    \begin{macrocode}
+\def\ekd@wrong@ilabel{
+  \PackageError{ekdosis}%
+  {Unknown ``ilabel'' in \string\ilabel{}}%
+  {Please check for an ``ilabel'' that exists.}
+}
+%    \end{macrocode}
 % \paragraph{Configuration File} Finally, if a configuration file
 % named |\jobname-ekd.cfg| can be found, this file is read and its
 % contents loaded into the document preamble. This provides a
@@ -10165,6 +10516,7 @@ Sample text with a \textcolor{red}{word} in red.
 %    \begin{macrocode}
 \IfFileExists{\jobname-ekd.cfg}{\input{\jobname-ekd.cfg}}{}
 %    \end{macrocode}
+%
 % \iffalse
 %</package>
 % \fi
@@ -10242,10 +10594,11 @@ local citecmds = lpeg.Cs(lpeg.P("icite")
 			    + lpeg.P("autocite")
 			    + lpeg.P("Autocite")
 			    + lpeg.P("autocite *")
-			    + lpeg.P("Autocite *")
-)
+			    + lpeg.P("Autocite *"))
+
 --
 -- Bind to local variables
+--
 local next = next
 
 -- General
@@ -10600,6 +10953,8 @@ local texpatttotags = {
    {a="\\indentpattern%s+{(.-)}", b=""},
    {a="\\ekdnohfmark%s+", b=""},
    {a="\\settowidth%s+{(.-)}{(.-)}", b=""},
+   {a="\\teidirectE%s+(%b[]){(.-)}", b="<%2 ekd@os%1ekd@cs/>"},
+   {a="\\teidirectE%s+{(.-)}", b="<%1/>"},
    {a="\\poemlines%s+{(.-)}", b=""},
    {a="\\pagebreak%s+%[[1-4]%]", b=""},
    {a="\\pagebreak%s+", b=""},
@@ -10607,6 +10962,7 @@ local texpatttotags = {
    {a="\\teidirect%s+{(.-)}(%b{})", b="<%1>ekd@ob%2ekd@cb</%1>"},
    {a="\\altrfont%s+", b=""},
    {a="\\endmark%s+", b=""},
+   {a="\\ilabel%s+(%b{})", b=""},
    {a="\\unskip%s+", b=""},
    {a="\\ekdpb%s+%*?%[(.-)%]{(.-)}", b=""},
    {a="\\ekdpb%s+%*?{(.-)}", b=""},
@@ -11095,8 +11451,42 @@ local function cmdtotei(str)
       end)
    end
    -- temporarily:
-   str = string.gsub(str, "\\(getsiglum)%s?(%b{})",
+   -- lacunae
+   str = gsub(str,
+	      spcenc^-1 *
+	      dblbkslash *
+		 lpeg.Cs(lpeg.P("lacunaStart") + lpeg.P("lacunaEnd")) *
+		 spcenc^-1 *
+		 bsqbrackets^-1 *
+		 spcenc^-1,
+		 function(bkslash, cmd, opt)
+		    if opt == nil
+		    then
+		       return string.format("<%s/>", cmd)
+		    else
+		       opt = string.sub(opt, 2, -2)
+		       teiwit = get_attr_value(opt, "wit")
+		       if teiwit ~= "" then teiwit = " wit=\""..ekdosis.getsiglum(teiwit, "tei").."\"" else end
+		       teisource = get_attr_value(opt, "source")
+		       if teisource ~= "" then teisource = " source=\""..ekdosis.getsiglum(teisource, "tei").."\"" else end
+		       if opt == ""
+		       then
+			  return string.format("<%s></%s>", cmd, cmd)
+		       else
+			  return string.format("<%s%s%s></%s>",
+					       cmd, teiwit, teisource, cmd)
+		       end
+		    end
+   end)
+   str = string.gsub(str, "\\(getTEIxmlid)%s?(%b{})",
 		     function(cmd, body)
+			body = string.sub(body, 2, -2)
+			teisiglum = ekdosis.getsiglum(body, "tei")
+ 			-- body = cmdtotei(body)
+			return string.format("%s", teisiglum)
+   end)
+   str = string.gsub(str, "\\(getsiglum)%s?(%b[])(%b{})",
+		     function(cmd, opt, body)
 			body = string.sub(body, 2, -2)
 			teisiglum = ekdosis.getsiglum(body, "tei")
  			printsiglum = ekdosis.getsiglum(body)
@@ -12469,6 +12859,7 @@ local lnlab_salt = 0
 local current_lnlab = nil
 local prev_lnlab = nil
 local prev_prev_lnlab = nil
+local indexed_labs = {}
 local notelabs = {}
 local current_notelab = nil
 local prev_notelab = nil
@@ -12482,16 +12873,24 @@ local function mdvisintable(table, value)
    return false
 end
 
-function ekdosis.dolnlab(str)
+function ekdosis.dolnlab(str, indexlab)
    if prev_lnlab ~= nil then prev_prev_lnlab = prev_lnlab end
    prev_lnlab = current_lnlab
    current_lemma = str
    i = md5.sumhexa(str)
    if not mdvisintable(lnlabs, i) then
       table.insert(lnlabs, i)
+      if indexlab ~= nil
+      then
+	 indexed_labs[indexlab] = i
+      end
    else
       i = i..salt
       table.insert(lnlabs, i)
+      if indexlab ~= nil
+      then
+	 indexed_labs[indexlab] = i
+      end
       salt = salt + 1
    end
    current_lnlab = i
@@ -12510,6 +12909,14 @@ function ekdosis.getprevprevlnlab()
    return prev_prev_lnlab
 end
 
+function ekdosis.getindexedlab(str)
+   if indexed_labs[str] == nil
+   then return "\\csname ekd@wrong@ilabel\\endcsname"
+   else
+      return "\\linelabel{" .. indexed_labs[str] .. "-e}"
+   end
+end
+
 function ekdosis.setnotelab(str)
    current_notelab = str
    if isfound(notelabs, current_notelab)
@@ -12535,38 +12942,45 @@ function ekdosis.getprevnotelab()
 end
 
 local cmdstorm = lpeg.P(lpeg.P("note")
-			   + lpeg.P("linelabel")
-			   + lpeg.P("index"))
+			+ lpeg.P("linelabel")
+			+ lpeg.P("ilabel")
+			+ lpeg.P("index"))
 
 local function remove_from_app(str)
    str = gsub(str, dblbkslash * cmdstorm * cmdargs, "")
    return str
 end
 
-function ekdosis.mdvappend(str, teitype)
+function ekdosis.mdvappend(str, teitype, ilabel)
    if current_lemma == ""
    then
       current_lemma = "\\ekdunspace"
    end
+   local labelbegin = "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
+   local labelend = "\\linelabel{" .. current_lnlab .. "-e}"
+   if ilabel ~= nil
+   then
+      labelend = ""
+   end
    if teitype == nil
    then
-   return "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
-      ..
-      current_lemma
-      ..
-      "\\linelabel{" .. current_lnlab .. "-e}"
-      ..
-      "\\csname append@app\\endcsname{"
-      .. remove_from_app(str) .. "}"
+      return labelbegin
+	 ..
+	 current_lemma
+	 ..
+	 labelend
+	 ..
+	 "\\csname append@app\\endcsname{"
+	 .. remove_from_app(str) .. "}"
    else
-   return "\\linelabel{" .. current_lnlab .. "-b}\\wordboundary{}"
-      ..
-      current_lemma
-      ..
-      "\\linelabel{" .. current_lnlab .. "-e}"
-      ..
-      "\\csname append@app\\endcsname" .. "[" .. teitype ..  "]{"
-      .. remove_from_app(str) .. "}"
+      return labelbegin
+	 ..
+	 current_lemma
+	 ..
+	 labelend
+	 ..
+	 "\\csname append@app\\endcsname" .. "[" .. teitype ..  "]{"
+	 .. remove_from_app(str) .. "}"
    end
 end
 
-- 
cgit v1.2.3

