Context:
In order to create DOI links I define a command\doi{<enter doi here>}
as
\newcommand{\doi}[1]{\href{http://dx.doi.org/#1}{doi:#1}}
Problem:
However this breaks with stupid input™ like 10.1007/1-84628-249-7{\textunderscore }13
. Because it seems to interpret the underscore, but doesn't remove the curly braces:
http://dx.doi.org/10.1007/1-84628-249-7{_}13
How would one define a command
\hrefcleanbefore{http://dx.doi.org/10.1007/1-84628-249-7{\textunderscore }13}{text}
to replace the {\textunderscore }
with a real underscore (works by default) and removing the braces resulting in a working
\href{http://dx.doi.org/10.1007/1-84628-249-7_13}{text}
(use of or hint to additional packages is welcome)
Background:
I have a great bibliographic tool which creates my .bib files but has stupid escapes for my doi field
doi = {10.1007/1-84628-249-7{\textunderscore }13}
I tackled with different options of preprocessing the .bib-file but they all lack the convenience of fitting in the build process.
I don't think this is a complex tasks if one knows all low-level TeX commands, but all my tests seem to be inferior or conflict with the \href
implementation.
MWE:
\documentclass{article}
\usepackage{hyperref}
\newcommand{\doi}[1]{\href{http://dx.doi.org/#1}{doi:#1}}
\begin{document}
DOI not clickable: \doi{10.1007/1-84628-249-7{\textunderscore }13}
HREF with \{\} not clickable: \href{http://dx.doi.org/10.1007/1-84628-249-7{_}13}{doi:10.1007/1-84628-249-7_13}
HREF correct and clickable: \href{http://dx.doi.org/10.1007/1-84628-249-7_13}{doi:10.1007/1-84628-249-7_13}
\end{document}
hyperref
package, the syntax\doi{1234{\textunderscore }5}
works fine for me. In contrast,\doi{1234_5}
does not compile.\doi{1234_5}
to compile, I expect doi to always be entered as\doi{1234{\textunderscore }5}
, just to supply\href
with a different version. (I think that is the main reason the software doesn't use a plain underscore).