## Modes

As LaTeX processes your document, at any point it is in one of six modes. They fall into three categories of two each, the horizontal modes, the math modes, and the vertical modes. Some commands only work in one mode or another (in particular, many commands only work in one of the math modes), and error messages will refer to these.

- Paragraph mode is what LaTeX is in when processing ordinary text. It breaks the input text into lines and breaks the lines into pages. This is the mode LaTeX is in most of the time.

  LR mode (for left-to-right mode; in plain TeX this is called restricted horizontal mode) is in effect when LaTeX starts making a box with an `\mbox` command. As in paragraph mode, LaTeX’s output is a string of words with spaces between them. Unlike in paragraph mode, in LR mode LaTeX never starts a new line, it just keeps going from left to right. (Although LaTeX will not complain that the LR box is too long, when it is finished and next tries to put that box into a line, it could very well complain that the finished LR box won’t fit there.)

- Math mode is when LaTeX is generating an inline mathematical formula.

  Display math mode is when LaTeX is generating a displayed mathematical formula. (Displayed formulas differ somewhat from inline ones. One example is that the placement of the subscript on `\int` differs in the two situations.)

- Vertical mode is when LaTeX is building the list of lines and other material making the output page. This is the mode LaTeX is in when it starts a document.

  Internal vertical mode is in effect when LaTeX starts making a `\vbox`. This is the vertical analogue of LR mode.

For instance, if you begin a LaTeX article with ‘`Let \( x \) be ...`’ then these are the modes: first LaTeX starts every document in vertical mode, then it reads the ‘`L`’ and switches to paragraph mode, then the next switch happens at the ‘`\(`’ where LaTeX changes to math mode, and then when it leaves the formula it pops back to paragraph mode.

Paragraph mode has two subcases. If you use a `\parbox` command or a `minipage` then LaTeX is put into paragraph mode. But it will not put a page break here. Inside one of these boxes, called a parbox, LaTeX is in inner paragraph mode. Its more usual situation, where it can put page breaks, is outer paragraph mode (see Page breaking).

### `\ensuremath`

Synopsis:

    \ensuremath{formula}

Ensure that formula is typeset in math mode.

For instance, you can redefine commands that ordinarily can be used only in math mode, so that they can be used both in math and in plain text.

    \newcommand{\dx}{\ensuremath{dx}}
    In $\int f(x)\, \dx$, the \dx{} is an infinitesimal.

Caution: the `\ensuremath` command is useful but not a panacea.

    \newcommand{\alf}{\ensuremath{\alpha}}
    You get an alpha in text mode: \alf.
    But compare the correct spacing in $\alf+\alf$ with that in \alf+\alf.

Best is to typeset math things in a math mode.