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.

I'm trying to make a URL with a tilde character (~) in it:

\usepackage{url}
...
\url{http://lyle.smu.edu/~tspell/jaws}

It looks right in the resulting PDF, but when clicking on it the browser goes to a wrong URL: http://lyle.smu.edu/%18tspell/jaws

If I type in the browser %7e (escape code for '~') instead of %18 the browser then goes to the correct URL.

Any idea how to get a correct link in the PDF?

share|improve this question
    
1  
@MartinTapankov: I don't think its a duplicate of theses questions. It's about the tilde in an URL, i.e. more like verbatim, then producing the the tilde symbol. However, this post is very similar: tex.stackexchange.com/q/5260/2975 –  Martin Scharrer Feb 15 '11 at 12:06
add comment

1 Answer 1

up vote 22 down vote accepted

You should use the hyperref package (which uses url internally but improves on it). It will not only format the link but also place a real hyperlink into the PDF. With url alone the link is only normal text, but is probably recognized as hyperlink by your PDF viewer, but with the wrong code for ~. LaTeX tends to substitute the code of these special characters depending on the font you use instead of taking the ASCII code.

This works fine with Acrobat Reader:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\url{http://lyle.smu.edu/~tspell/jaws}
\end{document}

A funny thing is that %18 is the ASCII code for "CAN (cancel)", which doesn't make much sense and \char"18 isn't the tilde in the tt font. I can't follow how this specific code was produced.

share|improve this answer
1  
Wow, this is one great package! (and it solved the problem too - thanks). –  Hagai Cibulski Feb 11 '11 at 18:20
    
@Hagai Cibulski Be careful with hyperref: it is temperamental, as a search of this site will reveal. It likes being the last package loaded (apart from packages that need loading after it)... –  Seamus Feb 15 '11 at 12:36
    
I think that the problem is the hyperref changes the definition of things, (like chapter and section and toc and cite entries) by adding a link to them, this will fail if you load another package that changes the way these command are defined. –  Yossi Farjoun Feb 15 '11 at 15:43
1  
@Hagai: in this case use hyperref s \nolinkurl macro, and disable the PDF bookmarks. –  Martin Scharrer Feb 16 '11 at 8:49
1  
@MartinScharrer I took your MWE, compiled it with MiKTeX 2.9, opened the pdf with Adobe Reader 11, clicked the link, which was opened in FF 19, but it tried to open http://lyle.smu.edu/%257Etspell/jaws (%257E is ~ encoded twice, i.e. % in %7E (~) encoded into %25). SumatraPDF and PDF-X Change Viewer opened the correct link in FF, so it might even be a bug / undesirable behavior on the side of Adobe Reader? Any idea if we can work around this? –  doncherry Mar 7 '13 at 22:49
show 2 more comments

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.