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


The preamble is set to:

% ... many other packages ...

The code for the \path command:

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

The (PDF) output is missing the space:


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


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!

2 Answers 2


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 Commented Dec 12, 2010 at 16:57
  • Would that work with beamer? I guess I'll find out soon enough...
    – PatrickT
    Commented Feb 21, 2014 at 8:17
  • 2
    @PatrickT I guess so, or \PassOptionsToPackage{obeyspaces}{url} before loading beamer.
    – Stefan Kottwitz
    Commented Feb 21, 2014 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
    Commented Feb 21, 2014 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).

\begingroup \lccode`+=32 \lowercase
 {\endgroup \def\Url@ObeySp{\Url@Edit\Url@String{ }{+}}}
 \def\Url@space{\penalty\Url@sppen\ }
\path{c:\Program Files\Java\jdk1.6.0_22}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .