%%%&glo2.fmt
% !TEX encoding = UTF-8
% !TeX program =XeLaTeX (build)
% !TeX spellcheck = fr_FR
\def\encodingdefault{OT1}\normalfont
\everyjob\expandafter{\the\everyjob\def\encodingdefault{TU}\normalfont}
\PassOptionsToPackage{svgnames,fixpdftex,hyperref}{xcolor}
\documentclass[a4paper,10pt]{article}
\usepackage{ifxetex}
\usepackage{etoolbox}
\ifxetex \relax
\else
	\usepackage[utf8]{inputenc}
	\usepackage[greek,main=french]{babel}
	\usepackage[LGR,T1]{fontenc}
  	\usepackage{mathtools,amssymb}
	\usepackage{lmodern}
%	\DeclareUnicodeCharacter{2329}{\ensuremath{\langle}}			% \b<> \color{red}
%	\DeclareUnicodeCharacter{232A}{\ensuremath{\rangle}}			% \b<> \color{black}
	\AtBeginDocument{%
		\newcommand\gr{\selectlanguage{greek} }%
	}
\fi

\usepackage{silence}
%\WarningsOff[lipsum]
%\usepackage{lipsum}
\usepackage[color,notref,notcite]{showkeys}
\makeatletter
\def\SK@labelcolor{\color{LightSeaGreen}}
\makeatother
%\definecolor{labelkey}{rgb}{1,0,1}
%	\definecolor{refkey}{rgb}{1,0.5,0}
\usepackage[margin=25mm]{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
%\usepackage{footnote}
%\usepackage{xparse}
\newcommand{\mymeaning}[1]{{\small\noindent{\bfseries\string #1}=\meaning #1\par\medskip}}\usepackage{enumitem}
%\WarningsOff[listofitems]
\usepackage{listofitems}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\usepackage{ninecolors}
\usepackage{xspace}
\usepackage[normalem]{ulem}
\newcommand\ul[1]{\uline{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\csname endofdump\endcsname
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifxetex
	\usepackage{fontsetup}
	\usepackage{fontspec,unicode-math}
	\usepackage{polyglossia}
	\setotherlanguage[variant=polygreek]{greek}
	\newfontfamily\hebrewfont{NewCM10}[
	  	Extension = .otf,
%	  	Script = hebr ,
%	  	Language = Hebrew ,
		UprightFont = *-Regular,
		BoldFont = *-Bold,
		ItalicFont = *-Italic,
		BoldItalicFont = *-BoldItalic]
		
%	\newfontfamily\hebrewfont{NewCMSans10}[
%	  	Extension = .otf,
%	  	Script = hebr ,
%%	  	Language = hebr ,
%		UprightFont = *-Book,
%		BoldFont = *-Bold,
%		ItalicFont = *-BookOblique,
%		BoldItalicFont = *-BoldOblique]
		
	\setdefaultlanguage{french}
	\setotherlanguage{hebrew}
	\setotherlanguage[variant=polygreek]{greek}
	\newcommand\he{\selectlanguage{hebr} }%
	\newcommand\gr{\selectlanguage{gr} }%
\fi

%\usepackage[colorlinks]{hyperref}%\usepackage{stringstrings }
%\AtBeginEnvironment{gloses}{\catcode`\<=13\def\b<{$\langle$}\catcode`\>=13\def>{$\rangle$}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\Acc{\textsc{Acc}\xspace}
\def\NMV{{\scshape [nmv]}\xspace}
\def\MV{{\scshape [mv]}\xspace}
\def\PP{{\scshape pp}\xspace}
\def\PF{{\scshape pf}\xspace}
\def\BF{{\scshape bf}\xspace}
\def\AF{{\scshape af}\xspace}
\renewcommand\P[1]{{\scshape p#1}\xspace}
\newcommand\red[1]{\textcolor{red}{#1}}
\newcommand\blue[1]{\textcolor{blue}{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newtoks\gl@trans
\newtoks\gl@opt
\newtoks\gl@trad
\def\bracketcolor{red}
\newenvironment{gl@braket}{$\langle$\color{\bracketcolor}}{\color{black}$\rangle$}
\newcounter{gen@glose@count}
\def\glosenumlevel{section}
\newcounter{glose@count}[\glosenumlevel]

%%% Main commands

\NewDocumentEnvironment{gloses}{s d()}{%
%	\@addtoreset{glose@count}{#2}
	\IfBooleanTF{#1}{%
		\setcounter{glose@count}{0}%
		\refstepcounter{gen@glose@count}%
		\gdef\theglose@count{G\arabic{gen@glose@count}.\arabic{glose@count}}%
	}{%
		\gdef\theglose@count{\csuse{the\glosenumlevel}.\arabic{glose@count}}%
	}%
	\setlength{\parindent}{0pt}%\setlength{\parskip}{\baselineskip}%
	\SetTblrInner{vlines={0.2pt,LightGray,dashed},hlines={0.2pt,LightGray,dashed},%
		rowsep=1pt,leftsep=0pt,rightsep=8pt}%
	\SetTblrOuter{baseline=T}%
}{%
\relax
}

% #1 optionnal orifinal enclosed in ()
% #2 mandatory tranliterated text in{}
% #3 optional analysis in []
% #4 mandatory translation in {}

\NewDocumentCommand\glo{+d() +m +o +m} {%
%\savenotes
	\begingroup
	% get number or elts in glose, from arg #2
	\setsepchar{&}\greadlist*\gl@list{#2}%
	\def\gl@colspan{\gl@listlen}%
	% if argument (#1) and global \citelang set swich to lang for it
	\IfNoValueTF{#1}{%
		\gl@trans{#2}%
		\def\gl@pretolang{}
	}{%
		\gl@trans{#1 \\ #2}
		\def\gl@pretolang{\csuse{text\citelang}}
	}%
	\gl@opt{\\ #3}%
	\gl@trad{\\ \SetCell[c=\gl@colspan]{c} #4}%
	% start typesetting
	\setlength{\leftmargin}{2em}%
	\refstepcounter{glose@count}%
	\label{glo.\theglose@count}%
	\par\vspace*{0.5ex}%
	\hspace*{0pt}\rlap{\bfseries(\arabic{glose@count})}%
	\hspace*{3em}%
	%create table
	\begin{tblr}[expand=\the]{row{1}={preto=\bfseries,cmd=\gl@pretolang},row{Z}={preto=\slshape}}%
	\the\gl@trans
	\the\gl@opt
	\the\gl@trad
	\end{tblr}%
	\endgroup
	\par\vspace*{1ex}%
%\spewnotes%
}

\newcommand\gref[1]{%
\setsepchar{.}\greadlist*\reflist{#1}%
\ifnumequal{\numexpr\reflist[2]}{\value{\glosenumlevel}}{(\reflist[3]) de cette \glosenumlevel}%
{(\reflist[3]) de la \glosenumlevel~\reflist[2]}%
}

\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

Πάτερ ἡμῶν ὁ ἐν τοῖς οὐρανοῖς· ἁγιασθήτω τὸ ὄνομά σου·
ἐλθέτω ἡ βασιλεία σου·

Άά Έέ Ήή Ίί Όό Ύύ Ώώ ΐ ΰ Ϊϊ Ϋϋ

\section{Test glose}

\begin{gloses}
\makeatletter%
\catcode`<=\active\gdef<{\gl@braket}%
\catcode`>=\active\gdef>{\endgl@braket}%
\makeatother%


Orientation «agentive» de la phrase :
\glo{B<um>ilí          & ka	            &	[<ng>       	 &	damít]	 & [para  & sa & bata]}%
[Acheter <Acc.Actif.\AF> & \MV\PP.\AF.\P2	& \NMV Actant &	vêtement & prép.	&\NMV \P3.Datif &	enfant]%
{\ul{Tu} as acheté un vêtement pour un enfant.}

Orientation « patientive » de la phrase :
\glo{B<in>ilí           & mo	            &	[ang  &	damít]	  & [sa		       & tindahan]}%
[Acheter<Acc.Passif.\PF> &  \NMV Gén.\P2	  & \MV &	vêtement  &\NMV Datif   &	magasin]
{{(Le vêtement a été acheté par toi au magasin.)\\= Tu as acheté \ul{le/ce vêtement} dans un magasin.}}

Orientation « bénéfactive de la phrase » :
\glo{ I-b<in>ilí        & mo     & [ng	    & damít] & [ang	& bata]}
[\BF Acheter<Acc.Passif>	&\NMV Gén.\P2	& vêtement &\MV	&enfant.\BF]
{{(L’enfant s’est vu acheter un vêtement par toi.)\\= Tu as acheté un vêtement pour \ul{cet/l’enfant}.}}

\end{gloses}

\section{Autre glose}

\begin{gloses}
\makeatletter
\catcode`<=\active \def<{\gl@braket}
\catcode`>=\active \def>{\endgl@braket}
\makeatother

\def\citelang{hebrew}
Exemple en hébreu biblique :
%\glo{..we-Yisråel 	&	ʔåhav 	&	ʔet-yosef }%
\glo(ְ{אֶת-יֹוסֵף}&{אָהַב}&{ְיִשְׂרָאֵל})
{..we-Yisråel 	&	ʔåhav 	&	ʔet-yosef}%
[et-Israël(Jacob)	&aimer.\red{Inacc}\P3 & 	2act Joseph]%
{\bfseries « ..et Jacob \red{aimait} Joseph » (Gn 37,3)..}

\end{gloses}

\bigskip

Ceci est une référence à la glose~\gref{glo.1.2}\dots

et ici une référence à la glose~\gref{glo.2.1}

\end{document}

% \AfterEndPreamble{%
%	\usepackage{fontsetup}
%	\usepackage{fontspec,unicode-math}

%	\usepackage{polyglossia}
%	\WarningsOff[unicode-math,fontspec]
%	\setmainfont{NewCM10}[%
%		Ligatures=TeX,
%		Extension = .otf,
%		UprightFont = *-Regular,
%		BoldFont=*-Bold,
%		ItalicFont=*-Italic,
%		BoldItalicFont=*-BoldItalic,
%		SmallCapsFeatures={Numbers=OldStyle}]
%	
%	\setsansfont{NewCMSans10}[%
%		Extension = .otf,
%		UprightFont = *-Regular,
%		BoldFont=*-Bold,
%		ItalicFont=*-Oblique,
%		BoldItalicFont=*-BoldOblique]
%	
%	\setmonofont{NewCMMono10}[
%		Extension = .otf,
%		UprightFont = *-Regular,
%		BoldFont=*-Bold,
%		ItalicFont=*-Italic,
%		BoldItalicFont=*-BoldOblique]
%	\setmathfont{NewCMMath} 

%	\setmainfont{Latin Modern Roman}[
%  SmallCapsFont = Latin Modern Roman Caps,
%  UprightFeatures = {SmallCapsFeatures = {}}, % Suppresses warning about missing smcp feature.
%  BoldFeatures = {SmallCapsFont = {CMU Serif Bold}},
%  ItalicFeatures = {SmallCapsFont = {CMU Serif Roman Slanted}},
%  BoldItalicFeatures = {SmallCapsFont = {CMU Serif Bold Slanted}},
%  SmallCapsFeatures={Letters=SmallCaps}]
%	\setmainfont[SmallCapsFont=Latin Modern Roman Caps,SmallCapsFeatures={Letters=SmallCaps}]{Latin Modern Roman}
%	\setsansfont{Latin Modern Sans}
%	\setmonofont{Latin Modern Mono}
%	\setmathfont{Latin Modern Math}
%	}
%\setmainfont{NewCM10}%[
%  NFSSFamily=NewCMRoman,
%  Extension=.otf,
%  Numbers=OldStyle,
%  UprightFont=*-Book,
%  ItalicFont=*-BookItalic,
%  BoldFont=*-Bold,
%  BoldItalicFont=*-BoldItalic,
%  SlantedFont=*-Book,
%  SlantedFeatures={FakeSlant=0.25},
%  BoldSlantedFont=*-Bold,
%  BoldSlantedFeatures={FakeSlant=0.25},
%  SmallCapsFeatures={Numbers=OldStyle},
%]
%	\setdefaultlanguage{french}
%	\setotherlanguage[variant=polygreek]{greek}
%	\newfontfamily\greekfont{NewCM10}
%   \setmainfont[Ligatures=TeX]{TeX Gyre Termes}
%   \setmathfont{texgyrepagella-math.otf}[math-style=TeX]
%   \setmathfont{TeX Gyre Pagella Math}
%}

% \newfontfamily\hebrewfont{David Libre}[
%  Script = Hebrew ,
%  Language = Hebrew ,
%  UprightFeatures = { Ligatures = {Common, Discretionary} } ,
%  BoldFeatures = { Ligatures = {Common, Discretionary} } ,
%  ItalicFont = [DavidCLM-MediumItalic] ,
%  BoldItalicFont = [DavidCLM-BoldItalic] ] 
