# Alternatives to \$\backslash\$

## Background

Instead of marking up the text with bold or emphasis, I read (and agree) that it is better to define a command, or environment, that describes the content. Then apply text formatting later.

## Problem

In LyX, it is trivial to highlight and make bold a Windows directory name. For example

C:\apache-tomcat\webapps\

Many such paths exist in the document I am writing. What I would like to do is create a new layout/style called `filename` that describes the content:1

``````\filename{C:\apache-tomcat\webapps\}
``````

But `\` is the escape character. This means that the backslash must be transformed:

``````\filename{C:\$\backslash\$apache-tomcat\$\backslash\$webapps\$\backslash\$}
``````

The `filename` command is defined as follows:

``````\newcommand{\filename}[1]{\textbf{#1}}
``````

## Question

Is there another way to define the `filename` command that does not mandate the use of `\$\backslash\$` everywhere; rather keep using the literal `\` character? Something like:

``````\newcommand{\filename}[1]{\textbf{\verbatim{#1}}}
``````

(I want to temporarily disable the special meaning of backslash.)

Thank you!

1 What I really want to do is define my own styles/layouts in LyX while using the KOMA Script v2 class. However, the documentation on this aspect has insufficient detail for me to extend the class. That way I can simply highlight the text and apply the style, rather than resorting to LaTeX and ERT within LyX.

-
As an aside, rather than using `\$\backslash\$` you can use `\textbackslash` to get a backslash –  Aditya Dec 11 '10 at 17:56
@Aditya: What about the space? `C:\textbackslash jsp\textbackslash cities` produces `C:\ jsp\ cities`, which is not the same as `C:\jsp\cities`. Unless `\textbackslash` removes the space immediately following? Certainly I cannot do `C:\textbackslashjsp`? –  Dave Jarvis Dec 11 '10 at 19:23
@Aditya: I see. I could use `\textbackslash{}`. LyX performs this translation automatically. I type `c:\jsp` and LyX encodes what I typed as `c:\textbackslash{}jsp`. –  Dave Jarvis Dec 11 '10 at 19:52
You should use the `\path` macro from the `url` package. Alternatively, you can make your own macro that behaves that way using `\DeclareUrlCommand`. For example, `\path` is (basically) defined as follows.
``````\DeclareUrlCommand\path{\urlstyle{tt}}
Of course, if you want bold, then you should use `bf` instead of `tt`.