summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/robustindex/robustsample.tex
blob: c7d9c959aba2b7781363597cd18cdcb5e2b92bf7 (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
% robustsample.tex 2018/03/23
\documentclass{book}

\usepackage{makeidx}
\usepackage{robustindex}
\usepackage{robustglossary}
\usepackage[plainpages=false,hyperindex=false,colorlinks=true]{hyperref}

\title {A file with robust index}

\author{Wilberd van der Kallen\index{Wilberd}}
\date{}

\makeindex    % obligatory with robustindex
\makeglossary % obligatory with robustglossary

\begin{document}
\renewcommand\thepage{\roman{page}}

\maketitle

\tableofcontents
\addcontentsline{toc}{chapter}{Contents}

\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
\markboth{Preface}{Preface}
This file illustrates some features of the \verb!robustindex! package.

Although this is not a book, we have chosen the book style for illustration.

We will recall the purpose of  \verb|robustindex.sty| in appendix
\ref{purpose}.


If you want to see how \verb|robustindex.sty| may be used, compare the file
\verb|robustsample.tex| or appendix \ref{appendix} with the output.

If you are interested in our usage of \verb|robustglossary.sty|, you must read
the source file \verb|robustsample.tex|.

This preface has an \emph{indexed term}.\index{indexed term} (You see this in the source file only.)

% Let us pretend this page explains $\mathrm{Ext}^i_B(M,N)$.
\glossary{$\mathrm{Ext}^i_B(M,N)$&Ext group in the category $\mathcal C_B$}

\chapter{Introduction}\sloppy
\renewcommand\thepage{\arabic{page}}
\addtocounter{page}{-2}% Just to get overlap in roman and arabic page numbers.
This introduction has another indexed term
\index{other term!cited twice on same page}
as well as the old indexed term.\index{indexed term}
The page number is again 5, but now in arabic.
If you index the same term twice on the same page, then one simply gets
a repeat in the index.\index{other term!cited twice on same page}
That is inherent in our method.
Indeed we had to disable the implicit page range formation of makeindex.
% Let us pretend this page explains $H^0(X,\mathcal L)$.
\glossary{$H^0(X,\mathcal L)$&the sections of the vector bundle
$\mathcal L|_X$ over $X$}


Traditionally page ranges and fonts for page numbers could be done with the
encapsulating construction of makeindex, but that construction is broken by our
package.
(The encapsulating construction uses the encap character $|$ in the argument of
\verb|\index|.)

We have restored encapsulating to some extent, sufficient for common practice,
but our rules are more naive than those of makeindex.
Thus it becomes possible
to have a page range as on
page \pageref{range}, which has several fonts in its page numbers.
That is actually bad style, but this file just illustrates features.

See the file \verb|robustsample.tex| for details.

Subentries are still supported. We illustrate this in
\verb|robustsample.tex| and appendix \ref{appendix} with alpha, beta and gamma.
This also illustrates the use of \verb|\gobblepageref|.
\index{alpha!see beta}
\index{alpha!see also gamma\gobblepageref}

After running \LaTeX\ on {\it filename} one must run makeindex on {\it
filename} to get the index entries in {\it filename}.\texttt{ind}.
Before this there may be error messages about labels or names.
Do not exclude any relevant files. For instance, do not use
\verb|\includeonly|.

Say we wish the index to occur in the table of contents.
We then give the command \verb|\indexincontents| before the index.

The package \verb|hyperref| may break our code. Therefore
one must use the option
\verb|hyperindex=false|, as in
\verb|\usepackage[hyperindex=false]{hyperref}|.
Note that \verb|robustindex| already puts
hyperlinks in the index. Alternatively one may go against the advice of
\verb|hyperref| and put \verb|robustindex| later in the preamble.
In the file \verb|robustsample.tex| we actually used
\verb|\usepackage[plainpages=false,hyperindex=false]{hyperref}|
because of the roman page numbers in the beginning.

% For special effects you could simply edit the filename.ind file.
% If you insist on using encapsulation, you can experiment with constructs
% like those below.
%
% Let us first describe some rules.
% In \index{arg} the argument "arg" may contain at most one "|".
% If it contains "|", then the part after "|" is for encapsulating.
% It may be of one of the following two types.
%
% 1. A sequence of letters like "texttt" with the property that if "\"
% is prepended, as in "\texttt", the result is a valid command that takes
% one argument. This command will be applied to the page number.
%
% 2. One of the brackets "(" or ")", or one of those brackets followed by
% a sequence as in type 1.
% Any "(" must be matched by its ")", and this ")" must occur in a later
% \index command that shares the part before the "|". 
% If an intervening \index command has this same part before the "|",
% then it does not appear in the index.
%
% Makeindex also attaches special meanings to @, !, ". These meanings stay,
% but " can no longer be used to escape |. One must simply replace | with
% \vert, when | is not intended to start encapsulation. Here is an example:
%
\index{page range!risky@this $\vert$is$\vert$ complicated|(textbf}%
% The "(" means that this starts a page range, and "textbf" means that
% one wants to apply \textbf to the page number that starts the range.
% The name "risky" of the subentry is used for sorting by makeindex, and will
% not be printed.
%
%
\index{page range|(textbf}%
% This belongs to the entry "page range" in the index. The previous
% \index command started a subentry of this entry.
%
% The next three index commands do not contribute, as they occur 
% before the page range is ended.
\index{page range!risky@this $\vert$is$\vert$ complicated|textbf}%
\index{page range!risky@this $\vert$is$\vert$ complicated}%
\index{page range!risky@this $\vert$is$\vert$ complicated|textbf}%
%
\index{simpler!page range|(}%
\index{simplest page range|(}%
% encapsulating to be continued below

\appendix
\chapter{Structure of the \LaTeX\ file}\label{appendix}
\begin{verbatim}
\documentclass{book}

\usepackage{makeidx}
\usepackage{robustindex}
\usepackage[plainpages=false,hyperindex=false]{hyperref}
...
...\author{Wilberd van der Kallen\index{Wilberd}} 
...
\makeindex    % obligatory with robustindex

\begin{document}
...
\tableofcontents
...\index{indexed term}                          % on page v
...\index{other term!cited twice on same page}   % on page 5
...\index{indexed term}                          % on page 5
...\index{other term!cited twice on same page}   % on page 5
...
\index{alpha!see beta}                           % on page 5
\index{alpha!see also gamma\gobblepageref}       % on page 5
...
% For special effects you could simply edit filename.ind
% We illustrate our poor man's encapsulation.
\index{...|...}...                               % on page 6
\index{...|...}...                               % on page 7
\index{...|...}...                               % on page 9
....
\indexincontents %  before the index.
\printindex

\end{document}
\end{verbatim}

% continuation of encapsulating
% We close a page range, but now the page number is in italic.
% This is bad style, but we are just illustrating a feature.
\index{page range!risky@this $\vert$is$\vert$ complicated|)textit}
% encapsulating to be continued below

\chapter{Purpose of \texttt{robustindex.sty}}\label{purpose}
Amazingly often a third party changes the page numbers without rerunning
makeindex. It is much nicer to have an index that adapts itself to all
changes that do not involve
\verb|\index{|\textit{entry}\verb|}| commands.

The package achieves this
by invoking the \verb|\pageref| mechanism on automatically generated labels
of the form \verb|ind.2|, \verb|ind.4|, \dots.

Only after adding/deleting/modifying an \verb|\index{|\textit{entry}\verb|}|
command, or after changing the order of \verb|\index{|\textit{entry}\verb|}|
commands, does one have to run makeindex. But then it is important that you
do run makeindex, even when no warning is issued. The robustness has its
limits.

% continuation of encapsulating
%
\index{page range|)textit}%
\index{page range!risky@this $\vert$is$\vert$ complicated|texttt}
%
\index{page range!with risky label\label{range}}
% This label actually works and was used above in a \pageref{range} command.
%
\index{simpler!page range|)}%
\index{simplest page range|)}%
% end of encapsulating


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    Our glossary entries are given in the format
%    \glossaryentry{$B$&Borel subgroup}{page number}
%    which would be generated by \glossary{$B$&Borel subgroup}
%    and written into the filename.glo file.
%    So the & separates the formula from its explanation.
%    We assume the explanation fits on the line.
%
%    Our implementation:

\def\itemamp#1&#2{%
   \mbox{%
      \hbox to 10em{%
         #1%        the formula
         \hss
      }%
   }%
     #2%        its explanation
}%

\def\glossaryentry#1#2{%
   {\itemamp #1{\unskip, #2}%
   }\par
}%

\newenvironment{theglossary}{\parindent0pt\parskip0pt}{}

\chapter*{Glossary of Notations}

\begin{theglossary}\addcontentsline{toc}{chapter}{Glossary of Notations}

% Now we copy from filename.glo, making changes as appropriate.
% In this example we just changed the order of the entries.

\glossaryentry{$H^0(X,\mathcal L)$&the sections of the vector bundle $\mathcal
L
|_X$ over $X$}{\glopageref{4}}

\glossaryentry{$\mathrm{Ext}^i_B(M,N)$&Ext group in the category $\mathcal
C_B$}
{\glopageref{2}}

\end{theglossary}

% If you want the index in the table of contents, you may do
%
% \clearpage
% \phantomsection
% \addcontentsline{toc}{chapter}{\indexname}
%
% We have a command for this:

\indexincontents % before \printindex
\printindex
\end{document}