aboutsummaryrefslogtreecommitdiffstats
path: root/doc/user/str_indx
blob: b75c8db6f9fa2e8111bf515bfe26416317d7f4f0 (plain) (blame)
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
@Section
   @Title { Indexes }
   @Tag { indexes }
@Begin
@PP
Although Lout is not clever enough to guess what entries should go in
indexes. @Index { indexes }
your index, it will do almost everything else for you:  sort the
entries and attach the correct page numbers automatically.  As for
tables of contents, the default setting is to have an index in
books but not in other types of documents.  This and a few aspects of
the appearance of the index can be changed by changing the setup file,
as explained at the end of this section.
@PP
Now, suppose you are discussing Galileo and you want his name in your
index.  Let's be ambitious and say that you want the index to contain
something like this:
@ID @OneRow lines @Break {
Galileo Galilei
    life of, 201
    telescope, his use of, 201--203
    trial of, 205--211, 242, 395
}
Each line shows off one of Lout's four tricks:  the first is a
@I { raw entry } (no page number attached); the second is a
@I sub-entry (indented); the third has a @I { page number range }
instead of a single page number; and the fourth is a @I { merged entry }
(several page numbers or ranges within one entry).
@PP
We'll take each of them in turn in a moment, but first, let's see how
to get a basic entry, like this one:
@ID { Galileo Galilei, 201 }
To get this into your index, type
@ID @Code "galileo @Index { Galileo Galilei }"
at the point where you mention Galileo.  Nothing will be printed there,
but the object following the @Code "@Index" symbol will be placed in
the index, with a comma and the correct page number appended
automatically.
@PP
The object preceding the @Code "@Index" symbol is a compulsory key
which is used for sorting the index entries,
@FootNote {
The collating sequence used to decide what comes after what is either
the collating sequence used by the @Code "memcmp()" library routine (just
the underlying binary character codes), or else the one used by the
@Code "strcoll()" collating sequence, which understands accented
characters and whose effect depends on your locale.  To find out
whether @Code "strcoll()" is in use or not, type @Code "lout -V" which
prints out several lines of this and similar information, including
information about command line flags to switch between the two kinds of
collation.
@PP
If the sorting you get turns out to be not what you expected, the
first thing to try is the replacement of all accented letters in index
keys by unaccented ones.  Sorting is quite an intractable problem:  even
if @Code "strcoll()" gets the sorting right for one language, there still
remains the problem of sorting multilingual indexes.
@PP
Older versions of Lout assumed that the @I tab character was collated
before any character that could appear in a sorting key, causing
problems when this was not so.  Recent versions of Lout no longer
make this assumption.
}
but which is not itself printed anywhere.  It is best to construct these
sorting keys from lower-case letters and the . character only, beginning
with a letter, although multi-word keys are allowed.  These sorting keys
do not have to be distinct from the tags used in cross referencing;
however, they do have to be distinct from each other, unless you want
merged entries (see below).
@PP
Our first trick, raw entries (no page number attached), is very
easy:  just use @Code "@RawIndex" instead of {@Code "@Index"}.  So the
first line of our ambitious example is obtained by
@ID @Code "galileo @RawIndex { Galileo Galilei }"
This could go anywhere, since no page numbers are involved.
@PP
Another use for @Code "@RawIndex" is to get blank lines into the index
between the letters of the alphabet, by inserting phantom entries:
@ID @OneRow @Code {
"b @RawIndex {}"
"c @RawIndex {}"
"d @RawIndex {}"
"..."
"z @RawIndex {}"
}
In fact there is a symbol called @Code "@IndexBlanks" that makes
indexblanks. @Index @Code "@IndexBlanks"
exactly these 25 entries.  Unfortunately, these blanks will occasionally
appear at the top of a column, and if there are no tags beginning with
x, for example, there will be two blank lines between the w and y
entries.  You can start off with @Code "@IndexBlanks" and replace it
later by the appropriate subset, if necessary.
@FootNote {
For Lout to solve this problem automatically, it would need to be told
which letter each index entry belongs under, perhaps by symbols
{@Code "@AIndex"}, {@Code "@BIndex"}, etc.  The author felt that this
would have been too tedious.
}
@PP
Our second trick, sub-entries, is also very easy, since a sub-entry
differs from an ordinary entry only by having an indent.  The symbol
is {@Code "@SubIndex"}, so the second line of our ambitious example is
produced by
@ID @Code "galileo.life @SubIndex { life of }"
You should always give sub-entries the same sorting key as their
corresponding main entries, plus a . and another word, because then
you can be certain that the sorting will place sub-entries directly
after their main entries.  There is a @Code "@SubSubIndex" symbol that
produces a double indent, and there are @Code "@RawSubIndex" and
@Code "@RawSubSubIndex" symbols.
@PP
For our third trick, page number ranges, we use the @Code "to" option
of the {@Code "@Index"}, {@Code "@SubIndex"}, and {@Code "@SubSubIndex"}
symbols.  For example, to produce the sub-entry
@ID { telescope, his use of, 201--203 }
put
@ID @Code {
  "galileo.telescope @SubIndex to { gt.end } { telescope, his use of }"
}
at the beginning of the range, and
@ID @Code "@PageMark { gt.end }"
at the end.  You can use any tag you like inside the @Code "to" option,
as long as it differs from every other tag (notice that sorting keys
do not have to differ from tags, but @Code "to" options do:  this
is because @Code "to" options go into @Code "@PageMark" like other
tags do, and if two tags are the same we would have an ambiguous
result of {@Code "@PageOf"}).  If both ends of the range fall on the
same page, the @Code "to" option is ignored:  you will never get
201--201.
@PP
Our fourth and final trick is the merged entry:
@ID { trial of, 205--211, 242, 395 }
The main thing to grasp is that this merged entry was originally three
separate entries (sub-entries in this case):
@ID @OneRow lines @Break {
trial of, 205--211
trial of, 242
trial of, 395
}
We already know how to produce these three entries, using three
@Code "@SubIndex" symbols, one with a @Code "to" option.  Now we have
discovered that Lout is able to merge several entries into one
entry.  This raises two questions:  how does Lout know which entries
to merge? and given those entries, what does the merging produce?
@PP
The answer to the first question is that Lout merges entries whose
sorting keys are equal.  The merged entry above is produced by these
three entries, placed in the appropriate places:
@ID @OneRow @Code {
"galileo.trial @SubIndex to { gtrial.end } { trial of }"
"galileo.trial @SubIndex { trial of }"
"galileo.trial @SubIndex { trial of }"
}
The entries are merged because they have the same sorting key
({@Code "galileo.trial"}), not because they happen to have the
same content ({@Code "trial of"}).  In fact, once the page numbers are
added the content is not the same at all.
@PP
Now, having decided that the three entries
@ID @OneRow lines @Break {
trial of, 205--211
trial of, 242
trial of, 395
}
must be merged, what does Lout do?  Without being too formal, it
finds the shortest larger entry that contains everything in the
given entries, more or less, preserving the order in which
the entries' points of origin appear in the final printed document.
@PP
If the entries are not different at all, then the result will be
the same as each of them.  With this in mind, let us return to
our initial, ambitious example:
@ID @OneRow lines @Break {
Galileo Galilei
    life of, 201
    telescope, his use of, 201--203
    trial of, 205--211, 242, 395
}
We now know how to produce all four of these entries, but one problem
of some practical importance remains.  Suppose we delete the section on
the life of Galileo.  If we had put the entry that produces `Galileo
Galilei' in that section, we might inadvertently delete it, and the
other two sub-entries will lose their main entry.  Before deleting
anything, we must hunt through it for index entries and ponder their
significance, an error-prone and time-wasting thing to do.
@PP
The solution is as follows.  When an index entry has sub-entries, make
it raw, and repeat it just before each of its sub-entries:
@ID @OneRow @Code {
"galileo @RawIndex { Galileo Galilei }"
"galileo.life @SubIndex { life of }"
}
at the first place,
@ID @OneRow @Code {
"galileo @RawIndex { Galileo Galilei }"
"galileo.telescope @SubIndex { telescope, his use of }"
}
at the second, and so on.  Now it is easy to verify that every
sub-entry has a main entry; and when deleting a sub-entry we can and
should delete the adjacent main entry.  After sorting, our index
entries will be
@ID @Tab
    @Fmta { @Col @Code A ! @Col B }
{
@Rowa
    A { galileo }
    B { Galileo Galilei }
@Rowa
    A { galileo }
    B { Galileo Galilei }
@Rowa
    A { galileo }
    B { Galileo Galilei }
@Rowa
    A { galileo }
    B { Galileo Galilei }
@Rowa
    A { galileo }
    B { Galileo Galilei }
@Rowa
    A { galileo.life }
    B { {}    life of, 201 }
@Rowa
    A { galileo.telescope }
    B { {}    telescope, his use of, 201--203 }
@Rowa
    A { galileo.trial }
    B { {}    trial of, 205--211 }
@Rowa
    A { galileo.trial }
    B { {}    trial of, 242 }
@Rowa
    A { galileo.trial }
    B { {}    trial of, 395 }
}
The first five entries have the same sorting key, and will be merged
as required.
@PP
The language of the index entry will be the initial language of the
document as a whole, which is not necessarily the language at the point
where the index entry occurs.  To get the correct language you will need a
@Code "@Language" symbol following the @Code "@Index" symbol:
@ID @Code "galileo. @Index French @Language { Galileo Galilei }"
or whatever.  If you don't do this your index entry might be hyphenated
incorrectly.
@PP
Although the page numbers in index entries will be kept up to date
automatically as the document changes, as all cross references are, 
it is best to refrain from inserting index entries until the document
is complete and an overall plan of the structure of the index can
be made.
@PP
The remainder of this section describes how to change the appearance of
the index by setting options in the setup file.  For setup files and
their options in general, consult Section {@NumberOf setup}.
@PP
There are eight setup file options for the index.  Here they are with
their default values:
@ID @OneRow @Code @Verbatim {
@MakeIndex { No }
@IndexFont { }
@IndexBreak { oragged 1.2fx }
@IndexColumnNumber { 2 }
@IndexColumnGap { 1.00c }
@IndexCtd { Yes }
@IndexCtdWord { continued }
@IndexCtdFormat { @Body @I (@CtdWord) }
}
The @Code "@MakeIndex" option, which may be @Code Yes or {@Code No},
makeindex. @Index @Code "@MakeIndex"
determines whether to produce an index or not.  Although the default
value is {@Code No}, any type of document may be given an index just
by changing it to {@Code Yes}.  This has already been done in the
@Code book setup file, but not in the others.
@PP
@Code "@IndexFont" determines the font and font size of index entries
indexfont. @Index @Code "@IndexFont"
(e.g. {@Code "Times Base 12p"}).  Leaving it empty as above produces
the same font as the rest of the document.  @Code "@IndexBreak" is the
indexbreak. @Index @Code "@IndexBreak"
paragraph breaking style applied to index entries; @Code oragged is the
traditional and best way.
@PP
@Code "@IndexColumnNumber" and @Code "@IndexColumnGap" determine the
indexcolumnnumber. @Index @Code "@IndexColumnNumber"
indexcolumngap. @Index @Code "@IndexColumnGap"
number of index columns per page, and the gap between them, and are
exactly analogous to the @Code "@ColumnNumber" and @Code "@ColumnGap"
options described in Section {@NumberOf columns}.
@PP
The last three options work together to control the appearance of
running headers
@FootNote {
Index running headers are new in Version 3.19 of Lout.
}
in the index.  If an @Code "@Index" entry has @Code "@SubIndex" entries
that run over to the next column, Lout will print an unobtrusive running
header at the top of that column, something like this in English:
@ID { procrastination @I (ctd.) }
It will print two running headers if a @Code "@SubIndex" entry has
@Code "@SubSubIndex" entries that run over, one for the main entry and an
indented one for the sub-entry.  You can turn off these running headers by
setting @Code "@IndexCtd" to {@Code No}.  A particular word is associated
with index running headers; by default it is @Code "ctd." in English and
its equivalent in other languages.  This is what the default value,
{@Code "continued"}, of the @Code "@IndexCtdWord" option gives you; if you
want some other word, change that option to the word you want.  Finally,
you can control the format of the running headers using
{@Code "@IndexCtdFormat"}.  Within this option, the symbol @Code "@Body"
stands for the value of the index entry that is running over (minus any
page numbers), and @Code "@CtdWord" stands for the word produced by the
@Code "@IndexCtdWord" option.  The default value of {@Code "@IndexCtdFormat"},
shown above, yields the index entry followed by @Code "@IndexCtdWord" in
italics and parentheses.
@PP
Lout offers the possibility of having up to three independent indexes
(useful for glossaries, author indexes, etc.).  The other two are called
index A and index B, and they precede the main index in the
output.  Just replace @Code Index by @Code IndexA to refer to index A,
and by @Code IndexB to refer to index B.  For example,
@ID @Code "smith.j @IndexA { Smith, John }"
will insert an index entry to index A, and @Code "@IndexBBlanks"
will insert the usual 25 blank entries into index B.
@PP
In large projects it might help to rename the @Code "@IndexA" symbol
to something else, such as {@Code "@AuthorIndex"}.  This can
be done by placing
@ID @Code {
"import @DocumentSetup"
"macro @AuthorIndex { @IndexA }"
}
in the @Code mydefs file.  See Section {@NumberOf definitions} for
an introduction to the @Code "mydefs" file; the word @Code macro
is needed here instead of @Code "def" because we are introducing
a new name for an existing symbol, not defining a new symbol.
@End @Section