1

I use this to create a custom display of my references in my document:

\DeclareCiteCommand{\citehyperref}
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
    \ifhyperref
    {\hyperlink{\thefield{entrykey}}{\usebibmacro{title}\printtext[parens]{\printfield{year}}}}
    {\usebibmacro{title}\printtext[parens]{\printfield{year}}}}
{\multicitedelim}
{\usebibmacro{postnote}}

\DeclareFieldFormat[article,book,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{\printnames{author}\addcolon\space\textit{#1}\isdot}

I have want I want: an hyperlink with "Last name, first name: title (date)". The only problem is that the hyperlink sens to the top of the document instead of the corresponding reference in the bibliography at the end of the document.

How can I solve this? Thanks in advance.

EDIT:

.tex file:

\documentclass[twoside,openright,12pt]{report}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=3cm]{geometry}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}

% BIBLIOGRAPHY %\usepackage{natbib} % première bibliographie \usepackage{csquotes}

\usepackage[style=authoryear-icomp,autolang=hyphen]{biblatex} \addbibresource{essai.bib}

\DeclareCiteCommand{\citehyperref} {\usebibmacro{prenote}} {\usebibmacro{citeindex}% \ifhyperref {\hyperlink{\thefield{entrykey}}{\usebibmacro{title}\printtext[parens]{\printfield{year}}}} {\usebibmacro{title}\printtext[parens]{\printfield{year}}}} {\multicitedelim} {\usebibmacro{postnote}}

\DeclareFieldFormat[article,book,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{\printnames{author}\addcolon\space\textit{#1}\isdot}

\usepackage{setspace} \usepackage[french]{babel} \usepackage[pdftex]{graphicx} \usepackage{float} \usepackage{epigraph}

\begin{document}

This is a citation

\citehyperref{MY_REF}

\newpage \newpage \newpage

\addcontentsline{toc}{chapter}{Bibliographie} \chaptermark{Bibliographie} \printbibheading \printbibliography \end{document}

And this is my .bib file:

@book{MY_REF,
    title = {TITLE},
    isbn = {2-7578-2258-6},
    pagetotal = {312},
    publisher = {Points documents},
    author = {XXX, YYY},
    urldate = {2023-03-11},
    date = {2011-04-21},
}
moewe
  • 175,683
  • 2
    always provide a small but complete example that can be used for a test. – Ulrike Fischer Apr 02 '23 at 10:38
  • I don't know how to provide an example as the only thing to do is to write "\citehyperref{MY_REF}" in the .tex file and MY_REF is inside a .bib file, I did my best but I haven't found an online latex example generator handling several files, such as .tex and .bib. – djcaesar9114 Apr 02 '23 at 11:03
  • your example is quite ok, it only lacks the \end{document} and loads some unneeded packages like epigraph, float, setspace. Also you should load hyperref later. And you cite shepard_absolument_2011, but your example entry uses MY_REF. – Ulrike Fischer Apr 02 '23 at 12:32
  • 1
    Adding \printnames{author} into the \DeclareFieldFormat feels a bit odd. (Not sure if it can cause actual trouble in standard use cases, but it definitely is not a standard idiom.) I couldn't find a question on here that discusses the exact style you want, but https://tex.stackexchange.com/q/547735/35864, https://tex.stackexchange.com/q/249762/35864, https://tex.stackexchange.com/q/540982/35864, https://tex.stackexchange.com/q/123104/35864 (note: the accepted answer is not best practice) are related and might be helpful. – moewe Apr 02 '23 at 16:02

1 Answers1

1

biblatex offers \bibhyperref to handle links. It will also work if hyperref is not used:

\documentclass{report}
\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{csquotes}

\usepackage[style=authoryear-icomp,autolang=hyphen]{biblatex} \addbibresource{test.bib}

\DeclareCiteCommand{\citehyperref} {\usebibmacro{prenote}} {\usebibmacro{citeindex}% \bibhyperref{\usebibmacro{title}\printtext[parens]{\printfield{year}}}}
{\multicitedelim} {\usebibmacro{postnote}}

\DeclareFieldFormat[article,book,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{\printnames{author}\addcolon\space\textit{#1}\isdot} \usepackage{hyperref}

\begin{document}

This is a citation

\citehyperref{shepard_absolument_2011}

\newpage \printbibliography[heading=bibintoc] \end{document}

Ulrike Fischer
  • 327,261
  • Thanks a lot, that is indeed the perfect solution as it's more native. – djcaesar9114 Apr 02 '23 at 14:33
  • 1
    Generally in cite command definitions, bib drivers and bibmacros \printtext[bibhyperref] would be safer than the bare \bibhyperref because it interacts with the punctuation buffer. The code here will probably work well enough in most circumstances, but it might be good to adhere to best practices anyway. – moewe Apr 02 '23 at 15:57