## B.7 Mathematical Formulae

- Math Mode Environment
- Common Structures
- Square Root
- Unicode and mathematical symbols
- Putting one thing above/below/inside
- Math accents
- Spacing
- Changing Style

### B.7.1 Math Mode Environment

The three ways to use math mode (`$`…`$`, `\(`…`\)` and `\begin{math}`…`\end{math}`) are supported. The three ways to use display math mode (`$$`…`$$`, `\[`…`\]` and `\begin{displaymath}`… `\end{displaymath}`) are also supported. Furthermore, `\ensuremath` behaves as expected.

The `equation`, `eqnarray`, `eqnarray*` environments are supported. Equation labelling and numbering is performed in the first two environments, using the `equation` counter. Additionally, numbering can be suppressed in one row of an `eqnarray`, using the `\nonumber` command.

Math mode is not as powerful in HEVEA as in LATEX. The limitations of math mode can often be surpassed by using math display mode. As a matter of fact, math mode is for in-text formulas. From the html point of view, this means that math mode does not close the current flow of text and that formulas in math mode must be rendered using text-level elements only. By contrast, displayed formulas can be rendered using block-level elements. This means that HEVEA have much more possibilities in display context than inside normal flow of text. In particular, stacking text elements one above the over is possible only in display context. For instance compare how HEVEA renders `$\frac{1}{\sum_{i=1}^{\infty} i$` as: 1/∑i=1∞ i, and `$$\frac{1}{\sum_{i=1}^{\infty} i$$` as:

1

∞
∑
i=1

i

### B.7.2 Common Structures

HEVEA admits, subscript (`_`), superscripts (`^`) and fractions (`\frac{`numer`}{`denom`}`). The best effect is obtained in display mode, where html `table` element is extensively used. By contrast, when not in display mode, HEVEA uses only `SUB` and `SUP` text-level elements to render superscrits and subscript, and the result may not be very satisfying.

However, simple subscripts and superscripts, such as `x_i` or `x^2`, are always rendered using the `SUB` and `SUP` text-level elements and their appearance should be correct even in in-text formulas.

When occurring outside math mode, characters `_` and `^` act as ordinary characters and get echoed to the output. However, a warning is issued.

An attempt is made to render all ellipsis constructs (`\ldots`, `\cdots`, `\vdots` and `\ddots`). The effect may be strange for the latter two.

### B.7.3 Square Root

The nth root command `\sqrt` is supported only for n=3,4, thanks to the existence of Unicode characters for the same. For the others, we shift to fractional exponents, in which case, the `\sqrt` command is defined as follows:

    \newcommand{\sqrt}[3][2]{\left(#2\right)^{1/#1}}

Then, the source fragment: `$$\sqrt[5]{\frac{1}{n!}} + \sqrt[3]{\pi} + \sqrt{\pi}$$` gets rendered as follows:

⎛
⎜
⎜
⎝

1
n!

⎞
⎟
⎟
⎠

1
5

+

∛

π

+

√

π

### B.7.4 Unicode and mathematical symbols

The support for unicode symbols offered by modern browsers allows to translate almost all math symbols correctly.

Log-like functions and variable sized-symbols are recognized and their subscripts and superscripts are put where they should in display mode. Subscript and superscript placement can be changed using the `\limits` and `\nolimits` commands. Big delimiters are also handled.

### B.7.5 Putting one thing above/below/inside

The commands `\stackrel`, `\underline` and `\overline` are recognized. They produce sensible output in display mode. In text mode, these macros call the `\textstackrel`, `\textunderline` and `\textoverline` macros. These macros perform the following default actions

\textstackrel
  Performs ordinary superscripting.
\textunderline
  Underlines its argument, using the `U` text-level element.
\textoverline
  Overlines using style-sheets (used <SPAN> with a top border).

The command `\boxed` works well both in display and normal math mode. Input of the form `\boxed{\frac{\pi}{2}}` produces π/2 in normal math, and

π
2

in display-math mode. The commands `\bigl,\bigr` etc. are also rendered well. Some examples can be found here.

### B.7.6 Math accents

Math accents that have coresponding text accents (`\hat`, `\tilde`, etc.) are handled by default. They in fact act as the corresponding text-mode accents (Section B.3.4). As a consequence, they work properly only on ascii letters. This may be quite cumbersome, but at least some warnings draw user’s attention on the problem. If accents are critical to your document and that HEVEA issues a lot of warnings, a solution is to redefine the math accent command. A suggested replacement is using limit superscripts. That way accents are positioned above symbols in display mode and after symbols in text mode.

    \renewcommand{\hat}[1]{\mathop{#1}\limits^{\textasciicircum}\nolimits}
    Displayed:
    $$
    \hat{\mu} = \hat{\Delta}.
    $$
    In text: $\hat{\mu} = \hat{\delta}$

An you get, displayed:

^
µ

=

^
Δ

.

In text: µ^ = δ^.

Whereas, with the default of `\hat` being `\^`, you get “µ = δ”, with the following warnings:

    ./tmp.tex:4652: Warning: Application of '\^' on '\mu' failed
    ./tmp.tex:4652: Warning: Application of '\^' on '\delta' failed

The `\vec` command is rendered differently in display and non-display mode. In display mode, the arrow appears in normal position, while in non-display the arrow appears as an ordinary superscript.

\vec{u} in text mode: u→, \vec{u} in display mode:

→
u

Most “extensible accents” (`\widetilde`, `\widehat`, etc.) are not even defined. There are a few exceptions: line “accents”:

abc

\underline

abc

\overline

Brace “accents”:

1 × 2 × ⋯ × n

◥

▼

◤

\underbrace

◢

▲

◣

1 × 2 × ⋯ × n

\overbrace

And arrow “accents”:

◂

1 × 2 × ⋯ × n

\overleftarrow

▸

1 × 2 × ⋯ × n

\overrightarrow

### B.7.7 Spacing

By contrast with LATEX, space in the input matters in math mode. One or more spaces are translated to one space. Furthermore, spaces after commands (such as `\alpha`) are echoed except for invisible commands (such as `\tt`). This allows users to control space in their formulas, output being near to what can be expected.

Explicit spacing commands (`\,`, `\!`, `\:` and `\;`) are recognized, the first two commands do nothing, while the others two output one space.

### B.7.8 Changing Style

Letters are italicized inside math mode and this cannot be changed. The appearance of other symbols can be changed using LATEX 2є style changing commands (`\mathbf`, etc.). The commands `\boldmath` and `\unboldmath` are not recognized. Whether symbols belonging to the symbol font are affected by style changes or not is browser dependent.

The `\cal` declaration and the `\mathcal` command (that yield calligraphic letters in LATEX) exist. They yield red letters by default.

Observe that this does not corresponds directly to how LATEX manage style in math mode and that, in fact, style cannot really change in math mode.

Math style changing declarations `\displaystyle` and `\textstyle` do nothing when HEVEA is already in the requested mode, otherwise they issue a warning. This is so because HEVEA implements displayed maths as tables, which require to be both opened and closed and introduce line breaks in the output. As a consequence, warnings on `\displaystyle` are to be taken seriously.

The commands `\scriptstyle` and `\scriptscriptstyle` perform type size changes.