3

Motivation

I would like to have the journal/publisher include a link to the doi.

MWE

Building on biblatex: Make title hyperlink to doi url (if available) I have the following "MWE" that works for the journal for @article and @inproceedings but not for @book.

\documentclass{article}

\usepackage[backend=bibtex]{biblatex}
\usepackage[colorlinks]{hyperref}

\ExecuteBibliographyOptions{doi=false}
\newbibmacro{string+doi}[1]{%
  \iffieldundef{doi}{#1}{\href{http://dx.doi.org/\thefield{doi}}{#1}}}
\DeclareFieldFormat*{journaltitle}{\usebibmacro{string+doi}{\mkbibemph{#1}}}
\DeclareFieldFormat*{booktitle}{\usebibmacro{string+doi}{\mkbibemph{#1}}}
\DeclareFieldFormat*{publisher}{\usebibmacro{string+doi}{\mkbibemph{#1}}}

\begin{filecontents}{\jobname.bib}
@book{Nielsen2012,
    doi = {10.1017/cbo9780511976667},
    year = 2012,
    publisher = {Cambridge University Press},
    author = {Michael A. Nielsen and Isaac L. Chuang},
    title = {Quantum Computation and Quantum Information}
}
@article{Lovett2010,
    doi = {10.1103/physreva.81.042330},
    year = 2010,
    volume = {81},
    number = {4},
    author = {Neil B. Lovett and Sally Cooper and Matthew Everitt and Matthew Trevers and Viv Kendon},
    title = {Universal quantum computation using the discrete-time quantum walk},
    journal = {Physical Review A}
}
@inproceedings{liu2021relaxed,
doi = {10.1109/CGO51591.2021.9370310},
  title={Relaxed peephole optimization: A novel compiler optimization for quantum circuits},
  author={Liu, Ji and Bello, Luciano and Zhou, Huiyang},
  booktitle={International Symposium on Code Generation and Optimization},
  year={2021},
  organization={IEEE}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
Here is \cite{liu2021relaxed} and \cite{Lovett2010} and \cite{Nielsen2012} 
\printbibliography
\end{document}

produces the output:

enter image description here Issue

Note that the book doesn't contain the doi link.

I suspect the command \DeclareFieldFormat*{publisher}{\usebibmacro{string+doi}{\mkbibemph{#1}}} is the likely culprit but I've been unable to resolve.

1 Answer 1

2

publisher is a list field. This means that \DeclareFieldFormat{publisher} will not work as expected. You can use list wrapper formatting if your biblatex is not too old.

\documentclass{article}

\usepackage[backend=bibtex]{biblatex}
\usepackage[colorlinks]{hyperref}

\ExecuteBibliographyOptions{doi=false}
\newbibmacro{string+doi}[1]{%
  \iffieldundef{doi}{#1}{\href{https://doi.org/\thefield{doi}}{#1}}}
\DeclareFieldFormat{journaltitle}{\usebibmacro{string+doi}{\mkbibemph{#1}}}
\DeclareFieldFormat{booktitle}{\usebibmacro{string+doi}{\mkbibemph{#1}}}
\DeclareListWrapperFormat{publisher}{\usebibmacro{string+doi}{#1}}

\begin{filecontents}{\jobname.bib}
@book{Nielsen2012,
  doi       = {10.1017/cbo9780511976667},
  year      = 2012,
  publisher = {Cambridge University Press},
  author    = {Michael A. Nielsen and Isaac L. Chuang},
  title     = {Quantum Computation and Quantum Information},
}
@article{Lovett2010,
  doi     = {10.1103/physreva.81.042330},
  year    = 2010,
  volume  = {81},
  number  = {4},
  author  = {Neil B. Lovett and Sally Cooper and Matthew Everitt
             and Matthew Trevers and Viv Kendon},
  title   = {Universal quantum computation using the discrete-time quantum walk},
  journal = {Physical Review A},
}
@inproceedings{liu2021relaxed,
  doi          = {10.1109/CGO51591.2021.9370310},
  title        = {Relaxed peephole optimization:
                  A novel compiler optimization for quantum circuits},
  author       = {Liu, Ji and Bello, Luciano and Zhou, Huiyang},
  booktitle    = {International Symposium on Code Generation and Optimization},
  year         = {2021},
  organization = {IEEE},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
Here is \cite{liu2021relaxed,Lovett2010,Nielsen2012} 
\printbibliography
\end{document}

Links for all three entries.

You must log in to answer this question.

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