summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/biblatex/examples/21-indexing-multiple.tex
blob: 81d8eee825ab6d1905df53f505dd638fd2d78c83 (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
%
% This file demonstrates indexing with the 'index' package.
% This file is processed as follows:
%
%   latex        file
%   bibtex/biber file
%   latex        file
%   makeindex -o file.ind file.idx (= makeindex file)
%   makeindex -o file.nnd file.ndx
%   makeindex -o file.tnd file.tdx
%   latex        file
%
% Note that the file name suffix may be omitted. It's 'latex file'
% and not 'latex file.tex'. Also note that '-t <file>' is optional.
%
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%
% The 'index' package provides advanced indexing facilities with
% support for multiple indexes.
\usepackage{index}
\usepackage[american]{babel}
\usepackage{csquotes}
%
% We set the 'indexing' package option and use the 'authortitle'
% style in this example.
\usepackage[indexing,style=authortitle,autolang=hyphen,backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
%
% We want three indexes: a general index, an index of names, and an
% index of titles. They are defined by way of \newindex, see the
% documentation of the 'index' package for details.
\newindex{default}{idx}{ind}{Subject Index}
\newindex{names}{ndx}{nnd}{Name Index}
\newindex{titles}{tdx}{tnd}{Title Index}
%
% We need to redefine some index formatting directives such that
% biblatex adds names and titles to separate indexes. All names
% should go to the name index, hence we simply redefine the default
% index formatting directive for names. The default definition,
% which is found in biblatex.def, looks like this:
%
%   \DeclareIndexNameFormat{default}{%
%     \usebibmacro{index:name}{\index}{#1}{#3}{#5}{#7}%
%   }
%
% As you can see, the data is simply passed on to a 'bibmacro' which
% takes care of the formatting of the name. The definition of the
% bibmacro, which is also found in biblatex.def, is not relevant in
% our example because all we want to do is change or rather extend
% the \index command, which happens to be the first argument of the
% 'index:name' bibmacro.
%
\makeatletter
\@ifpackageloaded{biblatex_legacy}
  {\DeclareIndexNameFormat{default}{%
     \usebibmacro{index:name}{\index[names]}{#1}{#3}{#5}{#7}}}
  {\DeclareIndexNameFormat{default}{%
     \nameparts{#1}%
     \usebibmacro{index:name}{\index[names]}
       {\namepartfamily}
       {\namepartgiven}
       {\namepartprefix}
       {\namepartsuffix}}}
\makeatother
%
% Titles are handled in a similar way. The formatting directive we
% need to modify is 'indextitle'. It's default definition looks like
% this:
%
%   \DeclareIndexFieldFormat{indextitle}{%
%     \usebibmacro{index:title}{\index}{#1}%
%   }
%
% We modify it such that the \index command writes to the index of
% titles:
%
\DeclareIndexFieldFormat{indextitle}{%
  \usebibmacro{index:title}{\index[titles]}{#1}%
}
%
% That's it as far as splitting the index is concerned. Let's have a
% look at some other facilities you may want to customize. By
% default, biblatex will index the author or editor and the title of
% all references. This behavior may be modified as desired. The
% indexing facilities are not hard-coded. All standard styles which
% ship with this package call two 'bibmacros' which handle the
% indexing. These macros are called 'citeindex' and 'bibindex', both
% of which are defined in biblatex.def. The former handles indexing
% in citations, the latter in the bibliography. Their default
% definitions are as follows:
%
%   \newbibmacro*{citeindex}{%
%     \ifciteindex
%       {\indexnames{labelname}%
%	 \indexfield{indextitle}}
%       {}}
%
%   \newbibmacro*{bibindex}{%
%     \ifbibindex
%       {\indexnames{labelname}%
%	 \indexfield{indextitle}}
%       {}}
%
% The 'labelname' field is a copy of the 'author' field, if there is
% an author, or a copy of the 'editor' field otherwise. 'indextitle'
% is the 'indextitle' field, if defined in the bib file, or a copy
% of the 'title' field otherwise.
%
% The mechanism works like this: the \indexnames and \indexfield
% fields tell biblatex which data to add to the index, the indexing
% directives tell it how to index the data.
%
% The default settings should be fine in most cases. As an example,
% we will modify them here such that author, editors, translators,
% and commentators in the bibliography are indexed:
%
\renewbibmacro*{bibindex}{%
  \ifbibindex
    {\indexnames{author}%
     \indexnames{editor}%
     \indexnames{translator}%
     \indexnames{commentator}%
     \indexfield{indextitle}}
    {}}
%
\begin{document}

\section*{Indexing with the \texttt{index} package}

% We add the contents of the entire bib file to the bibliography.
% Note that \nocite does not add anything to the index on its own.
\nocite{*}

% We cite a few items. These citations will be added to the index.
\cite{piccato,gaonkar,malinowski,coleridge,gerhardt,cicero}

% We also add an explicit index entry.
\index{Example entry}

\clearpage

% We print the printbibliography...
\printbibliography
% ...and the indexes
\raggedright
\printindex         % the general index
\printindex[names]  % the name index
\printindex[titles] % the title index

\end{document}