5

Based on this question/answer Automatically indexing references by author and year, I am trying to create an index of all my entries in the bibliography database. For that I am using biblatex to handle bibliography and imakeidx for the index, but I cannot put it to work.

The MWE is below:

\documentclass[%
    a4paper,
    english,
    11pt,
]{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Padial:2010,
    title={The integrative future of taxonomy},
    author={José M.~Padial and Aurélien Miralles and Ignacio De la Riva and Miguel Vences},
    journal={Frontiers in Zoology},
    year=2010,
    month=may,
    volume=7,
    number=16,
    pages={1--14},
    doi={10.1186/1742-9994-7-16},
    issn={1742-9994},
    keywords={biology, taxonomy},
}
\end{filecontents*}

\usepackage{fixltx2e}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{type1ec}
\usepackage{microtype}

\usepackage{csquotes}
\usepackage[style=authoryear,indexing,backend=biber]{biblatex}
\addbibresource{\jobname.bib}

\usepackage{imakeidx}
\makeindex[name=authors,title=Authors Index,columns=1]
\makeindex[name=years,title=Years Index,columns=1]

\makeatletter
% For the "years" index, we redefine the ordinary bibmacro
% which indexes titles, so that it indexes into the years
% index instead
\renewbibmacro*{index:title}[2]{%
  \iffieldundef{year}
     {\usebibmacro{index:years}%
      {\index}%
      {\undated}%
      {\thefield{indexsorttitle}}%
      {\thefield{entrykey}}}
    {\usebibmacro{index:years}%
      {\index}%
      {\thefield{year}}%
      {\thefield{indexsorttitle}}%
      {\thefield{entrykey}}}}

\newbibmacro*{index:years}[4]{%
    \begingroup
     \protected@edef\theindexentry{%
      \unexpanded{#1}\yearsindex{#2!#3\actualoperator\unexpanded{\citefield}{#4}{indextitle}}}%
     \theindexentry
     \endgroup}

% For authors we just redefine the field format (so that it
% includes title and year information
\DeclareIndexNameFormat{default}{%
  \iffieldundef{year}
    {\usebibmacro{index:name}%
      {\index}%
      {#1}%
      {#3}%
      {#5}%
      {#7}%
      {\thefield{indexsorttitle}}%
      {\thefield{entrykey}}%
      {}}
   {\usebibmacro{index:name}%
      {\index}%
      {#1}%
      {#3}%
      {#5}%
      {#7}%
      {\thefield{indexsorttitle}}%
      {\thefield{entrykey}}%
      { (\thefield{year})}}}
% ... and modify the relevant bibmacro to add the extra information
\renewbibmacro*{index:name}[8]{%
  \begingroup
  \ifuseprefix
    {\protected@edef\theindexentry{%
       \unexpanded{#1}\authorsindex{%
         \ifblank{#4}{}{#4 }%
         \@firstofone #2% remove spurious braces
         \ifblank{#5}{}{ #5}%
         \ifblank{#3}{}{, #3}%
         \actualoperator
         \ifblank{#4}{}{\MakeCapital{#4} }%
         #2%
         \ifblank{#5}{}{ #5}%
         \ifblank{#3}{}{, #3}!#6
            \actualoperator\unexpanded{\citefield}{indextitle}#8}}}%
    {\protected@edef\theindexentry{%
       \unexpanded{#1}\authorsindex{%
         \@firstofone #2% remove spurious braces
         \ifblank{#5}{}{ #5}%
         \ifblank{#3#4}{}{,}%
         \ifblank{#3}{}{ #3}%
         \ifblank{#4}{}{ #4}!#6\actualoperator
            \unexpanded{\citefield}{#7}{indextitle}#8}}}%
  \theindexentry
  \endgroup}
\makeatother
\newcommand{\yearsindex}{{years}}
\newcommand{\authorsindex}{{authors}}

% undated entries
\newcommand{\undated}{n.d.}

\usepackage[colorlinks]{hyperref}

\begin{document}

\nocite{*}

\printbibliography
\printindex[authors]
\printindex[years]

\end{document}
cacamailg
  • 8,405

1 Answers1

2

Correct the corresponding lines in your input to

\newcommand{\yearsindex}{[years]}
\newcommand{\authorsindex}{[authors]}

The syntax for \index is

\index[<name>]{<entry>}

You have braces instead of brackets.

egreg
  • 1,121,712
  • The output is not very good in the printed index. But I think it is now related with the definition of style by biblatex. – cacamailg May 01 '13 at 22:20
  • @cacamailg You're using a subitem which is quite long (the whole title), so it's split across lines. You may want to use a one column index: add the columns=1 option to the \makeindex commands. – egreg May 01 '13 at 22:37
  • I notice that later. I updated the question to include that option. Thanks. – cacamailg May 01 '13 at 22:43
  • @egreg I tried this MWE with style=apa instead of style=authoryear and I get: Package imakeidx Warning: Undefined index file test' on input line 125. and LaTeX Warning: Citation 'indextitle' on page 1 undefined on input line 125 (test.tex is my file name). How could I tweak the macros to make it work with biblatex-apa? – Francesco Oct 23 '13 at 07:45