我正在写一篇文献综述,想添加作者和出版年份的索引(即两个分离索引)。现在,我可以手动输入相应的\index{}
命令,但这似乎是 biblatex 可以自动处理的事情。这肯定会使维护变得容易得多,这是一个重要的考虑因素,因为我打算在未来几年随着研究的进展,保持评论的更新。
我一直在使用 biblatex 内置的索引选项,但不知道如何使用多个索引(甚至按年份单独索引)。同样,我一直在研究以下问题这个关于编写自定义\cite
命令,但我也在努力了解它们的工作原理。
手动索引的最小工作示例(使用 biblatex 和 multind)显示了我想要的最终结果:
\documentclass{report}
\usepackage{filecontents}
\begin{filecontents*}{testing.bib}
@article{Author2010,
author="Author, A and Writer, B",
journal="Slackers Monthly",
title="An overly long treatise on procrastination",
year=2010,
month=jun,
}
@article{Writer2011,
author="Writer, B and Scribe, C",
journal="Fake Online Journal",
title="Waste of time or time of waste: procrastination in a modern society",
year=2011,
month=oct,
}
@book{Writer2003,
author="Writer, B",
title="Procrastination for dummies",
year=2003,
publisher="Procrastination House",
address="Auckland",
}
\end{filecontents*}
\usepackage[style=authoryear]{biblatex}
\addbibresource{testing}
\usepackage{multind}
\makeindex{authors}
\makeindex{years}
\begin{document}
\chapter{Introductory works}
\section{An overly long treatise on procrastination}
\fullcite{Author2010}
\index{authors}{Author, A!An overly long treatise on procrastination (2010)}
\index{authors}{Writer, B!An overly long treatise on procrastination (2010)}
\index{years}{2010!An overly long treatise on procrastination}
This paper was really useful in telling me how to waste more time rather
than doing real work.
\section{Waste of time or time of waste: procrastination in a modern society}
\fullcite{Writer2011}
\index{authors}{Writer, B!Waste of time or time of waste: procrastination in a modern society (2011)}
\index{authors}{Scribe, C!Waste of time or time of waste: procrastination in a modern society (2011)}
\index{years}{2011!Waste of time or time of waste: procrastination in a modern society}
Applies post-modern philosophical theory to procrastination.
\section{Procrastination for dummies}
\fullcite{Writer2003}
\index{authors}{Writer, B!Procrastination for dummies (2003)}
\index{years}{2003!Procrastination for dummies}
A classic reference book for anybody starting a research position.
\printbibliography
\printindex{authors}{Author index}
\printindex{years}{Year index}
\end{document}
以及一个用于编译它的 Makefile:
default:
xelatex mwe
bibtex mwe
xelatex mwe
xindy -M texindy -M page-ranges -L english -C utf8 authors.idx
xindy -M texindy -M page-ranges -L english -C utf8 years.idx
xelatex mwe
那么,是否可以使用自定义 cite 命令(或内置命令)来实现这一点?或者我最好编写一个脚本来解析 BibTeX/biber 输出以生成 xindy 的输入?
答案1
这个答案已经根据奥黛丽的敏锐评论进行了更新。
是的。有很多方法可以做到这一点。
下面的代码是我最初建议的修订版,(我希望)它能纠正其一般使用中的各种缺陷。具体来说:
我原来的代码不能很好地处理空白年份:但是这个可以。
我的原始代码“硬连线”
multind
的语法和您选择的索引名称:在此版本中,索引名称在宏中,这意味着它们可以更改。我的原始代码没有使用
indexsorttitle
和indextitle
字段:这个代码使用了,正如它应该的那样。我的原始代码可能会导致某些宏出现问题(例如,
\TeX
在 indextitles 中使用,正如 Audrey 正确指出的那样。我希望这可以正确处理这些问题。
对于您给出的例子,这些都没有改变任何东西——但我添加了另外两个示例条目,原始版本会错误或愚蠢地处理这些条目,而这个可以直接处理。
奇怪的是,\fullcite
似乎没有调用索引宏,这就是我使用它的原因\cite
;我敢说对此有一个解释,但我没有时间去深入研究它。
\documentclass{report}
\usepackage{filecontents}
\begin{filecontents*}{testing.bib}
@article{Author2010,
author="Author, A and Writer, B",
journal="Slackers Monthly",
title="An overly long treatise on procrastination",
year=2010,
month=jun,
}
@article{Writer2011,
author="Writer, B and Scribe, C",
journal="Fake Online Journal",
title="Waste of time or time of waste: procrastination in a modern society",
year=2011,
month=oct,
}
@book{Writer2003,
author="Writer, B",
title="Procrastination for dummies",
year=2003,
publisher="Procrastination House",
address="Auckland",
}
@book{knuth:ct:b,
hyphenation = {american},
sortyear = {1986-1},
sorttitle = {Computers & Typesetting B},
indexsorttitle = {TeX: The Program},
author = {Knuth, Donald E.},
title = {\TeX: The Program},
shorttitle = {\TeX},
maintitle = {Computers \& Typesetting},
volume = {B},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
date = {1986},
annotation = {The second volume of a five-volume book. Note the
\texttt{sorttitle} and \texttt{sortyear} fields. Also note the
\texttt{indexsorttitle} field}
}
@book{yearless,
author = {Lazy B. Ugger},
title = {I Can't Be Bothered with Years},
publisher = {Equally Lazee},
}
\end{filecontents*}
\usepackage[style=authoryear,indexing=cite]{biblatex}
\addbibresource{testing.bib}
\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
% redefine this if the index for years is differently named, or if using
% index or imakeidx
\newcommand{\yearsindex}{{years}}
% redefine this if the index for authors is differently named, or if
% using index or imakeidx
\newcommand{\authorsindex}{{authors}}
% undated entries
\newcommand{\undated}{n.d.}
\usepackage{multind}
\makeindex{authors}
\makeindex{years}
\begin{document}
\chapter{Introductory works}
\section{An overly long treatise on procrastination}
\fullcite{Author2010}
This paper was really useful in telling me how to waste more time rather
than doing real work.
\section{Waste of time or time of waste: procrastination in a modern society}
\cite{Writer2011}
Applies post-modern philosophical theory to procrastination.
\section{Procrastination for dummies}
\cite{Writer2003}
A classic reference book for anybody starting a research position.
\section{The Awkward Squad}
\cite{knuth:ct:b}
An author who uses a title that indexing programs find hard to cope
with, but certainly no procrastinator.
\cite{yearless}
An author so lazy that he cannot be bothered to put a year of publication.
\printbibliography
\printindex{authors}{Author index}
\printindex{years}{Year index}
\end{document}
(如果需要,您可以诱导 biblatex 进行非常复杂的索引:我刚刚完成了一个样式的第一个版本,它可以生成许多索引(超过 33 个!),并且该索引不仅基于标题字段,还使用后记来设置子项。设置起来并不令人兴奋,但就 biblatex 而言绝对是可行的。)
答案2
感谢 Maieul 的功能请求和 Paul 的反馈,2.3 版引入了许多辅助命令和宏biblatex
来帮助索引,尤其是使用子条目运算符 进行索引!
。文档 ( 22-indexing-subentry.tex
) 中的示例 22 演示了使用该包进行带有子条目的多个索引imakeidx
。以下是使用 的类似示例multind
。
\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[indexing=cite,style=authoryear,backend=bibtex]{biblatex}
% Define indices
\usepackage{multind}
\makeindex{authors}
\makeindex{years}
% Name indexing directive for names with title subentries
\DeclareIndexNameFormat{name:title}{%
\iffieldundef{title}
{\usebibmacro{index:name}{\index{authors}}{#1}{#3}{#5}{#7}}
{\usebibmacro{index:name:title:year}{\index{authors}}{#1}{#3}{#5}{#7}}}
% Based on index:name:title macro defined in biblatex.def, takes the arguments:
% {<index command>}{<last name>}{<first name>}{<first initials>}{<last name prefix>}
% The index:name:subentry macro (also defined in biblatex.def) takes two more:
% {<plain entry>}{<formatted entry>}
% and forms the subentry: !<plain entry>@<formatted entry>
\newbibmacro*{index:name:title:year}[5]{%
\iffieldundef{year}
{\usebibmacro{index:name:title}{#1}{#2}{#3}{#4}{#5}}
{\usebibmacro{index:name:subentry}{#1}{#2}{#3}{#4}{#5}
{\thefield{indexsorttitle}}
{\emph{\csfield{indextitle}}~(\thefield{labelyear})}}}
% Title indexing directive for years with title subentries
\DeclareIndexFieldFormat{year:title}{%
\iffieldundef{year}
{\usebibmacro{index:entry}{\index{years}}{%
\mkbibindexentry{0}{Not dated}%
\subentryoperator%
\mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}
{\usebibmacro{index:entry}{\index{years}}{%
\thefield{year}\subentryoperator%
\mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}}
\renewbibmacro*{citeindex}{%
\ifciteindex
{\indexnames[name:title]{author}%
\indexfield[year:title]{indextitle}}
{}}
% Index entries accessed via \fullcite
\DeclareCiteCommand{\fullcite}
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usedriver
{\DeclareNameAlias{sortname}{default}}
{\thefield{entrytype}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\addbibresource{biblatex-examples.bib}
\begin{document}
\fullcite{knuth:ct,knuth:ct:a,knuth:ct:c,knuth:ct:d}
\cite{aristotle:anima,aristotle:poetics,aristotle:physics,aristotle:rhetoric}
\printbibliography
\raggedright
\printindex{authors}{Author and Title Index}
\printindex{years}{Year and Title Index}
\end{document}
答案3
我使用脚本 python 来解决类似的问题http://geekographie.maieul.net/Un-index-des-sources-primaires-3。
我刚刚开了一张票来询问索引多个字段的可能性。https://github.com/plk/biblatex/issues/31