TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a GrayBox environment defined as follows.

It is used \begin{GrayBox}...\end{GrayBox} or \begin{GrayBox}[\textwidth]...\end{GrayBox}, that is, it can pass optional parameter to the environment.

I guess ???1 is the setup for default value, and ???2 is for setup for the value given.


How does ???2 possible? I mean, is it LaTeX's rule that if #1 is not given, the default value in [] is used instead? Is there any reference about this? Is the same technique can be applied to \newcommand?

\newenvironment{GrayBox}[1][\dimexpr\textwidth-4.5ex]% **** ???1
   {\setlength{\RoundedBoxWidth}{\dimexpr#1} **** ???2
   {   \end{minipage}
       \draw node[draw=black,fill=black!10,rounded corners,%
             inner sep=2ex,text width=\RoundedBoxWidth]%
share|improve this question
Why is there a ??? in the question, BTW? Was it intentional or some Unicode char that got corrupted? – ShreevatsaR Aug 4 '10 at 4:24
@ShreevatsaR : Just a mark to ask some question. – prosseek Aug 4 '10 at 4:30
BTW: you might want to add a \relax after the expression evaluated by \dimexpr just to be on the safe side, even if it's not strictly necessary here. – clemens Dec 24 '12 at 11:13
up vote 22 down vote accepted

It is LaTeX's rule that if the optional argument is not present, then #1 takes on the default value. That is,

\newenvironment{hello}[1][world]{\noindent Hello #1, }{Bye now!\\}
    nice to meet you.
    glad you could make it.

will produce

Hello world, nice to meet you. Bye now!
Hello Bob, glad you could make it. Bye now!

as its output. The same is true for commands defined with optional parameters, as in

\newcommand{\hi}[1][world!]{\noindent Hello #1}
  \hi \\

which results in the output

Hello world!
Hello Bob

share|improve this answer
Your example mixes environments and commands! Whilst environments are just fancy commands, would it be okay to edit it (either you or I) in to two examples: one an environment (with \begin{hello} ... \end{hello} and one a command? – Loop Space Aug 4 '10 at 7:48
Oh wow, can't believe I did that! Thanks for pointing it out Andrew, hopefully this version is a little more suitable. – Michael Underwood Aug 4 '10 at 17:43
Yup, looks fine now. – Loop Space Aug 4 '10 at 17:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.