2

The MWE below, is made to display a bibliography and to extract a name-title index from it. I'd like to remove the page number within this index. To do so I use this answer but unfortunately it doesn't work…

Command \renewcommand{\index}[1]{\OldIndex{#1|mygobble}} breaks normal behaviour.

% !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 Answer 1

1

You want to apply \mygobble only to your name-title index.

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

I also added \nopagebreak to avoid separating the name and the title.

enter image description here

1
  • I thought the \renewcommand\index was faulty, but I had no clue how to solve this. Many thanks!
    – NBur
    Commented Jul 27, 2018 at 13:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .