65

I am using biblatex with the authoryear styles.

So far I've been able to find everything I need easily in the excellent documentation, but I'm stuck on one thing.

With my current settings (below) citations only have the year hyperlinked to the bibliography entry. I think prior to using biblatex I would have the whole citation (authors + year) as a reference - I think this is easier to click etc. when browsing.

Is there an easy way to get this (or does it involve creating a new style).

\usepackage[style=authoryear,
            bibstyle=authoryear,
            citestyle=authoryear,
            natbib=true,
            hyperref=true,
            backref=true,
            abbreviate=true]{biblatex}
robince
  • 2,836
  • 1
    style=authoryear, bibstyle=authoryear, citestyle=authoryear, is equivalent to the much shorter style=authoryear,. – moewe May 27 '20 at 06:29

3 Answers3

41

Add the following to you preamble:

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\usebibmacro{citeyear}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
  \printtext[bibhyperref]{ \usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{textcite}}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}%
   \multicitedelim}
  {\usebibmacro{textcite:postnote}}

Note that this code snipped is basically taken from here and adapted to biblatex v0.9b, i.e. the definitions for \footcitetext and \textcite are added resp. changed. (I also decided not to add hyperlinks for \citeauthor and \citeyear.)

lockstep
  • 250,273
  • 7
    One thing I noticed with this is that for in text citations the closing bracket is not part of the hyperlink (although the rest of the text is) - so this looks a bit messy. Is there any way around that? – robince Jan 09 '11 at 19:38
  • 2
    @thrope Another user has requested a similar feature here. – Audrey Aug 31 '11 at 17:27
  • @robince Check out this answer. – Luke Davis Feb 20 '18 at 21:40
  • It should be noted that \printtext[bibhyperref] in these places has the potential to confuse biblatex's punctuation tracker. The solution is therefore not suitable for styles that make heavy use of the punctuation tracker (such as ...-comp styles). The approach (probably) works fine with style=authoryear, from the question, but is problematic for style=authoryear-comp,. (Note that since the \cite... command are defined slightly differently in the -comp styles, one should not copy the definitions directly anyway for those styles.) – moewe May 27 '20 at 06:29
  • This seems to break when making citations inside captions. – thesofakillers Dec 22 '22 at 14:53
  • This also breaks the display of only the SHORTAUTHOR in a \cite. Instead, both the AUTHOR and the SHORTAUTHOR are shown – devbf Jan 19 '24 at 08:05
8

As an addition to the answer provided by lockstep, the following code for \textcite includes the closing parenthesis in the link too, and, unfortunately, the space afterwards.

\DeclareCiteCommand{\textcite}
 {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
    \printtext[bibhyperref]{\printnames{labelname}%
      \printtext{ (\printfield{year}\printtext{)}}}}
 {\ifbool{cbx:parens}
  {\bibcloseparen\global\boolfalse{cbx:parens}}
  {}%
 \multicitedelim}
{\usebibmacro{textcite:postnote}}
Corentin
  • 9,981
maetra
  • 4,540
  • 2
    This appears to give the desired output only for \textcite{<entrykey>}, but doesn't handle notes properly. prenote gets ignored entirely. postnote is enclosed in a second set of parentheses. For example \textcite[postnote]{key} gives labelname (labelyear) (postnote), not labelname (labelyear, postnote). – Audrey Sep 01 '11 at 00:06
  • @Audrey Is there a workaround to the issue you are highlighting? – pluton Aug 20 '20 at 13:16
8

The biblatex style apa (which is a modified authoryear style) does this for you. For example:

\usepackage[american]{babel}
\usepackage[style=apa]{biblatex}
\DeclareLanguageMapping{american}{american-apa}

Note it is also recommended that you load the csquotes package.

It needs a relatively up to date version of biblatex to work.

Seamus
  • 73,242
  • 3
    I updated to MacTex / TexLive 2010 to try this but the apa style appears to be broken - my document wont compile with "Undefined control sequence. \mkbibdateapalongextra {year}{month}{day}" - same problem as here: http://www.developpez.net/forums/d984595/autres-langages/autres-langages/latex/bibtex/biblatex-style-apa/ – robince Jan 09 '11 at 19:39
  • 2
    Have you included the \DeclareLanguageMapping line? it is necessary... – Seamus Jan 09 '11 at 20:58
  • 2
    @thrope and, of course, got the right babel settings? This sounds like a localisation issue. – Seamus Jan 09 '11 at 21:04
  • 4
    I'm using babel with [english] so I put the mapping as {english}{english-apa}... I had another go being more careful to delete all the intermediate files and it seemed to compile successfully (using bibstyle=authoryear, citestyle=apa) - but it doesn't link the names... only the years of the citation are linked. – robince Jan 11 '11 at 10:22
  • @thrope What kind of citation command are you using (\textcite \parencite etc?) and what version of biblatex and biblatex-apa do you have? \textcite{key} should have both as a link. If you add postnotes, prenotes or things like that \textcite[postnote]{key} then only the year gets linked. – Seamus Jan 11 '11 at 11:20
  • 3
    @Seamus I am using \parencite with loaded option style=apa. Is there any recent solution to hyperlink both author and year? – Diaa Dec 07 '16 at 14:02
  • 1
    This does not work for me using TexLive 2019. Only year in linked. – MaxPowers Jan 14 '20 at 11:50
  • 1
    This doesn't work for me in Overleag, even the year won't get linked – Bersan Dec 20 '20 at 13:52
  • 1
    Doesn't work for me as well in Texmaker – Finley Huaxin Mar 17 '21 at 19:36
  • Not working for me with TeX Live 2022 – han-tyumi Aug 23 '23 at 18:10