245

How do you write a URL in Latex?

The subscripts and everything else make the font look very strange when it compiles.

Sam
  • 110
  • 1
  • 1
  • 8
danzig
  • 2,467
  • 2
  • 15
  • 3

4 Answers4

322

You can use \url

\usepackage{hyperref}
\url{http://stackoverflow.com/}
zs2020
  • 53,766
  • 29
  • 154
  • 219
60

You just need to escape characters that have special meaning: # $ % & ~ _ ^ \ { }

So

http://stack_overflow.com/~foo%20bar#link

would be

http://stack\_overflow.com/\~foo\%20bar\#link

Gabe
  • 84,912
  • 12
  • 139
  • 238
  • 3
    The `\verb` command is much less work than that! – Charles Stewart May 24 '10 at 13:21
  • 3
    The only problem with `\verb` is that it uses a typewriter font. I would have suggested `\verbatim` if that's what he asked for. – Gabe May 24 '10 at 13:52
  • As Gabe and Charles point out, the hyperref package is very good at wrapping URLs that would otherwise cause unsightly overfull hboxes. – Neil Steiner Jul 14 '15 at 00:00
  • 1
    This does not work correctly for me. For example, `\url{https://asdfg.com\#123}` produces `#` in text, however, the actual link it produces is `https://asdfg.com%23123`. – MaxPowers Aug 02 '20 at 13:23
49

Here is all the information you need in order to format clickable hyperlinks in LaTeX:

http://en.wikibooks.org/wiki/LaTeX/Hyperlinks

Essentially, you use the hyperref package and use the \url or \href tag depending on what you're trying to achieve.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
mandaleeka
  • 6,577
  • 1
  • 27
  • 34
29

A minimalist implementation of the \url macro that uses only Tex primitives:

\def\url#1{\expandafter\string\csname #1\endcsname}

This url absolutely won't break over lines, though; the hypperef package is better for that.

Jealie
  • 6,157
  • 2
  • 33
  • 36
Charles Stewart
  • 11,661
  • 4
  • 46
  • 85