2

I tried to use underbrace within a formula within makebox, but that always produced an error.

For example \makebox[100pc]{asdf $$\underbrace{3}$$} produces the error while \makebox[100pc]{asdf $$3$$} works perfectly fine. Why do we get an error there? Is there an alternative to makebox?

flawr
  • 1,123
  • 1
  • 9
  • 19
  • 1
    Never use $$ in LaTeX to begin with. Display math mode doesn't make any sense in a \makebox anyway, use a single $. By the way, it's quite likely that px means something very different from what you think. – egreg Oct 01 '16 at 16:28
  • What is wrong with using $$? (Yes the px should have been pc.) – flawr Oct 01 '16 at 16:30
  • http://tex.stackexchange.com/questions/503/why-is-preferable-to – Joseph Wright Oct 01 '16 at 16:35

1 Answers1

2

See Why is \[ ... \] preferable to $$ ... $$? for some reasons why not using $$ in LaTeX.

What happens in your case? You're typesetting a horizontal box and in this context $$ just makes an empty math formula (the rule is explained in the TeXbook). Thus \underbrace{3} appears outside math mode and you get the error.

The same happens in \makebox[100px]{asdf $$3$$}: you get “asdf”, a space, an empty math formula, “3” and another empty math formula; however, 3 is not illegal in text mode and you get output without errors.

Display math mode makes no sense in the argument to \makebox anyway. Just use

\makebox[100pc]{asdf $\underbrace{3}$}

(you need quite a wide sheet of paper for this, because it's over 40 centimeters or 16 inches, even a bit wider than ISO A2 paper).

egreg
  • 1,121,712