# Splitting a command syntax across a \newenvironment definition

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)

• Use \begin{minipage}{10cm} and \end{minipage} – egreg Jun 19 '13 at 17:44
• Actually I needed to put the parbox inside an fbox, and further, needed to center the framed box using {\centering .... \\}. – Chatterjee Jun 19 '13 at 17:48
• This is a job for the auxiliary environment lrbox; please state more clearly the real problem, because your simplification was too, well, simple. ;-) – egreg Jun 19 '13 at 17:51
• Added my specific situation! – Chatterjee Jun 19 '13 at 18:04
• You want to have a look at the mdframed package. – egreg Jun 19 '13 at 18:10

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.

• mdframed seems to be the answer to the problem. However there is a frame rendering issue in the resulting pdf, in that the frame is missing some sides with different zoom levels. Also, using symbols from the bbding and MnSymbol packages with mdframed is giving an error Missing $inserted. Any suggestions? – Chatterjee Jun 19 '13 at 18:45 • @Chatterjee: The zooming levels have nothing to do with LaTeX, but with the viewer and is a way of optimizing the visual layout. Printed versions will include all the necessary lines though. – Werner Jun 19 '13 at 18:57 • @Chatterjee the lines going is a feature of the viewer, the problem with math is most likely that you have a missing $. – David Carlisle Jun 19 '13 at 19:00