[Tex/LaTex] Problem with “\href{URL}{URLname}”

hyperrefurls

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:enter image description here

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:
enter image description here

What should I change?

Best Answer

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.

enter image description here

\documentclass{article}
\usepackage[hyphens,spaces,obeyspaces]{url}
\usepackage[colorlinks,allcolors=blue]{hyperref}

\begin{document}
\url{https://en.m.wikipedia.org/wiki/Spirit_way}

\href{https://en.m.wikipedia.org/wiki/Spirit_way}{Wikipedia page: Spirit Way}
\end{document}
Related Question