我知道有一个包 indxcite 允许您将 \citeyearpar 放入索引中,但我使用包 imakeidx 并且不想更改所有命令(例如将 \citeyearpar 更改为 \iciteyearpar)。那么,有没有一种简单的方法可以用 imakeidx 获得相同的结果?我只需要一个人员索引。
这是 MWE
\documentclass[12pt,a4paper]{scrreport}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[natbib=true,backend=biber,style=authoryear,indexing=cite]{biblatex}
\usepackage{hyperref}
\usepackage{imakeidx}
\usepackage{etoolbox}
\makeindex[columns=2,title=Titelregister]
\makeindex[columns=2,name=personenregister,title=Index of Persons]
\makeindex[columns=2,name=sachregister,title=Index of Subjects]
\DeclareIndexNameFormat{default}{%
\usebibmacro{index:name}{\index[personenregister]}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}
\begin{filecontents}{\jobname.bib}
@book{Hursthouse.1999,
author = {Hursthouse, Rosalind},
year = {1999},
title = {On Virtue Ethics},
address = {Oxford}
}
@book{Foot.2001,
author = {Foot, Philippa},
year = {2001},
title = {Natural Goodness},
address = {Oxford}
}
@book{Thompson.2008,
author = {Thompson, Michael},
year = {2008},
title = {Life and Action},
address = {Cambridge}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
In her book \textit{Natural Goodness} \citeyearpar{Foot.2001} the author says this and that, which is very similar to what Hursthouse\index[personenregister]{Husthouse, Rosalind} says
\citep[see also][p. 1]{Thompson.2008}
\printbibliography
\printindex[personenregister]
\end{document}
答案1
从某种意义上说,\citeyearpar
不向索引发送任何内容是有道理的:它只打印年份(该命令甚至没有考虑extradate
:尝试\citeyearpar{knuth:ct:b}
和\citeyearpar{knuth:ct:c}
并将biblatex-examples.bib
其与\autocite{knuth:ct:b}
和进行比较\autocite{knuth:ct:c}
)并且年份没有被索引biblatex
。
根据您要发送到索引的具体内容,您可以添加
\ifciteindex
{\indexnames{labelname}}
{}%
或者
\ifciteindex
{\indexfield{indextitle}}
{}%
或者
\usebibmacro{citeindex}%
的定义\citeyearpar
(你可以在blx-natbib.def
, 二。)。第一位代码只索引“主要名称”(通常author
或editor
按该顺序),第二位代码只索引作品的标题,最后一位代码索引与正常\cite
命令索引的相同内容,通常归结为主要名称和标题,但可以更改。
\documentclass[12pt,a4paper]{scrreport}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[natbib=true,backend=biber,style=authoryear,indexing=cite]{biblatex}
\usepackage{imakeidx}
\usepackage{hyperref}
\makeindex[columns=2,title=Titelregister]
\makeindex[columns=2,name=personenregister,title=Index of Persons]
\makeindex[columns=2,name=sachregister,title=Index of Subjects]
\DeclareIndexNameFormat{default}{%
\usebibmacro{index:name}{\index[personenregister]}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}
\DeclareCiteCommand{\citeyearpar}[\mkbibparens]
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexnames{labelname}}
{}%
\printfield{year}}
{\multicitedelim}
{\usebibmacro{postnote}}
\begin{filecontents}{\jobname.bib}
@book{Hursthouse.1999,
author = {Hursthouse, Rosalind},
year = {1999},
title = {On Virtue Ethics},
address = {Oxford},
}
@book{Foot.2001,
author = {Foot, Philippa},
year = {2001},
title = {Natural Goodness},
address = {Oxford},
}
@book{Thompson.2008,
author = {Thompson, Michael},
year = {2008},
title = {Life and Action},
address = {Cambridge},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{document}
In her book \citetitle{Foot.2001} \citeyearpar{Foot.2001}
the author says this and that,
which is very similar to what Hursthouse\index[personenregister]{Husthouse, Rosalind}
says \citep[see also][1]{Thompson.2008}
In her book \citetitle{Foot.2001} \parencite*{Foot.2001}
% often \parencite* gives better results than \citeyearpar
In his book \citetitle{knuth:ct:b} \parencite*{knuth:ct:b} \citeauthor{knuth:ct:b}
In his book \citetitle{knuth:ct:c} \parencite*{knuth:ct:c} \citeauthor{knuth:ct:c}
In his book \citetitle{knuth:ct:b} \citeyearpar{knuth:ct:b} \citeauthor{knuth:ct:b}
In his book \citetitle{knuth:ct:c} \citeyearpar{knuth:ct:c} \citeauthor{knuth:ct:c}
\printbibliography
\printindex[personenregister]
\end{document}
请注意,您不必Foot.2001
再次写标题,只需使用即可\citetitle{Foot.2001}
。
同样,不必输入作品的主要名称,只需使用 即可\citeauthor
。
根据所需的确切结果,我通常\parencite*
更喜欢 而不是 之类的东西\citeyearpar
。后者实际上只是为了提供出版年份。前者可用于提供引用标签,删除作者姓名(因为作者已被提及或隐含在所写内容中)。请注意,由于natbib
兼容模式,\citep*
的行为与 不同\parencite*
(而\citep
和\parencite
始终执行相同的操作)。