# Obey spaces with URL package (path command)

## Background

Using the \path command from the URL package to mark-up directory paths. Some of the paths have spaces.

## Problem

The preamble is set to:

\usepackage{algorithm}
\usepackage{booktabs}
% ... many other packages ...
\usepackage[automark,nouppercase]{scrpage2}
\usepackage[obeyspaces,dvipsnames,svgnames,x11names,table,hyperref]{xcolor}


The code for the \path command:

\path{c:\Program Files\Java\jdk1.6.0_22}


The (PDF) output is missing the space:

c:\ProgramFiles\Java\jdk1.6.0_22


The documentation for the URL package mentions obeyspaces. The documentation does not say how to enforce the parameter when the package is included indirectly.

## Question

How do you force the \path command to retain spaces in its parameter, without having to rewrite all the statements (to include a non-breaking space, or the LaTeX equivalent thereof)?

Thank you!

-

Specify the option obeyspaces as document class option. This should then be passed to the url package automatically.

-
I would maintain that thanks are the highest form of thought, and that gratitude is happiness doubled by wonder. ~Gilbert Keith Chesterton –  Dave Jarvis Dec 12 '10 at 16:57
Would that work with beamer? I guess I'll find out soon enough... –  PatrickT Feb 21 at 8:17
@PatrickT I guess so, or \PassOptionsToPackage{obeyspaces}{url} before loading beamer. –  Stefan Kottwitz Feb 21 at 9:12
Thanks Stefan, that's indeed what I ended up doing: apparently hyperref loads url already so \PassOptionsToPackage is a pretty good way to go. –  PatrickT Feb 21 at 16:32

The url package does not allow to set options later on with a \urlsetup command, so you must hack the code to get what you want. Before using this hack make sure that you cannot call beforehand the url package with the obeyspaces option either by putting \usepackage[obeyspaces]{url} or \PassOptionsToPackage{obeyspaces}{url} early enough (e.g. just after \documentclass).

\documentclass{article}
\usepackage{url}
\makeatletter
\begingroup \lccode+=32 \lowercase
{\endgroup \def\Url@ObeySp{\Url@Edit\Url@String{ }{+}}}
\def\Url@space{\penalty\Url@sppen\ }
\makeatother
\begin{document}
\path{c:\Program Files\Java\jdk1.6.0_22}
\end{document}
`
-
Thank you; I did try using the package as you mentioned elsewhere, but that usage conflicted. –  Dave Jarvis Dec 12 '10 at 16:58