I'm attempting to fill a box, within an environment, to be used after the environment is closed, similar to how \begin{lrbox}{\boxname} ... \end{lrbox}
works. However, for some reason it seems that after closing the environment the content of the box is gone.
\newsavebox{\somebox}
\newenvironment{myenv}
{
\begin{lrbox}{\somebox}
}{
\end{lrbox}
\usebox{\somebox} % This works
}
\begin{myenv}
Something
\end{myenv}
\usebox{\somebox} % This doesn't
In the example above \usebox{\somebox}
within myenv
's closing block seems to work as expected, but not if used after \end{myenv}
. Maybe there is some fundamental understanding of environments and/or boxes that I am missing, but I would expect what I am trying to do to be possible, since it's how the lrbox
environment works?
{...}
. Thus, by design, what happens in the environment is inaccessible to the outside code, unless the environment saves its content globally.\global\sbox{\somebox}{\usebox{\somebox}}
within the closing brace ofmyenv
makes the content available after\end{myenv}
. I guess thelrbox
environment must be doing something similar to that?lrbox
that is "at fault", but the environmentmyenv
which isolates the originallrbox
operation from the main code.lrbox
behavior to be the default. I think I follow now, thanks!