[Tex/LaTex] Splitting a command syntax across a \newenvironment definition

bracesenvironmentsgrouping

This question is a direct follow-up to the question Can a \newcommand Definition Contain Braces as Substitution Text? I asked yesterday.

The following example is once again a counter-intuitive one, to demonstrate what I wish to achieve. I'm trying to split the parbox syntax across the begin code and end code of a newenvironment. Using begingroup and endgroup does not seem to work here, and is producing an error.

\newenvironment{mybox}{\parbox{10cm}\begingroup}{\endgroup}

Is this possible in LaTeX?

Just to elaborate a bit on my specific need, I need a lot of centered, framed boxes to highlight some "warnings" and "best practices". For this, I thought of the following environment:

\newenvironment{mybox}[2]%
{%
  \begingroup \centering \fbox \begingroup \parbox{10cm} \begingroup #1 \hspace{5pt}
  {\large \textbf{\textsf{#2}}} \hfill \\
}%
{%
 \endgroup \endgroup \\ \endgroup \vspace{5pt} %
}

One of the arguments is for switching between the texts "Warning" and "Best Practices", and the other one is to provide a special symbol for each type (like a star or as shadowed box)

Best Answer

As noted in comments the standard minipage and lrbox environments are designed for this use, or for the particular case of framing a box, mdframed package.

To note why the definition shown does not work, you can not delimit macro arguments with \begingroup.

 \fbox \begingroup 

is the same as

 \fbox{\begingroup}

and passes the \begingroup token as the content of the box. After that things are bound to go wrong.

Similarly

\parbox{10cm} \begingroup 

is

\parbox{10cm}{\begingroup}

with \begingroup being passed as the argument to \parbox.

Related Question