[Tex/LaTex] Is it possible to make a reference clickable without showing its DOI or URL field

biblatexdoiurls

I'm using biblatex with the following options

\usepackage[backend=biber,style=numeric-comp,sorting=none,%
    isbn=false,url=false,doi=false,firstinits=true]{biblatex}

Thus, my bibliography contains neither url nor doi fields, making it nice and short. However, this comes with the disadvantage that references no longer contain clickable links leading to the download location of that particular source.

Is there a way to change this?

Best Answer

EDIT: Added Title clickable (1. just the title cickable and 2. the whole reference clickable)

1. Just the Title reference clickable

You can redefine the title macro and add the \href to the title using the DeclareFieldFormat. I edited the default definitions in the biblatex.def file.

\DeclareFieldFormat{title}{\myhref{\mkbibemph{#1}}}
\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {title}{\myhref{\mkbibquote{#1\isdot}}}

And the macros are:

\newcommand{\doiorurl}{%
  \iffieldundef{doi}
    {\iffieldundef{url}
       {}
       {\strfield{url}}}
    {http://dx.doi.org/\strfield{doi}}%
}

\newcommand{\myhref}[1]{%
 \ifboolexpr{%
   test {\ifhyperref}
   and
   not test {\iftoggle{bbx:url}}
   and
   not test {\iftoggle{bbx:doi}}
  }
  {\href{\doiorurl}{#1}}
  {#1}%
}

MWE

\documentclass{article}
\usepackage[backend=biber,style=numeric-comp,sorting=none,%
    isbn=false,url=false,doi=false,firstinits=true]{biblatex}
\usepackage{filecontents}
\usepackage{hyperref}

\begin{filecontents}{\jobname.bib}
@Article{usingdoi,
  author={The First Author},
  title={Using DOI},
  year={2014},
  journal={J. Med. Sc.},
  publisher={Springer},
  doi={10.1103/PhysRevLett.77.3865},
  pages={1-2},
}

@Article{usingurl,
  author={The Other Authors},
  title={Using URL},
  number={2},
  year={1998},
  month={4},
  journal={ACM Trans. Inf. Sys.},
  publisher={Springer},
  volume={16},
  pages={127-160},
  url={https://www.google.com}
}


@Article{nodoiurl,
  author={The Author},
  title={Neither doi or url},
  number={2},
  year={1998},
  month={4},
  journal={ACM Trans. Inf. Sys.},
  publisher={Springer},
  volume={16},
  pages={127-160},
}

\end{filecontents}

\newcommand{\doiorurl}{%
  \iffieldundef{doi}
    {\iffieldundef{url}
       {}
       {\strfield{url}}}
    {http://dx.doi.org/\strfield{doi}}%
}

\newcommand{\myhref}[1]{%
 \ifboolexpr{%
   test {\ifhyperref}
   and
   not test {\iftoggle{bbx:url}}
   and
   not test {\iftoggle{bbx:doi}}
  }
  {\href{\doiorurl}{#1}}
  {#1}%
}

\DeclareFieldFormat{title}{\myhref{\mkbibemph{#1}}}
\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished]
  {title}{\myhref{\mkbibquote{#1\isdot}}}



\addbibresource{\jobname.bib}

\begin{document}
    \nocite{*}
    \printbibliography
\end{document}%XXIII

enter image description here

2. The whole reference clickable

I found a way that allow to make a reference clickable (The whole text of the reference is clickable)

For this I Modified the definition of DeclareBibliographyDriver to add a \href to the full reference.

This is necessary before biblatex load the bibliography style.

By default, before load the style files, biblatex try load the file biblatex-dm.cfg (biblatex custom data model), then it is possible modify the DeclareBibliographyDriver using this file.

I created the file (biblatex-dm.cfg) in the work directory with the content:

\newcommand{\doiorurl}{%
  \iffieldundef{doi}
    {\iffieldundef{url}
       {}
       {\strfield{url}}}
    {http://dx.doi.org/\strfield{doi}}%
}

\newcommand{\bibdrivercontent}[1]{%
 \ifboolexpr{%
   test {\ifhyperref}
   and
   not test {\iftoggle{bbx:url}}
   and
   not test {\iftoggle{bbx:doi}}
  }
  {\href{\doiorurl}{#1}}
  {#1}%
}

\let\OldDeclareBibliographyDriver\DeclareBibliographyDriver
\renewcommand{\DeclareBibliographyDriver}[2]{\OldDeclareBibliographyDriver{#1}{\bibdrivercontent{#2}}}

This code use \href only if hyperref is loaded and doi and url options are false.

The MWE:

\documentclass{article}
\usepackage[backend=biber,style=numeric-comp,sorting=none,%
    isbn=false,url=false,doi=false,firstinits=true]{biblatex}
\usepackage{filecontents}
\usepackage{hyperref}

\begin{filecontents}{\jobname.bib}
@Article{usingdoi,
  author={The First Author},
  title={Using DOI},
  year={2014},
  journal={J. Med. Sc.},
  publisher={Springer},
  doi={10.1007/0000-0xz},
  pages={1-2},
}

@Article{usingurl,
  author={The Other Authors},
  title={Using URL},
  number={2},
  year={1998},
  month={4},
  journal={ACM Trans. Inf. Sys.},
  publisher={Springer},
  volume={16},
  pages={127-160},
  url={https://www.google.com}
}


@Article{nodoiurl,
  author={The Author},
  title={Neither doi or url},
  number={2},
  year={1998},
  month={4},
  journal={ACM Trans. Inf. Sys.},
  publisher={Springer},
  volume={16},
  pages={127-160},
}

\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
    \nocite{*}
    \printbibliography
\end{document}

And the result:

enter image description here