tags:

views:

5964

answers:

5

Following the previous questions on this topic, when you produce a website in LaTeX what is the best way to produce a url that contains a tilde? \verb produces the upper tilde that does not read well, and $\sim$ does not copy/pase well (adding a space when I do it). Solutions?

It seems like this should be one of those things that has a very easy fix... if it doesn't, why not?

+5  A: 

I'd look at the url package.

Jon Ericson
A `\url` provides a lowered tilde and correctly copy/pastes. Done and done.
vgm64
This works perfectly except that I find that it overrides any font style set for the document with a fixed-width font style for the URL text.
Ashwin
@Ashwin I found that this works to return the font to the font of the preceding text:`\newcommand{\urlwofont}[1]{\urlstyle{same}\url{#1}}`
vgm64
A: 

\symbol{126} would be another way, but in the default font it also yields a superscripted tilde. An ugly hack (but what isn't in LaTeX) would be to use

${}_{\textrm{\symbol{126}}}$

which produces a text tilde in Math mode and subscripts it. So it appears in the middle of the line. Seems to work for a clickable link as well. You can always put that into a command on its own :)

Joey
A: 

I'm not a latex user admittedly, but does this page help?

http://www.cse.wustl.edu/~mgeorg/html/tildalatex.html

They do the following:

\def\urltilda{\kern -.15em\lower .7ex\hbox{\~{}}\kern .04em}
\def\urldot{\kern -.10em.\kern -.10em}
\def\urlhttp{http\kern -.10em\lower -.1ex\hbox{:}\kern -.12em\lower 0ex\hbox{/}\kern -.18em\lower 0ex\hbox{/}}

The way this is used is

{\tt mgeorg@cse\urldot wustl\urldot edu}
{\tt \urlhttp www\urldot cse\urldot wustl\urldot edu/\urltilda mgeorg}
Jeremy Stanley
A: 

I think $_{\widetilde{~}}$ works good for the tilde issue.

Diego Medaglia
Ahh yes, it looks good. But it doesn't copy/paste from the pdf well!
vgm64
+1  A: 

I know this is an old question, but I recently came up with something that, despite a severe lack of elegance, works beautifully.

\catcode`~=11 % make LaTeX treat tilde (~) like a normal character
\newcommand{\urltilde}{\kern -.15em\lower .7ex\hbox{~}\kern .04em}
\catcode`~=13 % revert back to treating tilde (~) as an active character

Now you can use \urltilde inside of a \url tag (even in a .bib file) and: 1) the URL will render perfectly; 2) clicking on the URL will take you to the correct address; and, 3) copy-paste will put the correct address in the clipboard.

This is the only solution I have found that satisfies all three of these requirements. I hope it helps somebody out there.

Ryan
Nice answer, Ryan.
vgm64
Oops. Actually this does not work with the standard url.sty.However, this (even uglier) hack does:\catcode`~=11 \def\UrlSpecials{\do\~{\kern -.15em\lower .7ex\hbox{~}\kern .04em}}\catcode`~=13 % paste this immediately *after* you include url.sty, and you can just put tildes right in your URL without any special commands.
Ryan