抑制根据关键字对标题进行索引

抑制根据关键字对标题进行索引

后续问题这个。我现在想将我的主要书目中的作者和书名添加到索引中,这是可行的,但对于次要书目,我只想索引作者(编辑、翻译),而不是他们的书名。

\documentclass{memoir}
\usepackage{csquotes}
\makeindex
\usepackage{xpatch}
\usepackage[indexing=true,authordate,backend=biber,language=auto,autolang=other]{biblatex-chicago}
\usepackage{filecontents}

\renewbibmacro*{bibindex}{%
  \ifbibindex
    {\indexnames{author}%
     \indexnames{editor}%
     \indexnames{translator}%
     \indexnames{commentator}%
     \ifkeyword{pri}{\indexfield{indextitle}}{}
    }
    {}}


\renewbibmacro*{citeindex}{%
  \ifciteindex
    {\indexnames{author}%
     \indexnames{editor}%
     \indexnames{translator}%
     \indexnames{commentator}%
     \ifkeyword{pri}{\indexfield{indextitle}}{}
    }
    {}}

\begin{filecontents}{pri.bib}
@misc{Kuṭṭanīmata,
  entrysubtype = {classical},
  author = {Dāmodaragupta},
  title = {Kuṭṭanīmata},
  related = {DezsoGoodall2012},
  relatedoptions = {dataonly,useeditor=false,usetranslator=false}
}
\end{filecontents}
\begin{filecontents}{sec.bib}
@book{DezsoGoodall2012,
  title = {Dāmodaraguptaviracitaṃ Kuṭṭanīmatam},
  subtitle = {The Bawd’s Counsel, Being an Eighth-century Verse Novel in Sanskrit by Dāmodaragupta, Newly Edited and Translated into English},
  editor = {Csaba Dezső and Dominic Goodall},
  translator = {Csaba Dezső and Dominic Goodall},
  series =  {Groningen Oriental Studies},
  number = {23},
  location = {Groningen},
  publisher = {Egbert Forsten},
  year = {2012}
}
\end{filecontents}
\addbibresource{pri.bib}
\addbibresource{sec.bib}
\DeclareSourcemap{
  \maps{
    \map{
      \perdatasource{pri.bib}
      \step[fieldset=keywords, fieldvalue=pri]
      \step[fieldsource=title, final]
      \step[fieldset=sortkey, origfieldval]
    }
  }
}
\DeclareFieldFormat[misc]{title}{\mkbibemph{#1}\isdot}
\newbibmacro*{pri:titleofauthor}{%
  \ifentrytype{misc}
    {\iffieldequalstr{entrysubtype}{classical}
       {\ifbibliography
         {\printfield{title}%
          \ifnameundef{author}
            {}
            {\setunit*{\addspace}%
             \bibstring{of}%
             \setunit*{\addspace}%
             \printnames{author}%
             \clearname{author}}%
          \clearfield{title}}
         {\printtext[bibhyperref]{\printfield[citetitle]{title}}%
          \ifnameundef{labelname}
            {}
            {\setunit*{\addspace}%
             \bibstring{of}%
             \setunit*{\addspace}%
             \printnames{labelname}}%
          \clearfield{labeltitle}%
          \clearname{labelname}}}
       {}}
    {}}
\xpretobibmacro{cite}
  {\usebibmacro{pri:titleofauthor}}
  {}
  {}
\xpatchbibdriver{misc}
  {\usebibmacro{bibindex}}
  {\usebibmacro{bibindex}\usebibmacro{pri:titleofauthor}}
  {}
  {}
\begin{document}
Filler text \autocite{Kuṭṭanīmata}.

Filler text \autocite{DezsoGoodall2012}.

\printbibliography[title=Primary Sources, keyword=pri,heading=subbibliography]
\printbibliography[title=Secondary Sources, notkeyword=pri,heading=subbibliography]
\printindex
\end{document}

编辑:在示例中添加了bibindex和的重新定义,无条件地抑制标题的索引。我猜在这两种情况下(或者它们也可以连接?)都需要在 to-be-commented-back-in 之前添加一个条件。citeindex\indexfield{indextitle}

编辑:该命令\ifkeyword{}{}{}似乎正在执行所需的测试。但我仍然想知道是否真的有必要对bibindex和有相同的定义citeindex,或者是否有更好的方法来做到这一点。

答案1

你走在正确的道路上

\renewbibmacro*{bibindex}{%
  \ifbibindex
    {\indexnames{author}%
     \indexnames{editor}%
     \indexnames{translator}%
     \indexnames{commentator}%
     \ifkeyword{pri}{\indexfield{indextitle}}{}}
    {}}

\renewbibmacro*{citeindex}{%
  \ifciteindex
    {\indexnames{author}%
     \indexnames{editor}%
     \indexnames{translator}%
     \indexnames{commentator}%
     \ifkeyword{pri}{\indexfield{indextitle}}{}}
    {}}

应该做正确的事情。请注意我如何将条件语句中第一个分支的右括号向上移}一行以避免出现不必要的空格(参见行末百分号(%)有什么用?)。

是的,如果您同时为引文和参考书目启用了索引功能,则需要为bibindex和 分别定义一个(这样做)。理论上,您可以使用第三个辅助宏将两者连接起来citeindexindexing=true

\newbibmacro*{bothindex}{%
  \indexnames{author}%
  \indexnames{editor}%
  \indexnames{translator}%
  \indexnames{commentator}%
  \ifkeyword{pri}{\indexfield{indextitle}}{}}

\renewbibmacro*{bibindex}{%
  \ifbibindex
    {\usebibmacro{bothindex}}
    {}}

\renewbibmacro*{citeindex}{%
  \ifciteindex
    {\usebibmacro{bothindex}}
    {}}

我会让你决定这是否更好。

从某种角度来看,biblatex为引文和参考书目提供两个独立的宏是有意义的,因为在这两种情况下索引的内容会有所不同,这并非不可想象。(我个人不会索引引文中实际上在引文标签中不可见的名称。所以我的citeindex只会索引labelname而不是、authoreditor。)translatorcommentator

相关内容