0

I have this in a document:

\href{https://en.wikipedia.org/wiki/Something_(something)}{https://en.wikipedia.org/wiki/Something_\(something)}

I get multiple errors like this:

! Missing $ inserted." ....

I supposed that I should escape the parentheses but I didn't find the right way to do it yet. Also I'm not sure about this.

  • show a complete example, that makes it much easier to test your issue. – Ulrike Fischer May 23 at 18:59
  • You escaped the wrong bit: You want to escape _ to \_ not the (: You want \href{https://en.wikipedia.org/wiki/Something_(something)}{https://en.wikipedia.org/wiki/Something\_(something)}. But in this specific example \url{https://en.wikipedia.org/wiki/Something_(something} would be much easier. \href only makes sense if link target and text differ. – moewe May 23 at 18:59
  • @moewe : Thank you. I you post this as answer I could select it as solution. – TTT May 23 at 19:01
5

You escaped the wrong bit: You want to escape _ to \_. There is no need to escape the (

\href{https://en.wikipedia.org/wiki/Something_(something)}{https://en.wikipedia.org/wiki/Something\_(something)}

In this specific example it seems that

\url{https://en.wikipedia.org/wiki/Something_(something)}

would be much easier. Possibly with \urlstyle{same} if you don't want URLs in monospace font.

\href only makes sense if link target and text differ. Even then \nolinkurl might be a good choice

\href{https://en.wikipedia.org/wiki/Something_(something)}{\nolinkurl{https://en.wikipedia.org/wiki/Something_(something)}}

MWE

\documentclass{article}
\usepackage{hyperref}
%\urlstyle{same}

\begin{document}
\href{https://en.wikipedia.org/wiki/Something_(something)}{https://en.wikipedia.org/wiki/Something\_(something)}

\url{https://en.wikipedia.org/wiki/Something_(something)}

\href{https://en.wikipedia.org/wiki/Something_(something)}{\nolinkurl{https://en.wikipedia.org/wiki/Something_(something)}}
\end{document}

enter image description here

| improve this answer | |
  • Thank you. Regarding url/href ... I knew about it but if I test it now, url renders differently. I think that I have defined a custom style for href. Also, this was the final touch to a relatively long work so I don't think I will got through each link in the document in case href could be replaced by url ;-) – TTT May 23 at 19:15
  • @TTT You may be able to get the same result for \href and \url with \urlstyle{same}. The advantage of \url and \nolinkurl is that they allow for URL-specific line breaking. Something to keep in mind for your next project. – moewe May 23 at 19:17

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.