| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX Indexing Facilities, version 1 |
| 4 |
% |
| 5 |
% Synopsis: This file contains the tools for producing an index. |
| 6 |
% |
| 7 |
% Author: Paul C. Anagnostopoulos |
| 8 |
% Created: 20 May 2006 |
| 9 |
% |
| 10 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 11 |
% under The MIT License (opensource.org/licenses/MIT) |
| 12 |
% |
| 13 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 14 |
|
| 15 |
% Index Version |
| 16 |
% ----- ------- |
| 17 |
|
| 18 |
|
| 19 |
\def \indexversion #1{% |
| 20 |
\input zzindexv#1\relax} |
| 21 |
|
| 22 |
% Define Index Locator Types |
| 23 |
% ------ ----- ------- ----- |
| 24 |
|
| 25 |
|
| 26 |
% This list contains the definition of each locator. New ones must be |
| 27 |
% added to the end, and any program looking at the definitions must assume |
| 28 |
% that duplicates may exist, and that the last one prevails. |
| 29 |
|
| 30 |
\def \zixloclist {} |
| 31 |
|
| 32 |
|
| 33 |
%~ This command is deprecated in favor of |\definelocator|. |
| 34 |
|
| 35 |
\def \definelocatortype #1#2#3#4#5#6{% {name}{attributes}{precedence} |
| 36 |
% {beginning-punc}{templates} |
| 37 |
% {ending-punc} |
| 38 |
{\setflag \pg = \true |
| 39 |
\let \page = \relax |
| 40 |
\def \nopage {\setflag \pg = \false}% |
| 41 |
\setflag \txt = \false |
| 42 |
\def \text {\setflag \txt = \true}% |
| 43 |
\let \notext = \relax |
| 44 |
#2% |
| 45 |
\def \bpunc {#4}% |
| 46 |
\def \temp {#5}% |
| 47 |
\def \epunc {#6}% |
| 48 |
\edef \znext {% |
| 49 |
\noexpand\append{{#1}{\pg}{\txt}{#3}% |
| 50 |
{\expandafter\zdefof \meaning\bpunc\zmark}% |
| 51 |
{\expandafter\zdefof \meaning\temp\zmark}% |
| 52 |
{\expandafter\zdefof \meaning\epunc\zmark}}}% |
| 53 |
\znext{\zixloclist}% |
| 54 |
\if \txt |
| 55 |
\withname\gdef{\x#1}##1##2{\zixindex{#1}{##1}{S}{##2}}% |
| 56 |
\if \pg |
| 57 |
\withname\gdef{\x#1begin}##1##2{\zixindex{#1}{##1}{B}{##2}}% |
| 58 |
\withname\gdef{\x#1end}##1##2{\zixindex{#1}{##1}{E}{##2}}% |
| 59 |
\fi |
| 60 |
\else |
| 61 |
\withname\gdef{\x#1}##1{\zixindex{#1}{##1}{S}{}}% |
| 62 |
\if \pg |
| 63 |
\withname\gdef{\x#1begin}##1{\zixindex{#1}{##1}{B}{}}% |
| 64 |
\withname\gdef{\x#1end}##1{\zixindex{#1}{##1}{E}{}}% |
| 65 |
\fi |
| 66 |
\fi}} |
| 67 |
|
| 68 |
|
| 69 |
% This command is deprecated. |
| 70 |
|
| 71 |
\def \defineindexlocator #1#2#3#4#5#6{% {name}{attributes}{precedence} |
| 72 |
% {punctuation}{single-template} |
| 73 |
% {range-template} |
| 74 |
} |
| 75 |
|
| 76 |
% Builtin Locator Types |
| 77 |
% ------- ------- ----- |
| 78 |
|
| 79 |
|
| 80 |
% Precedences 0--1 and 6--9 are reserved for specific books. |
| 81 |
|
| 82 |
\definelocatortype{term}{\page\notext}{2.3} |
| 83 |
{, |}{\bold{~P}|\bold{~P--~Q}|, }{. |} |
| 84 |
\definelocatortype{biblio}{\page\notext}{2.5} |
| 85 |
{, |}{~P|~P--~Q|, }{. |} |
| 86 |
\definelocatortype{cite}{\page\notext}{2.5} |
| 87 |
{, |}{~P|~P--~Q|, }{. |} |
| 88 |
\definelocatortype{page}{\page\notext}{2.5} |
| 89 |
{, |}{~P|~P--~Q|, }{. |} |
| 90 |
\definelocatortype{figure}{\page\notext}{2.7} |
| 91 |
{, |}{~P\+\emph{f}|~P--~Q\+\emph{f}|, }{. |} |
| 92 |
\definelocatortype{glossary}{\page\notext}{2.7} |
| 93 |
{, |}{~P\+\emph{g}|~P--~Q\+\emph{g}|, }{. |} |
| 94 |
\definelocatortype{note}{\page\notext}{2.8} |
| 95 |
{, |}{~P\+\emph{n}|~P--~Q\+\emph{n}|, }{. |} |
| 96 |
\definelocatortype{sidebar}{\page\notext}{2.7} |
| 97 |
{, |}{~P\+\emph{s}|~P--~Q\+\emph{s}|, }{. |} |
| 98 |
\definelocatortype{table}{\page\notext}{2.7} |
| 99 |
{, |}{~P\+\emph{t}|~P--~Q\+\emph{t}|, }{. |} |
| 100 |
\definelocatortype{see}{\nopage\text}{3} |
| 101 |
{. |\See\ }{~T||; }{. |} |
| 102 |
\definelocatortype{seealso}{\nopage\text}{4} |
| 103 |
{. |\Seealso\ }{~T||; }{. |} |
| 104 |
\definelocatortype{consult}{\nopage\text}{5} |
| 105 |
{. |\Consult\ }{~T||; }{. |} |
| 106 |
|
| 107 |
% Index Preparation File |
| 108 |
% ----- ----------- ---- |
| 109 |
|
| 110 |
|
| 111 |
% The \produceindex command must appear before the \document command. |
| 112 |
|
| 113 |
\setflag \zindexing = \false |
| 114 |
|
| 115 |
|
| 116 |
\def \produceindex #1#2{% {type}{prep-file} |
| 117 |
{\processdesign{\index}{#1}% |
| 118 |
\immediate\openout \zwritea = #2.zzh\relax |
| 119 |
\immediate\write \zwritea {root \jobname}% |
| 120 |
\immediate\write \zwritea {type #1}% |
| 121 |
\immediate\write \zwritea {divisions {\the\divisions}}% |
| 122 |
\immediate\write \zwritea {locators {\the\locators}}% |
| 123 |
\immediate\write \zwritea {\the\indexparams}% |
| 124 |
\maplist{\immediate\write \zwritea {define-locator ##1}}{\zixloclist}% |
| 125 |
\immediate\closeout \zwritea}% |
| 126 |
\global\setflag \zindexing = \true} |
| 127 |
|
| 128 |
% Index File Handling |
| 129 |
% ----- ---- -------- |
| 130 |
|
| 131 |
\definewrite{\zixrootfile} |
| 132 |
\definewrite{\zixdivfile} |
| 133 |
\setflag \zixdivopen = \false |
| 134 |
|
| 135 |
|
| 136 |
\def \zindexinit {% |
| 137 |
\if \zindexing |
| 138 |
\immediate\openout \zixrootfile = \jobname.zzi\relax |
| 139 |
\immediate\write \zixrootfile |
| 140 |
{\zcomment Raw index entry file for book `\jobname'.}% |
| 141 |
\fi} |
| 142 |
|
| 143 |
\def \zindexfinal {% |
| 144 |
\if \zindexing |
| 145 |
\immediate\write \zixrootfile {\zcomment [end]}% |
| 146 |
\immediate\closeout \zixrootfile |
| 147 |
\fi} |
| 148 |
|
| 149 |
\def \zindexdivinit #1{% {division} |
| 150 |
\if \zindexing |
| 151 |
\immediate\openout \zixdivfile = #1.zzi\relax |
| 152 |
\immediate\write \zixdivfile |
| 153 |
{\zcomment Raw index entry file for book `\jobname', division `#1'.}% |
| 154 |
\global\setflag \zixdivopen = \true |
| 155 |
\fi} |
| 156 |
|
| 157 |
\def \zindexdivfinal {% |
| 158 |
\if \zixdivopen |
| 159 |
\immediate\write \zixdivfile {\zcomment [end]}% |
| 160 |
\immediate\closeout \zixdivfile |
| 161 |
\global\setflag \zixdivopen = \false |
| 162 |
\fi} |
| 163 |
|
| 164 |
% Generate Index Entry |
| 165 |
% -------- ----- ----- |
| 166 |
|
| 167 |
|
| 168 |
% This macro is called from the indexing macros generated by |
| 169 |
% \definelocatortype. |
| 170 |
|
| 171 |
\def \zixindex #1#2#3#4{% {locator}{level}{page-code}{text} |
| 172 |
\tcounta = #2\relax |
| 173 |
\if \notp{\rangep{\tcounta}{1}{3}}% |
| 174 |
\error{invindexlvl}{Invalid index level '#2' specified}% |
| 175 |
\tcounta = 1 |
| 176 |
\fi |
| 177 |
\name{\zixindex\romannumeral\tcounta}{#1}{#2}{#3}{#4}} |
| 178 |
|
| 179 |
\def \zixindexi #1#2#3#4#5{% |
| 180 |
\zixindexw{#1}{#2}{#3}{#4}{#5}{}{}{\noexpand\folio}} |
| 181 |
\def \zixindexii #1#2#3#4#5#6{% |
| 182 |
\zixindexw{#1}{#2}{#3}{#4}{#5}{#6}{}{\noexpand\folio}} |
| 183 |
\def \zixindexiii #1#2#3#4#5#6#7{% |
| 184 |
\zixindexw{#1}{#2}{#3}{#4}{#5}{#6}{#7}{\noexpand\folio}} |
| 185 |
|
| 186 |
\catcode"B8 = \catother |
| 187 |
|
| 188 |
\gdef \zixindexw #1#2#3#4#5#6#7#8{% {locator}{level}{page-code}{text} |
| 189 |
% {heading1}{heading2}{heading3}{page} |
| 190 |
\if \notp{\zindexing}% |
| 191 |
\warning{notindexing}{An indexing command was encountered, |
| 192 |
but no \string\produceindex}% |
| 193 |
\fi |
| 194 |
\zbeginhidewrite |
| 195 |
\def \zhdx {#5}% |
| 196 |
\def \zhdy {#6}% |
| 197 |
\def \zhdz {#7}% |
| 198 |
\def \ztxt {#4}% |
| 199 |
\edef \znext {#1^^b8% |
| 200 |
#2^^b8% |
| 201 |
\expandafter\zdefof \meaning\zhdx\zmark^^b8% |
| 202 |
\expandafter\zdefof \meaning\zhdy\zmark^^b8% |
| 203 |
\expandafter\zdefof \meaning\zhdz\zmark^^b8% |
| 204 |
#3^^b8% |
| 205 |
#8^^b8% |
| 206 |
\expandafter\zdefof \meaning\ztxt\zmark}% |
| 207 |
\write \if \zixdivopen \zixdivfile \else \zixrootfile \fi |
| 208 |
\expandafter{\znext}% |
| 209 |
\if \vmodep \repeatpenalty \fi % In case glue follows write. |
| 210 |
\zendhidewrite} |
| 211 |
|
| 212 |
\catcode"B8 = \catinvalid |
| 213 |
|
| 214 |
% Discussion of Index Formatting |
| 215 |
% ---------- -- ----- ---------- |
| 216 |
|
| 217 |
|
| 218 |
% An index is formatted inside an index block, which is more or less |
| 219 |
% like a text block. Within the index block are occurences of the |
| 220 |
% \indexentry macro, one for each entry. In addition, the |
| 221 |
% \alphabreak macro can be used to produce breaks preceding the `A' |
| 222 |
% entries, `B' entries, etc. |
| 223 |
% |
| 224 |
% In an index block, parts 4 and 5 of the mark are used to remember |
| 225 |
% index entries so they can be carried forward to subsequent columns |
| 226 |
% or pages. The mark is used as follows: |
| 227 |
% |
| 228 |
% Part Subpart Usage |
| 229 |
% 4 1 Boolean, true if in the midst of a first-level entry. |
| 230 |
% 4 2 The first-level entry text. |
| 231 |
% 5 1 Boolean, true if in the midst of a second-level entry. |
| 232 |
% 5 2 The second-level entry text. |
| 233 |
|
| 234 |
% Index Block |
| 235 |
% ----- ----- |
| 236 |
|
| 237 |
|
| 238 |
\defineblock{\index}{\endindex}{\false}{} |
| 239 |
|
| 240 |
%~block index Type |
| 241 |
% \def \alphaformat ##1{...} % Alpha break formatter. |
| 242 |
% \bodyfont = {\size\style} % Body font. |
| 243 |
% \clubpenalty = penalty % Club penalty is often different. |
| 244 |
% \columngutter = glue % Column gutter. |
| 245 |
% \divisions = {...} % Which divisions to include. |
| 246 |
% \leftindent = glue % Left indentation. |
| 247 |
% \locators = {...} % Which locators to include. |
| 248 |
% \indexparams = {...} % Parameters for index generator. |
| 249 |
% \parhang = glue % Paragraph hang. |
| 250 |
% \parindent = dimen % Paragraph indent. |
| 251 |
% \parrag = dimen % Paragraph raggedness. |
| 252 |
% \parskip = glue % Paragraph skip. |
| 253 |
% \position = {...} % Position and number of columns. |
| 254 |
% \rightindent = glue % Right indentation. |
| 255 |
%~end |
| 256 |
|
| 257 |
\definetoks{\locators} |
| 258 |
\definetoks{\indexparams} |
| 259 |
|
| 260 |
\definecount{\previndexlevel}{0} |
| 261 |
\definecount{\zixcols}{0} |
| 262 |
|
| 263 |
|
| 264 |
\def \index #1{% {type} |
| 265 |
\blockcantbein{\index}{\index}% |
| 266 |
\beginblockscope{index}% |
| 267 |
\global\increment \indexdepth |
| 268 |
\clubpenalty = \breakallowed %~default soft |
| 269 |
\parskip = 0pt %~default soft |
| 270 |
\processdesign{\index}{#1}% |
| 271 |
\global\increment \indexnumber |
| 272 |
\def \zixtype {#1}% |
| 273 |
\zixparsepos |
| 274 |
\indexformat} |
| 275 |
|
| 276 |
\def \indexformat {% |
| 277 |
\the\bodyfont |
| 278 |
\alterindentation{\leftindent}{\rightindent}% |
| 279 |
\setparrag{\parrag}% |
| 280 |
\setpagecolumns{\zixpageuse}{\the\zixcols}{\columngutter}% |
| 281 |
\everycolumn = {\zixcarryover}% |
| 282 |
\begingroup |
| 283 |
\let \zfullcolumnbreak = \fullcolumnbreak |
| 284 |
\let \fullcolumnbreak = \indexbreak |
| 285 |
\let \shortcolumnbreak = \indexbreak |
| 286 |
\global\previndexlevel = 0\relax} |
| 287 |
|
| 288 |
\def \endindex {% |
| 289 |
\endgraf % End last entry. |
| 290 |
\vbox{}% % Force start of column if not already. |
| 291 |
\endgroup |
| 292 |
\clearindexmarks |
| 293 |
\everycolumn = {}% |
| 294 |
\setpagecolumns{\usetextmeasure}{1}{0pt}% |
| 295 |
\global\decrement \indexdepth |
| 296 |
\endblockscope{index}} |
| 297 |
|
| 298 |
\def \zixparsepos {% |
| 299 |
\zixcols = 1 |
| 300 |
\let \oneup = \relax |
| 301 |
\def \twoup {\zixcols = 2}% |
| 302 |
\def \threeup {\zixcols = 3}% |
| 303 |
\def \zixpageuse {\usetextmeasure}% |
| 304 |
\let \textarea = \relax |
| 305 |
\def \typearea {\def \zixpageuse {\usetypewidth}}% |
| 306 |
\let \leftmargin = \typearea |
| 307 |
\the\position} |
| 308 |
|
| 309 |
% Index Entries |
| 310 |
% ----- ------- |
| 311 |
|
| 312 |
|
| 313 |
\setflag \zixbreak = \false |
| 314 |
|
| 315 |
|
| 316 |
\def \indexentry #1#2#3{% level{heading}{locators} |
| 317 |
\endgraf |
| 318 |
\ifcase #1% |
| 319 |
\or % Level 1 heading: |
| 320 |
\clearindexmarks |
| 321 |
\zixmaybebreak |
| 322 |
\hangindent = \parhang \hangafter = 1 |
| 323 |
{\name{\index\zixtype entryiformat}{#2\setmarkinfo{4}{\true}{#2}}{#3}}% |
| 324 |
%%% \setmarkinfo{4}{\true}{#2}% |
| 325 |
\or % Level 2 heading: |
| 326 |
\setmarkinfo{5}{\false}{}% |
| 327 |
\zixmaybebreak |
| 328 |
\hangindent = \parhang \hangafter = 1 |
| 329 |
{\name{\index\zixtype entryiiformat}{#2\setmarkinfo{5}{\true}{#2}}{#3}}% |
| 330 |
%%% \setmarkinfo{5}{\true}{#2}% |
| 331 |
\or % Level 3 heading: |
| 332 |
\zixmaybebreak |
| 333 |
\hangindent = \parhang \hangafter = 1 |
| 334 |
{\name{\index\zixtype entryiiiformat}{#2}{#3}}% |
| 335 |
\fi |
| 336 |
\global\previndexlevel = #1\relax} |
| 337 |
|
| 338 |
\def \alphabreak #1{% {text} |
| 339 |
\endgraf |
| 340 |
\clearindexmarks |
| 341 |
\zixmaybebreak |
| 342 |
\alphaformat{#1}% |
| 343 |
\endgraf} |
| 344 |
|
| 345 |
\def \indexbreak {% |
| 346 |
\setflag \zixbreak = \true} |
| 347 |
|
| 348 |
\def \clearindexmarks {% |
| 349 |
\setmarkinfo{4}{\false}{}% |
| 350 |
\setmarkinfo{5}{\false}{}} |
| 351 |
|
| 352 |
\def \zixmaybebreak {% |
| 353 |
\if \zixbreak |
| 354 |
\zfullcolumnbreak |
| 355 |
\setflag \zixbreak = \false |
| 356 |
\fi} |
| 357 |
|
| 358 |
|
| 359 |
% This macro is invoked at the beginning of each column to perform |
| 360 |
% any first- and second-level entry carryovers. It only includes |
| 361 |
% carryovers on the first column of versos. |
| 362 |
|
| 363 |
\def \zixcarryover {% |
| 364 |
\if \andp{\evenpagep}{\firstcolumnp}% |
| 365 |
{\setflag \znext = {\markinfo{\bottommark}{4}{1}}% |
| 366 |
\if \znext |
| 367 |
\hangindent = \parhang \hangafter = 1 |
| 368 |
\name{\index\zixtype carryiformat}{\markinfo{\bottommark}{4}{2}}% |
| 369 |
\setflag \znext = {\markinfo{\bottommark}{5}{1}}% |
| 370 |
\if \znext |
| 371 |
\hangindent = \parhang \hangafter = 1 |
| 372 |
\name{\index\zixtype carryiiformat}{\markinfo{\bottommark}{5}{2}}% |
| 373 |
\fi |
| 374 |
\endgraf |
| 375 |
\tdimena = \zoutputcoldepth % Compensate for depth of |
| 376 |
\advance \tdimena by -\prevdepth % previous column v. depth |
| 377 |
\kern \tdimena % of carryover line(s). |
| 378 |
\fi}% |
| 379 |
\fi} |