summaryrefslogtreecommitdiff
path: root/macros/generic/midnight/gloss.tex
blob: 2fa5352d2eeffd1f5149f4fcea44007056dcdc09 (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
\ifx\GLOSS\relax\endinput\else\let\GLOSS=\relax\fi % \input only once
%
% 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
%	You can use these macros to typeset documents. You may
%	distribute this file freely, provided that you also distribute
%	the accompanying documentation.
%	    You may make changes to this file, or extract portions
%	of it for inclusion in other files, provided that
%	    (1) you change the name of the file;
%	    (2) you give proper credit and include copyright
%		information where applicable;
%	    (3) explain how an unchanged version can be obtained; and
%	    (4) document the usage of your macros/changes (if usage
%		of your macros is not worth documenting, they must not
%		be worth using).
%	You are not allowed to use the name ``Midnight Macros'' for
%	any changed files.
%	    The above rules for making changes do not apply where it
%	is explicitly noted in this file that something can be changed
%	to conform to your local installation.
%
% USAGE:
%   See the file gloss.doc
%
% original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex
%	    (use anonymous ftp). Also in various archives.
% 
% I wrote these macros after reading a request for something like this
% from Robert Malouf (SUNY Buffalo) on usenet in comp.text.tex.
%
% Caltech, Pasadena  ---  Marcel van der Goot
%			  marcel@cs.caltech.edu
%			    Caltech 256--80
%			    Pasadena, CA 91125
%			    (818) 356--4603
%

% update history:
% version 1.0: This one.
%	release 9 Nov 1990: used % instead of \endlinechar (no functional
%		changes involved).
%	release 26 Nov 1990: This one.
% version 8 Nov 1990: Same as this, but with less readable documentation.
% version 7 Nov 1990: Used the names \fontone and \fonttwo instead of
%	\eachwordone and \eachwordtwo.
% version 6 Nov 1990:  Could not easily typeset a '+', handled
%	linespacing incorrectly.

%%%%%% CODE: (you don't need to read this to use the macros)

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

\let\eachwordone=\it
\let\eachwordtwo=\rm


\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%
    \loop\lastword{\eachwordone}{\lineone}{\wordone}%
         \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
	 \global\setbox\gline=\hbox{\unhbox\gline
				    \hskip\glossglue
			            \vbox{\box\wordone
					  \nointerlineskip
				          \box\wordtwo
				         }%
			   	   }%
	 \testdone
	 \ifnotdone
    \repeat
    \egroup % matches \bgroup in \gloss
   }
} % restore \catcode`\^^M

\def\gloss
   {\bgroup
    \catcode`\^^M=12
    \twosent
   }