I'm trying to write a command that prints appropriately hyperlinked DOIs for a bibliography system. Here was my first attempt
This works very well for most DOIs. However, some DOIs have pesky non-LaTeX-friendly characters in them like
_. It turns out that if you butcher the DOI by transforming the
_ to a
\_, then everything works! (Even the LINK in the
\href is correct.)
I'm not happy with this solution, because it means that we have to include butchered DOIs in our BibTeX database, which could confuse other users. I would like a solution that permits me to use legitimate DOIs as input.
Well, I just learned about the
\detokenize command. With this, I can update the command above to
which works very well for the hyperlink part; however, underscores naturally confuse typesetting of the second argument. Is there a simple solution? I had thought to use the verbatim environment here, but it does not seem to be robust enough to be used in a function this way.
Any help much appreciated. A few more constraints:
- I would like to minimize the number (and complexity) of included packages since this all takes place inside a style file for a journal.
- It would be good enough for a small piece of code that transformed every
\_; is such a thing easy to come by?
All the best, Alex