0

Follow up question to this one. I would now like to add authors and titles in my primary bibliography to the index, which works, but for the secondary bibliography I would like to index only the authors (editors, translators), not the titles of their books.

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

EDIT: Added redefinitions of bibindex and citeindex to the example, which unconditionally suppress the indexing of titles. I guess in both cases (or maybe they could also be joined?) one would need to add a condition before the to-be-commented-back-in \indexfield{indextitle}.

EDIT: The command \ifkeyword{}{}{} seems to be doing the required test. Still I am wondering if it is really necessary to have identical definitions of bibindex and citeindex, or if there's a better way of doing this.

muk.li
  • 3,620

1 Answers1

1

You are on the right track

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

should do the right thing. Note how I moved to closing brace } of the first branch in the conditionals up one line to avoid an unwanted space (see What is the use of percent signs (%) at the end of lines?).

Yes, you need to have one definition for bibindex and one for citeindex if you have indexing turned on for both citations and bibliography (indexing=true does that). In theory you could join the two by use of a third, auxiliary macro

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

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

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

I'll let you decide whether or not that is better.

From a biblatex perspective it makes sense to offer two independent macros for citations and the bibliography since it is not inconceivable at all that the contents indexed in the two cases will differ. (I for one would not index names in citations that are not actually visible in the citation label. So my citeindex would only index labelname and not author, editor, translator and commentator.)

moewe
  • 175,683