依作者和年份自動索引參考文獻

依作者和年份自動索引參考文獻

我正在寫一篇文獻綜述,並且想添加作者和出版年份的索引(即兩個分離指數)。現在,我可以手動輸入適當的\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

這個答案已經根據奧黛麗的敏銳評論進行了更新。

是的。有多種方法可以做到這一點。

下面的程式碼是我最初建議的修訂版,(我希望)能糾正其一般使用中的各種缺陷。具體來說:

  • 我原來的程式碼並沒有很好地處理空虛的歲月:這確實如此。

  • 我的原始程式碼「hardwired」multind的語法和您選擇的索引名稱:在此版本中,索引名稱位於巨集中,這表示它們可以更改。

  • 我的原始程式碼沒有使用indexsorttitleindextitle字段:這確實如此,因為它應該。

  • 我的原始程式碼可能會導致某些巨集出現問題(例如\TeX在索引標題中使用,正如奧黛麗正確指出的那樣)。

在你給出的例子中,這些都沒有改變任何東西——但我添加了兩個另外的範例條目,原始版本會錯誤或愚蠢地處理這些條目,而這個可以直接處理。

奇怪的是,\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

相關內容