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
|
%%%%%%%%%%%%%%%%%% JAMBOX: RIGHT-COLUMN ANNOTATIONS %%%%%%%%%%%%%%%%
%
% Alexis Dimitriadis
%
% This is version 0.3 (informal release, Nov. 2003).
%
% Line up material a fixed distance from the right margin. For annotating
% example sentences, usually with a short note in parentheses.
% May overflow to the left or right, or line up on the next line as necessary.
%
% \jambox[width]{text} Align 'text' starting 'width' distance from the
% right margin (default \the\jamwidth).
% \jam(something) Align a note delimited by parentheses (which are
% retained). No optional argument.
% \jambox*{text} Set \jamwidth to the width of 'text', then align it.
% (\jamwidth stays set for the rest of the environment).
%
% Notes:
%
% Distance from the right margin can be set to an explicit amount, or to the
% width of some piece of text, as follows:
%
% \jamwidth=2in\relax Or
% \settowidth\jamwidth {(``annotation'')}
%
% \jamwidth is locally scoped, so it can be set globally or inside an example
% environment.
%
% BUG: Not compatible with ragged-right mode.
%
% Incompatibilities: Not useful with the vanilla cgloss4e.sty, which ends
% glossed lines prematurely.
% I do have a suitably modified file, cgloss.sty. With it you can do the
% following:
% \gll To kimeno. \\
% the text \\ \jambox{(Greek)}
% \trans `The text.'
\newdimen\jamwidth \jamwidth=2in
\def\jambox{\@ifnextchar[{\@jambox}
{\@ifnextchar*{\@jamsetbox}{\@jambox[\the\jamwidth]}}}
% Quickie invocation: The argument is delimited by the parentheses (no width
% argument allowed). I redefine it in my documents to add formatting.
% Syntax: \jam(Some note)
%
\def\jam(#1){\jambox{(#1)}}
% Set width AND display the argument.
% The star is read and ignored; the argument #1 is boxed, used to set
% \jamwidth, then passed to \@jambox (which also puts it in \@tempboxa!)
%
\def\@jamsetbox*#1{\setbox\@tempboxa\hbox{#1}\jamwidth=\wd\@tempboxa
\@jambox[\the\jamwidth]{\box\@tempboxa}}
%% Version 1: old & stupid
%% \def\@jambox[#1]#2{\hfill\hbox to #1 {#2\hfil}}
% Version 2:
% Always takes up \jamwidth space, even if it means breaking the line. But it
% works on ragged-right mode, too.
% \def\@jambox[#1]#2{\setbox\@tempboxa\hbox {#2\hfil}%
% \ifdim \wd\@tempboxa<#1\relax \wd\@tempboxa=#1\relax\fi
% \hskip 0.5em plus 1fill
% \penalty 100\vadjust{}\nobreak\hfill\box\@tempboxa\par}
% The penalty enables a break. \vadjust inserts an empty element
% at the beginning of the next line, protecting \hfill from being discarded.
% Version 3:
% This seems to cover everything! But unfortunately, it won't work in
% ragged-right mode-- the line is broken BEFORE the last word, to make enough
% space...
\def\@jambox[#1]#2{{\setbox\@tempboxa\hbox {#2}%
\ifdim \wd\@tempboxa<#1\relax % if label fits in the alloted space:
\@tempdima=#1\relax \advance\@tempdima by-\wd\@tempboxa % remaining \hspace
\unskip\nobreak\hfill\penalty250 % break line here if necessary
\hskip 1.2em minus 1.2em % used when the line extends past the margin
\hbox{}\nobreak\hfill\box\@tempboxa\nobreak
\hskip\@tempdima minus \@tempdima\hbox{}%
\else % the label is too wide: just right-align it
\hfill\penalty50\hbox{}\nobreak\hfill\box\@tempboxa
\fi
% suppress closing glue:
\parfillskip=0pt \finalhyphendemerits=0 \par}}
% The penalty enables a break, taken only if the line cannot fit.
% The \hbox{} ensures the next line does not begin with \hfill, which would
% be discarded if initial.
% (\vadjust inserts an empty element at the beginning of the next line, so
% that COULD be used instead of \hbox{}).
% Algorithm adapted from The TeXBook.
%
% The closing \par could be a problem if there is a \parskip...
|