4

I want to write URLs, but the stylesheet cannot be used with url or hyperref packages. Then if I copy the urls from my pdf file and paste them to the browser, tilde symbols become %2(+a weird character which looks like o with something on it) and I cannot reach the websites. What should I do with this problem?

  • 1
    %7e is nothing but ascii tilde... On my browser it automatically becomes ~ – Symbol 1 Sep 30 '16 at 03:58
  • 1
    %7e is the precent encodnig ( https://en.wikipedia.org/wiki/Percent-encoding ) of ~. However, does this question help you or answer your problem? http://tex.stackexchange.com/questions/10858/url-with-tilde-character – Ronny Sep 30 '16 at 04:54
  • @Symbol1 Sorry, I made a mistake. What I saw was different, so updated the question. However, you are right. I could write %7e directly on my draft and it worked. Thanks. –  Sep 30 '16 at 05:11
  • @Ronny Thanks, but it does not answer my question because I cannot use url or hyperref package. –  Sep 30 '16 at 05:12
  • 1
    You'll need to give us more details: all that url does is define \url and appropriate mechanisms to print URLs, so there's no obvious need for an alternative! – Joseph Wright Sep 30 '16 at 05:15
  • The stylesheet I am using is simply incompatible with url and hyperref. This is the only reason I posted this question. –  Sep 30 '16 at 05:22
  • 2
    I am not aware that package url conflicts with other packages. What's the problem? – Heiko Oberdiek Sep 30 '16 at 05:56
  • 3
    @Nickel Please edit in an example: as Heiko says, it's hard to imagine a set up where url is not usable. – Joseph Wright Sep 30 '16 at 05:59

2 Answers2

5

A primitive way of writing URLs is the \verb command:

\verb|http://example.org/~user/index.html#start|

Of course, this does not create any link, package hyperref can do this. But, some PDF viewers use a heuristics to detect links in text.

Heiko Oberdiek
  • 271,626
2

Allows line breaking at /, -, _ and ~ characters (more can be added). I added sloppypar, since even this many breakpoints may stress the flushing algorithms.

\documentclass{article}
\usepackage[nopar]{lipsum}
%%%%%%%%%%%
\newcommand\fauxurl[1]{\bgroup\ttfamily\fauxurlhelp#1\relax\relax\egroup}
\def\fauxurlhelp#1#2\relax{%
  \ifx/#1#1\penalty0\else%
    \ifx-#1#1\penalty0\else%
      \ifx\_#1#1\penalty0\else%
        \ifx~#1\char"7E\penalty0\else#1%
  \fi\fi\fi\fi%
  \ifx\relax#2\relax\else\fauxurlhelp#2\relax\fi}
%%%%%%%%%%%
\begin{document}
\begin{sloppypar}
\lipsum[4]
\fauxurl{%
http://tex.stackexchange.com/questions/331979/is~there~a-good-way-to-write~urls-with-tilde-without-using-url-or-hyperref-packa%
}
\lipsum[2]
\end{sloppypar}
\end{document}

enter image description here