9

When used in concert with the hyperref package, biblatex automatically creates hyperrefs for citations but not if they are inserted using \citeyear or \citeyearpar.
Is it possible to add a hyperref to year only citations?

\documentclass{article}

\usepackage[backend=biber,natbib=true, style=authoryear-comp]{biblatex}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{ref1,
  author = {Doe, John D.},
  title = {Hyperrefs to citations},
  journaltitle = {Links Everywhere},
  volume = {1},
  date = {2000},
  pages = {1--2},
}

\end{filecontents}

\addbibresource{\jobname.bib}

\usepackage{hyperref}

\begin{document}

citet -- \citet{ref1}

citeyear -- \citeyear{ref1}

citeyearpar -- \citeyearpar{ref1}

\printbibliography

\end{document}

enter image description here

19

One has to redefine the citation commands instructing to use hyperlink, namely:

\DeclareCiteCommand{\citeyear}
    {}
    {\bibhyperref{\printdate}}
    {\multicitedelim}
    {}

\DeclareCiteCommand{\citeyearpar}
    {}
    {\mkbibparens{\bibhyperref{\printdate}}}
    {\multicitedelim}
    {}
| improve this answer | |
  • 4
    I think \printfield{year} should be preferred over \printdate in some cases: If there is a month given, the standard \citeyear command would only print the year, whereas \printdate outputs the month as well. \printfield{year} avoids this. – CL. Aug 5 '16 at 14:31
  • 1
    Actually, the ideal solution should also include the extrayear field, so that multiple publications on a same year get the correct letter after the year, e.g. 1997a, 1997b, 1997c. This can be done by replaceing \bibhyperref{\printdate} with \bibhyperref{\printfield{year}}\bibhyperref{\printfield{extrayear}} – gilbertohasnofb Feb 25 '19 at 17:46
  • I suggested an edit to the answer above as these functions should also handle prenote and postnote fields, so that one can add page numbers to them, for instance. – gilbertohasnofb Feb 25 '19 at 18:19
5

Another alternative is to use the \cite* command which is provided by all by all author-year and author-title styles. See the manual, section 3.7.2 "Style-specific Commands".

| improve this answer | |
  • 1
    Be aware though that \cite* is a "style-specific" command and as such only available in authoryear and authortitle; it also changes its behaviour depending on the style used. That is with authoryear it prints the year while with authortitle it prints the title. – moewe Mar 31 '14 at 9:30
  • Yes. My feeling is that the \citeyear behaviour is intentional in biblatex, thus my hint about \cite*. In a numeric citation style you want the [1]; in authortitle you want the title, along with the year. Only in authoryear does the link actually belong with the year, hence the \cite* command. – Jan-Åke Larsson Mar 31 '14 at 14:00
1

Improving on Guido's answer, these are similar functions to his but with the following modifications: 1) use \printfield{year} instead of \printdate so only the year is printed, 2) use the extrayear field so that they handle multiple publications by a same author in a same year (such as 1997a, 1997b, 1997c), and 3) they can use prenote and postnote, so that one can continue to use page numbering such as in \citeyearpar[3--4]{bib_reference_id}. The functions are:

\DeclareCiteCommand{\citeyear}
    {\usebibmacro{prenote}}
    {\bibhyperref{\printfield{year}}\bibhyperref{\printfield{extrayear}}}
    {\multicitedelim}
    {\usebibmacro{cite:postnote}}

\DeclareCiteCommand{\citeyearpar}[\mkbibparens]
    {\usebibmacro{prenote}}
    {\bibhyperref{\printfield{year}}\bibhyperref{\printfield{extrayear}}}
    {\multicitedelim}
    {\usebibmacro{cite:postnote}}

Edit: this code above works with style=authoryear-ibid. If using style=authoryear, substitute both instances of cite:postnote for postnote.

| improve this answer | |
  • 1
    This are the options I am using with biblates: bibstyle=authoryear-ibid, citestyle=authoryear-ibid, ibidtracker=false, sorting=nyt, backend=biber, maxbibnames=9, giveninits=true, uniquename=init, doi=false, isbn=false, urldate=long, dateabbrev=false, eprint=false. Could you try using these options and see if your problem goes away? If so, it will help you figure out what option is causing the issue. – gilbertohasnofb Mar 15 '19 at 11:47
  • 1
    From the accepted answer to this question: 'Sometimes the definition of the \cite commands vary across different styles in very minute ways, this is what happens here: postnote vs cite:postnote.' So try using bibstyle=authoryear-ibid and citestyle=authoryear-ibid and see if the problem goes away. If it does, do report back so I can update my answer. – gilbertohasnofb Mar 15 '19 at 11:48
  • 1
    What do you mean you can't use the latter style? Regardless, it seems that changing both cite:postnote to postnote seems to make the problem go away with authoryear, could you check that? – gilbertohasnofb Mar 16 '19 at 16:51
  • 1
    Thanks! I confirm that postnote works with style=authoryear and cite:postnote with style=authoryear-ibid. I said that I can't use the latter style only because that doesn't fit to the standard publication style in our field of science---Sorry for my confusing comment. – Ryo Mar 18 '19 at 3:10
  • 1
    When I get a chance, I will take a look at their source code and perhaps submit a pull request to their repository. Thanks again for confirming the fix. – gilbertohasnofb Mar 18 '19 at 12:24

Your Answer

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

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