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.

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?

share|improve this question
    
@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

2 Answers 2

up vote 14 down vote accepted

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

enter image description here

\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}
share|improve this answer
7  
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.

enter image description here

\documentclass{article}

\usepackage{menukeys}

\makeatletter

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

% --- reset the path separator (macro expands to original style def) ---
\newcommand\resetpathsep
{%
     \tw@declare@style@simple*{paths}{%
       {\ttfamily\CurrentMenuElement}%
    }[%
       \hspace{0.2em plus 0.1em}%
       \raisebox{0.08ex}{%
          \tikz{\fill[\usemenucolor{txt}] (0,0) -- (0.5ex,0.5ex)%
                    -- (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}
share|improve this answer
3  
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
2  
:-) 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

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.