How to typeset a file path?

I would like to properly typeset a file path, e.g.

C:\Program Files\Some program\bin\executable.exe


The first problem I encountered was that LaTeX tries to treat \Program as a command. I tried escaping it with another backslash which created a linebreak.

Then I found this package menukeys but I am not really happy because it typesets system-specific delimiters (i.e. \ for Windows and / for Unix-like) as some weird arrows.

Which leads to my question: what is the preferred way of typesetting a file path in LaTeX?

-
@Mico Oh, thanks, did it like in the wikibook. Did not occur to me at firt that url will be the responsible package but now it works. You still have to escape the \ though. –  all3fox Mar 8 at 18:54
Sorry, I meant to write \url{C:\Program Files\Some program\bin\executable.exe}. –  Mico Mar 8 at 18:58

You could load the package url with the option obeyspaces and encase the fully qualified file name in a \url instruction:

\documentclass{article}
\usepackage[obeyspaces]{url}
\begin{document}
\path{C:\Program Files\Some program\bin\executable.exe} % equivalent to \url{...}, but more semantic
\end{document}


Addendum: If you need or wish to allow line breaks at the spaces, choose the spaces option as well:

\usepackage[obeyspaces,spaces]{url}

-
Package url also defines the command \path{<some\thing>}. It is doing just the same, but it seems semantically better. –  Johannes_B Mar 8 at 22:16

I'm quite fond of menukeys, and I think you should still consider using it.

Unfortunately, menukeys currently doesn't provide its users a way of customising the output path separator (the "weird arrow" you're referring to). However, I'm sure Tobias "Tobi" Weh (the author of menukeys) would add that feature in a future release if he sees this question.

In the meantime, here is a way of customising the path separator.

\documentclass{article}

\makeatletter

% --- macro for changing path sep ---
\newcommand\setnewpathsep[1]
{%
\tw@declare@style@simple*{paths}{%
}[%
#1%
]{blacknwhite}
}

% --- reset the path separator (macro expands to original style def) ---
\newcommand\resetpathsep
{%
\tw@declare@style@simple*{paths}{%
}[%
\hspace{0.2em plus 0.1em}%
\raisebox{0.08ex}{%
-- (0,1ex) -- cycle;}%
}%
\hspace{0.2em plus 0.1em}%
]{blacknwhite}
}

\makeatother

\begin{document}
% original style
\directory{C:/Program Files/Some program/bin/executable.exe}

% Windows style
\setnewpathsep{\textbackslash}
\directory{C:/Program Files/Some program/bin/executable.exe}

% Unix style
\setnewpathsep{/}
\directory{C:/Program Files/Some program/bin/executable.exe}

% back to original style
\resetpathsep
\directory{C:/Program Files/Some program/bin/executable.exe}
\end{document}

-
There is a way to change the output sep, but it’s not the good documented ;-) so thanks for your answer so far. I plan a new version, since the user interface isn't that good an the manual neither … but I can't tell when :-/ –  Tobi Mar 8 at 22:39
@Tobi No problem. Looking forward to the next release, but no pressure... –  Jubobs Mar 8 at 23:23
:-) You may like to follow on GitHub, I think I need some Beta-Testers ;-) An there you can add feature request too … –  Tobi Mar 9 at 2:11
@Tobi I'll do that. –  Jubobs Mar 25 at 11:08