summaryrefslogtreecommitdiff
path: root/macros/xetex/latex/langsci/langsci-cgloss.sty
blob: 325ba04506cad028123ef7bdc9ce18f086ffe074 (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%      File: langsci-cgloss.sty
%%    Author: Language Science Press (http://langsci-press.org)
%%      Date: 2016-01-16 16:47:43 UTC
%%   Purpose: This file contains an adpated version of the cgloss
%%            package for glossing linguistic examples.
%%  Language: LaTeX
%%   Licence:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% -*- LaTeX -*-

% Modified version of cgloss4e.sty.  Hacked and renamed cgloss.sty
% by Alexis Dimitriadis (alexis@babel.ling.upenn.edu)

% Following borrows from Covington's style files inspired by Midnight by M.
% de Groot, adapted to be used with gb4e.sty: examples beginning with \ex can
% contain glosses directly. Default is
% Linguistic Inquiry style with all lines in \rm; to change a line (eg. to
% \it for a particular journal, change the appropriate line: e.g.,
% \let\eachwordone=\rm in a copy of this file. Note that it will NOT work
% to put \it before the line as the words are parsed separately.

% Use \singlegloss to force single-spaced glosses even in double-space
% environments. Works also in footnotes (^M as delimiter replaced by
% \\)---hpk
%

% Changes by Alexis Dimitriadis
%
% Removed flushleft environment and initial vskip to make macros usable
% on the same line with earlier and/or later text, e.g.,
% \item Q: \gll ... \\
%               ... \\   \hfill (Greek)
%    \trans Q: `...'
% Note: Text following the gloss will appear on line one of the example;
% To get a line break, insert one manually with \\ or use \trans or \glt.
% (\gln does not end the line, since it was already the
% case in cgloss4e that a translation must be ended with a line break).
%
% Modified \glt to keep translation on the same page as the text.

% BUGS: does not work very gracefully with double spacing (struts are not
% automatically inserted after the \vboxes used by the macros).
% In double space mode without \nosinglegloss, when a translation
% is not given, the next line of text is single-spaced from the glossed text.
% With \nosinglegloss, the translation is set too close to the bottom line.


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

% See covingtn.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.'
%
% 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.'
%
% 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).
%
% Thanks to Marcel R. van der Goot for permission to reproduce code.
\let\@gsingle=1
\def\singlegloss{\let\@gsingle=1}
\def\nosinglegloss{\let\@gsingle=0}
\@ifundefined{new@fontshape}%
   {\def\@selfnt{\ifx\@currsize\normalsize\@normalsize\else\@currsize\fi}}
   {\def\@selfnt{\selectfont}}

\def\gll%                  % Introduces 2-line text-and-gloss.
   {\raggedright%
     \bgroup %\begin{flushleft}
     \ifx\@gsingle1%           conditionally force single spacing (hpk/MC)
	 \def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \twosent
}

\def\glll%                  % Introduces 3-line text-and-gloss.
   {\bgroup %\begin{flushleft}
     \ifx\@gsingle1%        conditionally force single spacing (hpk/MC)
	\def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \threesent
}


\def\gllll%                  % Introduces 4-line text-and-gloss.
   {\bgroup %\begin{flushleft}
     \ifx\@gsingle1%        conditionally force single spacing (hpk/MC)
	\def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \foursent
}


\def\glllll%                  % Introduces 5-line text-and-gloss.
   {\bgroup %\begin{flushleft}
     \ifx\@gsingle1%        conditionally force single spacing (hpk/MC)
	\def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \fivesent
}


\def\gllllll%                  % Introduces 6-line text-and-gloss.
   {\bgroup %\begin{flushleft}
     \ifx\@gsingle1%        conditionally force single spacing (hpk/MC)
	\def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \sixsent
}


\def\glllllll%                  % Introduces 7-line text-and-gloss.
   {\bgroup %\begin{flushleft}
     \ifx\@gsingle1%        conditionally force single spacing (hpk/MC)
	\def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \sevensent
}


\def\gllllllll%                  % Introduces 8-line text-and-gloss.
   {\bgroup %\begin{flushleft}
     \ifx\@gsingle1%        conditionally force single spacing (hpk/MC)
	\def\baselinestretch{1}\@selfnt\fi
%        \vskip\baselineskip\def\baselinestretch{1}%
%        \@selfnt\vskip-\baselineskip\fi%
    \bgroup
    \eightsent
}

% \def\glt{\vskip.0\baselineskip}

% redefine \gltoffset to set off translation from ex and gloss
\@ifundefined{gltoffset}{\def\gltoffset{0pt}}{}

\def\glt{\ifhmode\\*[\gltoffset]\else\nobreak\vskip\gltoffset\nobreak\fi}


% Introduces a translation
\let\trans\glt

\def\gln{\relax}
\def\glend{} % obsolete
      % 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 Midnight/gloss.tex and Midnight/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\linefour
\newbox\linefive
\newbox\linesix
\newbox\lineseven
\newbox\lineeight
\newbox\wordone % a word from the first line (hbox)
\newbox\wordtwo
\newbox\wordthree
\newbox\wordfour
\newbox\wordfive
\newbox\wordsix
\newbox\wordseven
\newbox\wordeight
\newbox\gline % the constructed double line (hbox)
\newskip\glossglue % extra glue between glossed pairs or tuples
\glossglue = 0pt plus 2pt minus 1pt % allow stretch/shrink between words
%\glossglue = 5pt plus 2pt minus 1pt % allow stretch/shrink between words
\newif\ifnotdone

\@ifundefined{eachwordone}{\let\eachwordone=\upshape}{\relax}
\@ifundefined{eachwordtwo}{\let\eachwordtwo=\upshape}{\relax}
\@ifundefined{eachwordthree}{\let\eachwordthree=\upshape}{\relax}
\@ifundefined{eachwordfour}{\let\eachwordfour=\upshape}{\relax}
\@ifundefined{eachwordfive}{\let\eachwordfive=\upshape}{\relax}
\@ifundefined{eachwordsix}{\let\eachwordsix=\upshape}{\relax}
\@ifundefined{eachwordseven}{\let\eachwordseven=\upshape}{\relax}
\@ifundefined{eachwordeight}{\let\eachwordeight=\upshape}{\relax}

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

\gdef\getwords(#1,#2)#3 #4\\% #1=linebox, #2=\each, #3=1st word, #4=remainder
   {\setbox#1=\vbox{\hbox{#2\strut#3{} }% adds space, the {} is needed for CJK otherwise the space
                                        % would be ignored
                    \unvbox#1%
                   }%
    \def\more{#4}%
    \ifx\more\empty\let\more=\donewords
    \else\let\more=\getwords
    \fi
    \more(#1,#2)#4\\%
   }

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

\gdef\twosent#1\\ #2\\{% #1 = first line, #2 = second line
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}

\gdef\threesent#1\\ #2\\ #3\\{% #1 = first line, #2 = second line, #3 = third
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \getwords(\linethree,\eachwordthree)#3 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}



\gdef\foursent#1\\ #2\\ #3\\ #4\\{% #1 = first line, #2 = second line, #3 = third
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \getwords(\linethree,\eachwordthree)#3 \\%
    \getwords(\linefour,\eachwordfour)#4 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \lastword{\eachwordfour}{\linefour}{\wordfour}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                          \nointerlineskip
                                          \box\wordfour
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}



\gdef\fivesent#1\\ #2\\ #3\\ #4\\ #5\\{% #1 = first line, #2 = second line, #3 = third
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \getwords(\linethree,\eachwordthree)#3 \\%
    \getwords(\linefour,\eachwordfour)#4 \\%
    \getwords(\linefive,\eachwordfive)#5 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \lastword{\eachwordfour}{\linefour}{\wordfour}%
         \lastword{\eachwordfive}{\linefive}{\wordfive}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                          \nointerlineskip
                                          \box\wordfour
                                          \nointerlineskip
                                          \box\wordfive
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}



\gdef\sixsent#1\\ #2\\ #3\\ #4\\ #5\\ #6\\{% #1 = first line, #2 = second line, #3 = third
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \getwords(\linethree,\eachwordthree)#3 \\%
    \getwords(\linefour,\eachwordfour)#4 \\%
    \getwords(\linefive,\eachwordfive)#5 \\%
    \getwords(\linesix,\eachwordsix)#6 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \lastword{\eachwordfour}{\linefour}{\wordfour}%
         \lastword{\eachwordfive}{\linefive}{\wordfive}%
         \lastword{\eachwordsix}{\linesix}{\wordsix}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                          \nointerlineskip
                                          \box\wordfour
                                          \nointerlineskip
                                          \box\wordfive
                                          \nointerlineskip
                                          \box\wordsix
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}



\gdef\sevensent#1\\ #2\\ #3\\ #4\\ #5\\ #6\\ #7\\{% #1 = first line, #2 = second line, #3 = third
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \getwords(\linethree,\eachwordthree)#3 \\%
    \getwords(\linefour,\eachwordfour)#4 \\%
    \getwords(\linefive,\eachwordfive)#5 \\%
    \getwords(\linesix,\eachwordsix)#6 \\%
    \getwords(\lineseven,\eachwordseven)#7 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \lastword{\eachwordfour}{\linefour}{\wordfour}%
         \lastword{\eachwordfive}{\linefive}{\wordfive}%
         \lastword{\eachwordsix}{\linesix}{\wordsix}%
         \lastword{\eachwordseven}{\lineseven}{\wordseven}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                          \nointerlineskip
                                          \box\wordfour
                                          \nointerlineskip
                                          \box\wordfive
                                          \nointerlineskip
                                          \box\wordsix
                                          \nointerlineskip
                                          \box\wordseven
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}



\gdef\eightsent#1\\ #2\\ #3\\ #4\\ #5\\ #6\\ #7\\ #8\\{% #1 = first line, #2 = second line, #3 = third
    \getwords(\lineone,\eachwordone)#1 \\%
    \getwords(\linetwo,\eachwordtwo)#2 \\%
    \getwords(\linethree,\eachwordthree)#3 \\%
    \getwords(\linefour,\eachwordfour)#4 \\%
    \getwords(\linefive,\eachwordfive)#5 \\%
    \getwords(\linesix,\eachwordsix)#6 \\%
    \getwords(\lineseven,\eachwordseven)#7 \\%
    \getwords(\lineeight,\eachwordeight)#8 \\%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
         \lastword{\eachwordthree}{\linethree}{\wordthree}%
         \lastword{\eachwordfour}{\linefour}{\wordfour}%
         \lastword{\eachwordfive}{\linefive}{\wordfive}%
         \lastword{\eachwordsix}{\linesix}{\wordsix}%
         \lastword{\eachwordseven}{\lineseven}{\wordseven}%
         \lastword{\eachwordeight}{\lineeight}{\wordeight}%
         \global\setbox\gline=\hbox{\unhbox\gline
                                    \hskip\glossglue
                                    \vtop{\box\wordone   % vtop was vbox
                                          \nointerlineskip
                                          \box\wordtwo
                                          \nointerlineskip
                                          \box\wordthree
                                          \nointerlineskip
                                          \box\wordfour
                                          \nointerlineskip
                                          \box\wordfive
                                          \nointerlineskip
                                          \box\wordsix
                                          \nointerlineskip
                                          \box\wordseven
                                          \nointerlineskip
                                          \box\wordeight
                                         }%
                                   }%
         \testdone
         \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   \gl@stop}

%\def\gl@stop{{\hskip -\glossglue}\unhbox\gline\end{flushleft}}

% \leavevmode puts us back in horizontal mode, so that a \\ will work
\def\gl@stop{{\hskip -\glossglue}\unhbox\gline\leavevmode \egroup}

\endinput