# using fbox in a newenvironment [duplicate]

I am trying to write a new enviroment to add text into a \fbox, when I use \fbox on its own, it works quite nicely

\fbox{\begin{minipage}{0.9\textwidth}
does this work, I would love if it did
\end{minipage}}


If I then add this into a new comand called notes Latex dosen't seem to like it

\newenvironment{notes}
{\fbox{\begin{minipage}{0.9\textwidth}}}
{\end{minipage}}


When I then enter something into this environment in my document it comes up with errors

\begin{notes}
Does this work, I would love if it did
\end{notes}


The error I recieve is:

! Extra }, or forgotten \endgroup.
\fbox ...xsep {#1}\kern \fboxsep \color@endgroup }
\@frameb@x \relax
l.80 \begin{notes}

?


## marked as duplicate by egreg, Peter Jansson, Claudio Fiandrino, Thorsten, WernerNov 19 '13 at 19:40

• Is there any reason you NEED it in an environment form? It is simple to just make it a macro \newcommand\notes[1]{\fbox{\begin{minipage}{0.9\textwidth}#1\end{minipage}}}. Then the usage is \notes{Does this work, I would love if it did} – Steven B. Segletes Nov 19 '13 at 15:19
• This was the motivation for adding lrbox in latex2e, see the fbox/lrbox example on page 13 of usrguide (texdoc usrguide in texlive at least or texdoc.net/texmf-dist/doc/latex/base/usrguide.pdf – David Carlisle Nov 19 '13 at 15:34

This shows how to do it in both macro (\notes) and environment (\begin{Notes}) forms. EDIT: Thanks to jfbu for the proper syntax that allows one to avoid environment nesting.

\documentclass{article}
\newsavebox{\mybox}
\newenvironment{Notes}
{\begin{lrbox}{\mybox}\begin{minipage}{0.9\textwidth}}
{\end{minipage}\end{lrbox}\fbox{\usebox{\mybox}}}

\newcommand\notes[1]{%
\fbox{\begin{minipage}{0.9\textwidth}#1\end{minipage}}}
\begin{document}
\notes{Does this work, I would love if it did}

\begin{Notes}
Does this work in an environment form?  I would love if it did
\end{Notes}
\end{document}


• Thank you for this, works a treat!!! I am now trying to add a figure environment inside the note environment, I can add an image through \includegraphics but would ideally like an image, is there a away of doing this or does latex not allow an environment in an environment? \begin{Notes} Does this work in an environment form? I would love if it did \begin{figure}[H] \centering \includegraphics[scale=0.8]{testimage} \caption{testimage is lena}} \label{fig:lena} \end{figure} Doesn't like this... \end{Notes} – Gnemsid Nov 19 '13 at 16:41
• is there a reason for not doing all the job in the Notes environment? – user4686 Nov 19 '13 at 16:46
• @jbfu For some reason, the box wasn't available for use within the inner box (it came up blank), so I nested it. I perhaps did something inefficiently. – Steven B. Segletes Nov 19 '13 at 17:09
• in the Notes environment I can't get \caption to work, comes up with the following error ! LaTeX Error: \caption outside float., it allows me in insert the graphic and centering is applied to the whole environment, not just the figure – Gnemsid Nov 19 '13 at 17:10
• It works with \newenvironment{Notes} {\begin{lrbox}{\mybox}\begin{minipage}{0.9\textwidth}} {\end{minipage}\end{lrbox}\fbox{\usebox{\mybox}}} – user4686 Nov 19 '13 at 18:33