Debian Codegraph @

texmf-dist/doc/latex/robustindex/robustsample.tex

raw
1 % robustsample.tex 2018/03/23
2 \documentclass{book}
3
4 \usepackage{makeidx}
5 \usepackage{robustindex}
6 \usepackage{robustglossary}
7 \usepackage[plainpages=false,hyperindex=false,colorlinks=true]{hyperref}
8
9 \title {A file with robust index}
10
11 \author{Wilberd van der Kallen\index{Wilberd}}
12 \date{}
13
14 \makeindex % obligatory with robustindex
15 \makeglossary % obligatory with robustglossary
16
17 \begin{document}
18 \renewcommand\thepage{\roman{page}}
19
20 \maketitle
21
22 \tableofcontents
23 \addcontentsline{toc}{chapter}{Contents}
24
25 \chapter*{Preface}
26 \addcontentsline{toc}{chapter}{Preface}
27 \markboth{Preface}{Preface}
28 This file illustrates some features of the \verb!robustindex! package.
29
30 Although this is not a book, we have chosen the book style for illustration.
31
32 We will recall the purpose of \verb|robustindex.sty| in appendix
33 \ref{purpose}.
34
35
36 If you want to see how \verb|robustindex.sty| may be used, compare the file
37 \verb|robustsample.tex| or appendix \ref{appendix} with the output.
38
39 If you are interested in our usage of \verb|robustglossary.sty|, you must read
40 the source file \verb|robustsample.tex|.
41
42 This preface has an \emph{indexed term}.\index{indexed term} (You see this in the source file only.)
43
44 % Let us pretend this page explains $\mathrm{Ext}^i_B(M,N)$.
45 \glossary{$\mathrm{Ext}^i_B(M,N)$&Ext group in the category $\mathcal C_B$}
46
47 \chapter{Introduction}\sloppy
48 \renewcommand\thepage{\arabic{page}}
49 \addtocounter{page}{-2}% Just to get overlap in roman and arabic page numbers.
50 This introduction has another indexed term
51 \index{other term!cited twice on same page}
52 as well as the old indexed term.\index{indexed term}
53 The page number is again 5, but now in arabic.
54 If you index the same term twice on the same page, then one simply gets
55 a repeat in the index.\index{other term!cited twice on same page}
56 That is inherent in our method.
57 Indeed we had to disable the implicit page range formation of makeindex.
58 % Let us pretend this page explains $H^0(X,\mathcal L)$.
59 \glossary{$H^0(X,\mathcal L)$&the sections of the vector bundle
60 $\mathcal L|_X$ over $X$}
61
62
63 Traditionally page ranges and fonts for page numbers could be done with the
64 encapsulating construction of makeindex, but that construction is broken by our
65 package.
66 (The encapsulating construction uses the encap character $|$ in the argument of
67 \verb|\index|.)
68
69 We have restored encapsulating to some extent, sufficient for common practice,
70 but our rules are more naive than those of makeindex.
71 Thus it becomes possible
72 to have a page range as on
73 page \pageref{range}, which has several fonts in its page numbers.
74 That is actually bad style, but this file just illustrates features.
75
76 See the file \verb|robustsample.tex| for details.
77
78 Subentries are still supported. We illustrate this in
79 \verb|robustsample.tex| and appendix \ref{appendix} with alpha, beta and gamma.
80 This also illustrates the use of \verb|\gobblepageref|.
81 \index{alpha!see beta}
82 \index{alpha!see also gamma\gobblepageref}
83
84 After running \LaTeX\ on {\it filename} one must run makeindex on {\it
85 filename} to get the index entries in {\it filename}.\texttt{ind}.
86 Before this there may be error messages about labels or names.
87 Do not exclude any relevant files. For instance, do not use
88 \verb|\includeonly|.
89
90 Say we wish the index to occur in the table of contents.
91 We then give the command \verb|\indexincontents| before the index.
92
93 The package \verb|hyperref| may break our code. Therefore
94 one must use the option
95 \verb|hyperindex=false|, as in
96 \verb|\usepackage[hyperindex=false]{hyperref}|.
97 Note that \verb|robustindex| already puts
98 hyperlinks in the index. Alternatively one may go against the advice of
99 \verb|hyperref| and put \verb|robustindex| later in the preamble.
100 In the file \verb|robustsample.tex| we actually used
101 \verb|\usepackage[plainpages=false,hyperindex=false]{hyperref}|
102 because of the roman page numbers in the beginning.
103
104 % For special effects you could simply edit the filename.ind file.
105 % If you insist on using encapsulation, you can experiment with constructs
106 % like those below.
107 %
108 % Let us first describe some rules.
109 % In \index{arg} the argument "arg" may contain at most one "|".
110 % If it contains "|", then the part after "|" is for encapsulating.
111 % It may be of one of the following two types.
112 %
113 % 1. A sequence of letters like "texttt" with the property that if "\"
114 % is prepended, as in "\texttt", the result is a valid command that takes
115 % one argument. This command will be applied to the page number.
116 %
117 % 2. One of the brackets "(" or ")", or one of those brackets followed by
118 % a sequence as in type 1.
119 % Any "(" must be matched by its ")", and this ")" must occur in a later
120 % \index command that shares the part before the "|".
121 % If an intervening \index command has this same part before the "|",
122 % then it does not appear in the index.
123 %
124 % Makeindex also attaches special meanings to @, !, ". These meanings stay,
125 % but " can no longer be used to escape |. One must simply replace | with
126 % \vert, when | is not intended to start encapsulation. Here is an example:
127 %
128 \index{page range!risky@this $\vert$is$\vert$ complicated|(textbf}%
129 % The "(" means that this starts a page range, and "textbf" means that
130 % one wants to apply \textbf to the page number that starts the range.
131 % The name "risky" of the subentry is used for sorting by makeindex, and will
132 % not be printed.
133 %
134 %
135 \index{page range|(textbf}%
136 % This belongs to the entry "page range" in the index. The previous
137 % \index command started a subentry of this entry.
138 %
139 % The next three index commands do not contribute, as they occur
140 % before the page range is ended.
141 \index{page range!risky@this $\vert$is$\vert$ complicated|textbf}%
142 \index{page range!risky@this $\vert$is$\vert$ complicated}%
143 \index{page range!risky@this $\vert$is$\vert$ complicated|textbf}%
144 %
145 \index{simpler!page range|(}%
146 \index{simplest page range|(}%
147 % encapsulating to be continued below
148
149 \appendix
150 \chapter{Structure of the \LaTeX\ file}\label{appendix}
151 \begin{verbatim}
152 \documentclass{book}
153
154 \usepackage{makeidx}
155 \usepackage{robustindex}
156 \usepackage[plainpages=false,hyperindex=false]{hyperref}
157 ...
158 ...\author{Wilberd van der Kallen\index{Wilberd}}
159 ...
160 \makeindex % obligatory with robustindex
161
162 \begin{document}
163 ...
164 \tableofcontents
165 ...\index{indexed term} % on page v
166 ...\index{other term!cited twice on same page} % on page 5
167 ...\index{indexed term} % on page 5
168 ...\index{other term!cited twice on same page} % on page 5
169 ...
170 \index{alpha!see beta} % on page 5
171 \index{alpha!see also gamma\gobblepageref} % on page 5
172 ...
173 % For special effects you could simply edit filename.ind
174 % We illustrate our poor man's encapsulation.
175 \index{...|...}... % on page 6
176 \index{...|...}... % on page 7
177 \index{...|...}... % on page 9
178 ....
179 \indexincontents % before the index.
180 \printindex
181
182 \end{document}
183 \end{verbatim}
184
185 % continuation of encapsulating
186 % We close a page range, but now the page number is in italic.
187 % This is bad style, but we are just illustrating a feature.
188 \index{page range!risky@this $\vert$is$\vert$ complicated|)textit}
189 % encapsulating to be continued below
190
191 \chapter{Purpose of \texttt{robustindex.sty}}\label{purpose}
192 Amazingly often a third party changes the page numbers without rerunning
193 makeindex. It is much nicer to have an index that adapts itself to all
194 changes that do not involve
195 \verb|\index{|\textit{entry}\verb|}| commands.
196
197 The package achieves this
198 by invoking the \verb|\pageref| mechanism on automatically generated labels
199 of the form \verb|ind.2|, \verb|ind.4|, \dots.
200
201 Only after adding/deleting/modifying an \verb|\index{|\textit{entry}\verb|}|
202 command, or after changing the order of \verb|\index{|\textit{entry}\verb|}|
203 commands, does one have to run makeindex. But then it is important that you
204 do run makeindex, even when no warning is issued. The robustness has its
205 limits.
206
207 % continuation of encapsulating
208 %
209 \index{page range|)textit}%
210 \index{page range!risky@this $\vert$is$\vert$ complicated|texttt}
211 %
212 \index{page range!with risky label\label{range}}
213 % This label actually works and was used above in a \pageref{range} command.
214 %
215 \index{simpler!page range|)}%
216 \index{simplest page range|)}%
217 % end of encapsulating
218
219
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %
222 % Our glossary entries are given in the format
223 % \glossaryentry{$B$&Borel subgroup}{page number}
224 % which would be generated by \glossary{$B$&Borel subgroup}
225 % and written into the filename.glo file.
226 % So the & separates the formula from its explanation.
227 % We assume the explanation fits on the line.
228 %
229 % Our implementation:
230
231 \def\itemamp#1&#2{%
232 \mbox{%
233 \hbox to 10em{%
234 #1% the formula
235 \hss
236 }%
237 }%
238 #2% its explanation
239 }%
240
241 \def\glossaryentry#1#2{%
242 {\itemamp #1{\unskip, #2}%
243 }\par
244 }%
245
246 \newenvironment{theglossary}{\parindent0pt\parskip0pt}{}
247
248 \chapter*{Glossary of Notations}
249
250 \begin{theglossary}\addcontentsline{toc}{chapter}{Glossary of Notations}
251
252 % Now we copy from filename.glo, making changes as appropriate.
253 % In this example we just changed the order of the entries.
254
255 \glossaryentry{$H^0(X,\mathcal L)$&the sections of the vector bundle $\mathcal
256 L
257 |_X$ over $X$}{\glopageref{4}}
258
259 \glossaryentry{$\mathrm{Ext}^i_B(M,N)$&Ext group in the category $\mathcal
260 C_B$}
261 {\glopageref{2}}
262
263 \end{theglossary}
264
265 % If you want the index in the table of contents, you may do
266 %
267 % \clearpage
268 % \phantomsection
269 % \addcontentsline{toc}{chapter}{\indexname}
270 %
271 % We have a command for this:
272
273 \indexincontents % before \printindex
274 \printindex
275 \end{document}