使用 biblatex 和 imakeidx 生成作者/年份索引

使用 biblatex 和 imakeidx 生成作者/年份索引

根据这个问题/答案按作者和年份自动索引参考文献,我正在尝试为参考书目数据库中的所有条目创建索引。为此,我用它biblatex来处理参考书目和imakeidx索引,但我无法使用它。

如下MWE

\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}

答案1

将输入中的相应行更正为

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

语法\index

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

使用大括号而不是方括号。

相关内容