Some URLs include unicode characters. For example https://en.wikipedia.org/wiki/Durbin–Watson_statistics
. All (most?) webbrowsers are able to handle such URLs but some PDF viewers (like Mac's Preview and Skim) aren't. How would one show such a URL in a LaTeX document?
You can obviously use \href{encoded URL}{original URL}
but this one fails to linebreak the "original URL" part.
The plain \url{original URL}
command does print the correct URL but this hyperlink doesn't work because it contains unicode characters.
Using the encoded URL \url{encoded URL}
does work and it linebreaks but it's too ugly to print.
I think it would be nice if the \url
command encoded the URL for the hyperlink without altering the text it prints.
\documentclass{article}
\usepackage{xurl}
\usepackage[breaklinks]{hyperref}
\begin{document}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\noindent%
1. blah blah blah blah blah blah\href{https://en.wikipedia.org/wiki/Durbin\%E2\%80\%93Watson_statistic}%
{https://en.wikipedia.org/wiki/Durbin–Watson\_statistic}
\noindent%
2. blah blah blah blah blah blah\url{https://en.wikipedia.org/wiki/Durbin\%E2\%80\%93Watson_statistic}
\noindent%
3. blah blah blah blah blah blah\url{https://en.wikipedia.org/wiki/Durbin–Watson\_statistic}
\end{document}
Edit: Thank you for the solution below, where \nolinkurl
solves the problem even with pdflatex, but this discussion has made me realize that pdflatex is not quite able to handle unicode gracefully. If you copy the URL text from the generated PDF, the text in the clipboard is not always "correct":
\documentclass{article}
\usepackage[colorlinks=true,urlcolor=blue]{hyperref}
\begin{document}
\href{https://en.wikipedia.org/wiki/Schr\%C3\%B6dinger}%
{\nolinkurl{https://en.wikipedia.org/wiki/Erwin\_Schr}ö\nolinkurl{dinger}}
\end{document}
pdflatex this document, open it with a PDF viewer, copy the text of the URL, and paste it into the address box of a webbrowser. The character ö is copied as * ̈o* and this URL doesn't work.
Unfortunately, this isn't a contrived complaint because you sometimes want to copy the URL instead of clicking on it. (Sometimes you just don't want to click on it.)
lualatex produces ö in the PDF. This problem isn't directly relevant to my original problem. I should've used lualatex in the first place.