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!


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 '14 at 8:17
  • 2
    @PatrickT I guess so, or \PassOptionsToPackage{obeyspaces}{url} before loading beamer. – Stefan Kottwitz Feb 21 '14 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 '14 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.