How to write URLs in Latex? [closed]
Asked Answered
S

4

250

How do you write a URL in Latex?

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

Serilda answered 24/5, 2010 at 4:18 Comment(1)
Plus if there are any _s in your URLs, Latex will not be nice to you.Soonsooner
L
329

You can use \url

\usepackage{hyperref}
\url{http://stackoverflow.com/}
Leckie answered 24/5, 2010 at 4:20 Comment(3)
Is there a way to escape special characters like & or _ automatically, when its part of the url? Those characters are often getting used in URLs as separator for dynamic values.Acaulescent
Much better: \href{https://example.com}{links label}Lobito
it doesnt show the second tag \url, what to do?Horrific
P
59

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

Phonotypy answered 24/5, 2010 at 4:42 Comment(4)
The \verb command is much less work than that!Soonsooner
The only problem with \verb is that it uses a typewriter font. I would have suggested \verbatim if that's what he asked for.Phonotypy
As Gabe and Charles point out, the hyperref package is very good at wrapping URLs that would otherwise cause unsightly overfull hboxes.Summerwood
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.Kilogrammeter
C
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.

Chatwin answered 24/5, 2010 at 4:21 Comment(0)
S
28

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.

Soonsooner answered 24/5, 2010 at 13:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.