summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/plain/zztex/zzindexv1.tex
blob: c809d20c9fca1631834587f0c5f851ffa1c5672c (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Module:    ZzTeX Indexing Facilities, version 1
%
% Synopsis:  This file contains the tools for producing an index.
%
% Author:    Paul C. Anagnostopoulos
% Created:   20 May 2006
%
% Copyright 1989--2020 by Paul C. Anagnostopoulos
% under The MIT License (opensource.org/licenses/MIT)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%                       Index Version
%                       ----- -------


\def \indexversion #1{%
  \input zzindexv#1\relax}

%                       Define Index Locator Types
%                       ------ ----- ------- -----


% This list contains the definition of each locator. New ones must be
% added to the end, and any program looking at the definitions must assume
% that duplicates may exist, and that the last one prevails.

\def \zixloclist {}


%~ This command is deprecated in favor of |\definelocator|.

\def \definelocatortype #1#2#3#4#5#6{%  {name}{attributes}{precedence}
                                     %  {beginning-punc}{templates}
                                     %  {ending-punc}
  {\setflag \pg = \true
   \let \page = \relax
   \def \nopage {\setflag \pg = \false}%
   \setflag \txt = \false
   \def \text {\setflag \txt = \true}%
   \let \notext = \relax
   #2%
   \def \bpunc {#4}%
   \def \temp {#5}%
   \def \epunc {#6}%
   \edef \znext {%
     \noexpand\append{{#1}{\pg}{\txt}{#3}%
                      {\expandafter\zdefof \meaning\bpunc\zmark}%
                      {\expandafter\zdefof \meaning\temp\zmark}%
                      {\expandafter\zdefof \meaning\epunc\zmark}}}%
   \znext{\zixloclist}%
   \if \txt
     \withname\gdef{\x#1}##1##2{\zixindex{#1}{##1}{S}{##2}}%
     \if \pg
       \withname\gdef{\x#1begin}##1##2{\zixindex{#1}{##1}{B}{##2}}%
       \withname\gdef{\x#1end}##1##2{\zixindex{#1}{##1}{E}{##2}}%
     \fi
   \else
     \withname\gdef{\x#1}##1{\zixindex{#1}{##1}{S}{}}%
     \if \pg
       \withname\gdef{\x#1begin}##1{\zixindex{#1}{##1}{B}{}}%
       \withname\gdef{\x#1end}##1{\zixindex{#1}{##1}{E}{}}%
     \fi
   \fi}}


% This command is deprecated.

\def \defineindexlocator #1#2#3#4#5#6{% {name}{attributes}{precedence}
                                      % {punctuation}{single-template}
                                      % {range-template}
}

%                       Builtin Locator Types
%                       ------- ------- -----


% Precedences 0--1 and 6--9 are reserved for specific books.

\definelocatortype{term}{\page\notext}{2.3}
                           {, |}{\bold{~P}|\bold{~P--~Q}|, }{. |}
\definelocatortype{biblio}{\page\notext}{2.5}
                           {, |}{~P|~P--~Q|, }{. |}
\definelocatortype{cite}{\page\notext}{2.5}
                           {, |}{~P|~P--~Q|, }{. |}
\definelocatortype{page}{\page\notext}{2.5}
                           {, |}{~P|~P--~Q|, }{. |}
\definelocatortype{figure}{\page\notext}{2.7}
                           {, |}{~P\+\emph{f}|~P--~Q\+\emph{f}|, }{. |}
\definelocatortype{glossary}{\page\notext}{2.7}
                           {, |}{~P\+\emph{g}|~P--~Q\+\emph{g}|, }{. |}
\definelocatortype{note}{\page\notext}{2.8}
                           {, |}{~P\+\emph{n}|~P--~Q\+\emph{n}|, }{. |}
\definelocatortype{sidebar}{\page\notext}{2.7}
                           {, |}{~P\+\emph{s}|~P--~Q\+\emph{s}|, }{. |}
\definelocatortype{table}{\page\notext}{2.7}
                           {, |}{~P\+\emph{t}|~P--~Q\+\emph{t}|, }{. |}
\definelocatortype{see}{\nopage\text}{3}
                           {. |\See\ }{~T||; }{. |}
\definelocatortype{seealso}{\nopage\text}{4}
                           {. |\Seealso\ }{~T||; }{. |}
\definelocatortype{consult}{\nopage\text}{5}
                           {. |\Consult\ }{~T||; }{. |}

%                       Index Preparation File
%                       ----- ----------- ----


% The \produceindex command must appear before the \document command.

\setflag \zindexing = \false


\def \produceindex #1#2{%                               {type}{prep-file}
  {\processdesign{\index}{#1}%
   \immediate\openout \zwritea = #2.zzh\relax
   \immediate\write \zwritea {root \jobname}%
   \immediate\write \zwritea {type #1}%
   \immediate\write \zwritea {divisions {\the\divisions}}%
   \immediate\write \zwritea {locators {\the\locators}}%
   \immediate\write \zwritea {\the\indexparams}%
   \maplist{\immediate\write \zwritea {define-locator ##1}}{\zixloclist}%
   \immediate\closeout \zwritea}%
  \global\setflag \zindexing = \true}

%                       Index File Handling
%                       ----- ---- --------

\definewrite{\zixrootfile}
\definewrite{\zixdivfile}
\setflag \zixdivopen = \false


\def \zindexinit {%
  \if \zindexing
    \immediate\openout \zixrootfile = \jobname.zzi\relax
    \immediate\write \zixrootfile 
      {\zcomment Raw index entry file for book `\jobname'.}%
  \fi}

\def \zindexfinal {%
  \if \zindexing
    \immediate\write \zixrootfile {\zcomment [end]}%
    \immediate\closeout \zixrootfile
  \fi}

\def \zindexdivinit #1{%                                {division}
  \if \zindexing
    \immediate\openout \zixdivfile = #1.zzi\relax
    \immediate\write \zixdivfile
      {\zcomment Raw index entry file for book `\jobname', division `#1'.}%
    \global\setflag \zixdivopen = \true
  \fi}

\def \zindexdivfinal {%
  \if \zixdivopen
    \immediate\write \zixdivfile {\zcomment [end]}%
    \immediate\closeout \zixdivfile
    \global\setflag \zixdivopen = \false
  \fi}

%                       Generate Index Entry
%                       -------- ----- -----


% This macro is called from the indexing macros generated by
% \definelocatortype.

\def \zixindex #1#2#3#4{%                  {locator}{level}{page-code}{text}
  \tcounta = #2\relax
  \if \notp{\rangep{\tcounta}{1}{3}}%
    \error{invindexlvl}{Invalid index level '#2' specified}%
    \tcounta = 1
  \fi
  \name{\zixindex\romannumeral\tcounta}{#1}{#2}{#3}{#4}}

\def \zixindexi #1#2#3#4#5{%
  \zixindexw{#1}{#2}{#3}{#4}{#5}{}{}{\noexpand\folio}}
\def \zixindexii #1#2#3#4#5#6{%
  \zixindexw{#1}{#2}{#3}{#4}{#5}{#6}{}{\noexpand\folio}}
\def \zixindexiii #1#2#3#4#5#6#7{%
  \zixindexw{#1}{#2}{#3}{#4}{#5}{#6}{#7}{\noexpand\folio}}

\catcode"B8 = \catother

\gdef \zixindexw #1#2#3#4#5#6#7#8{% {locator}{level}{page-code}{text}
                                  % {heading1}{heading2}{heading3}{page}
  \if \notp{\zindexing}%
    \warning{notindexing}{An indexing command was encountered,
                          but no \string\produceindex}%
  \fi
  \zbeginhidewrite
    \def \zhdx {#5}%
    \def \zhdy {#6}%
    \def \zhdz {#7}%
    \def \ztxt {#4}%
    \edef \znext {#1^^b8%
                  #2^^b8%
                  \expandafter\zdefof \meaning\zhdx\zmark^^b8%
                  \expandafter\zdefof \meaning\zhdy\zmark^^b8%
                  \expandafter\zdefof \meaning\zhdz\zmark^^b8%
                  #3^^b8%
                  #8^^b8%
                  \expandafter\zdefof \meaning\ztxt\zmark}%
    \write \if \zixdivopen \zixdivfile \else \zixrootfile \fi
      \expandafter{\znext}%
    \if \vmodep \repeatpenalty \fi      % In case glue follows write.
  \zendhidewrite}

\catcode"B8 = \catinvalid

%                       Discussion of Index Formatting
%                       ---------- -- ----- ----------


% An index is formatted inside an index block, which is more or less
% like a text block. Within the index block are occurences of the
% \indexentry macro, one for each entry. In addition, the
% \alphabreak macro can be used to produce breaks preceding the `A'
% entries, `B' entries, etc.
%
% In an index block, parts 4 and 5 of the mark are used to remember
% index entries so they can be carried forward to subsequent columns
% or pages. The mark is used as follows:
%
%   Part  Subpart  Usage
%     4      1     Boolean, true if in the midst of a first-level entry.
%     4      2     The first-level entry text.
%     5      1     Boolean, true if in the midst of a second-level entry.
%     5      2     The second-level entry text.

%                       Index Block
%                       ----- -----


\defineblock{\index}{\endindex}{\false}{}

%~block index Type
% \def \alphaformat ##1{...}            % Alpha break formatter.
% \bodyfont = {\size\style}             % Body font.
% \clubpenalty = penalty                % Club penalty is often different.
% \columngutter = glue                  % Column gutter.
% \divisions = {...}                    % Which divisions to include.
% \leftindent = glue                    % Left indentation.
% \locators = {...}                     % Which locators to include.
% \indexparams = {...}                  % Parameters for index generator.
% \parhang = glue                       % Paragraph hang.
% \parindent = dimen                    % Paragraph indent.
% \parrag = dimen                       % Paragraph raggedness.
% \parskip = glue                       % Paragraph skip. 
% \position = {...}                     % Position and number of columns.
% \rightindent = glue                   % Right indentation.
%~end

\definetoks{\locators}
\definetoks{\indexparams}

\definecount{\previndexlevel}{0}
\definecount{\zixcols}{0}


\def \index #1{%                                        {type}
  \blockcantbein{\index}{\index}%
  \beginblockscope{index}%
  \global\increment \indexdepth
  \clubpenalty = \breakallowed          %~default soft
  \parskip = 0pt                        %~default soft
  \processdesign{\index}{#1}%
  \global\increment \indexnumber
  \def \zixtype {#1}%
  \zixparsepos
  \indexformat}

\def \indexformat {%
  \the\bodyfont
  \alterindentation{\leftindent}{\rightindent}%
  \setparrag{\parrag}%
  \setpagecolumns{\zixpageuse}{\the\zixcols}{\columngutter}%
  \everycolumn = {\zixcarryover}%
  \begingroup
    \let \zfullcolumnbreak = \fullcolumnbreak
    \let \fullcolumnbreak = \indexbreak
    \let \shortcolumnbreak = \indexbreak
    \global\previndexlevel = 0\relax}

\def \endindex {%
    \endgraf                    % End last entry.
    \vbox{}%                    % Force start of column if not already.
  \endgroup
  \clearindexmarks
  \everycolumn = {}%
  \setpagecolumns{\usetextmeasure}{1}{0pt}%
  \global\decrement \indexdepth
  \endblockscope{index}}

\def \zixparsepos {%
  \zixcols = 1
  \let \oneup = \relax
  \def \twoup {\zixcols = 2}%
  \def \threeup {\zixcols = 3}%
  \def \zixpageuse {\usetextmeasure}%
  \let \textarea = \relax
  \def \typearea {\def \zixpageuse {\usetypewidth}}%
  \let \leftmargin = \typearea
  \the\position}

%                       Index Entries
%                       ----- -------


\setflag \zixbreak = \false


\def \indexentry #1#2#3{%                       level{heading}{locators}
  \endgraf
  \ifcase #1%
  \or                                           % Level 1 heading:
    \clearindexmarks
    \zixmaybebreak
    \hangindent = \parhang \hangafter = 1
    {\name{\index\zixtype entryiformat}{#2\setmarkinfo{4}{\true}{#2}}{#3}}%
%%%    \setmarkinfo{4}{\true}{#2}%
  \or                                           % Level 2 heading:
    \setmarkinfo{5}{\false}{}%
    \zixmaybebreak
    \hangindent = \parhang \hangafter = 1
    {\name{\index\zixtype entryiiformat}{#2\setmarkinfo{5}{\true}{#2}}{#3}}%
%%%    \setmarkinfo{5}{\true}{#2}%
  \or                                           % Level 3 heading:
    \zixmaybebreak
    \hangindent = \parhang \hangafter = 1
    {\name{\index\zixtype entryiiiformat}{#2}{#3}}%
  \fi
  \global\previndexlevel = #1\relax}

\def \alphabreak #1{%                           {text}
  \endgraf
  \clearindexmarks
  \zixmaybebreak
  \alphaformat{#1}%
  \endgraf}

\def \indexbreak {%
  \setflag \zixbreak = \true}

\def \clearindexmarks {%
  \setmarkinfo{4}{\false}{}%
  \setmarkinfo{5}{\false}{}}

\def \zixmaybebreak {%
  \if \zixbreak
    \zfullcolumnbreak
    \setflag \zixbreak = \false
  \fi}


% This macro is invoked at the beginning of each column to perform
% any first- and second-level entry carryovers. It only includes
% carryovers on the first column of versos.

\def \zixcarryover {%
  \if \andp{\evenpagep}{\firstcolumnp}%
    {\setflag \znext = {\markinfo{\bottommark}{4}{1}}%
     \if \znext
       \hangindent = \parhang \hangafter = 1
       \name{\index\zixtype carryiformat}{\markinfo{\bottommark}{4}{2}}%
       \setflag \znext = {\markinfo{\bottommark}{5}{1}}%
       \if \znext
         \hangindent = \parhang \hangafter = 1
         \name{\index\zixtype carryiiformat}{\markinfo{\bottommark}{5}{2}}%
       \fi
       \endgraf
       \tdimena = \zoutputcoldepth              % Compensate for depth of
       \advance \tdimena by -\prevdepth         % previous column v. depth
       \kern \tdimena                           % of carryover line(s).
     \fi}%
  \fi}