[Tex/LaTex] Create environment out of eqnarray with frame box

environmentsequationsframed

Could you help me to create an environment out of this code:

\smallskip\centering\framebox[0.9\textwidth]{
\begin{minipage}[c]{0.8\textwidth}
\begin{eqnarray}
I & = & -\mu\frac{W}{L}\int_{V_{S}}^{V_{D}} Q_{m} \cdot \ud{}V_{ch} \\
v_{g} - \Delta\phi_{i} - v_{ch} + \ln(\frac{q_{int}}{2}) & = & 4 q_{g} + \ln(q_{g}) + \ln\left( 1 + q_{g}\frac{C_{ox}}{C_{Si}} \right) \\
i & \approx & -q_{mD}^2 + q_{mD} - (-q_{mS}^2 + q_{mS})
\end{eqnarray}
\[\mathrm{where:} \quad v_{x} = \frac{V_{x}}{U_{T}},\ q_{int} = \frac{e n_{i} t_{Si}}{4 C_{ox} U_{T}},\ q_{x} = \frac{Q_{x}}{4 C_{ox} U_{T}},\ C_{Si} = \frac{\varepsilon_{Si}} {t_{Si}}\]
\medskip
\end{minipage}}

I have in mind something like:

\newenvironment{\MyMathBox}
{\smallskip\centering\framebox[0.9\textwidth]{
\begin{minipage}[c]{0.8\textwidth}}
{\medskip
\end{minipage}}}

The eqnarray block must be implementable inside the environment.

Best Answer

enter image description here

Please always post complete documents defining all commands used (I made up something for \ud.

You need lrbox to save the contents into a box register which you can then put a frame around. As the comments have noted it's usually better to use ams alignments than eqnarray. (Not least as it handles moving the label out of the way of large entries, as shown in the image eqnarray isn't so good at that.)

\documentclass{article}

\newenvironment{mymathbox}
{\par\smallskip\centering\begin{lrbox}{0}%
\begin{minipage}[c]{0.8\textwidth}}
{\end{minipage}\end{lrbox}%
\framebox[0.9\textwidth]{\usebox{0}}%
\par\medskip
\ignorespacesafterend}


\begin{document}

\def\ud{}
\begin{mymathbox}
\begin{eqnarray}
I & = & -\mu\frac{W}{L}\int_{V_{S}}^{V_{D}} Q_{m} \cdot \ud{}V_{ch} \\
v_{g} - \Delta\phi_{i} - v_{ch} + \ln(\frac{q_{int}}{2}) & = & 4 q_{g} + \ln(q_{g}) + \ln\left( 1 + q_{g}\frac{C_{ox}}{C_{Si}} \right) \\
i & \approx & -q_{mD}^2 + q_{mD} - (-q_{mS}^2 + q_{mS})
\end{eqnarray}
\end{mymathbox}
\end{document}