I've written a my own little script system for generating homeworks & tests using a database of problems. Below is one particular problem which is giving me a issue for the last option, "d)":

 Problem 5. What is the quadratic formula?
a) $${b \pm \sqrt{b^2 - 4ac} \over 2a}$$  \ \ \ \ \  b) $${-b \pm \sqrt{4ac - b^2} \over 2a}$$  \ \ \ \ \  c) $${-b \pm \sqrt{b^2 - 4ac} \over 2a}$$  \ \ \ \ \  \hbox{ d) $${-b \pm \sqrt{4ac - b^2} \over 2}$$   }

The \hbox is always produced by the script, and is there to (normally) keep choices from getting cut into multiple lines -- although in this case I'm making an exception and trying to get a new line just so the equation will be bigger. Anyway, it seems to mess up the "$$", so LaTeX produces the error:

! Missing $ inserted.
<inserted text>  
l.39 ...over 2a}$$  \ \ \ \ \  \hbox{ d) $${-b \pm
                                                   \sqrt{4ac - b^2} \over 2}...

It doesn't seem to matter if I use "$$...$$" or "[...]" or "\begin{equation}...\end{equation}". It does work if I use the single "$...$" construction, but then the result looks too small for my taste.

Can anyone offer a suggestion? I'd like to keep the \hbox{} as a general grouping directive, so my preference would be something that would work inside it.

(Of course, taking out the \hbox{} would work, but as I say this is automatically generated by my script for the entire database and normally I want this behavior. I want to edit this one particular problem, not the entire script...if possible.) Thanks.

  • 1
    welcome to TeX.SX! You should not use $$ at all
    – user31729
    Feb 10, 2015 at 13:22
  • 3
    Plus, if you put \displaystyle into $...$ at the beginning, it will show as if you write inside $$...$$. But don't use $$ pair anymore. You don't even need \hbox and shouldn't use \hbox anyways but that's a different story
    – percusse
    Feb 10, 2015 at 13:23
  • Is this plain TeX? (normally LaTeX is assumed unless you say otherwise, and your document fragments do not look like LaTeX) (but then you mention \begin{equation} ?? Feb 10, 2015 at 14:01
  • since you mention \begin{equation} perhaps you are using latex in which case the document should not have $$, or \hbox or \over Feb 10, 2015 at 14:04

2 Answers 2


In restricted horizontal mode, $$ produces an empty formula. From the TeXbook, page 87:

Whenever TeX looks at a token of input to decide what should be done next, the current mode has a potential influence on what that token means. For example, \kern specifies vertical spacing in vertical mode, but it specifies horizontal spacing in horizontal mode; a math shift character like ‘$’ causes entry to math mode from horizontal mode, but it causes exit from math mode when it occurs in math mode; two consecutive math shifts ($$) appearing in horizontal mode will initiate display math mode, but in restricted horizontal mode they simply denote an empty math formula. TeX uses the fact that some operations are inappropriate in certain modes to help you recover from errors that might have crept into your manuscript. Chapters 24 to 26 explain exactly what happens to every possible token in every possible mode.

See also the end of chapter 25, page 287, for more details about this.

You find something also in TeX by Topic, page 201:

Exception: displays are not possible in restricted horizontal mode, so inside an \hbox the sequence $$ is an empty math formula and not the start of a displayed formula.

Actually it doesn't make sense to have a displayed formula in restricted horizontal mode. Perhaps you want

\hbox{... $\displaystyle ...$ ...}

If you are using LaTeX, you should never use $$ anyway, see Why is \[ … \] preferable to $$?


OK, egreg cited TeXbook and TeX by Topic, I can cite TeXbook naruby, page 93, section "six modes of main processor":

Při prvním výskytu značky ... When the $_3 occurs first then TeX checks if there is next token in the same catcode 3. This is for making difference between internal or display math mode. This feature has an exception in internal horizontal mode: The notation $$ means no entering to display mode but entering to and immediately leaving from internal math mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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