3

I am writing my thesis as a collection of papers and I want to have the full bibliography at the end of the thesis. As there is several references that are used in more than one chapter, I would like to "reset" the longnamesfirst option of the natbib package at each chapter. To illustrate here is a MWE.

\documentclass[11pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}

\usepackage[round,longnamesfirst]{natbib}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @ARTICLE{ahuja2002,
        author = {Ahuja, R.K. and Ergun, {\"O}. and Orlin, J.B. and Punnen, A.P.},
        title = {A survey of very large-scale neighborhood search techniques},
        journal = {Discrete Applied Mathematics},
        year = {2002},
        volume = {123},
        pages = {75--102},
        number = {1},
        publisher = {Elsevier}
    }
\end{filecontents}


\begin{document}
    \chapter{First chapter}
        \cite{ahuja2002}\\
    \chapter{Second chapter}
        \cite{ahuja2002} $\leftarrow$ That guy should be ``longnamesfirst'' as well!
    \bibliographystyle{plainnat}
    \bibliography{\jobname} 
\end{document}

I use the memoir document class for the thesis, so the question is tagged as well.

1 Answer 1

7
+100

Here is one way of doing it. Natbib does it thing by defining a special macro the first time each key is cited. Subsequent citations check for this macro. We thus need two things: (1) to undefine these macros at the start of each chapter and (2) know a list of all the possible keys.

The later is gathered via knowing that the cited keys are in the aux file, so we overload \bibcite to also add the keys to a global list. That list is then looped through at the start of each chapter. (after the title)

\documentclass[11pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}

\usepackage[round,longnamesfirst]{natbib}

\usepackage{etoolbox}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @ARTICLE{ahuja2002,
        author = {Ahuja, R.K. and Ergun, {\"O}. and Orlin, J.B. and Punnen, A.P.},
        title = {A survey of very large-scale neighborhood search techniques},
        journal = {Discrete Applied Mathematics},
        year = {2002},
        volume = {123},
        pages = {75--102},
        number = {1},
        publisher = {Elsevier}
    }
\end{filecontents}

%\bibcite{ahuja2002}{{1}{2002}{{Ahuja et~al.}}{{Ahuja, Ergun, Orlin,
%and Punnen}}}
\let\bibitemkeylist\relax
\AtEndPreamble{
  \let\normalbibcite\bibcite
  \renewcommand\bibcite[2]{%
    \listgadd{\bibitemkeylist}{#1}
    \normalbibcite{#1}{#2}%
  }
}
\makeatletter
\newcommand\RESETHANDLER[1]{\global\cslet{bv@#1\@extra@b@citeb}\relax}
\newcommand\RESET{
  \forlistloop\RESETHANDLER\bibitemkeylist
}

\renewcommand\memendofchapterhook{\RESET}

\makeatother
\usepackage{hyperref}



\begin{document}
    \chapter{First chapter}
    First: \cite{ahuja2002}

    Second: \cite{ahuja2002}




    \chapter{Second chapter}

    First: \cite{ahuja2002}

    Second: \cite{ahuja2002}

    \bibliographystyle{plainnat}
    \bibliography{\jobname} 
\end{document}
2
  • Nice solution! It works exactly as I hoped it would!
    – Sune
    Commented Apr 4, 2016 at 13:49
  • 1
    Remember to accepted it it worked. I've tested it with hyperref and it should work with that as well
    – daleif
    Commented Apr 4, 2016 at 14:01

You must log in to answer this question.

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