# Natbib: merging author(s) with the same name(s)

I defined the following command in my manuscript:

\newcommand{\citesep}[2]{\citeauthor{#1}#2~\cite{#1}}


which allows me to print, for instance, "Knuth and Tarjan's algorithm [16]" using \citesep{knuth-681}{'s algorithm}.

However, this causes an unwanted behaviour with papers with the same authors; for example, \citesep{knuth-681,knuth-702}{'s work} produces "Knuth and Tarjan, Knuth and Tarjan's work [16,17]" whereas I'd like it to print "Knuth and Tarjan's work [16,17]".

Any idea how to fix that?

-
You could always just write out the names once and then \cite the papers normally after that. Otherwise, biblatex might have the resources to deal with this problem. [Are you sure the authors' names are exactly the same in the two fields? If one is "D. Knuth" and the other is "Donald Knuth", that will cause them to be treated as different... –  Seamus Oct 5 '10 at 11:41
Yes, author names are exactly the same. \citet does compress them appropriately, I guess a solution could therefore be obtained by modifying it so as to remove reference numbers, but I've had a look at natbib.sty and I don't really see how to do that. –  Anthony Labarre Oct 5 '10 at 13:44
Can you try IEEE bibtex styles? I'm pretty sure they do that. –  Dima Oct 13 '10 at 6:10
Oddly enough, neither ieeetr.bst nor ieeepes.bst prints any names using my \citesep command. –  Anthony Labarre Oct 13 '10 at 7:14

I finally came up with what seems like a solution. I did the following:

• Dig into natbib.sty in search for the macro segment that is responsible for typesetting the author's name(s). Trial and error revealed that \NAT@nm does the "raw" typesetting and in turn is formatted by \NAT@nmfmt.

• Redefine \NAT@nmfmt so that it will additionally typeset the expansion of the new \nameadjunct command (which does nothing by default).

• Define the new commands \citeposs and \citesep which are wrappers for \citet but will locally redefine \nameadjunct to "'s" respectively \citesep's second mandatory argument.

\documentclass{article}

\usepackage{natbib}

\makeatletter
\makeatother

\newcommand*{\citeposs}[2][]{%
\begingroup
\citet[#1]{#2}%
\endgroup
}

\newcommand*{\citesep}[3][]{%
\begingroup
\citet[#1]{#2}%
\endgroup
}

\begin{filecontents}{\jobname.bib}
@misc{Knu01,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2001},
title = {A new algorithm},
}
@misc{Knu02,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2002},
title = {More about our algorithm},
}\end{filecontents}

\begin{document}

\citet{Knu01,Knu02}

\citeposs{Knu01,Knu02}

\citesep{Knu01,Knu02}{'s algorithm}

\bibliographystyle{plainnat}
\bibliography{\jobname}

\end{document}

-

I don't comprehend natbib's intricacies, but here's a solution using biblatex. (Note: My \citesep command works well for simultaneously citing several papers with the same author(s), but will yield strange results for different authors.)

\documentclass{article}

\usepackage{biblatex}

\makeatletter

% COPIED FROM \newbibmacro*{textcite}
\iffieldequals{namehash}{\cbx@lasthash}
{\multicitedelim}
{\cbx@tempa
\ifnameundef{labelname}
{\printfield[citetitle]{labeltitle}}
%       {\printnames{labelname}}% DELETED
{\printnames{labelname}% NEW
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite}%
\savefield{namehash}{\cbx@lasthash}%
\gdef\cbx@tempa{\bibclosebracket\multicitedelim}}

% COPIED FROM \DeclareCiteCommand{\textcite}
{\let\cbx@tempa=\empty
\undef\cbx@lasthash}
{\usebibmacro{citeindex}%
%   \usebibmacro{textcite}}% DELETED
{}
{\usebibmacro{postnote}%
\bibclosebracket}

\newcommand*{\citeposs}[2][]{%
}

\newcommand*{\citesep}[3][]{%
}

\makeatother

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{Knu01,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2001},
title = {A new algorithm},
}

@misc{Knu02,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2002},
title = {More about our algorithm},
}
\end{filecontents}

\bibliography{\jobname}

\begin{document}

This was \citeposs{Knu01,Knu02} work~\dots

As shown in \citesep{Knu01,Knu02}{'s algorithm}~\dots

\printbibliography

\end{document}


EDIT: Extended MWE to include a \citeposs command.

-
Just for the reader's reference, there is a similar post devoted to biblatex: tex.stackexchange.com/q/22273 –  Audrey Jul 28 '13 at 2:47