# How to prevent \url from removing the spaces in a path?

The following code

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{"a b c.tex"}
one
two
\end{filecontents*}

\usepackage{listings}
\usepackage{hyperref}

\begin{document}
\lstinputlisting[caption={\url{a b c.tex}}]{"a b c.tex"}
\end{document}


produces a hyperlink with suppressed spaces given in the path.

How to prevent \url from removing the spaces in a path?

-
I'd encode the spaces anyway, as %20. It's annoying, and ugly, but clearer for someone who may be copying your URL, as users do not expect URLs to contain spaces. –  TRiG Oct 13 '12 at 23:22
Are you not happy with the answer you received to this question? It's usually a good idea to specify what's missing from existing answers when offering a bounty on a question, so people know how they can help you better. –  Jake Jan 2 '13 at 14:11
@Jake: I am very happy with the existing answer. –  I am who I say I am Jan 2 '13 at 14:14
@AdorableCreature: Ah, okay. A better/cheaper way to emphasise the relation between the two questions might be to post a link to this question as a comment on the other question, which will create an entry in the "Linked" list on the right-hand side. Also, you could vote to close as a duplicate, which (if successful) creates a very prominent link at the top of the other question. –  Jake Jan 2 '13 at 14:34
URL (or URI, URN...) can't contain space character: it's an unsafe character! A space must be encoded (%20). See RFC 1738. –  Paul Gaborit Jan 2 '13 at 22:33

\usepackage[obeyspaces]{url}% http://ctan.org/pkg/url
\usepackage{hyperref}% http://ctan.org/pkg/hyperref


See the UK TeX FAQ entry Typesetting URLs. Or, since hyperref loads url by default, perhaps with other package options, use:

\PassOptionsToPackage{obeyspaces}{url}% ~ \usepackage[...,obeyspaces]{url}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref


See Option clash for package, also from the UK TeX FAQ.

-
When I click the link, the browser fails to load the file because of additional 25 inserted between % and 20. Please see these screenshots. –  I am who I say I am Feb 15 '13 at 8:26
@GarbageCollector: I'm having no such problems, even when setting Google Chrome to my default application to open .tex files. The file opens as expected. –  Werner Feb 15 '13 at 17:31
OK. Thanks. I have to try the earlier version of Adobe Reader. –  I am who I say I am Feb 15 '13 at 17:36