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'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.

share|improve this question
    
Short answer: no. –  egreg Jan 3 '13 at 20:33
    
@egreg what about a workaround? another package? –  Jeremy Jan 3 '13 at 20:42
3  
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
show 6 more comments

1 Answer 1

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}

enter image description here

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.

share|improve this answer
    
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
add comment

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.