0

I'm trying to recreate the \cite behaviour for multiple authors using a custom citing format. Essentially I want to have the author's name in black text, while the year is a colored hyperlink. Would anyone know how to accomplish this?

My current attempt is to recursively build the citation by feeding in the last author (#1 in addcite) and the remaining list of works to be cited (#2,#3). The first work to be cited is popped off from the remaining list (\citeauthor{#2}) and compared to the reported last author (#1), then the behavior is decided based on if it is the same author or not. However, I cannot get the comparison to work (I think it has to do with the comparison not comparing the literal text, but maybe differing because they have different hyperrefs, being the same author but different works). And for some reason the first work is always lost (but works fine when given a single citation).

\newcommand{\mycite}[1]{(\addcite(,#1,))}

\def\addcite(#1,#2,#3){%
\def\temp{\citeauthor{#2}}%
\ifx\temp#1%
\citeyear{#2}%
\else{\hypersetup{citecolor=black}\citeauthor{#2}}~\citeyear{#2}%
\fi%
\def\tempA{\citeauthor{#2}}%
\ifx\relax#3%
\relax%
\else; \addcite(\tempA,#3)%
\fi
}

Ideal working solution would take

\mycite{AuthorA_Year1,AuthorA_Year2,AuthorB_Year1,AuthorB_Year3}

and return (punctuation not important):

AuthorA (Year1; Year2); AuthorB (Year1; Year3)

Where AuthorA and AuthorB are in black, and the years are in whatever the citecolor is defined as from hyperref.

  • " I want to have the author's name in black text, while the year is a colored hyperlink" Reinventing the wheel? This is exactly what you obtain by default with the authoryear style in biblatex plus hyperref with the colorlinks option, and as a gift, the year will be a also a link to the reference. See the last example form here but in the second line add \usepackage[colorlinks]{hyperref} – Fran Jun 26 at 15:13
  • I wasn't aware the wheel already existed, as I am using natbib. Thanks for the reference, though currently biblatex is not playing nicely with backref, but I will look into that and see if I can get the configuration I am after. – Novice C Jun 27 at 0:52
  • biblatex do not need backref to have back references – Fran Jun 27 at 1:04
  • Biblatex do not need backref to have back references! Anway, natbib also can use hyperref to link the cite, although including also the author part in the link, that I think that is better than link only the year, but If you are picky about this, see here. – Fran Jun 27 at 1:29

Your Answer

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

Browse other questions tagged or ask your own question.