# Using \boxed{} in \newenvironment{envname}{here}{and here}

There's a type of environment (shown below) which I'm using very frequently. I would like to define a new environment to begin it and end it with single commands.

$$\boxed{\boxed{ \begin{gathered} i(t)=\frac{V_s}{R}\left[1-e^{-\frac{R}{L}t}\right]\\ \textnormal{Time Constant (} \tau_L \textnormal{)} =\frac{L}{R} \end{gathered} }}$$


However, it seems *\boxed{}* cannot be split between the beginning-and-ending braces of \newenvironment{} \newenvironment{envname}{ *\boxed{* }{ *}* } (the parts enclosed in the asterisks have bad syntax).

Splitting two instances of "\boxed{}" is even worse syntactically.

For reference, this is the output I want:

I have to type out these formatted equations very frequently, and any way to condense the necessary commands is appreciated... Is there a way to get around the syntactical issues and define a \newenvironment{name}{beginning}{ending} properly? If possible, I would like to avoid using extra packages.

Sorry if any part of this post seems stupid. I'm new to StackExchange...

• Welcome to TeX SX! Should the environment include equation and gathered? Aug 27 at 9:01
• Thank you! Yes, I want the environment to include both of those things Aug 27 at 9:42
• You can use if you prefer also tcolorbox package. Aug 27 at 12:14

Of course you cannot have unbalanced braces in the begin/end code. A way out is to use \boxes:

\documentclass[twocolumn]{article}

\usepackage{amsmath}

\newenvironment{boxedeq}{%
\equation\setbox0=\hbox\bgroup$\gathered }{% \endgathered$\egroup
\fbox{\fbox{\box0}}%
\endequation
}

\begin{document}

\begin{boxedeq}
i(t)=\frac{V_s}{R}\left[1-e^{-\frac{R}{L}t}\right] \\
\textnormal{Time Constant ($\tau_L$)} =\frac{L}{R}
\end{boxedeq}

\end{document}


• This seems to work too, thanks! What do the % signs denote though? Aug 27 at 9:50
• @Sisyphus The % are comment signs to hide the line endings. They are not strictly necessary here but they can be crucial in other situations, or you find spurious spaces. Aug 27 at 10:14
• Ohh yeah, those. I thought perhaps they had a different purpose here. It makes sense now. Thanks Aug 27 at 12:17
• Beware that this may not be color safe. Aug 27 at 20:05
• @egrer Uhm, how so? The  adds a group, and gathered adds further three (a box, a \ialign and a further math group). Or am I misunderstanding something? Aug 28 at 10:18 With a “save box”: \documentclass{article} \usepackage{amsmath} \newsavebox{\doubleboxedbox} \newenvironment{doubleboxed} {\begin{lrbox}{\doubleboxedbox}\displaystyle}
{$\end{lrbox}\boxed{\boxed{\usebox{\doubleboxedbox}}}} \begin{document} $$\begin{doubleboxed} \begin{gathered} i(t)=\frac{V_s}{R}\left[1-e^{-\frac{R}{L}t}\right]\\ \text{Time Constant (\tau_L)}=\frac{L}{R} \end{gathered} \end{doubleboxed}$$ \end{document}  (I simplified the input for the second line). With expl3 facilities: \documentclass{article} \usepackage{amsmath} \NewDocumentEnvironment{doubleboxed}{b}{\boxed{\boxed{#1}}}{} \begin{document} $$\begin{doubleboxed} \begin{gathered} i(t)=\frac{V_s}{R}\left[1-e^{-\frac{R}{L}t}\right]\\ \text{Time Constant (\tau_L)}=\frac{L}{R} \end{gathered} \end{doubleboxed}$$ \end{document}  • This seems to work, and thank you for simplifying the input! Aug 27 at 9:48 Another solution, using a patched version of the \doublebox command from fancybox: \documentclass{article} \usepackage{amsmath} \usepackage{fancybox} \usepackage{xpatch} \makeatletter \xpatchcmd{\@doublebox}{\advance\fboxsep .5pt}{\advance\fboxsep 2.5pt}{}{} \newenvironment{boxedequation}{\equation\doublebox\bgroup$\gathered}
{\endgathered\$\egroup\endequation}
\makeatother

\begin{document}

\begin{boxedequation}
i(t)=\frac{V_s}{R}\left[1-e^{-\frac{R}{L}t}\right]\\
\textnormal{Time Constant (} \tau_L \textnormal{)} =\frac{L}{R}
\end{boxedequation}

\end{document}


• A bit too complicated for me right now, but it works otherwise. Might use it in the future. Thanks Aug 27 at 12:22
• I think it looks complicated because of the patch to adapt the distance between the frames to the image posted. Try it without the patch and see what the default \doublebox produces. Aug 27 at 12:27