I would like to combine the power of \DefineVerbatimEnvironment with \UseVerbatim within a combined beamer presentation and handout scenario. I have already defined the environment coding, and now I can typeset my code using
\begin{coding}
foo->bar( ).
\end{coding}
I can also define and re-use verbatim snippets in their stand-alone version:
\begin{SaveVerbatim}{Foo}
foo->bar( ).
\end{SaveVerbatim}
\UseVerbatim{Foo}
The problem is that the latter is typeset using the default fancyvrb options. How can I combine the two so that the saved text is displayed using my custom environment?
\documentclass{article}
\usepackage{fancyvrb}
\DefineVerbatimEnvironment{coding}{Verbatim}{numbers=left,fontsize=\small}
\begin{document}
\begin{coding}
foo->bar( ).
\end{coding}
Yup. This works.
\begin{SaveVerbatim}{Foo}
foo->bar( ).
boo->baz( ).
cat->code( ).
\end{SaveVerbatim}
\UseVerbatim{Foo}
\UseVerbatim{Foo}
\UseVerbatim{Foo}
Yup, this works as well -- but it uses the default format, not my custom environment: larger font, no line numbers.
\end{document}
SaveVerbatimas you used to create thecodingenvironment. – Andrew Swann Mar 10 '13 at 14:50SaveVerbatimwon't work in my case, because I need slightly different environment definitions for the slides and the handouts (different font sizes). – vwegert Mar 10 '13 at 15:02\UseVerbatimcommand as an optional argument, e.g.\UseVerbatim[fontsize=\small]{Foo}. However, line numbering doesn't seem to work in this set-up. – Andrew Swann Mar 10 '13 at 15:45