Debian Codegraph @

texmf-dist/doc/latex/biblatex-ms/examples/22-indexing-subentry-ms.tex

raw
1 %
2 % This file demonstrates indexing with the 'imakeidx' package.
3 % This file is processed as follows:
4 %
5 % latex file
6 % bibtex/biber file
7 % latex file
8 % latex file
9 %
10 % Note that the file name suffix may be omitted. It's 'latex file' and not
11 % 'latex file.tex'. Also note that '-t <file>' is optional.
12 %
13 \documentclass[a4paper]{article}
14 \usepackage[T1]{fontenc}
15 \usepackage[utf8]{inputenc}
16 %
17 % The 'imakeidx' package provides advanced indexing facilities with support for
18 % multiple indexes. Unlike the 'index' package, 'imakeidx' does not generate
19 % "self-protecting" index entries. So we need to protect control sequences in
20 % indexing fields from expansion. For an example see the 'knuth:ct:a' entry in
21 % biblatex-examples.bib.
22 %
23 \usepackage{imakeidx}
24 \usepackage[american]{babel}
25 \usepackage{csquotes}
26 %
27 % We set the 'indexing' package option and use the 'authortitle'
28 % style in this example.
29 %
30 \usepackage[indexing=cite,style=authortitle,autolang=hyphen,backend=biber]{biblatex-ms}
31 \addbibresource{biblatex-examples.bib}
32 %
33 % We want two indexes: an index of names with title subentries, an index of
34 % titles organized by year. They are defined by way of \makeindex, see the
35 % documentation of the 'imakeidx' package for details.
36 %
37 \makeindex[name=name-title,title={Name and Title Index}]
38 \makeindex[name=year-title,title={Year and Title Index}]
39 %
40 % A 'name:title' indexing bibmacro can be found in biblatex.def. It takes the same
41 % arguments as the 'index:name' bibmacro. Note that the title fields are accessed
42 % inside the name indexing directive. So we have to test for missing titles.
43 %
44 \makeatletter
45 \@ifpackageloaded{biblatex_legacy}
46 {\DeclareIndexNameFormat{name:title}{%
47 \iffieldundef{title}
48 {\usebibmacro{index:name}{\index[name-title]}{#1}{#3}{#5}{#7}}
49 {\usebibmacro{index:name:title}{\index[name-title]}{#1}{#3}{#5}{#7}}}}
50 {\DeclareIndexNameFormat{name:title}{%
51 \iffieldundef{title}
52 {\usebibmacro{index:name}{\index[name-title]}
53 {\namepartfamily}
54 {\namepartgiven}
55 {\namepartprefix}
56 {\namepartsuffix}}
57 {\usebibmacro{index:name:title}{\index[name-title]}
58 {\namepartfamily}
59 {\namepartgiven}
60 {\namepartprefix}
61 {\namepartsuffix}}}}
62 \makeatother
63 %
64 % Auxiliary indexing macros in biblatex.def can be used to define additional
65 % indexing directives with subentries. The following directive creates entries
66 % for the year-title index.
67 %
68 \DeclareIndexFieldFormat{with:year}{%
69 \iffieldundef{year}
70 {\usebibmacro{index:entry}{\index[year-title]}{%
71 \mkbibindexentry{0}{Not dated}%
72 \subentryoperator%
73 \mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}
74 {\usebibmacro{index:entry}{\index[year-title]}{%
75 \thefield{year}\subentryoperator%
76 \mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}}
77 %
78 % We redefine the 'citeindex' bibmacro to use the new indexing directives.
79 %
80 \renewbibmacro*{citeindex}{%
81 \ifciteindex
82 {\indexnames[name:title]{labelname}%
83 \indexfield[with:year]{indextitle}}
84 {}}
85
86 \begin{document}
87
88 \section*{Indexing with the \texttt{imakeidx} package}
89
90 % We cite a few items. These citations will be added to the indexes.
91 \cite{knuth:ct,knuth:ct:a,knuth:ct:c,knuth:ct:d}
92 \cite{aristotle:anima,aristotle:poetics,aristotle:physics,aristotle:rhetoric}
93
94 \clearpage
95
96 % We print the printbibliography...
97 \printbibliography
98 % ...and the indexes
99 \raggedright
100 \printindex[name-title] % the name-title index
101 \printindex[year-title] % the year-title index
102
103 \end{document}