Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The tutorial LaTeX/Hyperlinks shows that the following should be compilable.

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\href{mailto:a_b@c.def}{a_b@c.def}

\end{document}

However, I cannot compile it. Is it necessary to escape underscores in \href with a pair of $s or \?

Note that escaping the underscores with a pair of $ does not make sense in the above context, of course!

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

You need to escape the printed text (the second argument) since that is interpreted by LaTeX. The first argument is set according to the PDF specification which doesn't follow the same rules:

enter image description here

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\href{mailto:a_b@c.def}{a\_b@c.def}

\end{document}

You could also use \textunderscore in place of \_.

share|improve this answer
1  
Should this be edited in the Wikibook the OP linked to? Or could there be a case when the code as shown there would just work? –  Jake Apr 26 '12 at 6:53
    
@Jake: It looks to me like a bad example, since \nolinkurl removes the requirement to escape the underscore. Perhaps if the example used my-address@wikibooks.org instead, it would be less error-prone. –  Werner Apr 26 '12 at 6:59
2  
I really miss an \email macro by hyperref which handles this itself. –  Martin Scharrer Apr 26 '12 at 7:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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