Natbib: How to replace the last comma in a \citet-based citation list with "and"?

This sounded like a challenge, and I like challenges. This is what I came up with

% #1 {, } - #2 { and } - #3 \cmd - #4 list
\makeatletter
\newcommand\textlist[4]{%
  \let\last@item\relax
  \let\last@sep\relax
  \@for\@ii:=#4\do{%
    \ifx\last@item\relax\else
      \ifx\last@sep\relax
        \def\last@sep{#2}%
      \else#1\fi
      #3{\last@item}%
    \fi
    \let\last@item\@ii
  }%
  \ifx\last@item\relax\else
    \last@sep#3{\last@item}%
  \fi
}
\makeatother

\newcommand{\citett}{\textlist{, }{ and }{\citet}}

This defines a \textlist which basically applies a given command to a list of arguments, and using one of the two given separators as appropriate. Then you can write

\citett{paper1,paper2,paper3}

And produce something as if you had typed

\citet{paper1}, \citet{paper2} and \citet{paper3}

I encourage others to comment on possible improvements to my defined commands, and also suggest alternative definitions using other tool-boxes, TeX-flavors, etc.

Tags:

Natbib

Citing