# How to make fancyvrb's \DefineShortVerb work in other commands?

I'm using the fancyvrb package with the \DefineShortVerb{\|}. However, using | inside of any command doesn't work. MWE:

\documentclass{scrbook}
\usepackage{fancyvrb}

\DefineShortVerb{\|}

\begin{document}

\section{|Pipe| doesn't work here}
THe |pipe| works here just fine. \marginpar{|Pipe| doesn't work here either.}

\end{document}


Is it possible to define a ShortVerb and have it work inside of other commands? I wasn't able to find anything about this in the documentation.

-
Short answer: no. –  egreg Jan 3 '13 at 20:33
@egreg what about a workaround? another package? –  Jeremy Jan 3 '13 at 20:42
It doesn't depend on how many packages you load: verbatim material cannot go inside the argument to another command. If the characters to appear verbatim satisfy some restrictions, it can be done; but if you want arbitrary material, you're out of luck. –  egreg Jan 3 '13 at 20:45
@egreg that's what I was afraid of. –  Jeremy Jan 3 '13 at 20:52
fancyvrb comes with a \SaveVerb command and UseVerb command that let's you work around these sorts of issues. But as @egreg has said, the short aswer is "no". –  A.Ellett Jan 3 '13 at 20:53

If you're really wedded to the idea of using verbatim and since you're already using fancyvrb you can do the following:'

\documentclass{article}
\usepackage{fancyvrb}
\pagestyle{empty}
\begin{document}
\DefineShortVerb{\|}
\SaveVerb{verb:example}|\this is saved|
\fbox{\UseVerb{verb:example}}
\end{document}


This will also work in a \section command if you prepend \protect\UseVerb{verb:example}. Though I'm not sure how this will effect TOC.

Otherwise, I would stick with @egreg's suggestions.

-
This is a good idea if I had to reuse the same thing many times, but is a little much for one-off formatting. –  Jeremy Jan 3 '13 at 21:05