3

I am using BibLaTeX for my references but as you see in my attached image it only colors and links the year and not the rest of it. Why is that? How can I change that?

enter image description here

MWE

\documentclass{book}

\usepackage{fontspec}

\setmainfont
[%
  Path = Fonts/NotoSans/,
  UprightFont = *Regular,
  BoldFont = *Bold,
  ItalicFont = *Italic,
  BoldItalicFont = *BoldItalic
]{NotoSans.ttf}

\usepackage[greek, english]{babel}

\usepackage{csquotes}
\usepackage[style=apa]{biblatex}
\DeclareLanguageMapping{english}{english-apa}
\DeclareLanguageMapping{greek}{greek-apa}
\addbibresource{Bibliography.bib}

\usepackage[
    colorlinks,
    citecolor=blue,
    urlcolor=blue,
    bookmarks=false,
    hypertexnames=true
]{hyperref} 

\begin{document}

Text \parencite{author1}

\printbibliography
\addcontentsline{toc}{chapter}{Bibliography}

\end{document}

Bib

@book{author1,
  title={Book Title},
  author={Author},
  year={2014},
  publisher={Publisher}
}
5
  • 3
    It is like that because the original biblatex author decided only to link the year (or title in authortitle styles) and not the author. Over the time arguments have been made that this is less ambiguous when you have comp citations and it is certainly less complicated to implement, but I don't know if we have a definitive answer from the developer.
    – moewe
    Commented Apr 1, 2020 at 16:22
  • 1
    biblatex-apa is quite complex and can be tricky to modify, in any case -comp styles like that are always tricky to combine with full linking. tex.stackexchange.com/q/457411/35864 may help
    – moewe
    Commented Apr 1, 2020 at 16:26
  • 1
    Completely unrelated to your issue, but in an article the ToC entry prodcued by \addcontentsline{toc}{chapter}{Bibliography} probably does not make sense (article does not have chapters). In general lines like \addcontentsline{toc}{chapter}{Bibliography} are not necessary with biblatex if you instead use the correct heading option to \printbibliography: \printbibliography[heading=bibintoc]. With a current version of biblatex and biblatex-apa you will not need the \DeclareLanguageMappings.
    – moewe
    Commented Apr 1, 2020 at 16:30
  • @moewe Thank you very much for all those insights! I guess I will just leave this question here as a reference to others with the same issue.
    – Adam
    Commented Apr 1, 2020 at 16:37
  • @moewe I am writing a book with chapters but in the MWE I forgot to change from article to a book. I will edit my question with that.
    – Adam
    Commented Apr 1, 2020 at 17:08

1 Answer 1

3

As I wrote in the comments I don't think we can explain the why conclusively. The fact of the matter is that all biblatex standard styles have only ever linked the year (in author-year styles or title in author-title styles). Over the time various arguments have been made that all come down to saying that this allows for unambiguous links in -comp situation, where we might have

Knuth (1984, 1986)

(If we wanted to link the author here as well should it link to the 1984 or 1986 work?)

Whether or not you buy that argument is of course a different question.

In any case I can confidently say that the solution only linking the year is much easier to implement and avoids unfortunate edge cases that could otherwise be problematic. This might not be immediately obvious for a simple \parencite in style=authoryear, but there are many subtleties with the implementation of \textcite in style=authoryear-comp, for example that make full linking much trickier. This is mainly related to use of the punctuation buffer and the exact scope of the produced link.

Linking and cite colouring face the same underlying issues, so we can look at Custom citation (coloured) for select keys only to try and see if we can get more linking to work in APA style. The following solution is in my opinion the cleanest solution that produces the fullest links possible without having to rewrite how large parts of the code in biblatex-apa work.

Please note that biblatex-apa code is subject to change. This code here may not work for all versions. It was tested with v9.16 (2022/06/22). Leave a comment if this no longer works for the current biblatex-apa version on CTAN.

\documentclass{article}

\usepackage[style=apa,backend=biber]{biblatex}
\usepackage{hyperref}

\makeatletter
\renewbibmacro*{cite:author}{%
  \iffieldequals{namehash}{\cbx@lasthash}
% Multiple cites in one command
   {\setunit{\compcitedelim}%
    \printtext[bibhyperref]{%
      \usebibmacro{cite:plabelyear+extradate}}}%
% Single cite
   {\printtext[bibhyperref]{%
      \ifnameundef{labelname}
% No author/editor
       {\usebibmacro{cite:noname}%
         \savefield{namehash}{\cbx@lasthash}}
% Normal cite
       {\ifnameundef{shortauthor}
         {\printnames{labelname}}%
         {\cbx@apa@ifnamesaved
            {\printnames{shortauthor}}
            {\printnames[labelname]{author}%
             \addspace\printnames[sabrackets]{shortauthor}}}%
          \savefield{namehash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}

\renewbibmacro*{cite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
% Multiple cites in one command
   {\setunit{\compcitedelim}%
    \printtext[bibhyperref]{%
      \usebibmacro{cite:plabelyear+extradate}}}%
% Single cite
   {\printtext[bibhyperref]{%
      \ifnameundef{labelname}
% No author/editor
       {\usebibmacro{cite:noname}%
         \setunit{\printdelim{nameyeardelim}}%
         \usebibmacro{cite:plabelyear+extradate}%
         \savefield{namehash}{\cbx@lasthash}}
% Normal cite
       {\ifnameundef{shortauthor}
         {\printnames{labelname}}%
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\printnames[labelname]{author}%
            \addspace\printnames[sabrackets]{shortauthor}}}%
         \setunit{\printdelim{nameyeardelim}}%
        \usebibmacro{cite:plabelyear+extradate}%
        \savefield{namehash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
     \printtext[bibhyperref]{%
       \usebibmacro{cite:plabelyear+extradate}}}
% New cite
    {\ifbool{cbx:parens}
       {\bibcloseparen\global\boolfalse{cbx:parens}}
       {}%
     \setunit{\textcitedelim}%
     \ifnameundef{labelname}
     % No author/editor
       {\iffieldundef{shorthand}%
    % Cite using title
         {\printtext[bibhyperref]{\usebibmacro{cite:noname}}%
          \setunit{\global\booltrue{cbx:parens}%
                   \printdelim{nonameyeardelim}%
                   \bibopenparen}%
          \printtext[bibhyperref]{%
            \usebibmacro{cite:plabelyear+extradate}}}
    % Cite using shorthand
         {\printtext[bibhyperref]{%
            \usebibmacro{cite:shorthand}}}}
  % Normal cite with author/editor
  % Normal full cite
       {\printtext[bibhyperref]{%
          \ifnameundef{shortauthor}%
    % Normal full cite
           {\printnames{labelname}}
    % Cite using short author
           {\cbx@apa@ifnamesaved
             {\printnames{shortauthor}}
             {\printnames[labelname]{author}}}}%
  % Year
        \setunit{\global\booltrue{cbx:parens}%
                 \printdelim{nameyeardelim}%
                 \bibopenparen}%
  % Put the shortauthor inside the year brackets if necessary
        \printtext[bibhyperref]{%
          \ifnameundef{shortauthor}
           {}
           {\cbx@apa@ifnamesaved
             {}
             {\printnames{shortauthor}%
              \setunit{\printdelim{innernameyeardelim}}}}%
  % Print prenote (belongs to first cite)
        \ifnumequal{\value{citecount}}{1}
           {\usebibmacro{prenote}}
           {}%
  % Actual year printing
        \usebibmacro{cite:plabelyear+extradate}%
  % Save name hash for checks later
        \savefield{namehash}{\cbx@lasthash}}%
    \stepcounter{textcitecount}}}}

\renewbibmacro*{cite:plabelyear+extradate}{%
  \iffieldundef{labelyear}{}
    {\clearfield{labelmonth}% don't want months in citations
     \clearfield{labelday}% don't want days in citations
     \clearfield{labelendmonth}% don't want months in citations
     \clearfield{labelendday}% don't want days in citations
     \clearfield{labelyeardivision}% don't want yeardivisions in citations
     \clearfield{labelendyeardivision}% don't want yeardivisions in citations
     \iffieldsequal{labelyear}{labelendyear}% Don't want no-op year ranges
       {\clearfield{labelendyear}}
       {}%
     \iffieldundef{origyear}
       {}
       {\printorigdate%
        \setunit*{\addslash}}%
     \iffieldundef{related}
       {}
       {\iffieldequalstr{relatedtype}{reprintfrom}
         {\entrydata*{\thefield{related}}{\printlabeldateextra}%
          \setunit*{\addslash}}
         {}}%
     \printlabeldateextra}}

\renewbibmacro*{citeyear}{%
  \iffieldundef{labelyear}
    {\usebibmacro{cite:init}}
    {\iffieldequals{namehash}{\cbx@lasthash}
       {\setunit{\compcitedelim}%
        \printtext[bibhyperref]{\usebibmacro{cite:plabelyear+extradate}}}
       {\printtext[bibhyperref]{\usebibmacro{cite:plabelyear+extradate}}%
        \savefield{namehash}{\cbx@lasthash}}}%
  \setunit{\multicitedelim}}
\makeatother


\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \parencite{sigfridsson}

ipsum \parencite{knuth:ct:a,knuth:ct:b}

dolor \parencite{nussbaum,geer,worman}

Lorem \textcite{sigfridsson}

ipsum \textcite{knuth:ct:a,knuth:ct:b}

dolor \textcite{nussbaum,geer,worman}

\printbibliography
\end{document}

Linked citation labels.

5
  • Thanks for the elaborate solution. I will take your word for it and accept it without trying it.
    – Adam
    Commented Apr 9, 2020 at 1:42
  • This may be a weird question, but can I include this code in a custom class that I plan to post on Github?
    – avs
    Commented Jul 28, 2020 at 16:01
  • @avs Sure. Since the code was posted on this site you should probably be able to use it under a CC BY-SA 4.0 license, but if you prefer you can also use it under LPPL 1.3c (or above). I have to say though that this operates on internals of biblatex-apa code, so this may break if biblatex-apa's internals change (biblatex-apa is not as stable as the standard styles).
    – moewe
    Commented Jul 28, 2020 at 16:09
  • FYI @moewe I think this is currently out-of-date, see the new code. e.g., there is no cbx:np now.
    – Miles
    Commented Jan 23, 2023 at 2:46
  • 1
    @Miles Updated for v9.16
    – moewe
    Commented Apr 15, 2023 at 7:15

You must log in to answer this question.

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