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.

  • 1
    \newcommand{\dirpath}{\url} But there's already \path. – egreg Jun 20 '17 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 Jun 20 '17 at 15:49
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}

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.