Describe a file path in a tex document / TeX でファイルパスを記述する方法

English

The url.sty package is very useful to describe URL or URL-like strings such as file path, but a path which contains space characters cannot be acceptable for the url package because the default behavior of url package trims any space characters. The solution for the problem is "obeyspaces" option.

\usepackage[obeyspaces]{url}

This option forces url package not to trim any space characters.

Another useful command is "\path" command. This command is also declared in the url package, which can describe a path containing back slash (a path separator in Windows) without escaping back slash.

\path{C:\Documents and Settings\tmishina}

Japanese

url.sty パッケージを使うと、URLもしくはそれに類する文字列を整形して表示してくれる。しかしファイルパスのように、スペース文字を含んでいる文字列を表示しようとするとうまくいかない。なぜならurl.styパッケージはデフォルトであらゆるスペース文字を削除するよう設定されているから。解決方法は "obeyspaces" オプションを付けること。

\usepackage[obeyspaces]{url}

これでスペース文字を削除しなくなる。

もうひとつ便利なコマンドが "\path"。これは url.sty で定義されているコマンドで、バックスラッシュ(円記号)をエスケープなしで使えるようになる。つまりWindowsのパスを簡単に書ける。

\path{C:\Documents and Settings\tmishina}