Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Natbib's \citet command currently has the following output when I type \citet{maddison-cct,ridley-comparative}:

Maddison [8], Ridley [13]

Is there another command I did not found, or is there a way to redefine it so as to obtain the following instead?

Maddison [8] and Ridley [13]

(and more generally, I'd like \citet{x1,x2,...,xn} to output x1 [1], x2 [2], ..., xn-1 [n-1] and xn [n]).

share|improve this question
1  
Have you tried playing with the \bibpunct command? This will only work with the case of two citations, since it sets the separator between citations in a list. So for more than 2 it will yield x1 [1] and x2[2] and x3 [3] ... and xn [n] which is undesireable. –  Willie Wong Oct 29 '10 at 9:42
    
No, I did not know about that, and as you said it won't really help. But thanks anyway. –  Anthony Labarre Oct 29 '10 at 10:26
    
Barring better solutions, there's probably a way of hacking together a way to do it using etextools, which has nice list processing abilities (extending that of etoolbox). I can't install them on the computer I am using now; maybe I'll take a look later. –  Willie Wong Oct 29 '10 at 10:28
    
(Essentially you can use \csvloop! to extract the list length, if it is more than 1 you can extract and delete the last element from the csvlist, process the rest using \citet, add the word "and", and process the remaining item using \citet.) –  Willie Wong Oct 29 '10 at 10:30
1  
I'm sure a biblatex solution would be possible. And likely easier. –  Seamus Oct 29 '10 at 11:36

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
Thanks, it works perfectly! –  Anthony Labarre Nov 4 '10 at 10:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.