Biblatex bibliography – how to output DOI/URL differently based on digital copy/to-be printed copy

biblatexbibliographiesdoihyperrefurls

What is the best practice using biblatex and hyperref packages to tweak the bibliography so that when the URL/DOI/ISBN "IDs" are present, they are shown as links with the placeholder "URL/DOI/ISBN" respectively, for instance? Is there some already available properties?

I would also like to switch to hard-copy to-be-printed too, so that this feature is turned off and the above information is printed fully.

Best Answer

The output of fields in biblatex is controlled via field formats.

The standard format for doi is (ll. 495-499 in biblatex.def (v3.16))

\DeclareFieldFormat{doi}{%
  \mkbibacro{DOI}\addcolon\space
  \ifhyperref
    {\href{https://doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}

that for URL (l. 582 in biblatex.def (v3.16))

\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\url{#1}}

you can easily change these formats so that they only print a "DOI" or "URL" and link that with \href{<link target>}{<text>} (note that you then need to load hyperref).

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

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

\DeclareFieldFormat{doi}{%
  \href{https://doi.org/#1}{\mkbibacro{DOI}}}

\DeclareFieldFormat{url}{%
  \href{#1}{\mkbibacro{URL}}}

\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \autocite{sigfridsson,ctan}

\printbibliography
\end{document}

CTAN (2006). CTAN. The Comprehensive TeX Archive Network. url (visited on 01/10/2006).
Sigfridsson, Emma and Ulf Ryde (1998). ‘Comparison of methods for deriving atomic charges from the electrostatic potential and moments’. In: Journal of Computational Chemistry 19.4, pp. 377–395. doi.