The url package

Typesets web addresses, e-mail addresses and file paths with \url and \path: special characters are typed as they are, and long addresses break across lines.

Loading the package

\usepackage{url}

An address typed as normal text causes trouble twice: characters such as _, %, #, & and ~ have a special meaning in LaTeX, and TeX does not break the address at the end of a line. Inside \url{...} these characters are printed as typed, and the address may break after slashes, dots and similar characters, without a hyphen.

The package only typesets the address. With hyperref loaded, which loads url itself, \url also becomes a clickable link.

Main commands

\url{https://example.org/a_b?x=1&y=2}An address in typewriter type.
\path{C:\Users\name\file_1.tex}The same for file paths; with hyperref it does not become a link.
\urlstyle{same}Font of the addresses: tt (default), rm, sf or same for the font of the surrounding text.
\urldef{\shopurl}\url{https://example.org/50%_off}Stores an address in a command that is safe in headings, captions and footnotes.
\usepackage[hyphens]{url}Allows line breaks after hyphens as well.
\DeclareUrlCommand\email{\urlstyle{sf}}Defines a command of your own that works like \url with other settings.

Complete example

\documentclass{article}
\usepackage[hyphens]{url}
\urldef{\shopurl}\url{https://example.org/sale?discount=50%&code=A_1}
\begin{document}
\section{Sources}
The data set is at \url{https://example.org/data/2026/results_final.csv}.

The settings are stored in \path{C:\Users\name\project\config_1.ini}.

An address with a percent sign works in a footnote through a stored
command.\footnote{\shopurl}

\urlstyle{same}
In the text font: \url{https://example.org/~user/index.html}
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages