从 biblatex 中删除索引内的页码

从 biblatex 中删除索引内的页码

下面的 MWE 用于显示参考书目并从中提取名称标题索引。我想删除此索引中的页码。为此,我使用这个答案但不幸的是,它不起作用……

命令\renewcommand{\index}[1]{\OldIndex{#1|mygobble}}破坏正常行为。

% !TeX TS-encoding = utf8
% !TeX TS-spellcheck = fr_FR
% !BIB TS-program = biber
% !TeX TS-program = lualatex

\documentclass[12pt, a4paper]{memoir}

\makeatletter
\RequirePackage{csquotes}
\RequirePackage{imakeidx}
\RequirePackage{ifthen}
\usepackage[%
language=french,
backend=biber,
sorting=nyt,
backref=true,
indexing=true,
maxnames=99,
style=authoryear-icomp,
url=false,
]{biblatex}
\usepackage{letltxmacro}

\@ifpackageloaded{biblatex_legacy}
{\DeclareIndexNameFormat{name:title}{%
        \iffieldundef{title}
        {\usebibmacro{index:name}{\index[name-title]}{#1}{#3}{#5}{#7}}
        {\usebibmacro{index:name:title}{\index[name-title]}{#1}{#3}{#5}{#7}}}}
{\DeclareIndexNameFormat{name:title}{%
        \iffieldundef{title}
        {\usebibmacro{index:name}{\index[name-title]}
            {\namepartfamily}
            {\namepartgiven}
            {\namepartprefix}
            {\namepartsuffix}}
        {\usebibmacro{index:name:title}{\index[name-title]}
            {\namepartfamily}
            {\namepartgiven}
            {\namepartprefix}
            {\namepartsuffix}}}}
%
% Auxiliary indexing macros in biblatex.def can be used to define additional
% indexing directives with subentries. The following directive creates entries
% for the year-title index.
%
\DeclareIndexFieldFormat{with:year}{%
    \iffieldundef{year}
    {\usebibmacro{index:entry}{\index[year-title]}{%
            \mkbibindexentry{0}{Not dated}%
            \subentryoperator%
            \mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}
    {\usebibmacro{index:entry}{\index[year-title]}{%
            \thefield{year}\subentryoperator%
            \mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}}
%
% We redefine the 'citeindex' bibmacro to use the new indexing directives.
%
\renewbibmacro*{citeindex}{%
    \ifciteindex
    {\indexnames[name:title]{labelname}%
        \indexfield[with:year]{indextitle}}
    {}}
\renewbibmacro*{bibindex}{%
    \ifbibindex
    {\indexnames[name:title]{labelname}%
        \indexfield[with:year]{indextitle}}
    {}}
\makeatother
\begin{filecontents*}{document.bib}
    @article{Nejstgaard2008,
        title={Quantitative PCR to estimate copepod feeding},
        author={Nejstgaard, Jens C and Frischer, Marc E and Simonelli,    Paolo and Troedsson, Christofer and Brakel, Markus and Adiyaman, Filiz and Sazhin, Andrey F and Artigas, L Felipe},
        journal={Marine Biology},
        volume={153},
        pages={565--577},
        year={2008},
        publisher={Springer}
    }
    @ARTICLE{Smith1882,
        author = {John Smith},
        title = {I'm {J}ohn {S}mith},
        year = {1882}
    }
\end{filecontents*}
\begin{filecontents*}{document.ist}
    quote '+'
    delim_0 " "
    delim_1 " "
    delim_2 " "
    delim_n " "
\end{filecontents*}

\addbibresource{document.bib}
\makeindex[program=makeindex,options=-s document.ist, name=name-title, title={Index des noms et des titres}, intoc]
\makeatletter
\let\mygobble\@gobble
\LetLtxMacro\OldIndex\index
\renewcommand{\index}[1]{\OldIndex{#1|mygobble}} 
\makeatother
\begin{document}
    \nocite{*}
    \printbibliography

    \printindex[name-title]
\end{document}

答案1

您只想应用于\mygobble您的name-title索引。

\begin{filecontents*}{\jobname.bib}
    @article{Nejstgaard2008,
        title={Quantitative PCR to estimate copepod feeding},
        author={Nejstgaard, Jens C and Frischer, Marc E and Simonelli, Paolo and Troedsson, Christofer and Brakel, Markus and Adiyaman, Filiz and Sazhin, Andrey F and Artigas, L Felipe},
        journal={Marine Biology},
        volume={153},
        pages={565--577},
        year={2008},
        publisher={Springer}
    }
    @ARTICLE{Smith1882,
        author = {John Smith},
        title = {I'm {J}ohn {S}mith},
        year = {1882}
    }
\end{filecontents*}
\begin{filecontents*}{\jobname.ist}
    quote '+'
    delim_0 "\\nopagebreak "
    delim_1 " "
    delim_2 " "
    delim_n " "
    item_x1 "\n    \\nopagebreak\\subitem"
\end{filecontents*}

\documentclass[12pt, a4paper]{memoir}

\usepackage{csquotes}
\usepackage{imakeidx}
\usepackage[
  language=french,
  backend=biber,
  sorting=nyt,
  backref=true,
  indexing=true,
  maxnames=99,
  style=authoryear-icomp,
  url=false,
]{biblatex}

\makeatletter
\@ifpackageloaded{biblatex_legacy}
{\DeclareIndexNameFormat{name:title}{%
        \iffieldundef{title}
        {\usebibmacro{index:name}{\index[name-title]}{#1}{#3}{#5}{#7}}
        {\usebibmacro{index:name:title}{\index[name-title]}{#1}{#3}{#5}{#7}}}}
{\DeclareIndexNameFormat{name:title}{%
        \iffieldundef{title}
        {\usebibmacro{index:name}{\index[name-title]}
            {\namepartfamily}
            {\namepartgiven}
            {\namepartprefix}
            {\namepartsuffix}}
        {\usebibmacro{index:name:title}{\index[name-title]}
            {\namepartfamily}
            {\namepartgiven}
            {\namepartprefix}
            {\namepartsuffix}}}}
%
% Auxiliary indexing macros in biblatex.def can be used to define additional
% indexing directives with subentries. The following directive creates entries
% for the year-title index.
%
\DeclareIndexFieldFormat{with:year}{%
    \iffieldundef{year}
    {\usebibmacro{index:entry}{\index[year-title]}{%
            \mkbibindexentry{0}{Not dated}%
            \subentryoperator%
            \mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}
    {\usebibmacro{index:entry}{\index[year-title]}{%
            \thefield{year}\subentryoperator%
            \mkbibindexfield{\thefield{indexsorttitle}}{\emph{#1}}}}}
%
% We redefine the 'citeindex' bibmacro to use the new indexing directives.
%
\renewbibmacro*{citeindex}{%
    \ifciteindex
    {\indexnames[name:title]{labelname}%
        \indexfield[with:year]{indextitle}}
    {}}
\renewbibmacro*{bibindex}{%
    \ifbibindex
    {\indexnames[name:title]{labelname}%
        \indexfield[with:year]{indextitle}}
    {}}
\makeatother

\addbibresource{\jobname.bib}
\makeindex[
  program=makeindex,
  options=-s \jobname.ist,
  name=name-title,
  title={Index des noms et des titres},
  intoc
]

\makeatletter
\let\mygobble\@gobble
\makeatother

\let\OldIndex\index
\renewcommand{\index}[2][]{%
  \ifstrempty{#1}
   {\OldIndex{#2}}
   {%
    \ifstrequal{#1}{name-title}
     {\OldIndex[#1]{#2|mygobble}}
     {\OldIndex[#1]{#2}}%
   }%
}

\begin{document}
    \nocite{*}
    \printbibliography

    \printindex[name-title]
\end{document}

我还添加了\nopagebreak以避免分离名称和标题。

enter image description here

相关内容