1

With url-Package imported like this

\usepackage[obeyspaces, hyphens]{url}

defining a command like this

\newcommand{\dirpath}[1]{{\url{#1}}}

will when used like this

\dirpath{Documents\BliBla\bludsdus\dssdsd}

produce spaces in the output:

spaces in output

For comparison:

\dirpath{Documents\BliBla\bludsdus\dssdsd}\linebreak\linebreak
\url{Documents\BliBla\bludsdus\dssdsd}

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.

2
  • 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

5

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

Sample output

\documentclass{article}

\usepackage[obeyspaces, hyphens]{url}

\DeclareUrlCommand{\dirpath}{\def\UrlLeft{\textrm{``}}\def\UrlRight{\textrm{''}}}

\begin{document}

\dirpath{Documents\BliBla\bludsdus\dssdsd}

\end{document}

You must log in to answer this question.

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