[Tex/LaTex] biblatex: make title hyperlink to DOIs, URL or ISBN

biblatexdoihyperrefurls

This is a follow up question to biblatex: Make title hyperlink to doi url (if available). My reference database contains some DOI codes, but mainly normal URLs and some ISBN/ISSN codes. What I would like to achieve is extending the code from Herbert and hyperlink the title of the entry with the following priority: 1. DOI, 2. URL, 3. ISBN/ISSN. What I mean is, if both DOI and URL is available, use DOI. If URL and ISBN is available use URL. If only ISBN is available use that.

There are two further isses:

  • The URL field might contain several URLs, which are just seperated by a white space. In that case just the first URL should be used.
  • Herbert's code just extends to articles. I would like to extend this to all entry types.

The code from Herbert to Hyperlink the Title with DOIs is:

\newbibmacro{string+doi}[1]{%
  \iffieldundef{doi}{#1}{\href{http://dx.doi.org/\thefield{doi}}{#1}}}
\DeclareFieldFormat{title}{\usebibmacro{string+doi}{\mkbibemph{#1}}}
\DeclareFieldFormat[article]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}

This far surpasses my skill, so it would be great if someone could give me some guidance how to achieve that.

Best Answer

One possibility is to extend Herbert's bibmacro to several nested conditions. (The following example contains only placeholder links for the ISBN/ISSN fields because I don't know how this links must be formatted.)

With regard to your further issues:

  • I'm not sure if the url field allows to specify several URLs separated by white spaces; if it does, I don't know how to retain only the first URL.

  • Herbert's code actually first covers all entry types, then specifies a special title format (quotes instead of emphasis) for articles.


\documentclass{article}

\usepackage[doi=false,url=false,isbn=false]{biblatex}

\usepackage[colorlinks]{hyperref}

\newbibmacro{string+doiurlisbn}[1]{%
  \iffieldundef{doi}{%
    \iffieldundef{url}{%
      \iffieldundef{isbn}{%
        \iffieldundef{issn}{%
          #1%
        }{%
          \href{http://books.google.com/books?vid=ISSN\thefield{issn}}{#1}%
        }%
      }{%
        \href{http://books.google.com/books?vid=ISBN\thefield{isbn}}{#1}%
      }%
    }{%
      \href{\thefield{url}}{#1}%
    }%
  }{%
    \href{http://dx.doi.org/\thefield{doi}}{#1}%
  }%
}

\DeclareFieldFormat{title}{\usebibmacro{string+doiurlisbn}{\mkbibemph{#1}}}
\DeclareFieldFormat[article,incollection]{title}%
    {\usebibmacro{string+doiurlisbn}{\mkbibquote{#1}}}

\begin{filecontents}{\jobname.bib}
@article{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
  doi = {doi},
  url = {url},
  issn = {isbn-issn},
}
@book{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
  url = {http://tex.stackexchange.com/},
  isbn = {isbn-issn},
}
@incollection{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
  isbn = {9780521867016},
}
@misc{D04,
  author = {Duthor, D.},
  year = {2004},
  title = {Delta},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

enter image description here