动机
我希望期刊/出版商包含 doi 链接。
平均能量损失
构建于
biblatex:将标题超链接到 doi url(如果可用)
我有以下“MWE”,它适用于和的期刊@article
,但@inproceedings
不适用于@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}
产生输出:
问题
请注意,该书不包含 doi 链接。
我怀疑该命令
\DeclareFieldFormat*{publisher}{\usebibmacro{string+doi}{\mkbibemph{#1}}}
可能是罪魁祸首,但我无法解决。
答案1
publisher
是一个列表字段。这意味着它\DeclareFieldFormat{publisher}
不会按预期工作。如果您的版本biblatex
不是太旧,您可以使用列表包装器格式。
\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}