Definitions, Numbering
Author: Luc Maranget

B.8 | Definitions, Numbering

- Defining Commands
- Defining Environments
- Theorem-like Environments
- Numbering
- The `ifthen` Package

B.8.1 | Defining Commands

HEVEA understands command definitions given in LATEX style. Such definitions are made using `\newcommand`, `\renewcommand` and `\providecommand`. These three constructs accept the same arguments and have the same meaning as in LATEX, in particular it is possible to define an user command with one optional argument. However, HEVEA is more tolerant: if command name already exists, then a subsequent `\newcommand{`name`}`...is ignored. If macro name does not exists, then `\renewcommand{`name`}`...performs a definition of name. In both cases, LATEX would crash, HEVEA just issues warnings.
The behavior of `\newcommand` allows to shadow document definition, provided the new definitions are processed before the document definitions. This is easily done by grouping the shadowing definition in a specific style file given as an argument to HEVEA (see section 5.1). Conversely, changes of base macros (i.e., the ones that HEVEA defines before loading any user-specified file) must be performed using `\renewcommand`.
Scoping rules apply to macros, as they do in LATEX. Environments and groups define a scope and command definition are local to the scope they occur.
It is worth noticing that HEVEA also partly implements TeX definitions (using `\def`) and bindings (using `\let`), see section B.16.2 for details.

B.8.2 | Defining Environments

HEVEA accepts environment definitions and redefinitions by `\newenvironment` and `\renewenvironment`. The support is complete and should conform to [LATEX, Sections C.8.2].
Environments define a scope both for commands and environment definitions.

B.8.3 | Theorem-like Environments

New theorem-like environments can also be introduced and redefined, using `\newtheorem` and `\renewtheorem`.
Note that, by contrast with plain environments definitions, theorem-like environment definitions are global definitions.

B.8.4 | Numbering

LATEX counters are (fully ?) supported. In particular, defining a counter cmd with `\newcounter{`cmd`}` creates a macro `\the`cmd that outputs the counter value. Then the `\the`cmd command can be redefined. For instance, section numbering can be turned into alphabetic style by:

    \renewcommand{\thesection}{\alph{section}}

Note that TeX style for counters is not supported at all and that using this style will clobber the output. However, HEVEA implements the calc package that makes using TeX style for counters useless in most situations (see section B.17.3).

B.8.5 | The `ifthen` Package

The `ifthen` package is partially supported. The one unsupported construct is the `\lengthtest` test expression, which is undefined.
As a consequence, HEVEA accepts the following example from the LATEX manual:

    \newcounter{ca}\newcounter{cb}%
    \newcommand{\printgcd}[2]{%
      \setcounter{ca}{#1}\setcounter{cb}{#2}%
      Gcd(#1,#2) =
      \whiledo{\not\(\value{ca}= \value{cb}\)}%
        {\ifthenelse{\value{ca}>\value{cb}}%
          {\addtocounter{ca}{-\value{cb}}}%
          {\addtocounter{cb}{-\value{ca}}}%
        gcd(\arabic{ca}, \arabic{cb}) = }%
      \arabic{ca}.}%
    For example: \printgcd{54}{30}

For example: Gcd(54,30) = gcd(24, 30) = gcd(24, 6) = gcd(18, 6) = gcd(12, 6) = gcd(6, 6) = 6.
Additionally, a few boolean registers are defined by HEVEA. Some of them are of interest to users.

`hevea`
  Initial value is `true`. The `hevea.sty` style file also defines this register with initial value false.
`mmode`
  This register value reflects HEVEA operating mode, it is true in math-mode and false otherwise.
`display`
  This register value reflects HEVEA operating mode, it is true in display-mode and false otherwise.
`french`
  This register value reflects the `-french` command line option internally (see Section C.1.1.4).
`footer`
  Initial value is `true`. When set false, HEVEA does not insert its footer ``This document has been translated by HEVEA''.

Finally, note that HEVEA also recognized à la TeX conditional macros (see section B.16.2.4). Such macros are fully compatible with the boolean registers of the `ifthen` package, as it is the case in LATEX.