1

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?

  • 2
    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
2

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}
  • 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
  • Ok, but as stated, the boundaries \url produces are messed up - in any of my viewers. – Ludi Jul 31 '17 at 20:52
  • @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
  • @Ludi - Incidentally, by "boundaries", do you mean the margins of the text block? Please clarify. – Mico Jul 31 '17 at 20:55
  • 2
    \nolinkurl instead of \url inside the second argument of \href avoids a nested link. – Heiko Oberdiek Jul 31 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.