43

I'm new here so I'm not sure if this is the right way to express my question:

I'm using the excellent biblatex package with the author-year style and want the links in my citations to include the name of the author as well as the parentheses. The answer presented at hyperlink name with biblatex authoryear did exactly what I wanted but it seems the solution is broken with the newest biblatex version 1.4b. Can anyone help me by adapting the code to the newest biblatex version?

5
  • 1
    It's always best to provide a minimal example that we can test. Can you put one together, using some of the references in the biblatex example database if possible.
    – Joseph Wright
    Commented Apr 16, 2011 at 12:17
  • 1
    I tried and got the expected result.
    – egreg
    Commented Apr 16, 2011 at 13:08
  • 3
    Sorry, I checked again and it indeed works as in earlier versions. The reason I thought it was broken is a behaviour that looks awkward to me. If I use \textcite{key} the closing parenthesis after the date is not included in the hyperlink which looks awkward with colored links. It does make sense if you provide a page number like for example \textcite[27]{key}, but for a plain citation without a page number I think it would look better if the closing parenthesis was included. Is there a way to achieve this? Sorry for the mixup. Should I rather edit the whole question?
    – crusoli
    Commented Apr 17, 2011 at 12:44
  • 1
    Please provide an example we can test to see what you mean.
    – Joseph Wright
    Commented Apr 20, 2011 at 15:13
  • 1
    Also relevant: github.com/plk/biblatex/issues/428
    – moewe
    Commented Jun 17, 2018 at 17:08

1 Answer 1

60

The code below hyperlinks the entire citation label for most citation commands. For \textcite the hyperlink includes the brackets around labelyear+extrayear, unless there are pre- or postnotes. In this case the link is applied only to labelyear+extrayear.

\documentclass{report}
\usepackage[style=authoryear]{biblatex}
\usepackage{hyperref}

% Just for demo
\ExecuteBibliographyOptions{maxcitenames=1}

\DeclareFieldFormat{citehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{#1}}

\DeclareFieldFormat{textcitehyperref}{%
  \DeclareFieldAlias{bibhyperref}{noformat}% Avoid nested links
  \bibhyperref{%
    #1%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}}}

\savebibmacro{cite}
\savebibmacro{textcite}

\renewbibmacro*{cite}{%
  \printtext[citehyperref]{%
    \restorebibmacro{cite}%
    \usebibmacro{cite}}}

\renewbibmacro*{textcite}{%
  \ifboolexpr{
    ( not test {\iffieldundef{prenote}} and
      test {\ifnumequal{\value{citecount}}{1}} )
    or
    ( not test {\iffieldundef{postnote}} and
      test {\ifnumequal{\value{citecount}}{\value{citetotal}}} )
  }
    {\DeclareFieldAlias{textcitehyperref}{noformat}}
    {}%
  \printtext[textcitehyperref]{%
    \restorebibmacro{textcite}%
    \usebibmacro{textcite}}}

\renewcommand{\baselinestretch}{1.2}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\addbibresource{biblatex-examples.bib}
\begin{document}
\null\vfill
\textbf{Single citations}

Filler text \parencite{aristotle:poetics}. Filler text \parencite{kant:ku} \\
Filler text \parencite[See][23]{aristotle:poetics}.
Filler text \parencite[1--10]{kant:ku}. \\
\textcite{aristotle:poetics} and \textcite{kant:ku}.
\textcite[e.g.][]{aristotle:poetics} and \textcite[10]{kant:ku}. \\
Filler text.\footcite[23]{aristotle:poetics} Filler text.\footcite[1--10]{aristotle:rhetoric}
Filler text.\footnote{\smartcite[10--15]{companion}}

\textbf{Unqualified citation lists}

\textcite{aristotle:poetics,aristotle:rhetoric} \\
\textcite[e.g.][]{aristotle:poetics,aristotle:rhetoric} \\
\textcite[10--15]{aristotle:poetics,aristotle:rhetoric} \\
\textcite[e.g.][10--15]{aristotle:poetics,aristotle:rhetoric} \\
\parencite[See][for example]{aristotle:poetics,aristotle:rhetoric}

\textbf{Qualified citation lists}

\textcites{aristotle:poetics}{aristotle:rhetoric} \\
\textcites(See)(){aristotle:poetics}[cf.][]{aristotle:rhetoric} \\
\textcites(See)()[10]{aristotle:poetics}[10]{aristotle:rhetoric} \\
\textcites(See)()[10--15]{aristotle:poetics}[cf.][10]{aristotle:rhetoric} \\
\textcites(See)()[e.g.][10--15]{aristotle:poetics}[cf.][10]{aristotle:rhetoric} \\
\parencites(See)()[10--15]{aristotle:poetics}[cf.][10]{aristotle:rhetoric}

\textbf{Mix of qualified and unqualified citation lists}

\textcites(See)()[e.g.][]{aristotle:poetics}[10]{bertram,companion} \\
\textcites[e.g.][]{aristotle:poetics,aristotle:rhetoric}[10]{companion} \\
\textcites[10]{aristotle:poetics,aristotle:rhetoric}[cf.][]{bertram} \\
\textcites[15]{aristotle:poetics}[cf.][10]{bertram,companion}

\printbibliography
\end{document}

Here is the output you should obtain with biblatex 2.6 or earlier. The solution also works for later releases, where \textcite and friends use the and string as a final citation delimiter.

enter image description here

7
  • 41
    Why is this not an option in biblatex yet?
    – Oleg
    Commented Dec 20, 2015 at 20:16
  • 27
    Hmm, I rather think it should be the default.
    – PLK
    Commented Jun 5, 2016 at 17:23
  • 15
    has the feature eventually found its way into the biblatex package? can someone point me to the section where it is explained in the documentation?
    – thymaro
    Commented Apr 21, 2019 at 15:31
  • 3
    Update 2021: Reason why this is not part of BiBLaTeX: github.com/plk/biblatex/issues/1024 (2020) and github.com/plk/biblatex/issues/428 (2016). Commented Nov 25, 2021 at 21:36
  • 1
    I see I'm a decade late to this party. But a sketch of what the code above is doing would be much appreciated. Commented Dec 30, 2021 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .