1 %% An attempt to have several index files
2 %%
3 %% Defines \altindex{filename}{word to index}
4 %% and \makealtindex{filename}
5 %%
6 %% It is possible to define a macro for each index as follows:
7 %% \newcommand{\myindex}{\altindex{myindexfile}}
8 %%
9 %% This code is not really clean, there are still a number of things
10 %% that I don't understand... but it works.
11
12 %% \makealtindex{filename} opens filename.idx for writing.
13
14 \def\makealtindex#1{\if@filesw
15 \expandafter\newwrite\csname @#1altindexfile\endcsname
16 \immediate\openout\expandafter\csname @#1altindexfile\endcsname=#1.idx
17 \typeout{Writing alternate index file #1.idx}\fi}
18
19 %% \@wraltindex makes the assumes that a trailing `\fi' will get bound
20 %% to #2. So, it `eats' it as second parameter and reinserts it.
21 %% Quick and dirty, I know...
22 %% Writes the index entry #3 into #1.
23
24 \def\@wraltindex#1#2#3{\let\thepage\relax
25 \xdef\@gtempa{\write#1{\string
26 \indexentry{#3}{\thepage}}}\fi\endgroup\@gtempa
27 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}
28
29 %% \altindex{filename}{index entry} does nothing if
30 %% \@<filename>altindexfile is \relax (i.e. filename.idx not open).
31 %% Otherwise, writes the index entry, and closes the whole stuff (some
32 %% groups, and some \if).
33
34 \def\altindex#1{\@bsphack\begingroup
35 \def\protect##1{\string##1\space}\@sanitize
36 \@ifundefined{@#1altindexfile}%
37 {\endgroup\@esphack}%
38 {\@wraltindex{\expandafter\csname @#1altindexfile\endcsname}}
39 }
40