summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/covington/covington.sty
blob: 06792446c49b5a1adf62c9a7764ccf888b2efe1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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{2023/06/02}
\def\fileversion{2.10}
\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}

\ifownexcounter
  \newcounter{covex}
  \newcommand{\@exampleno}{\refstepcounter{covex}\thecovex}
\else
  \newcommand{\@exampleno}{\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

% 2022-08-20 (v. 2.8): optional preceding example text
\newcommand*\expreamblefs{\normalfont}
\newcommand\expreamble[1]{\bgroup\expreamblefs#1\egroup\par}

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

\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} },
    % fnnumberformat={template}
    fnumberformat.code = { \cov@parse@number@template{#1}{fnexfmt}{covexnumberfn} }
}

\newenvironment{covexample}[1][]{%
    \ifx#1\empty\else\SetKeys[covexpl]{#1}\fi%
    \begin{covexamples}
       \item\@ifundefined{cov@xp}{}{\expreamble{\cov@xp}}% insert preamble if given
}{%
   \@ifundefined{cov@xpst}{}{\if@cov@expst@star\unskip\fi\expostamble{\cov@xpst}}%
   \end{covexamples}%
}

\@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

\newenvironment{covexamples}[1][]{%         % define "examples" environment
  \ifx#1\empty\else\SetKeys[covexpl]{#1}\fi%
  \begin{list}%
  {%
    \covexamplenofs% font
    \ifcov@infootnote
      \covexnumberfn{\thecovfnex}%
    \else
      \covexnumber{\@@exampleno}%
    \fi
  }%
  {%
    \addtolength{\labelwidth}{\examplenumbersep}%
    \addtolength{\leftmargin}{\examplenumbersep}%
    \addtolength{\leftmargin}{\exampleind}%
    \ifcov@infootnote
      \setcounter{covexsave}{\arabic{covfnex}}%
      \usecounter{covfnex}%
      \setcounter{covfnex}{\arabic{covexsave}}%
    \else
      \ifownexcounter
        \renewcommand{\thecovex}{\exfmt{covex}}%
        \setcounter{covexsave}{\arabic{covex}}%
        \usecounter{covex}%                          % sets it to zero, unwantedly
        \setcounter{covex}{\arabic{covexsave}}%   % restores previous value
      \else
        \renewcommand{\theequation}{\exfmt{equation}}%
        \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}

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

\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 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} },
    % fnnumberformat={template}
    fnumberformat.code = { \cov@parse@number@template{#1}{fnexfmt}{covexnumberfn} },
    % subnumberformat={template}
    subnumberformat.code = { \cov@parse@number@template{#1}{subexfmt}{covsubexnumber} }
}

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

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

\let\subexfmt\alph

\newenvironment{covsubexamples}[1][]%         % define "subexamples" environment
{%
    \let\cov@xp\relax%
    \let\cov@xpst\relax%
    \ifx#1\empty\else\SetKeys[covsubexpl]{#1}\fi%
    \begin{covexample}%
    \@ifundefined{cov@sxp}{}{\bgroup\subexpreamblefs\cov@sxp\egroup}% insert preamble if given
    \begin{enumerate}
    \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{enumerate}
    \@ifundefined{cov@sxpst}{}{\subexpostamble{\cov@sxpst}}% insert postamble if given
    \let\cov@sxpst\relax
    \end{covexample}
}

\@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} },
    % fnnumberformat={template}
    fnumberformat.code = { \cov@parse@number@template{#1}{fnexfmt}{covexnumberfn} },
    % subnumberformat={template}
    subnumberformat.code = { \cov@parse@number@template{#1}{subexfmt}{covsubexnumber} }
}

% 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{}

\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
}

\def\glt{{\hskip -\glossglue}\cov@nopagebreak\unhbox\gline\smallskip\cov@nopagebreak\newline}  % \newline was \\
                           % Introduces translation.
                           % Required even if no translation follows.

\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@global{\cov@emphasized}
\newcommand*\glosslinetwo@global{\cov@normalfont}
\newcommand*\glosslinethree@global{\cov@normalfont}

\let\glosslineone\glosslineone@global
\let\glosslinetwo\glosslinetwo@global
\let\glosslinethree\glosslinethree@global

\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%
    \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\xthreesent#1\xgle#2\xgle#3\xgle% #1 = first line, #2 = second line, #3 = third
   {\xgetwords(\lineone,\eachwordone)#1 \xgle%
    \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%
    \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
   }

% 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[1]{%
  \def\tempx{#1}%
  \ifx\tempx\empty\gln
  \else\glt\glosslinetrans{#1}\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@enquote@tl@global\cov@enquote@tl@globaltrue
\def\cov@gl@preamble@global{}
\def\cov@gl@postamble@global{}

\DeclareKeys[covgloss]
{
    % 1. ex=<true|false>
    ex.if = cov@ex@gloss,
    % 2. tlr=<true|false>
    tlr.if = cov@tlr,
    % 3. font settings for gloss line i, ii, iii
    fsi.store = \lglosslineone,
    fsii.store = \lglosslinetwo,
    fsiii.store = \lglosslinethree,
    % 4. Gloss preamble text
    preamble.code = { \edef\cov@gl@preamble{#1} },
    % 5. Gloss postamble text
    postamble.store = \cov@gl@postamble,
    % 6. Gloss preamble font settings
    fspreamble.store = \cov@fsglpreamble@local,
    % 7. Gloss postamble font settings
    fspostamble.store = \cov@fsglpostamble@local,
    % 8. Enquote translation line
    enquotetl.if = cov@enquote@tl,
    % 9. translation line font settings
    fstl.store = \cov@fstl@local
}

\DeclareKeys[gcovgloss]
{
    % 1. ex=<true|false>
    ex.if = cov@ex@gloss@global,
    % 2. tlr=<true|false>
    tlr.if = cov@tlr@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} }
}


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

%
% General setting option
\newcommand*\setglossoptions[1]{\SetKeys[gcovgloss]{#1}}
%
% 1. \digloss[<opts>]{<line 1>}{<line 2>}{<translation>}
\newcommand*\digloss[4][\empty]{%
  \let\lglosslineone\relax%
  \let\lglosslinetwo\relax%
  \let\lglosslinethree\relax%
  \let\glosslineone\glosslineone@global%
  \let\glosslinetwo\glosslinetwo@global%
  \let\glosslinethree\glosslinethree@global%
  \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@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}%
  \ifx#1\empty\else\SetKeys[covgloss]{#1}\fi%
  \ifcov@ex@gloss
    \begin{covexample}
  \fi%
  \@ifundefined{lglosslineone}{}{\def\glosslineone{\lglosslineone}}%
  \@ifundefined{lglosslinetwo}{}{\def\glosslinetwo{\lglosslinetwo}}%
  \@ifundefined{lglosslinethree}{}{\def\glosslinethree{\lglosslinethree}}%
  \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}%
  \xgll #2\xgle
        #3\xgle
  \ifcov@tlr
    \gln #4%
  \else
    \glot{#4}%
  \fi
  \ifx\cov@gl@postamble@text\empty%
  \else%
     \glosslinepostamble{\cov@gl@postamble@text}\cov@nopagebreak%
  \fi%
  \glend
  \ifcov@ex@gloss
    \end{covexample}
  \fi%
  \let\lglosslineone\relax%
  \let\lglosslinetwo\relax%
  \let\lglosslinethree\relax%
  \let\cov@fsglpreamble@local\relax%
  \let\cov@fsglpostamble@local\relax%
  \let\cov@fstl@local\relax%
}

% 2. \trigloss[<opts>]{<line 1>}{<line 2>}{<line 3>}{<translation>}
\newcommand\trigloss[5][\empty]{%
  \let\lglosslineone\relax%
  \let\lglosslinetwo\relax%
  \let\lglosslinethree\relax%
  \let\glosslineone\glosslineone@global%
  \let\glosslinetwo\glosslinetwo@global%
  \let\glosslinethree\glosslinethree@global%
  \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@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}%
  \ifx#1\empty\else\SetKeys[covgloss]{#1}\fi%
  \ifcov@ex@gloss
    \begin{covexample}
  \fi%
  \@ifundefined{lglosslineone}{}{\def\glosslineone{\lglosslineone}}%
  \@ifundefined{lglosslinetwo}{}{\def\glosslinetwo{\lglosslinetwo}}%
  \@ifundefined{lglosslinethree}{}{\def\glosslinethree{\lglosslinethree}}%
  \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}%
  \xglll #2\xgle
         #3\xgle
         #4\xgle
  \ifcov@tlr
    \gln #5%
  \else
    \glot{#5}%
  \fi
  \ifx\cov@gl@postamble@text\empty%
  \else%
     \glosslinepostamble{\cov@gl@postamble@text}\cov@nopagebreak%
  \fi%
  \glend
  \ifcov@ex@gloss
    \end{covexample}
  \fi%
  \let\lglosslineone\relax%
  \let\lglosslinetwo\relax%
  \let\lglosslinethree\relax%
  \let\cov@fsglpreamble@local\relax%
  \let\cov@fsglpostamble@local\relax%
  \let\cov@fstl@local\relax%
}


%\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}
\@addtoreset{covexercise}{chapter}

\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 %%%%%%%%%%%%%%%%%