14

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!

2 Answers 2

12

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

4
  • 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
8

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}
0

You must log in to answer this question.

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