B.7 | Mathematical Formulas

- Math Mode Environment
- Common Structures
- Mathematical symbols
- Putting one thing above the other
- 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 labeling 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}$` as: 1/åi=1¥ ii, and `$$\frac{1}{\sum_{i=1}^{\infty}$$` as:

1

¥
å
i=1

ii

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.
The nth root command `\sqrt` is not supported. The ``root'' symbol is not necessary, thanks to fractional exponents. For instance, the `\sqrt` command can be defined as follows:

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

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

æ
ç
ç
è

1

n!

ö
÷
÷
ø

1/3

+

(

p

)

1/2

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 | Mathematical symbols

Symbols that can be printed using browser iso-latin1 or symbol fonts are translated. Other symbols are undefined most of the time. Attempting to translate them will thus generate ``Unknown macro'' warnings. Then, users can choose their own replacement for these symbols. These personal definitions are best placed in an ad-hoc style file, given as a command line argument to HEVEA. A suggested replacement is a mix of colors and available symbols. For instance, HEVEA cannot render the `\leadsto` symbol, but it can be defined as a red arrow by:

    \newcommand{\leadsto}{{\red\rightarrow}}

Then, `$$A \leadsto B$$` is rendered as follows:
A ® B
When given the `-nosymb` option, HEVEA silently replaces symbols that cannot be rendered by iso-latin1 only by text equivalents. These equivalents are English words by default, or French words when the `-francais` option is set.
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.4 | Putting one thing above the other

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, which can be changed by redefining them:

`\textstackrel`
  Performs ordinary superscripting.
`\textunderline`
  Underlines its argument, using the `U` text-level element.
`\textoverline`
  Sends a warning message to the console and echoes its argument in the output.

Math accents (`\hat`, `\tilde`, etc.) are not handled by default. However, the distribution includes a `mathaccents.hva` file that provides definitions for almost all math accents commands, except `\check` and `\breve`. Rendering is far from perfect and changes from display to text mode. More precisely, the accent is put (too far) above the symbol in display mode, and as an ordinary superscript in text mode.
For instance, given the formula `\tilde{v} \cdot \vec{U}`, we get ``v~ · U®'' in text mode and

~
v

·

®
U

in display mode.
If such a rendering is considered too ugly, one should not load the `mathaccents.hva` file and write alternative definitions. For instance, the following custom definitions issue color changes:

    \newcommand{\tilde}[1]{{\blue#1}}
    \newcommand{\vec}[1]{{\red#1}}

With such definitions the previous example now appears as: we get ``v · U'' in text mode and
v · U
in display mode. Of course, such a trick probably requires looking closely at HTML output to check whether the document is still understandable or not. It may be better to stay with a poorly formatted document that remains closer to universally understood notations for mathematics.

B.7.5 | 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.6 | Changing Style

Letters are italicized inside math mode and this cannot be changed. The appearance of other symbols can be changed using LATEX 2e 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.