5

Is there a way to insert the doi of an entry in the text as an hyperlink?

I've tried \citefield{<key>}{doi} but the result is not an hyperlink. I've also tried to use the above command within \url and \href but the result is not what I had in mind.

Thanks in advance

P.S. Here is a MWE:

\documentclass{article}%twoside
\usepackage{filecontents}
\begin{filecontents}{mybib.bib}
@Article{Chen-2015,
  author       = {Chen, Yi and Moore, Katie L. and Miller, Anthony J. and {McGrath}, Steve P. and Ma, Jian Feng and Zhao, Fang-Jie},
  title        = {The role of nodes in arsenic storage and distribution in rice},
  volume       = {66},
  pages        = {3717--3724},
  doi          = {10.1093/jxb/erv164},
  journaltitle = {Journal of Experimental Botany},
  url          = {http://jxb.oxfordjournals.org/content/66/13/3717},
}

@Article{Sasaki-2015,
  author       = {Sasaki, Akimasa and Yamaji, Naoki and Mitani-Ueno, Namiki and Kashino, Miho and Ma, Jian Feng},
  title        = {A node-localized transporter {OsZIP}3 is responsible for the preferential distribution of Zn to developing tissues in rice},
  volume       = {84},
  pages        = {374--384},
  doi          = {10.1111/tpj.13005},
  journaltitle = {The Plant Journal},
  url          = {http://onlinelibrary.wiley.com/doi/10.1111/tpj.13005/abstract},
}
\end{filecontents}

\usepackage{biblatex}
\usepackage{hyperref}
\bibliography{mybib}
\begin{document}
\citefield{Chen-2015}{doi}\\ %doi as it should be printed but not an hyperlink
\href{http://dx.doi.org/\citefield{Chen-2015}{doi}}{\citefield{Chen-2015}{doi}}\\ % Doesn't work
\citefield{Sasaki-2015}{doi}\\ 
\printbibliography
\end{document}
1
  • 1
    You can specify a different format for the citation using \citefield{<key>}[<format>]{<field>}. If needed, you can create a custom format using \DeclareFieldFormat.
    – cfr
    Jul 17, 2016 at 0:05

1 Answer 1

4

For example can you define a new field format mydoi with:

\DeclareFieldFormat{mydoi}{%
% \mkbibacro{DOI}\addcolon\space
  \ifhyperref
    {\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}%
}

That allows you to get rid of the leading DOI: (see commented line in the code above ...). Now you can use this new field format to get the result I think you want.

Please see the following MWE:

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@Article{Chen-2015,
  author       = {Chen, Yi and Moore, Katie L. and Miller, Anthony J. 
                  and {McGrath}, Steve P. and Ma, Jian Feng and Zhao, Fang-Jie},
  title        = {The role of nodes in arsenic storage and distribution in rice},
  volume       = {66},
  pages        = {3717--3724},
  doi          = {10.1093/jxb/erv164},
  journaltitle = {Journal of Experimental Botany},
  url          = {http://jxb.oxfordjournals.org/content/66/13/3717},
}
@Article{Sasaki-2015,
  author       = {Sasaki, Akimasa and Yamaji, Naoki and Mitani-Ueno, Namiki 
                  and Kashino, Miho and Ma, Jian Feng},
  title        = {A node-localized transporter {OsZIP}3 is responsible 
                  for the preferential distribution of Zn to developing 
                  tissues in rice},
  volume       = {84},
  pages        = {374--384},
  doi          = {10.1111/tpj.13005},
  journaltitle = {The Plant Journal},
  url          = {http://onlinelibrary.wiley.com/doi/10.1111/tpj.13005/abstract},
}
\end{filecontents}


\documentclass{article}%twoside

\usepackage{csquotes}
\usepackage{biblatex}
\addbibresource{\jobname.bib}

\usepackage{hyperref}


\DeclareFieldFormat{mydoi}{%
% \mkbibacro{DOI}\addcolon\space
  \ifhyperref
    {\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}%
}


\begin{document}
\citefield{Chen-2015}[doi]{doi}  

\citefield{Chen-2015}[mydoi]{doi} % <===================================

\citefield{Chen-2015}[citeurl]{url} % <=================================

\citefield{Chen-2015}[url]{url}

\citefield{Sasaki-2015}[mydoi]{doi} % <=================================

\cite{Chen-2015} \cite{Sasaki-2015}
\printbibliography
\end{document}

with the result:

enter image description here

I marked the relevant code lines for you with <==============.

2
  • 1
    If one needs the DOI more often, it could be a good idea to create a new dedicated command with \DeclareCiteCommand. That saves some typing of brackets and curly braces. See also How to extract BibTeX entries (as DOI, abstract, etc.)
    – moewe
    Jul 17, 2016 at 12:17
  • I don't think we should close this question as a duplicate, the plain \citefield command without an additional format argument did not give the expected result because the generic format citefield was used. The discussions of the formats is crucial here.
    – moewe
    Jul 18, 2016 at 7:03

You must log in to answer this question.

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