# Problem with “\href{URL}{URLname}”

Using the package hyperref, I can use \url to produce clickable URLs. But in the viewers I have their boundaries are very badly set. Example:

Hence, I prefer to use \href{}{}, which works most of the time. But in the examples in this picture it crashes. This is a near minimal crashing example:

\documentclass{article}

\usepackage{hyperref}

\begin{document}

%\url{https://en.m.wikipedia.org/wiki/Spirit_way}
\href{https://en.m.wikipedia.org/wiki/Spirit_way}{https://en.m.wikipedia.org/wiki/Spirit_way}

\end{document}


Here's the log:

What should I change?

• It is probably the underscore character in the URL that trips you up. Try using the url package, or just escape the underscore with a backslash: Spirit\_way – Michael Palmer Jul 31 '17 at 19:57
• @MichaelPalmer This solves it! – Ludi Jul 31 '17 at 20:39

You're mis-using the \href macro: The second argument should be a human-readable string, not some URL which may contain characters -- such as _ ("underscore") -- that are special to TeX.

If you insist on showing the full URL, just use the \url macro, not the \href macro.

\documentclass{article}
\usepackage[hyphens,spaces,obeyspaces]{url}

• If you (a) insist on showing a full URL string that contains TeX-special characters and (b) for some reason don't want to use \url{...} directly, you could type (though I wouldn't recommend it!) \href{https://en.m.wikipedia.org/wiki/Spirit_way}{\url{https://en.m.wikipedia.org/wiki/Spirit_way}}. – Mico Jul 31 '17 at 20:51
• @Ludi - Two questions: (1) Are you loading the url package with the options hyphens, spaces, and obeyspaces? (2) Why do you insist on showing the full URL? The whole point of using \href is not to have to show the underlying URL in the first place. – Mico Jul 31 '17 at 20:54
• \nolinkurl instead of \url inside the second argument of \href avoids a nested link. – Heiko Oberdiek Jul 31 '17 at 21:02