Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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

share|improve this answer
    
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
1  
@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
add comment

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}
share|improve this answer
    
Thank you; I did try using the package as you mentioned elsewhere, but that usage conflicted. –  Dave Jarvis Dec 12 '10 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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