%%% Preliminary declarations %%%
% Setup of fonts
% Using a versatile serif font available on Mac OSX Monterey 12.7.6 for main text
% Adjusting Greek font to use DejaVu Serif, or any font available as requested
\definefontfamily[mainface][rm][TexGyre Pagella]  % Using Palatino as it is aesthetically more suitable for academic work
\definefallbackfamily[mainface][rm][IFAOgrecunicode][range={greekandcoptic, greekextended}, force=yes, rscale=auto]
\setupbodyfont[mainface, 9pt]

% Page layout to avoid unnecessary blank pages and set specific margins
\setuplayout[backspace=20mm, topspace=20mm, header=10mm, footer=40mm, width=middle, height=middle]

% Page numbering setup
\setuppagenumbering[alternative=doublesided, location={header,inmargin}, start=1, state=start]

% Bibliography setup
\usebtxdataset[biblio][biblio.bib]
\usebtxdefinitions[apa]
\definebtxrendering[default][apa][dataset=biblio]
\setupbtxrendering[default][continue=yes]

% Setup footnotes for regular notes and lemma variants
\setupnotation[footnote][numbercommand=\relax]
\setupfootnotedefinition[location=serried, before={\hangindent=.5pc \hangafter=1}]


% Define linenotes for lemma variants by group
% Improved solution for handling large number of variants by using numbering rather than alphabetic labels

\definelinenote[variant]
\setuplinenote[variant][rule=on, location=bottom, paragraph=yes, inbetween={\hskip 1em}]

% Define lemma and reading commands using linenote for variants by group
 %\def\lemma#1{\variant{\emph{Lemme:}\kern0.4em #1}}
 % \def\reading#1#2{\variant{Variante (#1):\kern0.4em #2}}

% Define lemma and reading commands using linenote for variants by group
%\def\lemma#1{\variant{\emph{Lemme:}\kern0.5em\hskip0.3em #1}}
% \def\reading#1#2{\variant{Variante (#1):\kern0.5em\hskip0.3em #2}}

\def\lemma#1{\variant{\hbox{\emph{Lemme:}\kern0.5em #1}}}
\def\reading#1#2{\variant{\hbox{Variante (#1):\kern0.5em #2}}}



\starttext

% Title and author
\startalignment[middle]
    {\bf Ekdosis environment in \LaTeX  adapted to \ConTeXt : A Test Example} \blank[medium]
    {\emph{Jean-Pierre Delange}} \blank[medium]
    {\bf Adapted from a work in \LaTeX by Octavie Hans, CNRS, Centre Jean Pépin}\footnote{O. Hans, Stage avec EcdoTech juin 2023, \goto{Centre Jean Pépin CNRS–ENS-PSL UMR8230}[url(https://umr8230.cnrs.fr/)].} \blank[medium]
    {October 2024} \blank[medium]
\stopalignment

{\bf Summary} \blank[medium]
{\emph{When editing ancient texts, the question of lemmatization arises, along with manuscript variants. This involves displaying at the foot of the all the “lessons” and variants of a given text in various manuscripts. This is how a CNRS research team in France came up with the “EKDOSIS” environment for \LaTeX. The aim of the present work is to produce the equivalent of “EKDOSIS” with \ConTeXt.}} \blank[medium]
{\emph{Problem}: lemmatization is a headache for editors trying to account for variants in a manuscript. \ConTeXt lets you define complex environments using built-in macros. Here, in a simple example, we aim to display the analysis work known as lemmatization (i.e. the variants and lessons of the same text from different sources) at the bottom of the page (footer).}\blank[medium]
{\emph{Solution}: The technique explored is based on several types of declarations, such as definedescription[lem] and setupdescription, definelinenote, and definition of lemma. Below is a functional code that enables clean output in PDF format.}

\page[yes]
% Sigla and sources section

\startalignment[middle]
    {\bf Sigla and sources}
\stopalignment

% Cadre pour la tabulation des données
\startframed[frame=off, width=\textwidth]

% Mise en place de la tabulation avec trois colonnes
\starttabulate[|l|l|r|]

% Première colonne (Gauche), colonne du milieu avec les rubriques, et troisième colonne (Droite)

\NC  \NC {\em Ambrosianus} \NC \NR
\NC A \NC Biblioteca Ambrosiana E 147 sup. \NC \NR
\NC \NC M\high{1} \NC Prima manus \NR
\NC \NC M\high{2} \NC Seconda manus \NR
\NC \NC \NC \NR
 \NC \NC {\em Ancient authors} \NC  \NR
 \NC \NC \NC \NR
 \NC {\em Arusianus} \NC Arusianus \NC \NR
\NC {\em Eugraphius} \NC Eugraphius \NC \NR
\NC {\em Eutyches} \NC Euthyches \NC \NR
\NC  {\em Macrobius} \NC Macrobius  \NC \NR
\NC  {\em Priscianus} \NC Priscianus \NC \NR
\NC {\em codd. Sall.} \NC Sallustius \NC (manuscripts)\NR
\NC {\em Servius} \NC Servius \NC \NR
\NC {\em edd. Homer} \NC Homer\NC (editions) \NR
\NC \NC \NC \NR
\NC \NC {\em Editors}  \NC \NR
\NC \NC \NC \NR
\NC {\em Ahlberg} \NC Ahlberg \NC  {\em edition Sall.}\NR
\NC {\em della Corte} \NC della Corte \NC \NR
\NC {\em Haines} \NC Haines \NC ed. 1919-1920\NR
\NC {\em Hauler} \NC Hauler \NC \NR
\NC {\em Klussmann} \NC Klussmann\NC \NR
\NC {\em Mai{\high{1}}}\NC Mai\NC  {\em ed. princeps 1815}\NR
\NC {\em Naber}\NC Naber \NC {\em ed. 1867}\NR
\NC {\em Niebuhr} \NC Niebuhr \NC \NR
\NC {\em Orth}  \NC Orth\NC \NR
\NC  {\em Schwierczina} \NC Schwierczina  \NC \NR
\NC \NC \NC \NR
\NC \NC {\em Abbreviations} \NC  \NR
\NC \NC \NC \NR
\NC cod./codd. \NC {\em codex/coddices}\NC \NR
\NC a.c. \NC {\em  ante correctionem} \NC \NR
\NC del.\NC  {\em deleuit}  \NC \NR
\NC  ed./edd.\NC {\em  edition/editiones} \NC \NR
 \NC ras. \NC {\em in rasura}\NC \NR
 \NC lac. \NC {\em lacuna} \NC \NR
  \NC litt. \NC {\em litterae} \NC \NR
  \NC mg. \NC {\em in margine} \NC \NR
  \NC suppl. \NC {\em supplevit} \NC \NR

\stoptabulate
\stopframed
\page[yes]

% Begin main text
\startalignment[middle]
    \bgroup\tfa <CAESARI SVO FRONTO>\egroup\footnote{Ad M. I, 1}
\stopalignment

\blank[big]
\setuplinenumbering[step=1]
\startlinenumbering
% Latin text with Apparatus Criticus
\startnarrower[left]
\language[la]{
mittam\lemma{mittam}\reading{{\emph della Corte}}{<celerrime> mittam} \reading{{\emph Niebuhr}}{pote <celerrime>} igitur tibi quantum pote librum hunc descriptum.\par
Vale, Caesar, et ride\lemma{et ride}\reading{{\emph Klu}}{optime}\reading{{\emph Schw}}{egregie}\reading{Hai}{et vige}\reading{Ort}{et vive} et omnem vitam laetare\lemma{laetare}\reading{Mai2}{laetare}\reading{Naber}{laeta re}, et optimis parentibus ingenio tuo fruere \lemma{optimis ... fruere}\reading{litt. -s et ex et -io tuo fru- m2 in ras.}.\footnote{Ad. M. I, 4, 3}
}
\par

\blank[medium]
\language[la]{
se<d>\lemma{se<d> Mai1}\reading{se A corr. Mai1} quid somnus fecit?}\par
% Greek text
\language[gr]{
βουλὴ δὲ κακὴ νίκησεν\lemma{νίκησεν}\reading{νεικησεν A}~~ἑταίρων\par
ἀσκόν μὲ λῦσαν, ἄνεμοι δ᾽ ἐκ ἅπαντες ὄρουσαν\par
...\footnote{2 more verses not copied here.}}
\par
\language[la]{
quid rursum apud insulam Trinacriam ?
}
\stopnarrower

\blank[big]

% French translation
\startnarrower[left]
\startalignment[middle]
    \bgroup\tfa Fronton à son cher César\egroup
\stopalignment

Je t'enverrai donc dès que possible une copie de ce livre.
Porte-toi bien, César, ris, réjouis-toi de toutes les choses de la vie et profite de tes remarquables parents et de ton éminent esprit.\footnote{Cf. \cite[alternative=entry][biblio::fronto1988]}
\stopnarrower
\page[yes]
\startnarrower[left]
\language[la]{

	<et vo>luptaria\lemma{voluptatiba}\reading{m{\high{2}}} ‘sed in his erat Sempronia\lemma{Sempronia}\reading{Sempronia m<ulta>saepe <viri>lis audaciae facinora <com>miserat {\emph m{\high{2}} mg lac. suppl. Naber}}, quae multa saepe virilis audaciae facinora commiserat. haec mulier genere atque forma, praeterea viro, liberis satis fortunata\lemma{forma satis fortunata}\reading{ \emph m{\high{2}} mg} fuit; litteris Graecis, Latinis docta, psallere, saltare elegantius quam necesse probae, multa alia, quae instrumenta luxuriae\lemma{instrumenta luxuriae}\reading{ \emph m{\high{2}} mg} sunt, sed\lemma{sed in ... quam peteretur}\reading{Sall. Cat., 25, 1-3} ei cariora semper omnia quam decus atque pudicitia fuit; pecuniae an famae minus parceret, haud facile discerneres; libido sic accensa ut saepius peteret viros quam peteretur.'\par
'Quis rebus permota civitas atque immutata urbis facies erat.'
}
\stopnarrower
\stoplinenumbering

\page[yes]
Mais ce sont là les grands traits d’un général ; lis-en maintenant attentivement de plus charmants : “mais parmi elles se trouvait Sempronia\footnote{Il s'agit bien de la mère des Gracques.}, qui avait régulièrement accompli de nombreux méfaits d’une audace toute virile. Cette femme eut une chance certaine quant à son ascendance et son physique, ce à quoi s’ajoutèrent son mari et ses fils ; instruite dans les lettres grecques comme latines, elle savait chanter et danser trop élégamment pour une femme respectable, et bien d’autres choses, qui étaient autant d’incitations à la débauche, mais tout lui fut toujours plus cher que l’honneur et la pudeur ; de son argent ou de sa réputation, il est difficile de dire ce qu’elle ménageait le moins ; consumée par un désir tel qu’elle cherchait les hommes plus souvent qu’ils ne la recherchaient.”\par
“Et ces mesures plongèrent la cité dans le trouble et changèrent le visage de la ville.”

% Bibliography reference
\startbackmatter
\startchapter[title={Bibliographie}]
    \placelistofpublications[default][method=local]
\stopchapter
\stopbackmatter

\stoptext
