Background
Looking to apply a consistent style to file and directory names. The book's appendix has a subsection for every file referenced by the book. Every subsection has a label whose value is that of the subsection. In this fashion, changing the label will change all the references throughout the book, accordingly.
Problem
The \path{} command in the URL package takes an argument and applies its style while taking into consideration backslashes. For example, the following works as expected:
\path{cities.jsp}
What would be ideal is:
\path{\nameref{sub:cities.jsp}}
This will output \nameref{sub:cities.jsp} into the document, rather than the desired value of cities.jsp.
The purpose is so that if I change my mind about the file name, all I need to do is change the label "sub:cities.jsp" to "sub:city.jsp", for example, and the entire document now references "city.jsp". I use a subsection so that hyperlinks are automatically applied.
Question
How can a parameter be added to \path{} that first expands \nameref before passing the argument to \path{}? That is, how can I write the following:
\filename{sub:cities.jsp}
And have it become:
\path{cities.jsp}
I have tried a number of variations, but I do not understand how to use expandafter with parameters (and even the simplest expandafter examples that I can find are Latin to me). I also want to keep the \path command unchanged (as I use it for directory names, not file names) and add a new command \filename that references the files by their corresponding subsection. Examples from the preamble:
Attempt #1
% \newcommand{\filename}[1]{\path{#1}}
% \expandafter\filename\path
\expandafter\def\filename#1{\nameref{#1}} \path
The first line gives me the \filename command, but does not expand the parameter until \path looks at it, which is not surprising.
The second line fails because the parameter is not taken into consideration, nor \nameref.
The third line generates "Undefined control sequence" errors.
Attempt #2
\def \filename #1{\nameref{#1}}
\expandafter\def\filename \path


\pathso that, when time comes, I can use the URL package to change the font of all paths everywhere. If I use a mix of\pathand\texttt, then I have to change two things. Also,\textttis formatting, it does not describe the content. An interesting, solution, though, if I cannot figure this out. – Dave Jarvis Dec 11 '10 at 21:57