I can't get the following code to work correctly:
\documentclass{article}
\usepackage{pgfkeys}
\makeatletter
\newif\if@ae@nfig@verb@
\pgfkeys
{%%'
/ae/nfigverb/.is family,
/ae/nfigverb,
usegobble/.initial=,
gobble/.style = { usegobble={gobble=#1,}},
width/.initial=3in,
}
\newsavebox{\aetitlebox}
\newenvironment{nfigverb}[1][]
{%%'
\pgfqkeys{/ae/nfigverb}{#1}%%'
\edef\ae@begin@minipage{%%'
\noexpand\minipage{\pgfkeysvalueof{/ae/nfigverb/width}}}%%'
\lrbox\aetitlebox
\ae@begin@minipage
}
{%%'
\endminipage
\endlrbox
}
\makeatother
\begin{document}
\begin{nfigverb}[width=3in]
as;lfk slfjksd flsk fls dfls
\end{nfigverb}
\usebox{\aetitlebox}
\end{document}
When I try to compile this I get the error:
! Undefined control sequence.
\\nfigverb ...rbox \aetitlebox \ae@begin@minipage
l.32 \begin{nfigverb}[width=3in]
?
Because of the way I intend to use keys for setting parameters of various environments, I seem to need to go the route here of \noexpand on the macro specifying the environment name so that passed options get parsed correctly.
Note
This is actually part of a bigger question. But I couldn't even get this little snippet of code to work.
I seem to be able to fix this if I write:
\newenvironment{nfigverb}[1][]
{%%'
\lrbox\aetitlebox
\pgfqkeys{/ae/nfigverb}{#1}%%'
\edef\ae@begin@minipage{%%'
\noexpand\minipage{\pgfkeysvalueof{/ae/nfigverb/width}}}%%'
\ae@begin@minipage
}
{%%'
\endminipage
\endlrbox
}
I don't understand why this change makes any difference to what I'm using inside this environment. An explanation would be greatly appreciated.
Update
I'm trying to follow @tohecz 's answer at lrbox in \newenvironment.
The problem I'm having is that
\newenvironment{nfigverb}...
{\begin{lrbox}{\mybox}
....}{\end{lrbox}}
will not let me later call
\usebox{\mybox}
and print the contents from this new box.
\lrbox...\endlrbox, but always\begin{lrbox}...\end{lrbox}, because this environment does an\endgroupthat is exactly the cause of your problem. – egreg Jul 29 '13 at 20:18\begin{lrbox}, then the box is emptied once I leave the new environment. I need to use the box later in my document. – A.Ellett Jul 29 '13 at 20:22