I want to use hyperref with natbib for the elsarticle class, including correct DOIs but I get strange errors or output no matter what I try:
(All attempts compiled with bibtex and pdflatex)
Attempt 0: Success, without hyperref
\documentclass{elsarticle}
\usepackage{filecontents}
\begin{filecontents}{mwe.bib}
@article{Ashburner2005,
author = {Ashburner, John and Friston, Karl J},
doi = {10.1016/j.neuroimage.2005.02.018},
journal = {NeuroImage},
title = {{Unified segmentation.}},
year = {2005}
}
\end{filecontents}
\begin{document}
\cite{Ashburner2005}
\bibliographystyle{elsarticle-num-names}
\bibliography{mwe}
\end{document}
Output:
Attempt 1: Death by hyperref
\usepackage{hyperref} % <-- added this to preamble
Output:
ERROR:
Undefined control sequence. \doi{\bibinfo{doi}{10.1016/j.neuroimage.2005.02.018}}.
Attempt 2: uri package
\usepackage[doipre={DOI:~}]{uri} % <-- added this to preamble
Output:
No errors, but DOI is wrong.
Attempt 3-A: user-defined \doi command:
As suggested in another post, I tried:
\newcommand*{\doi}[1]{\href{http://dx.doi.org/{#1}}{doi: {#1}}}
Output:
ERROR:
Undefined control sequence. \doi{\bibinfo{doi}{10.1016/j.neuroimage.2005.02.018}}.
Compile failed
Attempt 3-B: user-defined \doi command, updated:
\newcommand*{\doi}[1]{\href{http://dx.doi.org/\detokenize{#1}}{doi: \detokenize{#1}}}
Output:
No errors, but DOI is wrong again, in a different way.
In every case where the DOI link is wrong, the link also breaks.
Any help is appreciated.




