0

I want the titles of every entry in my bibliography to have links to their respective urls if and only if some url is provided, while keeping urls out of sight. I have found this and this other similar questions, on whose answers I have based my approach. Unfortunately, I can't get the desired result. See the following MWE:

\documentclass{article}

\usepackage[url=false]{biblatex} \usepackage[colorlinks]{hyperref}

\newbibmacro{string+doi}[1]{% \iffieldundef{url}{#1}{\href{\thefield{url}}{#1}}} \DeclareFieldFormat{title}{\usebibmacro{string+doi}{\mkbibemph{#1}}} \DeclareFieldFormat[article]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}

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

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

As you can see in the schreenshot below, the problem is that the entry types other than @book @article do not get linkeable titles despite a url being provided. How can I get the desired effect bot only for the @book and @article classes but for @incollection, @phdthesis and @inbook classes too?

enter image description here

Thank you all!

EoDmnFOr3q
  • 2,299

2 Answers2

1

Adding

\DeclareFieldFormat[incollection]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}} 
\DeclareFieldFormat[thesis]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}%
\DeclareFieldFormat[inbook]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}

(or \DeclareFieldFormat[incollection,thesis, inbook]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}})

and changing the before the last reference to

@thesis{D04,
        author = {Duthor, D.},
        type   = {phdthesis},
        year = {2004},
        title = {Delta},
        url = {http://tex.stackexchange.com/},          
    }

c

\documentclass{article}

\usepackage[url=false]{biblatex}
\usepackage[colorlinks]{hyperref}

\newbibmacro{string+doi}[1]{% \iffieldundef{url}{#1}{\href{\thefield{url}}{#1}}} \DeclareFieldFormat{title}{\usebibmacro{string+doi}{\mkbibemph{#1}}} \DeclareFieldFormat[article]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}

\DeclareFieldFormat[incollection]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}} % added \DeclareFieldFormat[thesis]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}% added \DeclareFieldFormat[inbook]{title}{\usebibmacro{string+doi}{\mkbibquote{#1}}}% added

\begin{filecontents}[overwrite]{\jobname.bib} @article{A01, author = {Author, A.}, year = {2001}, title = {Alpha}, url = {http://tex.stackexchange.com/} } @book{B02, author = {Buthor, B.}, year = {2002}, title = {Bravo}, url = {http://tex.stackexchange.com/}, } @incollection{C03, author = {Cuthor, C.}, year = {2003}, title = {Charlie}, booktitle = "Fiber Optic Test and Measurement", url = {http://tex.stackexchange.com/}, } @thesis{D04, author = {Duthor, D.}, type = {phdthesis}, year = {2004}, title = {Delta}, url = {http://tex.stackexchange.com/},
}

@inbook{E05,
    author        = "H. E. Rose",
    title         = "A Course in Number Theory",
    publisher     = "Oxford Univ. Press",
    address       = "New York, NY",
    year          = "1988",
    url = {http://tex.stackexchange.com/},
    chapter       = "3"
}

\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

The last reference taken from biblatex-examples.bib

Simon Dispa
  • 39,141
1

The default title formats are (see biblatex.def, ll. 579-585 in v3.18)

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

In order to replicate them with linking you want

\documentclass{article}
\usepackage[url=false]{biblatex}
\usepackage[colorlinks]{hyperref}

\newbibmacro{string+doi}[1]{% \iffieldundef{url}{#1}{\href{\thefield{url}}{#1}}}

\DeclareFieldFormat{title}{\usebibmacro{string+doi}{\mkbibemph{#1}}} \DeclareFieldFormat [article,inbook,incollection,inproceedings,patent,thesis,unpublished] {title}{\usebibmacro{string+doi}{\mkbibquote{#1\isdot}}} \DeclareFieldFormat [suppbook,suppcollection,suppperiodical] {title}{\usebibmacro{string+doi}{#1}}

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

\nocite{*}

\begin{document} \printbibliography \end{document}

All titles in pink to show linking.

moewe
  • 175,683