%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% File covington.sty
%%
%% LaTeX macros for Linguistics
%%
%% Original author:
%% ================
%% Michael A. Covington
%% Artificial Intelligence Programs
%% The University of Georgia
%% Athens, Georgia 30602-7415 USA
%% mcovingt@aisun1.ai.uga.edu
%%
%% Contributors:
%% =============
%% Robin Fairbairns <rf10@cl.cam.ac.uk> 2014-05-16: patched setting of \textfloatsep
%% to use \setlength rather than \renewcommand; also converted to un*x line endings
%%
%% Current maintainer:
%% ===================
%% Juergen Spitzmueller <juergen@spitzmueller.org>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% 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.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Juergen Spitzmueller.
%%
%% Code repository and issue tracker: https://github.com/jspitz/covington
%%
%% See covington.tex for documentation.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%
%%% Metadata
%%%

\def\filedate{2025/08/13}
\def\fileversion{2.15}
\def\filename{covington.sty}

% Macro to issue warnings
\newcommand\cov@warning[1]{%
  \PackageWarning{covington}{#1}%
}

% Force redefinition of environments?
\newif\ifforceredef\forceredeffalse
% Tweak text layout?
\newif\iftweaklayout\tweaklayouttrue
% Prevent page breaks in glosses
\newif\ifnoglossbreaks\noglossbreaksfalse
% Use own example counter
\newif\ifownexcounter\ownexcounterfalse
% Use separate counter in footnote
\newif\ifownfnexcounter\ownfnexcounterfalse
% Reset separate counter in footnote
\newif\ifresetownfnexcounter\resetownfnexcounterfalse

\ProvidesPackage{covington}
	[\filedate\space v\fileversion\space Macros for Linguistics]

\DeclareKeys[covington]
{
    % 1. force=<true|false>
    force.if = forceredef,
    % 2. keeplayout=<true|false>
    keeplayout.ifnot = tweaklayout,
    % 3. noglossbreaks=<true|false>
    noglossbreaks.if = noglossbreaks,
    % 4. owncounter=<true|false>
    owncounter.if = ownexcounter,
    % 5. fnexamplecounter=<main|own|own-reset>
    fnexamplecounter.choice:,
    % a. main
    fnexamplecounter / main.code:n = { \ownfnexcounterfalse\resetownfnexcounterfalse },
    % b. own
    fnexamplecounter / own.code:n = { \ownfnexcountertrue\resetownfnexcounterfalse },
    % c. own-reset
    fnexamplecounter / own-reset.code:n = { \ownfnexcountertrue\resetownfnexcountertrue },
    fnexamplecounter.default:n = { main },
    % DEPRECATED OPTONS
    % force=<true|false>
    ownfncounter.code:n =
    { \ownfnexcountertrue
      \resetownfnexcounterfalse
      \cov@warning{Option 'ownfncounter' is deprecated!\MessageBreak
                   Please use fnexamplecounter=own instead.}
    },
    % force=<true|false>
    ownfncounter*.code = 
    { \ownfnexcountertrue
      \resetownfnexcountertrue
      \cov@warning{Option 'ownfncounter*' is deprecated!\MessageBreak
                   Please use fnexamplecounter=own-reset instead.}
    }
}

% Process package options
\ProcessKeyOptions[covington]

%
% Required packages
%
\RequirePackage{iftex}

%%%
%%% Preferences about how text is laid out
%%%

% New 2018-08-24: Option to opt-out these layout tweaks
\iftweaklayout
  \setlength{\textfloatsep}{0.7in}
  \raggedbottom
\fi

%%%
%%% Stacked accents
%%%

% This is adapted from the \diatop macro (designed by
% Mike Dunleavy, originally in cjlmac.sty, designed by
% Jean-Pierre Paillet) and included in wsuipa.sty
% (designed by Dean Guenther and Janene Winter).

% Length to adjust accent distance
% Introduced 2016-07-06 JSP. 
\newlength\twoaccsep
\setlength{\twoaccsep}{-0.8ex}
\newcommand*\SetDiaOffset[1]{\addtolength{\twoaccsep}{#1}}

\def\twoacc[#1|#2]{\leavevmode{\setbox1=\hbox{{#1{}}}%
                     \setbox2=\hbox{{#2{}}}%
                     \dimen0=\ifdim\wd1>\wd2\wd1\else\wd2\fi%
                     \dimen1=\ht2\advance\dimen1by\twoaccsep%
                     \setbox1=\hbox to1\dimen0{\hss#1{}\hss}%
                     \rlap{\raise1\dimen1\box1}%
                     \hbox to1\dimen0{\hss#2\hss}}}%

% Example of usage: \twoacc[\^|\={a}]

% 2017-05-21: Introduce a less odd syntax: \twodias{\^}{\=}{a}
\newcommand*\twodias[3]{\leavevmode{\setbox1=\hbox{{#1{}}}%
                     \setbox2=\hbox{{#2{#3}}}%
                     \dimen0=\ifdim\wd1>\wd2\wd1\else\wd2\fi%
                     \dimen1=\ht2\advance\dimen1by\twoaccsep%
                     \setbox1=\hbox to1\dimen0{\hss#1{}\hss}%
                     \rlap{\raise1\dimen1\box1}%
                     \hbox to1\dimen0{\hss#2{#3}\hss}}}

% Special cases:
\def\acm#1{\twodias{\'}{\=}{#1}}          % acute over macron
\def\grm#1{\twodias{\`}{\=}{#1}}          % grave over macron
% Use MODIFIER LETTER CIRCUMFLEX ACCENT (U+2C6) with Xe/LuaTeX
\iftutex
  \def\cim#1{\twodias{\char"2C6}{\=}{#1}} % circumflex over macron
\else
  \def\cim#1{\twodias{\^}{\=}{#1}}        % circumflex over macron
\fi

%%%
%%% Example numbering
%%%

% Example numbering uses the same counter as LaTeX's equation numbering
% by default.
% Thus, you can use \label and \ref to refer to numbered examples in
% exactly the same way as with equations.
% As of v. 2.2, it is also possible to use an own counter and thus separate
% equations from linguistic examples.

% \exampleno  increments the counter and gives you its current value.
%             You can use it anywhere to generate an example number.
%
%             For example, to display a sentence with a number at the
%             right margin, do this:
%
%             \begin{flushleft}
%             This is a sentence.  \hfill (\exampleno)
%             \end{flushleft}

% Counter to generate unique example ID
\newcounter{explid}

\def\ownexcounterprep{}
\ifownexcounter
  \newcounter{covex}
  \renewcommand{\thecovex}{\ownexcounterprep\arabic{covex}}%
  \newcommand{\@exampleno}{\stepcounter{explid}\refstepcounter{covex}\thecovex}
\else
  \newcommand{\@exampleno}{\stepcounter{explid}\refstepcounter{equation}\theequation}
\fi
\newcommand*\@@exampleno{\ifownexcounter\thecovex\else\theequation\fi}
\newcommand*\exampleno{\@ifstar{\@@exampleno}{\@exampleno}}

\let\fnexfmt\roman

\newif\ifcov@infootnote\cov@infootnotefalse
\ifownfnexcounter
  % Check whether we are in a footnote
  \AddToHook{cmd/@footnotetext/before}{\cov@infootnotetrue}
  \AddToHook{cmd/@footnotetext/after}{\cov@infootnotefalse}
  \ifresetownfnexcounter
    \newcounter{covfnex}[footnote]
  \else
    \newcounter{covfnex}
  \fi
  \renewcommand{\thecovfnex}{\fnexfmt{covfnex}}
\fi

%%%
%%% The 'example' environment
%%%

% Font setting possibility for example sentences
\newcommand*\covexamplefs{\normalfont\upshape}
\newcommand*\covexamplenofs{\normalfont\upshape}

% example     is an environment for displaying a single numbered 
%             example, preceded by its number.  Example of use:
%
%             \begin{example}
%             This is an example.
%             \end{example}
%
%             This is actually a special case of 'examples' where
%             the first \item is automatically supplied.
%
%             To display sub-examples with numbers such as
%             (3)(a), (3)(b), etc., you can use 'itemize', thus:
%             \begin{example}
%              \begin{itemize}
%              \item[(a)] This is the first example.
%              \item[(b)] This is the second example.
%              \end{itemize}
%             \end{example}
%
% New in 1.1 (2016-07-06):
%            We provide a covexample environment and only (re)define
%            example if it does not yet exist or if redefinition is
%            forced by the "force" option. This prevents clashes
%            with packages/classes that roll their own example environment
%            (such as beamer).

% Helper function for numbering templates
\newif\ifcov@have@exno\cov@have@exnofalse

\def\cov@parse@number@loop#1{%
   \ifx\relax#1\else%
      \cov@parse@number@loop@body{#1}\expandafter\cov@parse@number@loop%
   \fi%
}

\newcommand\cov@parse@number@loop@body[1]{%
  \ifcov@have@exno%
     \let\cov@@tmpfmtright\cov@tmpfmtright%
     \edef\cov@tmpfmtright{\cov@@tmpfmtright#1}%
  \else%
     \ifx 1#1%
        \cov@have@exnotrue%
        \let\cov@tmpfmt\arabic%
     \else%
        \ifx i#1%
           \cov@have@exnotrue%
           \let\cov@tmpfmt\roman%
        \else%
           \ifx I#1%
               \cov@have@exnotrue%
               \let\cov@tmpfmt\Roman%
           \else%
               \ifx a#1%
                   \cov@have@exnotrue%
                   \let\cov@tmpfmt\alph%
               \else%
                   \ifx A#1%
                       \cov@have@exnotrue%
                       \let\cov@tmpfmt\Alph%
                   \else%
                       \let\cov@@tmpfmtleft\cov@tmpfmtleft%
                       \edef\cov@tmpfmtleft{\cov@@tmpfmtleft#1}%
                   \fi%
               \fi%
           \fi%
        \fi%
     \fi%
  \fi%
}%

\newcommand\cov@parse@number@template[3]{%
  \cov@have@exnofalse%
  \let\cov@tmpfmt\roman%
  \def\cov@tmpfmtleft{}%
  \def\cov@tmpfmtright{}%
  \cov@parse@number@loop#1\relax%
  \expandafter\let\csname#2\endcsname\cov@tmpfmt%
  \expandafter\let\csname cov@tmpfmtleft#3\endcsname\cov@tmpfmtleft%
  \expandafter\let\csname cov@tmpfmtright#3\endcsname\cov@tmpfmtright%
  \ifcov@have@exno%
      \expandafter\renewcommand\csname#3\endcsname[1]{%
          \csname cov@tmpfmtleft#3\endcsname##1\csname cov@tmpfmtright#3\endcsname}%
  \else%
      \expandafter\renewcommand\csname#3\endcsname[1]{%
          \csname cov@tmpfmtleft#3\endcsname\csname cov@tmpfmtright#3\endcsname}%
  \fi%
}

\newif\if@cov@expst@star\@cov@expst@starfalse

% Commands to register and check preamble in (sub-)examples
% Adapted from etoolbox
\DeclareRobustCommand*{\RegisterExPreamble}[1]{%
   \expandafter\gdef\csname cov@havepreamble:#1\endcsname{}%
}

\newcommand*{\IfExPreamble}[1]{%
  \ifcsname cov@havepreamble:#1\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi%
}

% 2022-08-20 (v. 2.8): optional preceding example text
\newcommand*\expreamblefs{\normalfont}
\newcommand\expreamble[1]{%
   \bgroup\expreamblefs#1\egroup\par\cov@judge@marker%
   \if@filesw%
      \protected@write\@auxout{}{\protect\RegisterExPreamble{\theexplid}}%
   \fi%
   \ignorespaces%
}

% 2023.05.26 (v. 2.9): optional trailung subexample text
\newcommand*\expostamblefs{\normalfont}
\newcommand*\expostamble[1]{\bgroup\expostamblefs#1\egroup}

% 2023.06.04 (v. 2.11): judge marks
\newcommand*\cov@judge@fs{\normalfont\upshape}

% Track whether example format was changed via template
\newif\ifexfmtchanged
\newif\ifexfmtgchanged

\DeclareKeys[covexpl]
{
    % font settings
    fs.store = \covexamplefs,
    % font settings of the ex. number
    fsno.store = \covexamplenofs,
    % preamble
    preamble.store = \cov@xp,
    % postamble
    postamble.code = { \def\cov@xpst{#1}\@cov@expst@starfalse },
    % postamble* (no space)
    postamble*.code = { \def\cov@xpst{#1}\@cov@expst@startrue },
    % preamble font settings
    fspreamble.store = \expreamblefs,
    % postamble font settings
    fspostamble.store = \expostamblefs,
    % leftmargin
    leftmargin.code = { \setlength{\exampleind}{#1} },
    % addnumbersep
    addnumbersep.code = { \setlength{\examplenumbersep}{#1} },
    % numberformat={template}
    numberformat.code = {
       \cov@parse@number@template{#1}{exfmt}{covexnumber}
       \exfmtchangedtrue
    },
    % fnnumberformat={template}
    fnumberformat.code = { \cov@parse@number@template{#1}{fnexfmt}{covexnumberfn} },
    % judge=text
    judge.code = { \def\cov@judge@ex@text{#1} \settowidth\cov@judge@width{\cov@judge@fs#1} },
    % judgement shorthands: *, ?, *?, ??, #
    *.code = { \def\cov@judge@ex@text{*} \settowidth\cov@judge@width{\cov@judge@fs*} },
    ?.code = { \def\cov@judge@ex@text{?} \settowidth\cov@judge@width{\cov@judge@fs?} },
    *?.code = { \def\cov@judge@ex@text{*?} \settowidth\cov@judge@width{\cov@judge@fs*?} },
    ??.code = { \def\cov@judge@ex@text{??} \settowidth\cov@judge@width{\cov@judge@fs??} },
    #.code = { \def\cov@judge@ex@text{\#} \settowidth\cov@judge@width{\cov@judge@fs\#} },
    % judgement font settings
    fsjudge.store = \cov@judge@fs,
    % judgewith=<text>
    judgewidth.code = { \settowidth\cov@judge@width{\cov@judge@fs#1} },
    % addjudgesep=length
    addjudgesep.code = { \addtolength\cov@judge@sep{#1} }
}

\newif\if@cov@insingleex\@cov@insingleexfalse

\newenvironment{covexample}[1][]{%
    \@cov@insingleextrue%
    \let\cov@judge@ex@text\cov@judge@ex@text@global%
    \ifexfmtgchanged%
       \exfmtchangedtrue%
    \else
       \exfmtchangedfalse%
    \fi%
    \SetKeys[covexpl]{#1}%
    \begin{covexamples}
       \@ifundefined{cov@judge@ex@text}{\item}{\item<\cov@judge@ex@text>}%
       \ifx\cov@xp\empty\cov@judge@marker\else\expreamble{\cov@xp}\fi% insert preamble if given
}{%
   \@ifundefined{cov@xpst}{}{\if@cov@expst@star\unskip\fi\expostamble{\cov@xpst}}%
   \end{covexamples}%
   \@cov@insingleexfalse%
}

\@ifundefined{example}{%
  \newenvironment{example}[1][]{\begin{covexample}[#1]}{\end{covexample}}
}{%
\ifforceredef
  \renewenvironment{example}{\begin{covexample}}{\end{covexample}}
  \cov@warning{The example environment was already defined. Redefining it.}
\else
  \cov@warning{The example environment was already defined.^^J
               Covington does not touch it.^^J
               Use covexample if you want to access covington's^^J
               version, or use the force package option.}
\fi
}

%%%
%%% The 'examples' environment
%%%

% examples    is an environment for displaying a series of examples
%             together, each with its own example number.  Usage:
%
%             \begin{examples}
%             \item This is the first example.
%             \item This is the second example.
%             \end{examples}
%
% Thanks to Darrel Hankerson of Auburn University, and numerous others
% across the net, for help with this macro.
%
% New in 1.1 (2016-07-06):
%            We provide a covexamples environment and only (re)define
%            examples if it does not yet exist or if redefinition is
%            forced by the "force" option. This prevents clashes
%            with packages/classes that roll their own examples environment
%            (such as beamer).
%
% New in 1.8 (2018-12-07): Allow to redefine label (\covexnumber)

\newcounter{covexsave}          % used in trick with example number

\newlength\examplenumbersep
\setlength\examplenumbersep{0pt}

\newlength\exampleind
\setlength\exampleind{0pt}

\newcommand*\covexnumber[1]{(#1)}
\newcommand*\covexnumberfn[1]{\covexnumber{#1}}

\let\exfmt\arabic

% Allow for \item<judgment>[label]
\def\cov@judge@item<#1>{%
    \global\def\cov@judge{#1}%
    \@ifnextchar[%
      {\@item}%
      {\cov@item}%
}%

\newlength\cov@judge@width
\settowidth\cov@judge@width{?}
\newlength\cov@subjudge@width
\settowidth\cov@subjudge@width{?}
\newlength\cov@judge@sep
\setlength\cov@judge@sep{.1em}
\newlength\cov@judge@extra
\setlength\cov@judge@extra{0pt}

\newif\if@cov@insubex\@cov@insubexfalse

\def\cov@judge@marker{}

\def\covchapexsep{.}

\newenvironment{covexamples}[1][]{%         % define "examples" environment
  \if@cov@insubex%
     \let\cov@judge@ex@text\relax%
  \else%
     \if@cov@insingleex\else%
        \let\cov@judge@ex@text\cov@judge@ex@text@global%
        \ifexfmtgchanged%
           \exfmtchangedtrue%
        \else
           \exfmtchangedfalse%
        \fi%
      \fi%
  \fi%
  \ifx{#1}{\empty}\else\SetKeys[covexpl]{#1}\fi%
  \addtolength\cov@judge@extra{\cov@judge@width}%
  \addtolength\cov@judge@extra{\cov@judge@sep}%
  % parse <...> item argument
  \let\cov@item\item%
  \let\cov@@item\@item%
  \def\@item[##1]{%
     \cov@@item[##1] \@ifundefined{cov@judge}{}{%
         \def\cov@judge@marker{\hspace*{-\cov@judge@extra}%
             \makebox[\cov@judge@width][r]{\cov@judge@fs\cov@judge}%
             \hspace{\cov@judge@sep}\ignorespaces}%
          \IfExPreamble{\theexplid}{}{\cov@judge@marker\ignorespaces}%
     }%
  }
  \def\item{%
    \@inmatherr\item
    \@ifnextchar<{\cov@judge@item}%
                 {\@ifundefined{cov@judge@ex@text}%
                     {\global\let\cov@judge\relax}%
                     {\global\let\cov@judge\cov@judge@ex@text}%
                  \cov@item}%
  }%
  \begin{list}%
  {%
    \covexamplenofs% font
    \ifcov@infootnote%
      \covexnumberfn{\thecovfnex}%
    \else%
      \covexnumber{\@@exampleno}%
    \fi%
  }%
  {%
    \addtolength{\labelwidth}{\examplenumbersep}%
    \addtolength{\leftmargin}{\examplenumbersep}%
    \addtolength{\leftmargin}{\exampleind}%
    \stepcounter{explid}%
    \ifcov@infootnote
      \setcounter{covexsave}{\arabic{covfnex}}%
      \usecounter{covfnex}%
      \setcounter{covfnex}{\arabic{covexsave}}%
    \else
      \ifownexcounter
        \ifexfmtchanged%
           \renewcommand{\thecovex}{\ownexcounterprep\exfmt{covex}}%
        \fi%
        \setcounter{covexsave}{\arabic{covex}}%
        \usecounter{covex}%                          % sets it to zero, unwantedly
        \setcounter{covex}{\arabic{covexsave}}%   % restores previous value
      \else
        \ifexfmtchanged%
          \renewcommand{\theequation}{\ifnum\c@chapter>\z@\thechapter\covchapexsep\fi\exfmt{equation}}%
        \fi%
        \setcounter{covexsave}{\arabic{equation}}%
        \usecounter{equation}%                          % sets it to zero, unwantedly
        \setcounter{equation}{\arabic{covexsave}}%   % restores previous value
      \fi
    \fi
    \setlength{\listparindent}{0pt}%
    \def\makelabel##1{##1\hfil}%       % put labels flushleft in space available
  }%
  \raggedright%  text is flushleft, not justified
  \covexamplefs%
}%
{\end{list}}

\@ifundefined{examples}{%
  \newenvironment{examples}{\begin{covexamples}}{\end{covexamples}}
}{%
\ifforceredef
  \renewenvironment{examples}{\begin{covexamples}}{\end{covexamples}}
  \cov@warning{The examples environment was already defined. Redefining it.}
\else
  \cov@warning{The examples environment was already defined.^^J
               Covington does not touch it.^^J
               Use covexamples if you want to access covington's^^J
               version, or use the force package option.}
\fi
}


%%%
%%% The 'subexamples' environment
%%%

% New in v1.6 (2018-09-07)
% subexamples is an environment for displaying a series of examples
%             that belong together and thus share an example number
%             (with an alphabetic subcounter).  Usage:
%
%             \begin{subexamples}
%             \item This is the first subexample.
%             \item This is the second subexample.
%             \end{subexamples}

% 2019-06-21 (v. 2.3): optional preceding subexample text
\newcommand*\subexpreamblefs{\normalfont}
\newcommand\subexpreamble[1]{%
   \bgroup\subexpreamblefs#1\egroup\par\cov@judge@marker%
   \if@filesw%
      \protected@write\@auxout{}{\protect\RegisterExPreamble{\theexplid}}%
   \fi%
   \ignorespaces%
}

% 2023.05.26 (v. 2.9): optional trailung subexample text
\newcommand*\subexpostamblefs{\normalfont}
\newcommand*\subexpostamble[1]{\bgroup\subexpostamblefs#1\egroup}

\newcommand*\cov@closscomments@fs{\normalfont\upshape}

\DeclareKeys[covsubexpl]
{
    % font settings
    fs.store = \covexamplefs,
    % font settings
    fsno.store = \covexamplenofs,
    % preamble text
    preamble.store = \cov@sxp,
    % postamble text
    postamble.store = \cov@sxpst,
    % preamble text (alias)
    subpreamble.store = \cov@sxp,
    % postamble text (alias)
    subpostamble.store = \cov@sxpst,
    % preamble font settings
    fspreamble.store = \subexpreamblefs,
    % postamble font settings
    fspostamble.store = \subexpostamblefs,
    % preamble font settings (alias)
    fssubpreamble.store = \subexpreamblefs,
    % postamble font settings (alias)
    fssubpostamble.store = \subexpostamblefs,
    % leftmargin
    leftmargin.code = { \setlength{\exampleind}{#1} },
    % addnumbersep
    addnumbersep.code = { \setlength{\examplenumbersep}{#1} },
    % addnumbersep
    addsubnumbersep.code = { \setlength{\subexamplenumbersep}{#1} },
    % numberformat={template}
    numberformat.code = {
      \cov@parse@number@template{#1}{exfmt}{covexnumber}
      \exfmtchangedtrue
    },
    % fnnumberformat={template}
    fnumberformat.code = { \cov@parse@number@template{#1}{fnexfmt}{covexnumberfn} },
    % subnumberformat={template}
    subnumberformat.code = { \cov@parse@number@template{#1}{subexfmt}{covsubexnumber} },
    % judge=text
    judge.code = { \def\cov@subjudge@ex@text{#1} \settowidth\cov@subjudge@width{\cov@judge@fs#1} },
    % subjudge=text
    subjudge.code = { \def\cov@subjudge@ex@text{#1} \settowidth\cov@judge@width{#1} },
    % judgement shorthands: *, ?, *?, ??, #
    *.code = { \def\cov@subjudge@ex@text{*} \settowidth\cov@subjudge@width{\cov@judge@fs*} },
    ?.code = { \def\cov@subjudge@ex@text{?} \settowidth\cov@subjudge@width{\cov@judge@fs?} },
    *?.code = { \def\cov@subjudge@ex@text{*?} \settowidth\cov@subjudge@width{\cov@judge@fs*?} },
    ??.code = { \def\cov@subjudge@ex@text{??} \settowidth\cov@subjudge@width{\cov@judge@fs??} },
    #.code = { \def\cov@subjudge@ex@text{\#} \settowidth\cov@subjudge@width{\cov@judge@fs\#} },
    % judgement font settings
    fsjudge.store = \cov@judge@fs,
    % judgewith=<text>
    judgewidth.code = { \settowidth\cov@subjudge@width{\cov@judge@fs#1} },
    % addjudgesep=length
    addjudgesep.code = { \addtolength\cov@judge@sep{#1} }
}

\newlength\subexamplenumbersep
\setlength\subexamplenumbersep{0pt}

\newcommand*\covsubexnumber[1]{(#1)}

\let\subexfmt\alph

% Allow for \item<judgment>[label]
\def\cov@judge@subitem<#1>{%
    \global\def\cov@subjudge{#1}%
    \@ifnextchar[%
      {\@item}%
      {\cov@subitem}%
}%

% Copied from the kernel (enumerate) and adapted
% to accept <...> item arguments
\def\covsubexs{%
  \setlength\cov@judge@extra{\cov@subjudge@width}%
  \addtolength\cov@judge@extra{\cov@judge@sep}%
  \let\cov@subitem\item%
  \let\cov@@subitem\@item%
  \def\@item[##1]{%
     \cov@@subitem[##1] \@ifundefined{cov@subjudge}{}{%
         \def\cov@judge@marker{\hspace*{-\cov@judge@extra}%
            \makebox[\cov@subjudge@width][r]{\cov@judge@fs\cov@subjudge}%
            \hspace{\cov@judge@sep}\ignorespaces}%
          \IfExPreamble{\theexplid}{}{\cov@judge@marker\ignorespaces}%
     }%
  }%
  \def\item{%
    \@inmatherr\item
    \@ifnextchar<{\cov@judge@subitem}%
                 {\@ifundefined{cov@subjudge@ex@text}%
                     {\global\let\cov@subjudge\relax}%
                     {\global\let\cov@subjudge\cov@subjudge@ex@text}%
                  \cov@subitem}%
  }%
  \ifnum \@enumdepth >\thr@@\@toodeep\else
    \advance\@enumdepth\@ne
    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
      \expandafter
      \list
        \csname label\@enumctr\endcsname
        {\stepcounter{explid}\usecounter\@enumctr\def\makelabel##1{\hss\llap{##1}}}%
  \fi}
\let\endcovsubexs =\endlist


\newenvironment{covsubexamples}[1][]%         % define "subexamples" environment
{%
    \@cov@insubextrue%
    \let\cov@xp\relax%
    \let\cov@xpst\relax%
    \let\cov@judge@ex@text\relax%
    \ifexfmtgchanged%
       \exfmtchangedtrue%
    \else
       \exfmtchangedfalse%
    \fi%
    \ifx{#1}{\empty}\else\SetKeys[covsubexpl]{#1}\fi%
    \begin{covexample}%
    \@ifundefined{cov@sxp}{}{\bgroup\subexpreamblefs\cov@sxp\egroup}% insert preamble if given
    \begin{covsubexs}
    \addtolength{\labelsep}{\subexamplenumbersep}%
    \renewcommand\theenumi{\subexfmt{enumi}}
    \renewcommand\labelenumi{\covexamplenofs\covsubexnumber{\theenumi}}
    \renewcommand\p@enumi{\@@exampleno\,}%
    \setlength{\listparindent}{0pt}%
    \def\makelabel##1{##1\hfil}%       % put labels flushleft in space available
}%
{%
    \let\cov@sxp\relax
    \end{covsubexs}
    \@ifundefined{cov@sxpst}{}{\subexpostamble{\cov@sxpst}}% insert postamble if given
    \let\cov@sxpst\relax
    \end{covexample}
    \@cov@insubexfalse%
}

\@ifundefined{subexamples}{%
  \newenvironment{subexamples}[1][]{\begin{covsubexamples}[#1]}{\end{covsubexamples}}
}{%
  \ifforceredef
    \renewenvironment{subexamples}[1][]{\begin{covsubexamples}[#1]}{\end{covsubexamples}}
    \cov@warning{The subexamples environment was already defined. Redefining it.}
  \else
    \cov@warning{The subexamples environment was already defined.^^J
                 Covington does not touch it.^^J
                 Use covsubexamples if you want to access covington's^^J
                 version, or use the force package option.}
  \fi
}

\DeclareKeys[gcovexamples]
{
    % font settings
    fs.store = \covexamplefs,
    % font settings
    fsno.store = \covexamplenofs,
    % preamble
    preamble.store = \cov@xp,
    % postamble
    postamble.code = { \def\cov@xpst{#1}\@cov@expst@starfalse },
    % postamble* (no space)
    postamble*.code = { \def\cov@xpst{#1}\@cov@expst@startrue },
    % preamble text
    subpreamble.store = \cov@sxp,
    % postamble text
    subpostamble.store = \cov@sxpst,
    % preamble font settings
    fspreamble.store = \expreamblefs,
    % postamble font settings
    fspostamble.store = \expostamblefs,
    % preamble font settings
    fssubpreamble.store = \subexpreamblefs,
    % postamble font settings
    fssubpostamble.store = \subexpostamblefs,
    % leftmargin
    leftmargin.code = { \setlength{\exampleind}{#1} },
    % addnumbersep
    addnumbersep.code = { \setlength{\examplenumbersep}{#1} },
    % addsubnumbersep
    addsubnumbersep.code = { \setlength{\subexamplenumbersep}{#1} },
    % numberformat={template}
    numberformat.code = { 
       \cov@parse@number@template{#1}{exfmt}{covexnumber}
       \exfmtgchangedtrue
    },
    % fnnumberformat={template}
    fnumberformat.code = { \cov@parse@number@template{#1}{fnexfmt}{covexnumberfn} },
    % subnumberformat={template}
    subnumberformat.code = { \cov@parse@number@template{#1}{subexfmt}{covsubexnumber} },
    % judge=text
    judge.code = { \def\cov@judge@ex@text@global{#1} \settowidth\cov@judge@width{#1} },
    % subjudge=text
    subjudge.code = { \def\cov@subjudge@ex@text{#1} \settowidth\cov@judge@width{#1} },
    % judgement shorthands: *, ?, *?, ??, #
    *.code = 
       { \def\cov@judge@ex@text@global{*}
         \def\cov@subjudge@ex@text{*}
         \settowidth\cov@judge@width{\cov@judge@fs*}
       },
    ?.code =
       { \def\cov@judge@ex@text@global{?} 
         \def\cov@subjudge@ex@text{?} 
         \settowidth\cov@judge@width{\cov@judge@fs?}
       },
    *?.code =
       { \def\cov@judge@ex@text@global{*?}
         \def\cov@subjudge@ex@text{*?}
         \settowidth\cov@judge@width{\cov@judge@fs*?}
       },
    ??.code =
       { \def\cov@judge@ex@text@global{??}
         \def\cov@subjudge@ex@text{??}
         \settowidth\cov@judge@width{\cov@judge@fs??}
       },
    #.code =
      { \def\cov@judge@ex@text@global{\#}
        \def\cov@subjudge@ex@text{\#}
        \settowidth\cov@judge@width{\cov@judge@fs\#}
      },
    % judgement font settings
    fsjudge.store = \cov@judge@fs,
    % judgewith=<text>
    judgewidth.code = { \settowidth\cov@judge@width{#1} },
    % addjudgesep=length
    addjudgesep.code = { \addtolength\cov@judge@sep{#1} }
}

% General setting option
\newcommand*\setexampleoptions[1]{\SetKeys[gcovexamples]{#1}}



%%%
%%% Reference to examples including parentheses
%%%

% New in v1.6 (2018-09-07)
\providecommand*\pxref[1]{(\ref{#1})}


%%%
%%% Sentences with word-by-word glosses
%%%

% See covington.tex for full documentation.  Some examples:
%
% Displayed sentence with gloss and translation:
%
%             \gll Dit is een Nederlands voorbeeld.
%                  This is a Dutch example.
%             \glt `This is an example in Dutch.'
%             \glend
%
% Same, using bracketing where words do not correspond one-to-one:
%
%             \gll Dit is een voorbeeldje     in het Nederlands.
%                  This is a {little example} in {}  Dutch.
%             \glt `This is a little example in Dutch.'
%             \glend
%
% Same, with example number added at right:
%
%             \gll Dit is een voorbeeldje     in het Nederlands.
%                  This is a {little example} in {}  Dutch.
%             \glt `This is a little example in Dutch.' \hfill (\exampleno)
%             \glend
%
% Same, with number but no (line reserved for) translation:
%
%             \gll Dit is een voorbeeldje     in het Nederlands.
%                  This is a {little example} in {}  Dutch.
%             \gln \hfill (\exampleno)
%             \glend
%
% If you want to align 3 lines rather than two, use \glll instead of \gll.
%
% Layout is critical between \gll (or \glll) and \glt (or \gln).
% After \glt, environment is essentially the same as 'flushleft'.
%
% Thanks to Marcel R. van der Goot for permission to reproduce code.
%
% Modified 1992 Nov 8 to force single spacing regardless of 
% baselinestretch.

\@ifundefined{new@fontshape}%
   {\def\cov@selfnt{\ifx\@currsize\normalsize\@normalsize\else\@currsize\fi}}
   {\def\cov@selfnt{\selectfont}}
   % Thanks to Hans-Peter Kolb for this macro.

% Try to prevent page breaks in glosses if noglossbreaks option is set
\def\cov@nopagebreak{}
\ifnoglossbreaks
  \def\cov@nopagebreak{\let\reserved@e\vadjust\let\reserved@f\nobreak}
\fi

\def\cov@emphasized{\normalfont\itshape}%
\def\cov@normalfont{\normalfont\upshape}%

\def\cov@fsglpreamble@global{\cov@normalfont}
\def\cov@fsglpostamble@global{\cov@normalfont}
\def\cov@fstl@global{\cov@normalfont}

% 2019-05-07: optional preceding gloss text (non-interlinearized)
\def\fsglpreamble{\cov@fsglpreamble@global}
\newcommand*\glosslinepreamble[1]{\bgroup\fsglpreamble{}#1\egroup}
\def\cov@gl@preamble@text{}
\newcommand*\glosspreamble[1]{\def\cov@gl@preamble@text{#1}}

% 2021-09-01: optional trailing gloss text (non-interlinearized)
\def\fsglpostamble{\cov@fsglpostamble@global}
\newcommand*\glosslinepostamble[1]{\bgroup\fsglpostamble{}#1\egroup}
\def\cov@gl@postamble@text{}

% Optional extra space between gloss lines
\newlength\cov@glossline@sepi
\setlength\cov@glossline@sepi{0pt}
\newlength\cov@glossline@sepii
\setlength\cov@glossline@sepii{0pt}
\newlength\cov@glossline@sepiii
\setlength\cov@glossline@sepiii{0pt}
\newlength\cov@glossline@sepi@local
\setlength\cov@glossline@sepi@local{0pt}
\newlength\cov@glossline@sepii@local
\setlength\cov@glossline@sepii@local{0pt}
\newlength\cov@glossline@sepiii@local
\setlength\cov@glossline@sepiii@local{0pt}

\newlength\cov@glosswidth@local
\newlength\cov@glosssep@local
\newlength\cov@glosspwidth@local
\setlength\cov@glosswidth@local{0pt}
\setlength\cov@glosssep@local{0pt}
\setlength\cov@glosspwidth@local{0pt}

\def\gll{%                  % Introduces 2-line text-and-gloss.
  \begin{flushleft}
  \vskip\baselineskip%      % Added 1992 Nov 8 to force single spacing
  \def\baselinestretch{1}%
  \cov@selfnt%
  \vskip-\baselineskip%
  \bgroup
  \catcode`\^^M=12
  \twosent
}

\def\glll{%                  % Introduces 3-line text-and-gloss.
   \begin{flushleft}
   \vskip\baselineskip%      % Added 1992 Nov 8 to force single spacing
   \def\baselinestretch{1}%
   \cov@selfnt%
   \vskip-\baselineskip%
   \bgroup
   \catcode`\^^M=12
   \threesent
}


% The following two \x.. versions introduce special forms of glossing
% macros that do not activate the newline char. The latter does not
% work inside arguments (see http://tex.stackexchange.com/questions/169740)
% Inspired by this post of David Carlisle to the mentioned stackexchange thread:
% http://tex.stackexchange.com/a/169744/19291
% These macros require the gloss lines to be ended explicitly with \xgle
\def\xgll{%                 % Introduces 2-line text-and-gloss.
   \begin{flushleft}
   \vskip\baselineskip%      % Added 1992 Nov 8 to force single spacing
   \def\baselinestretch{1}%
   \cov@selfnt%
   \vskip-\baselineskip%
   \bgroup
   \ignorespaces\xtwosent
}

\def\xglll{%                 % Introduces 3-line text-and-gloss.
   \begin{flushleft}
   \vskip\baselineskip%      % Added 1992 Nov 8 to force single spacing
   \def\baselinestretch{1}%
   \cov@selfnt%
   \vskip-\baselineskip%
   \bgroup
   \ignorespaces\xthreesent
}

\newsavebox{\pline} % the constructed preamble line (hbox)

\RequirePackage{varwidth}

\newlength\glosswidth
\newlength\glosssep
\setlength\glosssep{1em}
\newlength\glosspwidth

\AtBeginDocument{\setlength\glosswidth{.6\textwidth}}%

\def\glt{%
    \setlength\glosswidth{.6\linewidth}%
    \if@cov@glosspline%
      %
      \begin{varwidth}[t]{\cov@glosswidth@local}
      	{\hskip -\glossglue}\unhbox\gline%
      \end{varwidth}%
      \hspace{\cov@glosssep@local}%
      \usebox{\pline}%
    \else%
       {\hskip -\glossglue}\cov@nopagebreak\unhbox\gline%
    \fi%
    \smallskip\cov@nopagebreak\newline% % \newline was \\
}
                           % Introduces translation.
                           % Required even if no translation follows.

\def\glnx{%
    \setlength\glosswidth{.6\linewidth}%
    \if@cov@glosspline%
      %
      \begin{varwidth}[t]{\cov@glosswidth@local}
      	{\hskip -\glossglue}\unhbox\gline%
      \end{varwidth}%
      \hspace{\cov@glosssep@local}%
      \usebox{\pline}%
    \else%
       {\hskip -\glossglue}\cov@nopagebreak\unhbox\gline%
    \fi%
}  

\def\gln{{\hskip -\glossglue}\unhbox\gline\hfill}
                           % Alternative to glt, when one wants to
                           % put a number but no translation.

\def\glend{%
   \end{flushleft}%
   \def\cov@gl@preamble@text{}%
   \def\cov@gl@postamble@text{}%
}  % Ends the gloss environment.

% The following TeX code is adapted, with permission, from:
% gloss.tex: Macros for vertically aligning words in consecutive sentences.
% Version: 1.0  release: 26 November 1990
% Copyright (c) 1991 Marcel R. van der Goot (marcel@cs.caltech.edu).
% Original gloss.tex and gloss.doc are available from
% csvax.cs.caltech.edu [131.215.131.131] in pub/tex
% and many other anonymous ftp archives.

\newbox\lineone % boxes with words from first line
\newbox\linetwo
\newbox\linethree
\newbox\wordone % a word from the first line (hbox)
\newbox\wordtwo
\newbox\wordthree
\newbox\gline % the constructed double line (hbox)
\newskip\glossglue % extra glue between glossed pairs or triples
% \glossglue = 0pt plus 2pt minus 1pt % allow stretch/shrink between words
\glossglue = 5pt plus 2pt minus 1pt % allow stretch/shrink between words
\newif\ifnotdone

% Font settings for gloss lines
\newcommand*\glosslineone{\cov@emphasized}
\newcommand*\glosslinetwo{\cov@normalfont}
\newcommand*\glosslinethree{\cov@normalfont}

\def\eachwordone{\glosslineone}
\def\eachwordtwo{\glosslinetwo}
\def\eachwordthree{\glosslinethree}

\def\lastword#1#2#3% #1 = \each, #2 = line box, #3 = word box
   {\setbox#2=\vbox{\unvbox#2%
                    \global\setbox#3=\lastbox
                   }%
    \ifvoid#3\global\setbox#3=\hbox{#1\strut{} }\fi
        % extra space following \strut in case #1 needs a space
   }

\def\testdone
   {\ifdim\ht\lineone=0pt
         \ifdim\ht\linetwo=0pt \notdonefalse % tricky space after pt
         \else\notdonetrue
         \fi
    \else\notdonetrue
    \fi
   }

{\catcode`\^^M=12 \endlinechar=-1 % 12 = other
\gdef\getwords(#1,#2)#3 #4^^M% #1=linebox, #2=\each, #3=1st word, #4=remainder
   {\setbox#1=\vbox{\hbox{#2\strut#3 }% adds space
                    \unvbox#1%
                   }%
    \def\more{#4}%
    \ifx\more\empty\let\more=\donewords
    \else\let\more=\getwords
    \fi
    \more(#1,#2)#4^^M%
   }

\gdef\donewords(#1,#2)^^M{}%

\gdef\twosent#1^^M#2^^M% #1 = first line, #2 = second line
   {\getwords(\lineone,\eachwordone)#1 ^^M%
    \getwords(\linetwo,\eachwordtwo)#2 ^^M%
    \ifx\cov@gl@preamble@text\empty%
    \else%
       \glosslinepreamble{\cov@gl@preamble@text}\cov@nopagebreak\newline%
    \fi%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{% vtop was vbox
                                          \box\wordone
                                          \nointerlineskip
                                          \box\wordtwo
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   }

\gdef\threesent#1^^M#2^^M#3^^M% #1 = first line, #2 = second line, #3 = third
   {\getwords(\lineone,\eachwordone)#1 ^^M%
    \getwords(\linetwo,\eachwordtwo)#2 ^^M%
    \getwords(\linethree,\eachwordthree)#3 ^^M%
    \ifx\cov@gl@preamble@text\empty%
    \else%
       \glosslinepreamble{\cov@gl@preamble@text}\cov@nopagebreak\newline%
    \fi%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{% vtop was vbox
                                          \box\wordone
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   }
} % restore \catcode`\^^M

% An explicit gloss line ending (for \xgll and \xglll variants=
\gdef\xgle{}
% Special versions of \getwords, \donewords, \twosent and \threesent for the \x..
% variants of gloss introducers (using \xgle as separator instead of active newline)
\gdef\xgetwords(#1,#2)#3 #4\xgle% #1=linebox, #2=\each, #3=1st word, #4=remainder
   {\setbox#1=\vbox{\hbox{#2\strut#3 }% adds space
                    \unvbox#1%
                   }%
    \def\more{#4}%
    \ifx\more\empty\let\more=\xdonewords
    \else\let\more=\xgetwords
    \fi
    \more(#1,#2)#4\xgle%
   }

\gdef\xdonewords(#1,#2)\xgle{}%

\gdef\xtwosent#1\xgle#2\xgle% #1 = first line, #2 = second line
   {\xgetwords(\lineone,\eachwordone)#1 \xgle%
    \xgetwords(\linetwo,\eachwordtwo)#2 \xgle%
    \ifx\cov@gl@preamble@text\empty%
    \else%
       \glosslinepreamble{\cov@gl@preamble@text}\cov@nopagebreak\newline%
    \fi%
    \ifx\cov@judge@gloss@text\empty%
    \else
       \bgroup\cov@judge@fs\cov@judge@gloss@text\egroup%
       \hspace{\cov@judge@sep}\ignorespaces%
    \fi
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \global\setbox\gline=\hbox{\unhbox\gline%
                                    \hskip\glossglue%
                                    \vtop{% vtop was vbox
                                          \box\wordone
                                          \vspace{\cov@glossline@sepi@local}
                                          \nointerlineskip
                                          \box\wordtwo
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   }

\gdef\xthreesent#1\xgle#2\xgle#3\xgle% #1 = first line, #2 = second line, #3 = third
   {\xgetwords(\lineone,\eachwordone)#1 \xgle%
    \vspace{\cov@glossline@sepi}%
    \xgetwords(\linetwo,\eachwordtwo)#2 \xgle%
    \xgetwords(\linethree,\eachwordthree)#3 \xgle%
    \ifx\cov@gl@preamble@text\empty%
    \else%
       \glosslinepreamble{\cov@gl@preamble@text}\cov@nopagebreak\newline%
    \fi%
    \ifx\cov@judge@gloss@text\empty%
    \else
       \bgroup\cov@judge@fs\cov@judge@gloss@text\egroup%
       \hspace{\cov@judge@sep}\ignorespaces%
    \fi
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{% vtop was vbox
                                          \box\wordone
                                          \vspace{\cov@glossline@sepi@local}
                                          \nointerlineskip
                                          \box\wordtwo
                                          \vspace{\cov@glossline@sepii@local}
                                          \nointerlineskip
                                          \box\wordthree
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   }

% V. 2.0: enquotable translation line
\newif\ifcov@enquote@tl\cov@enquote@tltrue
\def\cov@fstl{\cov@fstl@global}
\newcommand*\glosslinetrans[1]{\bgroup\cov@fstl\ifcov@enquote@tl\covenquote{#1}\else#1\fi\egroup}
\newcommand*\glot[2][]{%
  \def\tempx{#2}%
  \ifx\tempx\empty%
     \ifcov@tlr@star%
        \glnx
     \else%
        \gln
     \fi%
  \else%
     \glt%
      \ifx#1\empty\else%
        \hphantom{\cov@judge@fs#1}%
        \hspace{\cov@judge@sep}\ignorespaces%
      \fi%
     \glosslinetrans{#2}%
  \fi%
}

% V. 2.0: More convenient gloss macros
%
% Key-val options for the macros
%
\newif\ifcov@ex@gloss\cov@ex@glossfalse
\newif\ifcov@ex@gloss@global\cov@ex@gloss@globalfalse
\newif\ifcov@tlr\cov@tlrfalse
\newif\ifcov@tlr@global\cov@tlr@globalfalse
\newif\ifcov@tlr@star\cov@tlr@starfalse
\newif\ifcov@tlr@star@global\cov@tlr@star@globalfalse
\newif\ifcov@enquote@tl@global\cov@enquote@tl@globaltrue
\def\cov@gl@preamble@global{}
\def\cov@gl@postamble@global{}

\DeclareKeys[covgloss]
{
    % ex=<true|false>
    ex.if = cov@ex@gloss,
    % tlr=<true|false>
    tlr.if = cov@tlr,
    % tlr*=<true|false>
    tlr*.if = cov@tlr@star,
    % font settings for gloss line i, ii, iii
    fsi.store = \glosslineone@local,
    fsii.store = \glosslinetwo@local,
    fsiii.store = \glosslinethree@local,
    % Gloss preamble text
    preamble.code = { \edef\cov@gl@preamble{#1} },
    % Gloss postamble text
    postamble.store = \cov@gl@postamble,
    % Gloss preamble font settings
    fspreamble.store = \cov@fsglpreamble@local,
    % Gloss postamble font settings
    fspostamble.store = \cov@fsglpostamble@local,
    % Enquote translation line
    enquotetl.if = cov@enquote@tl,
    % translation line font settings
    fstl.store = \cov@fstl@local,
    % judge=text
    judge.code = { \def\cov@judge@gloss@text{#1} },
    % judgement shorthands: *, ?, *?, ??, #
    *.code = { \def\cov@judge@gloss@text{*} },
    ?.code = { \def\cov@judge@gloss@text{?} },
    *?.code = { \def\cov@judge@gloss@text{*?} },
    ??.code = { \def\cov@judge@gloss@text{??} },
    #.code = { \def\cov@judge@gloss@text{\#} },
    % judgement font settings
    fsjudge.store = \cov@judge@fs,
    % addjudgesep=length
    addjudgesep.code = { \addtolength\cov@judge@sep{#1} },
    % addlinesepi=length
    addlinesepi.code = { \addtolength\cov@glossline@sepi@local{#1} },
    % addlinesepii=length
    addlinesepii.code = { \addtolength\cov@glossline@sepii@local{#1} },
    % addlinesepiii=length
    addlinesepiii.code = { \addtolength\cov@glossline@sepiii@local{#1} },
    % glosswidth=length
    glosswidth.code = { \setlength\cov@glosswidth@local{#1} },
    % glosssep=length
    glosssep.code = { \setlength\cov@glosssep@local{#1} },
    % glosscommentwidth=length
    glosscommentwidth.code = { \setlength\cov@glosspwidth@local{#1} },
    % comment font settings
    fscomments.store = \cov@closscomments@fs
}

\DeclareKeys[gcovgloss]
{
    % 1. ex=<true|false>
    ex.if = cov@ex@gloss@global,
    % 2. tlr=<true|false>
    tlr.if = cov@tlr@global,
    % 2. tlr*=<true|false>
    tlr*.if = cov@tlr@star@global,
    % 3. font settings for gloss line i, ii, iii
    fsi.code = { \global\def\glosslineone@global{#1} },
    fsii.code = { \global\def\glosslinetwo@global{#1} },
    fsiii.code = { \global\def\glosslinethree@global{#1} },
    % 4. Gloss preamble text
    preamble.code = { \global\def\cov@gl@preamble@global{#1} },
    % 5. Gloss postamble text
    postamble.code = { \global\def\cov@gl@postamble@global{#1} },
    % 6. Gloss preamble font settings
    fspreamble.code = { \global\def\cov@fsglpreamble@global{#1} },
    % 7. Gloss postamble font settings
    fspostamble.code = { \global\def\cov@fsglpostamble@global{#1} },
    % 8. Enquote translation line
    enquotetl.if = cov@enquote@tl@global,
    % 9. translation line font settings
    fstl.code = { \global\def\cov@fstl@global{#1} },
    % judge=text
    judge.code = { \def\cov@judge@gloss@text@global{#1} },
    % judgement shorthands: *, ?, *?, ??, #
    *.code = { \def\cov@judge@gloss@text@global{*} },
    ?.code = { \def\cov@judge@gloss@text@global{?} },
    *?.code = { \def\cov@judge@gloss@text@global{*?} },
    ??.code = { \def\cov@judge@gloss@text@global{??} },
    #.code = { \def\cov@judge@gloss@text@global{\#} },
    % judgement font settings
    fsjudge.store = \cov@judge@fs,
    % addjudgesep=length
    addjudgesep.code = { \addtolength\cov@judge@sep{#1} },
    % addjudgesep=length
    addjudgesep.code = { \addtolength\cov@judge@sep{#1} },
    % addlinesepi=length
    addlinesepi.code = { \addtolength\cov@glossline@sepi{#1} },
    % addlinesepii=length
    addlinesepii.code = { \addtolength\cov@glossline@sepii{#1} },
    % addlinesepiii=length
    addlinesepiii.code = { \addtolength\cov@glossline@sepiii{#1} },
    % glosswidth=length
    glosswidth.code = { \setlength\glosswidth{#1} },
    % glosssep=length
    glosssep.code = { \setlength\glosssep{#1} },
    % glosscommentwidth=length
    glosscommentwidth.code = { \setlength\glosspwidth{#1} },
    % judgement font settings
    fscomments.store = \cov@closscomments@fs
}


\let\cov@fsglpreamble@local\relax%
\let\cov@fsglpostamble@local\relax%
\let\cov@fstl@local\relax%

\newif\if@cov@glosspline

%
% General setting option
\newcommand*\setglossoptions[1]{\SetKeys[gcovgloss]{#1}}

% Empty environment (to keep changes local)
\newenvironment{covgloss}{}{}
%
% 1. \digloss[<opts>]{<line 1>}[linepostamble1]
%                    {<line 2>}[linepostamble2]
%                    {<translation>}
\NewDocumentCommand\digloss{ o m o m o m }
{
  \@cov@glossplinefalse%
  \@cov@insubextrue%
  \@ifundefined{cov@judge@gloss@text@global}%
     {\let\cov@judge@gloss@text\relax}%
     {\let\cov@judge@gloss@text\cov@judge@gloss@text@global}%
  \let\glosslineone@local\relax%
  \let\glosslinetwo@local\relax%
  \let\glosslinethree@local\relax%
  \@ifundefined{glosslineone@global}{}{\def\glosslineone{\glosslineone@global}}%
  \@ifundefined{glosslinetwo@global}{}{\def\glosslinetwo{\glosslinetwo@global}}%
  \@ifundefined{glosslinethree@global}{}{\def\glosslinethree{\glosslinethree@global}}%
  \setlength\cov@glossline@sepi@local{\cov@glossline@sepi}%
  \setlength\cov@glossline@sepii@local{\cov@glossline@sepii}%
  \setlength\cov@glossline@sepiii@local{\cov@glossline@sepiii}%
  \setlength\cov@glosswidth@local{\glosswidth}%
  \setlength\cov@glosssep@local{\glosssep}%
  \setlength\glosspwidth{\textwidth}%
  \addtolength\glosspwidth{-\glosswidth}%
  \addtolength\glosspwidth{-\glosssep}%
  \setlength\cov@glosspwidth@local{\glosspwidth}%
  \ifcov@ex@gloss@global
    \SetKeys[covgloss]{ex=true}
  \else
    \SetKeys[covgloss]{ex=false}
  \fi%
  \ifcov@tlr@global
    \SetKeys[covgloss]{tlr=true}
  \else
    \SetKeys[covgloss]{tlr=false}
  \fi%
  \ifcov@tlr@star@global
    \SetKeys[covgloss]{tlr*=true}
  \else
    \SetKeys[covgloss]{tlr*=false}
  \fi%
  \ifcov@enquote@tl@global
    \SetKeys[covgloss]{enquotetl=true}
  \else
    \SetKeys[covgloss]{enquotetl=false}
  \fi%
  \def\cov@gl@preamble{\cov@gl@preamble@global}%
  \def\cov@gl@postamble{\cov@gl@postamble@global}%
  \IfNoValueF{#1}{\SetKeys[covgloss]{#1}}%
  \ifcov@ex@gloss
    \begin{covexample}
  \else%
    \begin{covgloss}
  \fi%
  \@ifundefined{glosslineone@local}{}{\def\glosslineone{\glosslineone@local}}%
  \@ifundefined{glosslinetwo@local}{}{\def\glosslinetwo{\glosslinetwo@local}}%
  \@ifundefined{glosslinethree@local}{}{\def\glosslinethree{\glosslinethree@local}}%
  \edef\cov@gl@preamble@text{\cov@gl@preamble}%
  \def\cov@gl@postamble@text{\cov@gl@postamble}%
  \@ifundefined{cov@fsglpreamble@local}%
       {\let\fsglpreamble\cov@fsglpreamble@global}%
       {\let\fsglpreamble\cov@fsglpreamble@local}%
  \@ifundefined{cov@fsglpostamble@local}%
       {\let\fsglpostamble\cov@fsglpostamble@global}%
       {\let\fsglpostamble\cov@fsglpostamble@local}%
  \@ifundefined{cov@fstl@local}%
       {\let\cov@fstl\cov@fstl@global}%
       {\let\cov@fstl\cov@fstl@local}%
  \ifcov@tlr@star%
     \@cov@glossplinetrue\def\lineonepa{%
        \glosslinetrans{#6}%
         \ifx\cov@gl@postamble@text\empty%
         \else%
           \glosslinepostamble{\cov@gl@postamble@text}\cov@nopagebreak%
         \fi%
     }%
     \def\linetwopa{\strut}%
  \else%
    \IfNoValueTF{#3}{\def\lineonepa{\strut}}%
                    {\@cov@glossplinetrue\def\lineonepa{\cov@closscomments@fs#3}}%
    \IfNoValueTF{#5}{\def\linetwopa{\strut}}%
                    {\@cov@glossplinetrue\def\linetwopa{\cov@closscomments@fs#5}}%
  \fi%
  \if@cov@glosspline%
      \savebox{\pline}{%
           \begin{varwidth}[t]{\cov@glosspwidth@local}
            \lineonepa\par
            \vspace{\cov@glossline@sepi@local}
            \linetwopa
           \end{varwidth}
       }%
  \fi
  \xgll #2\xgle
        #4\xgle
  \ifcov@tlr@star\glot{}\else%
    \ifcov@tlr
      \gln #6%
    \else
      \IfBlankF{#6}{%
         \vspace{\cov@glossline@sepii@local}%
      }%
      \ifx\cov@judge@gloss@text\empty%
        \glot{#6}%
      \else%
         \glot[\cov@judge@gloss@text]{#6}%
      \fi%
    \fi%
    \ifx\cov@gl@postamble@text\empty%
    \else%
       \glosslinepostamble{\cov@gl@postamble@text}\cov@nopagebreak%
    \fi%
  \fi%
  \glend
  \ifcov@ex@gloss
    \end{covexample}
  \else%
    \end{covgloss}
  \fi%
  \let\glosslineone@local\relax%
  \let\glosslinetwo@local\relax%
  \let\glosslinethree@local\relax%
  \let\cov@fsglpreamble@local\relax%
  \let\cov@fsglpostamble@local\relax%
  \let\cov@fstl@local\relax%
  \let\cov@judge@gloss@text\relax%
  \@cov@insubexfalse%
}

% 2. \trigloss[<opts>]{<line 1>}[linepostamble1]
%                    {<line 2>}[linepostamble2]
%                    {<line 3>}[linepostamble3]
%                    {<translation>}
\NewDocumentCommand\trigloss{ o m o m o m o m }
{%
  \@cov@insubextrue%
  \@ifundefined{cov@judge@gloss@text@global}%
     {\let\cov@judge@gloss@text\relax}%
     {\let\cov@judge@gloss@text\cov@judge@gloss@text@global}%
  \let\glosslineone@local\relax%
  \let\glosslinetwo@local\relax%
  \let\glosslinethree@local\relax%
  \@ifundefined{glosslineone@global}{}{\def\glosslineone{\glosslineone@global}}%
  \@ifundefined{glosslinetwo@global}{}{\def\glosslinetwo{\glosslinetwo@global}}%
  \@ifundefined{glosslinethree@global}{}{\def\glosslinethree{\glosslinethree@global}}%
  \setlength\cov@glossline@sepi@local{\cov@glossline@sepi}%
  \setlength\cov@glossline@sepii@local{\cov@glossline@sepii}%
  \setlength\cov@glossline@sepiii@local{\cov@glossline@sepiii}%
  \setlength\cov@glosswidth@local{\glosswidth}%
  \setlength\cov@glosssep@local{\glosssep}%
  \setlength\glosspwidth{\textwidth}%
  \addtolength\glosspwidth{-\glosswidth}%
  \addtolength\glosspwidth{-\glosssep}%
  \setlength\cov@glosspwidth@local{\glosspwidth}%
  \ifcov@ex@gloss@global
    \SetKeys[covgloss]{ex=true}
  \else
    \SetKeys[covgloss]{ex=false}
  \fi%
  \ifcov@tlr@global
    \SetKeys[covgloss]{tlr=true}
  \else
    \SetKeys[covgloss]{tlr=false}
  \fi%
  \ifcov@tlr@star@global
    \SetKeys[covgloss]{tlr*=true}
  \else
    \SetKeys[covgloss]{tlr*=false}
  \fi%
  \ifcov@enquote@tl@global
    \SetKeys[covgloss]{enquotetl=true}
  \else
    \SetKeys[covgloss]{enquotetl=false}
  \fi%
  \def\cov@gl@preamble{\cov@gl@preamble@global}%
  \def\cov@gl@postamble{\cov@gl@postamble@global}%
  \IfNoValueF{#1}{\SetKeys[covgloss]{#1}}%
  \ifcov@ex@gloss
    \begin{covexample}
  \else
    \begin{covgloss}
  \fi%
  \@ifundefined{glosslineone@local}{}{\def\glosslineone{\glosslineone@local}}%
  \@ifundefined{glosslinetwo@local}{}{\def\glosslinetwo{\glosslinetwo@local}}%
  \@ifundefined{glosslinethree@local}{}{\def\glosslinethree{\glosslinethree@local}}%
  \edef\cov@gl@preamble@text{\cov@gl@preamble}%
  \def\cov@gl@postamble@text{\cov@gl@postamble}%
  \@ifundefined{cov@fsglpreamble@local}%
       {\let\fsglpreamble\cov@fsglpreamble@global}%
       {\let\fsglpreamble\cov@fsglpreamble@local}%
  \@ifundefined{cov@fsglpostamble@local}%
       {\let\fsglpostamble\cov@fsglpostamble@global}%
       {\let\fsglpostamble\cov@fsglpostamble@local}%
  \@ifundefined{cov@fstl@local}%
       {\let\cov@fstl\cov@fstl@global}%
       {\let\cov@fstl\cov@fstl@local}%
  \ifcov@tlr@star%
     \@cov@glossplinetrue\def\lineonepa{%
        \glosslinetrans{#8}%
         \ifx\cov@gl@postamble@text\empty%
         \else%
           \glosslinepostamble{\cov@gl@postamble@text}\cov@nopagebreak%
         \fi%
     }%
     \def\linetwopa{\strut}%
  \else%
    \IfNoValueTF{#3}{\def\lineonepa{\strut}}{\@cov@glossplinetrue\def\lineonepa{\cov@closscomments@fs#3}}%
    \IfNoValueTF{#5}{\def\linetwopa{\strut}}{\@cov@glossplinetrue\def\linetwopa{\cov@closscomments@fs#5}}%
    \IfNoValueTF{#7}{\def\linethreepa{\strut}}{\@cov@glossplinetrue\def\linethreepa{\cov@closscomments@fs#7}}%
  \fi%
  \if@cov@glosspline%
      \savebox{\pline}{%
           \begin{varwidth}[t]{\cov@glosspwidth@local}
            \lineonepa\par
            \vspace{\cov@glossline@sepi@local}
            \linetwopa\par
            \vspace{\cov@glossline@sepii@local}
            \linethreepa
            \end{varwidth}
       }%
  \fi
  \xglll #2\xgle
         #4\xgle
         #6\xgle
  \ifcov@tlr@star\glot{}\else%
    \ifcov@tlr
      \gln #8%
    \else
      \IfBlankF{#8}{%
         \vspace{\cov@glossline@sepiii@local}%
      }%
      \ifx\cov@judge@gloss@text\empty%
        \glot{#8}%
      \else%
         \glot[\cov@judge@gloss@text]{#8}%
      \fi%
    \fi
    \ifx\cov@gl@postamble@text\empty%
    \else%
       \glosslinepostamble{\cov@gl@postamble@text}\cov@nopagebreak%
    \fi%
  \fi%
  \glend
  \ifcov@ex@gloss
    \end{covexample}
  \else%
    \end{covgloss}
  \fi%
  \let\glosslineone@local\relax%
  \let\glosslinetwo@local\relax%
  \let\glosslinethree@local\relax%
  \let\cov@fsglpreamble@local\relax%
  \let\cov@fsglpostamble@local\relax%
  \let\cov@fstl@local\relax%
  \let\cov@judge@gloss@text\relax%
  \@cov@insubexfalse%
}


%\def\gloss   % raw TeX macro for 2 aligned lines
%   {\bgroup
%    \catcode`\^^M=12
%    \twosent
%   }


%%%
%%% Phrase-structure rules
%%%

% \psr         To print S -> NP VP, use: \psr{S}{NP~VP}

\newcommand{\psr}[2]{\mbox{\cov@emphasized #1 $\rightarrow$ #2}}


%%%
%%% Feature structures
%%%

% \fs         To print a feature structure by itself, type for example
%             \fs{case:nom \\ person:P}
%
% \lfs        To print the same feature structure with the category
%             label N at the top, type:
%             \lfs{N}{case:nom \\ person:P}

%    Modified 1990 Dec 5 so that features are left aligned.
%    Modified 2001 Mar 27 so that italics are used without the user typing \it.
\newcommand{\fs}[1]
{
    \mbox{\small\cov@emphasized
          $
          \left[
          \!\!
          \begin{array}{l}
          #1
          \end{array}
          \!\!
          \right]
          $}
}

%     Modified 1990 Dec 5 so that features are left aligned.
\newcommand{\lfs}[2]
   {
     \mbox{\cov@emphasized
           $
           \!\!
           \begin{array}[t]{c}
           #1
           \\
           \mbox{\small%
                 $
                 \left[
                 \!\!
                 \begin{array}{l}
                 #2
                 \end{array}
                 \!\!
                 \right]
                 $}
           \end{array}
           \!\!
           $}
   }


%%%
%%% Discourse representation structures
%%%

% \drs        typesets a DRS in box notation a la Kamp.
%             Arguments:
%             1. List of discourse variables joined by ~
%             2. List of conditions joined by \\
%
%             Example:   \drs{X}{donkey(X)\\green(X)}
%
%             Example:   \drs{~}{purple(X,Y)}
%
%             Example:   \drs{X}
%                            {named(X,`Pedro') \\
%                             \drs{Y}{donkey(Y)\\owns(X,Y)}~~
%                             {\large $\Rightarrow$}~
%                             \drs{~}{feeds(X,Y)}
%                            }

% \sdrs       like \drs but first argument is a sentence
%             to be displayed above the drs.
%
%             Example:   \sdrs{A donkey is green.}{X}{donkey(X)\\green(X)}

% \ifdrs      forms 2 DRSes joined with a big arrow.
%             Usually used for DRSes nested within another.
%
%             Example:   \ifdrs{X}{donkey(X)\\hungry(X)}
%                              {~}{feeds(Pedro,X)}

% \alifdrs    is like \ifdrs but shifted to the left so that an
%             embedded `if' structure will line up with ordinary
%             DRS conditions.

% \negdrs     forms a DRS preceded by the negation symbol.
%
%             Example:   \negdrs{X}{donkey(X)\\green(X)}

% 2019-06-21 (v. 2.3): Do not define the macros if already defined.
%                      This allows to use covington with the drs package.


\providecommand{\drs}[2]
{
    {
    \cov@emphasized
    \begin{tabular}{|l|}
    \hline
    ~ \vspace{-2ex} \\
    #1
    \\
    ~ \vspace{-2ex} \\
    \hline
    ~ \vspace{-2ex} \\
    #2
    \\
    ~ \\    % can't vspace here or the line will come out wrong
    \hline
    \end{tabular}
    }
}

\providecommand{\sdrs}[3]{%
  \begin{tabular}{l}
  \mbox{\cov@emphasized #1} \\
  ~ \\
  \drs{#2}{#3}
  \end{tabular}%
}

\providecommand{\ifdrs}[4]
{
  \mbox{\drs{#1}{#2}~~{\large $\Rightarrow$}~\drs{#3}{#4}}
}

\providecommand{\alifdrs}[4]
{
  \mbox{$\!\!\!$\drs{#1}{#2}~~{\large $\Rightarrow$}~\drs{#3}{#4}}
}

\providecommand{\negdrs}[2]
{
  \mbox{{\large $\neg$}\drs{#1}{#2}}
}


%
% Exercises, reference lists, and miscellany
%

% exercise    Environment for exercises, numbered by subsection.
%             Optional argument for describing the exercise
%             ("Project" or the like).
%
% New in 1.1 (2016-07-06):
%            We provide a covexercise environment and only (re)define
%            exercise if it does not yet exist or if redefinition is
%            forced by the "force" option. This prevents clashes
%            with packages/classes that roll their own exercise environment.

% \bx         Abbreviation for \begin{covexercise}
% \ex         Abbreviation for \end{covexercise}

% reflist     Environment for hanging-indented list
%             (suitable for LSA-style reference list).
%             Does NOT require \item before entries.

% \sentence   Displays its argument, flushleft, italicized.

% \either     Displays its arguments as alternatives between
%             large curly brackets.  Good for alternatives
%             within sentences or PS-rules.

\ifcsname c@subsection\endcsname
  \newtheorem{covexercise}{Exercise}[subsection]
\else
  \newtheorem{covexercise}{Exercise}
\fi

% Exercise numbering resets to 0 not only at the start of
% a subsection, but also at the start of a section or chapter
% even if it is not divided into subsections.
\@addtoreset{covexercise}{section}
\ifcsname c@chapter\endcsname
  \@addtoreset{covexercise}{chapter}
\fi

\newcommand{\bx}{\begin{covexercise}}
\newcommand{\ex}{\end{covexercise}}

\@ifundefined{exercise}{%
  \newenvironment{exercise}{\begin{covexercise}}{\end{covexercise}}
}{%
  \ifforceredef
    \renewenvironment{exercise}{\begin{covexercise}}{\end{covexercise}}
    \cov@warning{The exercise environment was already defined. Redefining it.}
  \else
    \cov@warning{The exercise environment was already defined.^^J
                 Covington does not touch it.^^J
                 Use covexercise if you want to access covington's^^J
                 version, or use the force package option.}
  \fi
}

\newlength\reflistindent
\setlength\reflistindent{3em}
\newlength\reflistitemsep
\setlength\reflistitemsep{6pt}
\newlength\reflistparsep
\setlength\reflistparsep{\parsep}
\@ifundefined{reflist}{
  \newenvironment{reflist}{%
    \begin{list}{}{%
      \setlength{\labelwidth}{0pt}%
      \setlength{\labelsep}{0pt}%
      \setlength{\leftmargin}{\reflistindent}%
      \setlength{\itemindent}{-\reflistindent}%
      \setlength{\listparindent}{-\reflistindent}%
      \setlength{\itemsep}{\reflistitemsep}%
      \setlength{\parsep}{\reflistparsep}}\item%
    }{\end{list}}%
}
% Modified 1992 Nov 8 to skip defining reflist if reflist is already
% defined.  Permits using uga.sty with covingtn.sty.

% V. 2.0: Add macro for font settings customization
\newcommand*\sentencefs{\cov@emphasized}

\newcommand{\sentence}[1]{%
   \begin{flushleft}%
     {\sentencefs #1}%
   \end{flushleft}%
}

% V. 2.0: Further semantic markup
\providecommand*\lexp[1]{\textit{#1}}
\providecommand*\lcon[1]{\textsc{#1}}
\newcommand*\covenquote[1]{\textquoteleft #1\textquoteright}
\providecommand*\lmean[1]{\covenquote{#1}}

\AtBeginDocument{%
  \@ifundefined{enquote}{}{%
    \renewcommand\covenquote[1]{\enquote*{#1}}
  }
}

\newcommand{\either}[2]
{
     $
     \left\{
     \begin{array}{l}
     \makebox{#1} \\
     \makebox{#2} \\
     \end{array}
     \right\}
     $
}

%%%%%%%%%%%%%%%%% End of Covington's Macros %%%%%%%%%%%%%%%%%
