[Tex/LaTex] DOI’s hyperlink: include “doi:”

bibliographiesdoihyperrefpdftex

The package doi renders \doi{10.1000/182} as doi:10.1000/182, where 10.1000/182 is a boxed or colored hyperlink.

Can the hyperlink also include the doi: part? Omitting that is as peculiar as omitting the http:// from a conventional hyperlink. This also violates the DOI standard, which says that standard IETF guidelines for URI representations apply.

\documentclass{article}
\usepackage{doi}
\begin{document}
\bibliographystyle{IEEEtran}
\begin{thebibliography}{99}
\bibitem{bogus} Smith, J. ``Title,'' in J. Bogosity 42(7). \doi{10.1000/182}
\end{thebibliography}
\end{document}

I'm using pdflatex on Ubuntu 14 (pdfTeX 3.1415926-2.5-1.40.14), and doi.sty 2007/07/24 from Ubuntu package texlive-latex-extra. That file, doi.sty, is short enough to expect an answer that modifies that file.

Best Answer

While you can use \doitext to modify what is displayed before the doi, it will never be within the hyperlink. To simulate doi.sty (without using it), you can do the following:

\documentclass{article}

\usepackage{hyperref}

\makeatletter
\newcommand{\doitext}{doi:}

\newcommand*{\doi}{% 
  \begingroup 
  \lccode`\~=`\#\relax 
  \lowercase{\def~{\#}}%
  \lccode`\~=`\_\relax
  \lowercase{\def~{\_}}%
  \lccode`\~=`\<\relax 
  \lowercase{\def~{\textless}}%
  \lccode`\~=`\>\relax 
  \lowercase{\def~{\textgreater}}%
  \lccode`\~=0\relax 
  \catcode`\#=\active 
  \catcode`\_=\active 
  \catcode`\<=\active 
  \catcode`\>=\active 
  \@doi
}

%% this is the actual command which processes the argument, with the catcodes 
%% set in the previous command
%% it closes the group, and spits out the url.
\def\@doi#1{% 
  \let\#\relax
  \let\_\relax
  \let\textless\relax 
  \let\textgreater\relax 
  \edef\x{\toks0={{#1}}}% 
  \x
  \edef\#{\@percentchar23}%
  \edef\_{_}%
  \edef\textless{\@percentchar3C}% instead of {\string<} for Apple
  \edef\textgreater{\@percentchar3E}% instead of {\sting>} for Apple
  \edef\x{\toks1={\noexpand\href{http://dx.doi.org/#1}}}% 
  \x
  \edef\x{\endgroup\the\toks1 {\doitext\the\toks0}}%
  \x
}
\makeatother

\begin{document}
\doi{test}
\end{document}

The only thing I changed is that I grouped \doitext with \the\toks0. The macro \the\toks1, which comes before, contains the \href command, which then applies to the whole group.

You might want to contact one of the maintainers to ask them to make this an option in future versions of doi.sty.