3

This is related to this question

Special character in url link

but is specific to DOIs and does not involve unicode characters.

I have to use strange DOIs like this

10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2

So, I need to able to build a command like

\doi{10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2}
-> 
\href%
{http://doi.org/10.1175/1520-0485%281986%29016%3C1929%3ACTWOTE%3E2.0.CO%3B2}%
{doi:10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2}

That is, I need a valid URL in the first argument to \href based on a DOI which includes invalid characters as URL.

We can assume that there is an external command that escapes invalid characters in a URL:

$ urlencode '10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2'
10.1175/1520-0485%281986%29016%3C1929%3ACTWOTE%3E2.0.CO%3B2
$

If I knew how to call an external program and catch its standard output, I would be able to build such a LaTeX command.

Or maybe somebody already has a solution.

If urlencode can be used from within LaTeX, it would serve as a solution to the unicode character problem, too.

By the way, a URL with invalid characters still works on Adobe Reader, but it doesn't on Apple's PDF viewer and other PDF viewers that use Webkit (so I was told). I suspect that Apple wouldn't fix it because the URL is invalid after all.

Ryo
  • 871
  • 2
    you could use the doi package. – Ulrike Fischer Oct 13 '21 at 07:31
  • @UlrikeFischer Ah, so simple! Thanks! I'll modify the title and the contents of my question because the solution is specific to DOI, not general to include all invalid URLs. – Ryo Oct 13 '21 at 08:54

1 Answers1

2

It turns out that the doi package already provides such a command as described in the question (although I don't know whether it's actually expanded into an \href command or not). Thank you to @UrlikeFischer .

You just \usepackage{doi} in the preamble:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{doi}
\usepackage{url}
\usepackage{hyperref}
\begin{document}
\noindent
\href%
{http://doi.org/10.1175/1520-0485%281986%29016%3C1929%3ACTWOTE%3E2.0.CO%3B2}%
{URL including percent encoding}\\
\href%
{http://doi.org/10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2}%
{URL including invalid characters}\\
\url{http://doi.org/10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2}\\
\url{http://doi.org/10.1175/1520-0485%281986%29016%3C1929%3ACTWOTE%3E2.0.CO%3B2}\\
\doi{10.1175/1520-0485(1986)016<1929:CTWOTE>2.0.CO;2}
\end{document}

This is to demonstrate that the hyperlinks to invalid URLs don't work on Apple's PDF viewers.

Ryo
  • 871