[Tex/LaTex] How to limit the width of equations

equationsminipage

I want to control the width of the equations so they don't exceed a predefined width. Firstly I used minipage environment and put the eqnarray within that. This does not produce the line breaks before and after the equations. I manually use line break, then there would be extra space between text and equations. Is there any other way to set an specific width for an equation without affecting the line breaks? I specifically want to use eqnarray and not any other environments like align for typesetting equations.

\documentclass[]{article}
    \newenvironment{myenv}{ \begin{minipage}{5cm}\begin{eqnarray}
      }{\end{eqnarray}\end{minipage} }

\begin{document}


dummy text here
\begin{myenv}
  a &= s^3-s
  \\
  b &=s^2+s
\end{myenv}
dummy text here

\end{document}

enter image description here

with added line breaks:

\newenvironment{myenv}{\\ \begin{minipage}{5cm}\begin{eqnarray}
  }{\end{eqnarray}\end{minipage} \\}

enter image description here

Best Answer

enter image description here

\documentclass[]{article}
    \newenvironment{myenv}[1]
{\everydisplay{\setlength\displaywidth{#1}}\begin{eqnarray}}
{\end{eqnarray}\ignorespacesafterend}


\begin{document}

\noindent X\dotfill X

dummy text here X\dotfill X
\begin{myenv}{5cm}
  a &= s^3-s
  \\
  b &=s^2+s
\end{myenv}
dummy text here

dummy text here  X\dotfill X
\begin{myenv}{3cm}
  a &= s^3-s
  \\
  b &=s^2+s
\end{myenv}
dummy text here

dummy text here  X\dotfill X
\begin{myenv}{10cm}
  a &= s^3-s
  \\
  b &=s^2+s
\end{myenv}
dummy text here

\end{document}