5

I’m using natbib with the author-year style. For the reference list, I'd like to add the same labels as those I obtain with \citep in the text, i.e. [author, year]. I redefined \biblabel, but I can only get the reference number, i.e. [1]:

\documentclass{article}
\RequirePackage{natbib}
\makeatletter 
\renewcommand\NAT@biblabel[1]{[#1]} 
\makeatother
\begin{document}

Text \citep{ref}

\bibliographystyle{plainnat}
\bibliography{References}

\end{document}

How can I get author and year instead?

2 Answers 2

4

The author of the natbib package, Patrick Daly, kindly provided a solution that worked very well for me (but might require testing/modifications for other situations).

In order to use the redefinition of \NAT@biblabel that I have tried, \@lbibitem needs to be changed. The following definitions of \@lbibitem and \NAT@biblabel can be put in a separate file, called natbib.cfg. This will be loaded by natbib as the very last thing if it is present. Alternatively, it can be included in the LaTeX document preamble (with \makeatletter\makeatother).

\def\@lbibitem[#1]#2{%
  \if\relax\@extra@b@citeb\relax\else
    \@ifundefined{br@#2\@extra@b@citeb}{}{%
     \@namedef{br@#2}{\@nameuse{br@#2\@extra@b@citeb}}%
    }%
  \fi
  \@ifundefined{b@#2\@extra@b@citeb}{%
   \def\NAT@num{}%
  }{%
   \NAT@parse{#2}%
  }%
  \def\NAT@tmp{#1}%
  \expandafter\let\expandafter\bibitemOpen\csname NAT@b@open@#2\endcsname
  \expandafter\let\expandafter\bibitemShut\csname NAT@b@shut@#2\endcsname
  \@ifnum{\NAT@merge>\@ne}{%
   \NAT@bibitem@first@sw{%
    \@firstoftwo
   }{%
    \@ifundefined{NAT@b*@#2}{%
     \@firstoftwo
    }{%
     \expandafter\def\expandafter\NAT@num\expandafter{\the\c@NAT@ctr}%
     \@secondoftwo
    }%
   }%
  }{%
   \@firstoftwo
  }%
  {%
   \global\advance\c@NAT@ctr\@ne
   \@ifx{\NAT@tmp\@empty}{\@firstoftwo}{%
    \@secondoftwo
   }%
   {%
    \expandafter\def\expandafter\NAT@num\expandafter{\the\c@NAT@ctr}%
    \global\NAT@stdbsttrue
   }{}%
   \bibitem@fin
%   \item[\hfil\NAT@anchor{#2}{\NAT@num}]%
   \item[\hfil\NAT@anchor{#2}{\citealp{#2}}]% <<<<<< Changed here
   \global\let\NAT@bibitem@first@sw\@secondoftwo
   \NAT@bibitem@init
  }%
  {%
   \NAT@anchor{#2}{}%
   \NAT@bibitem@cont
   \bibitem@fin
  }%
  \@ifx{\NAT@tmp\@empty}{%
    \NAT@wrout{\the\c@NAT@ctr}{}{}{}{#2}%
  }{%
    \expandafter\NAT@ifcmd\NAT@tmp(@)(@)\@nil{#2}%
  }%
}%

\renewcommand\NAT@biblabel[1]{[#1]}
0

To support backref I had to fiddle things. There's gotta be a way to do this so it works if you're not using backref (but I'm too tired to look it up now). But if anyone uses this with backref, you can prevent it including references to the label in the bibitem with this:

\item[\hfil\NAT@anchor{#2}{\backrefsetup{disable}\citealp{#2}\backrefsetup{enable}}]% <<<<<< Changed here

You must log in to answer this question.

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