9

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?

4
  • 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
7

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}

\newcommand*{\nameadjunct}{\relax}
\makeatletter
\renewcommand*{\NAT@nmfmt}[1]{\NAT@up #1\nameadjunct}
\makeatother

\newcommand*{\citeposs}[2][]{%
  \begingroup
  \renewcommand*{\nameadjunct}{'s}%
  \citet[#1]{#2}%
  \endgroup
}

\newcommand*{\citesep}[3][]{%
  \begingroup
  \renewcommand*{\nameadjunct}{#3}%
  \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}
3

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}
\newbibmacro*{textadjunctcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
    {\multicitedelim}
    {\cbx@tempa
     \ifnameundef{labelname}
       {\printfield[citetitle]{labeltitle}}
%       {\printnames{labelname}}% DELETED
       {\printnames{labelname}% NEW
       \printfield{adjunct}}% NEW
     \addspace\bibopenbracket}%
  \ifnumequal{\value{citecount}}{1}
    {\usebibmacro{prenote}}
    {}%
  \usebibmacro{cite}%
  \savefield{namehash}{\cbx@lasthash}%
  \gdef\cbx@tempa{\bibclosebracket\multicitedelim}}

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

\newcommand*{\citeposs}[2][]{%
  \def\abx@field@adjunct{'s}%
  \textadjunctcite[#1]{#2}%
}

\newcommand*{\citesep}[3][]{%
  \def\abx@field@adjunct{#3}%
  \textadjunctcite[#1]{#2}%
}

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.
https://tex.stackexchange.com/questions/3781/natbib-merging-authors-with-the-same-names/6636
tex.stackexchange.com
crawl=CC-MAIN-2021-10
171603
application/http; msgtype=response
sha1:2AQHZMJHRB2T3ELEPTGTVUZ5JKZDTO7E
<urn:uuid:4938c188-46fb-4ed7-b60e-f493575920be>
2021-03-06T08:09:38Z
151.101.1.69
text/html
sha1:LUKY2TDI2OMUWAKFD2FDLQZ3IBNYYPQO
<urn:uuid:d978da28-0316-4b32-b79a-186fd7950725>
https://tex.stackexchange.com/questions/3781/natbib-merging-authors-with-the-same-names/6636
response
<urn:uuid:9c8e0fec-f099-4259-b79e-3e7c8eec9bb2>
isPartOf: CC-MAIN-2021-10
publisher: Common Crawl
description: Wide crawl of the web for February/March 2021
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-67-67-191.ec2.internal
software: Apache Nutch 1.18 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.2-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/