1

I would like to activate the doi-hyperlink over some fields of the bibliography. For @article, these are journal+volume+year+pages. For @book, on publisher+year.

The first goal is fully achieved by the following very useful code written by Marco Daniel in the answer to this thread . I copy&paste it below for convenience. Unfortunately, it does not handle @book bibliography entries. My question is whether someone can edit this code to implement the additional feature of doi-hyperlinks on fields publisher+year for @book entries.

\documentclass{article}
\usepackage[backend=biber,backref=true]{biblatex}
\addbibresource{biblatex-examples.bib}

\usepackage[colorlinks]{hyperref}

\ExecuteBibliographyOptions{doi=false}
\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{%
\iffieldundef{doi}{#1}%
{\href{http://dx.doi.org/\thefield{doi}}{#1}}}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \usebibmacro{in:}%
  \printtext[doilink]{%
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{note+pages}%
  }%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}


\begin{document}
\cite{kastenholz}\qquad\cite{herrmann}\qquad\cite{sigfridsson}
\printbibliography
\end{document}

1 Answer 1

0

You can use the same strategy for all entry types: Copy the relevant driver from standard.bbx and add \printtext[doilink]{...} around the stuff you want to link.

The following code shows the approach for the current version of @article and @book.

\documentclass{article}
\usepackage[backend=biber,backref=true]{biblatex}


\usepackage[colorlinks]{hyperref}

\ExecuteBibliographyOptions{doi=false}

\DeclareFieldFormat{doilink}{%
  \iffieldundef{doi}{#1}%
    {\href{https://doi.org/\thefield{doi}}
    {#1}}}


\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \usebibmacro{in:}%
  \printtext[doilink]{%
    \usebibmacro{journal+issuetitle}%
    \newunit
    \usebibmacro{byeditor+others}%
    \newunit
    \usebibmacro{note+pages}}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}

\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor+others/translator+others}%
  \setunit{\printdelim{nametitledelim}}\newblock
  \usebibmacro{maintitle+title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \printtext[doilink]{%
    \usebibmacro{publisher+location+date}}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}

\begin{filecontents}{\jobname.bib}
@book{elk,
  author    = {Anne Elk},
  title     = {A Theory on Brontosauruses},
  year      = {1972},
  publisher = {Monthy \& Co.},
  location  = {London},
  doi       = {10.0001/12345},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{kastenholz,herrmann,sigfridsson,elk}
\printbibliography
\end{document}

"Anne Elk. A Theory on Brontosauruses. London: Monthy & Co., 1972 (cit. on p. 1)." with linked publisher block.

2
  • Marvelous! I have implemented the code and works perfectly, thank you so much!!
    – EmFed
    Nov 13, 2020 at 18:02
  • I have also kind of understood the explanation. Not sure if I can replicate the solution for another entry, but now I have more insight on how it works.
    – EmFed
    Nov 13, 2020 at 18:14

You must log in to answer this question.

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