With url-Package imported like this

\usepackage[obeyspaces, hyphens]{url}

defining a command like this


will when used like this


produce spaces in the output:

spaces in output

For comparison:


enter image description here

How can one prevent these spaces to be added? I want to use the command to define how to format directory paths in my document.

  • 1
    \newcommand{\dirpath}{\url} But there's already \path.
    – egreg
    Commented Jun 20, 2017 at 15:44
  • This works for this specific replacement of the name for the command, but i actually want to surround the url part with for example quotes or something similar, like \newcommand{\dirpath}[1]{"\url{#1}"}, \newcommand{\dirpath}{"\ url "} doesnt work here.
    – scrimau
    Commented Jun 20, 2017 at 15:49

1 Answer 1


You can use the \DeclareUrlCommand and specify before and after text for the url via \UrlLeft and \UrlRight:

Sample output


\usepackage[obeyspaces, hyphens]{url}





You must log in to answer this question.

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