## 3 A note on style

- Spacing, Paragraphs
- Math mode
- Warnings
- Commands
- Style choices

### 3.1 Spacing, Paragraphs

Sequence of spaces normally are translated into one single space. Newlines in the input document undergo a special treatement. A newline triggers a special scanning mode that reads all following spaces and newlines. In case at least one additional newline character is read, then HEVEA executes the `\par` command. Otherwise, HEVEA outputs a single newline character. This process approximates TEX process for introducting paragraph breaks and, as a result, empty lines produce paragraph breaks.

Space after commands with no argument is skipped (as in LATEX) — however this is not true in math mode, as explained in section 3.2.1.

The following two subsections describe management of paragraphs and spaces after command sequences in greater detail. They can be skipped in first reading.

#### 3.1.1 Spurious Paragraphs

Paragraphs are rendered by the means of `p` elements. HEVEA is a bit simplistic in breaking paragraphs and spurious paragraphs may be present in the final html document. Normally, as HEVEA never outputs `p` elements whose contents is made of spaces only, this should not happen very often. Unfortunately, some commands do not produce any output in LATEX, while they do produce output in HEVEA: those commands are `\label`, `\index` etc. HEVEA translates `\label{`name`}` into the anchor `<a id="`name`"></a>`. As a result, the following source fragment will introduce a spurious paragraph.

    This a first paragraph.

    \label{label}

    This is another paragraph.

Indeed, whe have the following translation:

    <p>This a first paragraph.</p>
    <p><a id="label"></a></p>
    <p>This is another paragraph.</p>

Which your browser renders as follows — with additional borders emphasizing `p` elements.

> This a first paragraph.

> This is another paragraph.

Most of the time, such extra paragraphs remain unnoticed. Of course, they can be supressed by erasing one of the empty lines. For instance:

    This a first paragraph.

    \label{label}
    This is another paragraph.

A similar situation occurs when a sectioning command is followed by `\label` and a paragraph break:

    \section*{A section}\label{section:label}

    First paragraph.

Produced html is, after a few cosmetic simplifications:

    <h2 class="section">A section</h2>
    <p><a id="section:label"></a></p>
    <p>First paragraph.</p>

Output is so, because closing the element `h2` implies re-opening a new paragraph. Your browser renders the above html fragment as follows:

> ## A section

> First paragraph.

Here, two possible re-writing of source are:

    \section*{A\label{section:label} section}

    First paragraph.
    \section*{A section}

    \label{section:label}First paragraph.

In all cases, this amounts to avoiding a paragraph whose contents consists in a sole `\label` command.

Spurious paragraphs are more easily seen by running hevea with the command-line option -dv, which instructs hevea to add border on some of the elements it produces, including `p` elements.

#### 3.1.2 Spaces after Commands

Space after commands with no argument is skipped. Consider the following example:

    \newcommand{\open}{(}
    \newcommand{\close}{)}
    \open text opened by ``\verb+\open+''
    and closed by ``\verb+\close+''\close.

We get:

> (text opened by “`\open`” and closed by “`\close`”).

In the output above, the space after `\open` does not find its way to the output.

More generally, HEVEA tries to emulate LATEX behaviour in all situations, but discrepancies probably exist. Thus, users are invited to make explicit what they want. This is good practice anyway, because LATEX is mysterious here. Consider the following example, where the `\tryspace` macro is first applied and then expansed by hand:

    \newcommand{\bfsymbol}{\textbf{symbol}}
    \newcommand{\tryspace}[1]{#1 XXX}

    Some space: \tryspace{\bfsymbol}\\
    No space: \bfsymbol XXX

Spacing is a bit chaotic here, the space after symbol remains when `#1` is substituted for it by LATEX (or HEVEA).

> Some space | : | symbol XXX
> No space | : | symbolXXX

Note that, if a space before “XXX” is wanted, then one should probably write:

    \newcommand{\tryspace}[1]{#1{} XXX}

Finally, whether the tabulation character is a space or not is random, so avoid tabs in your source document.

### 3.2 Math mode

HEVEA math mode is not very far from normal text mode, except that all letters are shown in italics and that space after macros is echoed.

However, typesetting math formulas in html rises two difficulties. First, formulas contain symbols, such as Greek letters; second, even simple formulas do not follow the simple basic typesetting model of html.

#### 3.2.1 Spacing in math mode

By contrast with LATEX, spaces from the input are significant in math mode, this feature allows users to instruct HEVEA on how to put space in their formulas. For instance, `\alpha\rightarrow\beta` is typeset without spaces between symbols, whereas `\alpha \rightarrow \beta` produces these spaces.

`\alpha\rightarrow\beta` | : | α→β
`\alpha \rightarrow \beta` | : | α → β

Note that LATEX ignores spaces in math mode, so that users can freely adjust HEVEA output without changing anything to LATEX output.

#### 3.2.2 Symbols

> Figure 1: Some symbols

> \in: | ∈ |  | \notin: | ∉
> \int: | ∫ |  | \prod: | ∏
> \preceq: | ≼ |  | \prec: | ≺
> \leq: | ≤ |  | \geq: | ≥
> \cup: | ∪ |  | \cap: | ∩
> \supset: | ⊃ |  | \subset: | ⊂
> \supseteq: | ⊇ |  | \subseteq: | ⊆

With respect to previous versions of HEVEA since the begining, the treatment of symbols has significantly evolved. Outputting symbols is now performed by using Unicode character references, an option that much more complies whith standards than the previous option of selecting a “symbol” font. Observe that this choice is now possible, because more and more browsers correctly display such references. See Figure 1 for a few such symbols.

However, this means that ancient or purposely limited browsers (such as text-oriented browsers) cannot display maths, as translated by HEVEA. For authors that insist on avoiding symbols that cannot be shown by any browser, HEVEA offers a degraded mode that outputs text in place of symbols. HEVEA operates in this mode when given the -textsymbols command-line option. Replacement text is in English. For instance. the “∈” symbol is replace by “in”. This is far from being satisfactory, but degraded mode may be appropriate for documents than contain few symbols.

#### 3.2.3 Displays

Apart from containing symbols, formulas specify strong typesetting constraints: sub-elements must be combined together following patterns that departs from normal text typesetting. For instance, fractions numerators and denominators must be placed one above the other. HEVEA handles such constraints in display mode only.

The main two operating modes of HEVEA are text mode and display mode. Text mode is the mode for typesetting normal text, when in this mode, text items are echoed one following the other and paragraph breaks are just blank lines, both in input and output. The so called displayed-paragraph environments of LATEX (such as center or quote) are rendered by html block-level elements (such as div or blockquote). Rendering is correct becauses both LATEX displayed environments and html block-level elements start a new line. Conversly, since opening a html block-level elements means starting a new line, any text that sould appear inside a paragraph must be translated using only html text-level elements. HEVEA chooses to translate in-text formulas that way.

HEVEA display mode allows more control on text placement, since entering display mode means opening a html `table` element and that tables allow to control the relative position of their sub-elements. Displays come in two flavor, horizontal displays and vertical displays. An horizontal display is a one-row table, while a vertical display is a one-column table. These tables holds display sub-elements, displays sub-elements being centered vertically in horizontal display mode and horizontally in vertical display mode.

Display mode is first opened by opening a `displaymath` environment (e.g. by `$$` or `\[`). Then, sub-displays are opened by LATEX constructs which require them. For instance, a displayed fraction (`\frac`) opens a vertical display.

The distinction between text and display modes clearly appears while typesetting math formulas. An in-text formula such as `$\int_1^2 xdx = \frac{3}{2}$` appears as: ∫12 xdx =3/2, while the same formula has a better aspect in display mode:

∫ |
2
1
| xdx = |
3
2

As a consequence, HEVEA is more powerful in display mode and formulas should be displayed as soon as they get a bit complicated. This rule is also true in LATEX but it is more strict in HEVEA, since html capabilities to typeset formulas inside text are quite poor. In particular, it is not possible to get in-text “real” fractions or in-text limit-like subscripts.

Users should remember that HEVEA is not TEX or LATEX and that HEVEA author neither is D. E. Knuth nor L. Lamport. Thus, some formulas may be rendered poorly. For instance, two fractions with different denominator and numerator height look strange.

1
N
∑
i=0
| Ui
| = |
N
∑
i=0
| Ui
1

The reason is that vertical displays in an horizontal display are html tables that always get centered in the vertical direction. Such a crude model cannot faithfully emulate any TEX box placement.

Users can get an idea on how HEVEA combines elements in display mode by giving the -dv command-line option, which instructs HEVEA to add borders to the `table` elements introduced by displays.

#### 3.2.4 Arrays and display mode

By contrast with formulas, which HEVEA attempts to render with text-level elements only when they appear inside paragraphs, LATEX arrays always translate to the block-level element `table`, thereby introducing non-desired line breaks before and after in-text arrays. As a consequence, in-text arrays yield an acceptable output, only while alone in a paragraph.

Consider the following source:

    This is a small array:
    \begin{tabular}{|cc|}
    \hline item-1 & item-2 \\
    \hline\end{tabular}. Next sentence.

We get:

> This is a small array:

> item-1 | item-2

> . Next sentence.

However, since in some sense, all html tables are displayed, the `array` and `tabular` environments implicitly open display mode, thus allowing a satisfactory typesetting of formulas in arrays. More precisely, array elements whose column format specification is `l`, `c` or `r` are typeset in display mode (see section B.10.2).

### 3.3 Warnings

When HEVEA thinks it cannot translate a symbol or construct properly, it issues a warning. This draws user attention onto a potential problem. However, rendering may be correct.

In the following (silly) example, HEVEA gets nervous because of the complicated length given as argument to `\hspace`:

    \newlength{\mylength}\setlength{\mylength}{5pt}
    \begin{tabular}{c@{\hspace{\mylength}}c}
    Before & After
    \end{tabular}

Running HEVEA on this input produces a warning:

    # hevea manual.tex
    ...
    manual.tex:507: Warning: \hspace with arg '\mylength'
    ...

However the final rendering is correct:

> Before |  | After

Note that all warnings can be suppressed with the `-s` (silent) option. When a warning reveals a real problem, it can often be cured by writing a specific macro. The next two sections introduce HEVEA macros, then section 4 describes how to proceed with greater detail.

### 3.4 Commands

Just like LATEX, HEVEA can be seen as a macro language, macros are rewritten until no more expansion is possible. Then, either some characters (such as letters, integers…) are outputed or some internal operation (such as changing font attributes, or arranging text items in a certain manner) are performed.

This scheme favors easy extension of program capabilities by users. However, predicting program behaviour and correcting errors may prove difficult, since final output or errors may occur after several levels of macro expansion. As a consequence, users can tailor HEVEA to their needs, but it remains a subtle task. Nevertheless, happy LATEX users should enjoy customizing HEVEA, since this is done by writing LATEX code.

### 3.5 Style choices

LATEX and html differ in many aspects. For instance, LATEX allows fine control over text placement, whereas html does not. More symbols and font attributes are available in LATEX than in html. Conversely, html has font attributes, such as color, which standard LATEX has not.

Therefore, there are many situations where HEVEA just cannot render the visual effect of LATEX constructions. Here some choices have to be made. For instance, calligraphic letters (`\mathcal`) are rendered in red.

If you are not satisfied with HEVEA rendering of text style declarations, then you can choose your own, by redefining the `\cal` macros, using `\renewcommand`, the macro redefinition operator of LATEX. The key point is that you need not worry about HEVEA internals: just redefine the old-LATEX style text-style declarations (i.e. `\it`, `\sc`, etc.) and everything should get fine:

    \renewcommand{\sc}{\Huge}
    \renewcommand{\cal}{\em}

(See sections 4 and 5 on how to make such changes while leaving your file processable by LATEX, and section 10.2 for a more thorough descripton of customizing type styles).

With such redefinitions, we get:

> This is small caps and this is CALLIGRAPHIC LETTERS

Note that many of LATEX commands and environments are defined in the hevea.hva file that HEVEA loads before processing any input. These constructs are written using LATEX source code, in the end they invoke HEVEA internal commands.

Other LATEX constructs, such as LATEX key constructs or HEVEA internal commands (see section 8.3), that require special processing are defined in HEVEA source code. However, the vast majority of these definitions can be overridden by a redefinition. This may prove useless, since there is little point in redefining core constructs such as `\newcommand` for instance.