Debian Codegraph @

texmf-dist/tex/generic/midnight/gloss.tex

raw
1 \ifx\GLOSS\relax\endinput\else\let\GLOSS=\relax\fi % \input only once
2 %
3 % gloss.tex: Macros for vertically aligning words in consecutive sentences.
4 % version: 1.0 release: 26 November 1990
5 %
6 % copyright (c) 1991 Marcel R. van der Goot
7 % You can use these macros to typeset documents. You may
8 % distribute this file freely, provided that you also distribute
9 % the accompanying documentation.
10 % You may make changes to this file, or extract portions
11 % of it for inclusion in other files, provided that
12 % (1) you change the name of the file;
13 % (2) you give proper credit and include copyright
14 % information where applicable;
15 % (3) explain how an unchanged version can be obtained; and
16 % (4) document the usage of your macros/changes (if usage
17 % of your macros is not worth documenting, they must not
18 % be worth using).
19 % You are not allowed to use the name ``Midnight Macros'' for
20 % any changed files.
21 % The above rules for making changes do not apply where it
22 % is explicitly noted in this file that something can be changed
23 % to conform to your local installation.
24 %
25 % USAGE:
26 % See the file gloss.doc
27 %
28 % original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex
29 % (use anonymous ftp). Also in various archives.
30 %
31 % I wrote these macros after reading a request for something like this
32 % from Robert Malouf (SUNY Buffalo) on usenet in comp.text.tex.
33 %
34 % Caltech, Pasadena --- Marcel van der Goot
35 % [email protected]
36 % Caltech 256--80
37 % Pasadena, CA 91125
38 % (818) 356--4603
39 %
40
41 % update history:
42 % version 1.0: This one.
43 % release 9 Nov 1990: used % instead of \endlinechar (no functional
44 % changes involved).
45 % release 26 Nov 1990: This one.
46 % version 8 Nov 1990: Same as this, but with less readable documentation.
47 % version 7 Nov 1990: Used the names \fontone and \fonttwo instead of
48 % \eachwordone and \eachwordtwo.
49 % version 6 Nov 1990: Could not easily typeset a '+', handled
50 % linespacing incorrectly.
51
52 %%%%%% CODE: (you don't need to read this to use the macros)
53
54 \newbox\lineone % boxes with words from first line
55 \newbox\linetwo
56 \newbox\wordone % a word from the first line (hbox)
57 \newbox\wordtwo
58 \newbox\gline % the constructed double line (hbox)
59 \newskip\glossglue % extra glue between glossed pairs
60 \glossglue = 0pt plus 2pt minus 1pt % allow stretch/shrink between words
61 \newif\ifnotdone
62
63 \let\eachwordone=\it
64 \let\eachwordtwo=\rm
65
66
67 \def\lastword#1#2#3% #1 = \each, #2 = line box, #3 = word box
68 {\setbox#2=\vbox{\unvbox#2%
69 \global\setbox#3=\lastbox
70 }%
71 \ifvoid#3\global\setbox#3=\hbox{#1\strut{} }\fi
72 % extra space following \strut in case #1 needs a space
73 }
74
75 \def\testdone
76 {\ifdim\ht\lineone=0pt
77 \ifdim\ht\linetwo=0pt \notdonefalse % tricky space after pt
78 \else\notdonetrue
79 \fi
80 \else\notdonetrue
81 \fi
82 }
83
84 {\catcode`\^^M=12 \endlinechar=-1 % 12 = other
85 \gdef\getwords(#1,#2)#3 #4^^M% #1=linebox, #2=\each, #3=1st word, #4=remainder
86 {\setbox#1=\vbox{\hbox{#2\strut#3 }% adds space
87 \unvbox#1%
88 }%
89 \def\more{#4}%
90 \ifx\more\empty\let\more=\donewords
91 \else\let\more=\getwords
92 \fi
93 \more(#1,#2)#4^^M%
94 }
95
96 \gdef\donewords(#1,#2)^^M{}%
97
98 \gdef\twosent#1^^M#2^^M% #1 = first line, #2 = second line
99 {\getwords(\lineone,\eachwordone)#1 ^^M%
100 \getwords(\linetwo,\eachwordtwo)#2 ^^M%
101 \loop\lastword{\eachwordone}{\lineone}{\wordone}%
102 \lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
103 \global\setbox\gline=\hbox{\unhbox\gline
104 \hskip\glossglue
105 \vbox{\box\wordone
106 \nointerlineskip
107 \box\wordtwo
108 }%
109 }%
110 \testdone
111 \ifnotdone
112 \repeat
113 \egroup % matches \bgroup in \gloss
114 }
115 } % restore \catcode`\^^M
116
117 \def\gloss
118 {\bgroup
119 \catcode`\^^M=12
120 \twosent
121 }
122