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

When I try to compile the following document:


\newcommand{\modelDef}[2]{\item[#1] \hfill \\ #2}

  \modelDef{$test[a, b]$}{tmp}

I get a compilation error saying:

! Extra }, or forgotten $.
\sbox ...hbox {\color@setgroup #2\color@endgroup }

l.12   \modelDef{$test[a, b]$}{tmp}

However, if I remove the ] from the first argument of \modelDef, then it works. What's the problem, and how do I fix it?

share|improve this question
TeX isn't as good at matching square brackets [ as it is at matching curly braces {. You best bet might be to define a macro \def\foo{[a,b]} and then do \modelDef{$test\foo$}… – Seamus Feb 15 '12 at 12:02
Don't write test in mathmode, because it is taken as a product of four variables. Use at least \mathrm{test} or \mathit{test}. – Andrey Vihrov Feb 15 '12 at 12:05
@AndreyVihrov: I know - just didn't bother since this was an example. But thanks anyway. =) – gablin Feb 15 '12 at 13:26
up vote 11 down vote accepted

The problem arises due to instant grabbing of the entire [] part in \item. In your case it will grab $test[a, b as the argument, leaving you with an unfinished $ and a floating $ afterwards. Thus you need to tell LaTeX what belongs where.

You can circumvent this issue by adding a group like this

\newcommand{\modelDef}[2]{\item[{#1}] \hfill \\ #2}

Then it will not complain.

share|improve this answer
Ah of course. Thanks! – gablin Feb 15 '12 at 13:26

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.