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. – Steven B. Segletes May 21 '22 at 20:48\global\sbox{\somebox}{\usebox{\somebox}}within the closing brace ofmyenvmakes the content available after\end{myenv}. I guess thelrboxenvironment must be doing something similar to that? – Ramon May 21 '22 at 20:53lrboxthat is "at fault", but the environmentmyenvwhich isolates the originallrboxoperation from the main code. – Steven B. Segletes May 21 '22 at 20:55lrboxbehavior to be the default. I think I follow now, thanks! – Ramon May 21 '22 at 20:58