         The onlyamsmath package^{∗}

Harald Harders

                   h.harders@tu-bs.de

File date 2001/10/04, compiled October 4, 2001

Abstract

This package inhibits the usage of plain TEX and on demand of standard L^{A}TEX math environments. This is useful for class writers who want to force their clients to use the environments provided by the amsmath package.

Contents

1 Usage of the package 1

2 The implementation 2 2.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.2 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Copyright

Copyright 2001 Harald Harders.

This program can be redistributed and/or modified under the terms of the LaTeX Project Public License Distributed from CTAN archives in directory macros/latex/base/lppl.txt; either version 1 of the License, or any later version.

1 Usage of the package

Just load the package using \usepackage[options]{onlyamsmath}. If no option is given only the plain TEX environment $$… $$ is “destroyed”. This environment leads to centred equations even with the global option fleqn (f orce left equations) switched on:

a = b .

One further option is eqnarray to switch off the eqnarray and eqnarray* environments that add an unwished space before and after the aligned part of the formula as shown here:

a = b .

∗This file is version 0.04 last revision 2001/10/04, documentation from 2001/10/04.

A better result is achieved using the align environment provided by amsmath.sty:

a = b .

The most brutal option is all that inhibits the writer to use any of the TEX and L^{A}TEX math environments for non-inlined equations I know ($$… $$, eqnarray, eqnarray*, displaymath. The inlined mathematical modes ($… $, \(… \)) still work.

Then instead use the environments provided by amsmath.sty: equation,

align, gather, flalign, multiline, alignat, and split. All environments

except split have a starred variant. See the User’s Guide of the amsmath package for further details [1].

There are two more options that control the behaviour of the package if you still use one of the “forbidden” environments. If using error which is the default L^{A}TEX generates an error message that reminds you to use the environments of the amsmath package.

If using warning L^{A}TEX only produces warnings and proceeds.

Acknowledgement

David Kastrup (David.Kastrup@t-online.de) has written the part handling $$. I just have changed the call of the command producing the error message. Since I do not understand his code please don’t ask me things regarding it.

2 The implementation

Package header:

 1 \ProvidesPackage{onlyamsmath}[\onlyamsfiledate\space
 2 v\onlyamsversion\space destroy the standard math environments]

Load amsmath package:

 3 \RequirePackage{amsmath}

2.1 Options

All options set a boolean variable which is named simular to the option name.

Define the eqnarray option:

 4 \newif\ifonlyams@eqnarray
 5 \DeclareOption{eqnarray}{\onlyams@eqnarraytrue}

Define the all option:

 6 \newif\ifonlyams@all
 7 \DeclareOption{all}{
 8 \onlyams@alltrue
 9 \onlyams@eqnarraytrue

10 }

Define the error and warning options:

11 \newif\ifonlyams@error
12 \onlyams@errortrue
13 \DeclareOption{error}{\onlyams@errortrue}
14 \DeclareOption{warning}{\onlyams@errorfalse}

Set the default options:

15 \ExecuteOptions{error}

Process the options:

16 \ProcessOptions\relax

2.2 Commands

\onlyams@error Define a command that produces the error resp. warning messages. The argument specifies the name of the environment that produced the message.

17 \newcommand{\onlyams@error}[1]{%
18 \ifonlyams@error
19  \PackageError{onlyamsmath}{Environment #1 used}{Please use only the
20  environments provided by the amsmath package.}%
21 \else
22  \PackageWarning{onlyamsmath}{Environment #1 used, please use
23  \MessageBreak only the environments provided by the amsmath
24  \MessageBreak package}%
25 \fi

26 }

Here follows the part that is only executed when one of the options eqnarray or all is used:

27 \ifonlyams@eqnarray

\onlyams@eqnarray Copy the original \eqnarray command which is called by the commands

\begin{eqnarray} and \begin{eqnarray*} to be able to call it after produc-

ing the correspondig error message:

28 \let\onlyams@eqnarray\eqnarray

eqnarray Redefine the \eqnarray command:

29 \def\eqnarray{%

First generate an error or warning message:

30  \onlyams@error{eqnarray or eqnarray*}%

Then call the original eqnarray environment:

31  \onlyams@eqnarray}
32 \fi

Here follows the part that is only executed when the option all is used:

33 \ifonlyams@all
displaymath Redefine the \displaymath command:
34 \def\displaymath{%

First generate an error or warning message:

35  \onlyams@error{displaymath}%

Then call the \[ environment which normally is called by the displaymath environment:

36  \[}
37 \fi

Redefine the $$ environment. This part wass written by David Kastrup. Please don’t ask me anything about it.

\dollarcode
38 \def\dollarcode{\ifx\protect\@typeset@protect
39 \expandafter\futurelet\expandafter\next\expandafter\checkdsp
40 \else \expandafter$\fi}
41 \begingroup
42 \lccode`\~=`\$
43 \lowercase{\endgroup\let~}\dollarcode
\defdsp
44 \def\checkdsp{\ifx\next\dollarcode\expandafter\dspcomplain
45 \else\expandafter$\fi}

Now comes the part that I understand and in which I have made changes.

\dspcomplain This command controls the complaint when using $$.

46 \def\dspcomplain#1{%

If mathmode is active the code has found the second $$ of the environment. The complaint has already made and it is not necessary to do generate one. The environment has to be closed by using \]:

47 \ifmmode
48  \expandafter \]%
49 \else

If the mathmode isn’t active the first $$ of a mathematical environment has been found. First generate the warning or error message:

50  \onlyams@error{$$ $$}%

Then start the mathmode by using \[:

51  \expandafter \[
52 \fi}

Activate the complaining behaviour at \begin{document} to ensure that packages that internally use $$ can do that without an error:

53 \AtBeginDocument{\catcode`\$=13 }

References

[1] User’s Guide for the amsmath Package. American Mathematical Society, 1999/12/13.

Change History

0.01

General: First version . . . . . . . . . 1 0.02

General: Added switch nodollardollar . . . . . . . . . . . . . . . . . . . . . . . . 2 0.03

General: Changed definition of \dollarcode, by David Kastrup . . . . . . . . . . . . . . . . . . . . 4 Removed switches dollardollar

      and nodollardollar . . . . . . . . 2

0.04 General: Removed code that forbids

\[… \] . . . . . . . . . . . . . . . . . 3

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones underlined to the code line of the definition, the rest to the code lines where the entry is used.

Symbols

\$ . . . . . . . . . . . . 42, 53

\@typeset@protect . 38

\[ . . . . . . . . . . . . 36, 51 \] . . . . . . . . . . . . . . 48 \~ . . . . . . . . . . . . . . 42

A

\AtBeginDocument . . 53

C

\catcode . . . . . . . . . 53 \checkdsp . . . . . . 39, 44

D

\DeclareOption . . . .

. . . . . . 5, 7, 13, 14 \defdsp . . . . . . . . . . \underline{44}

\displaymath . . . . . . 34
displaymath (environ-

ment) . . . . . . . \underline{34}

\dollarcode . . \underline{38}, 43, 44
\dspcomplain . . . . 44, \underline{46}

E

\else …. 21, 40, 45, 49 environments:

   displaymath . . . . \underline{34}

                             eqnarray . . . . . . \underline{29}

\eqnarray . . . . . . 28, 29 eqnarray (environ-

ment) . . . . . . . \underline{29}

                          \ExecuteOptions . . . 15
                          \expandafter . . . 39,

40, 44, 45, 48, 51

F \fi 25, 32, 37, 40, 45, 52

                          \futurelet . . . . . . . 39

I \ifmmode . . . . . . . . . 47

                          \ifonlyams@all . . . 6, 33
                          \ifonlyams@eqnarray

. . . . . . . . . . 4, 27

                          \ifonlyams@error 11, 18

\ifx . . . . . . . . . . . 38, 44

L \lccode . . . . . . . . . . 42

                          \lowercase . . . . . . . 43

M

                          \MessageBreak . . . 23, 24

N \newif . . . . . . . . 4, 6, 11 \next . . . . . . . . . . 39, 44

O

                                                   \onlyams@alltrue . . . 8
                                                   \onlyams@eqnarray  \underline{28}, 31
                                                   \onlyams@eqnarraytrue

. . . . . . . . . . . 5, 9

                                                   \onlyams@error . . . .

…. \underline{17}, 30, 35, 50

                                                   \onlyams@errorfalse 14
                                                   \onlyams@errortrue .

. . . . . . . . . 12, 13

                                                   \onlyamsfiledate . . . 1
                                                   \onlyamsversion . . . . 2

P

                                                   \PackageError . . . . . 19
                                                   \PackageWarning . . . 22
                                                   \ProcessOptions . . . 16

\protect . . . . . . . . . 38

                                                   \ProvidesPackage . . . 1

R \relax . . . . . . . . . . . 16

                                                   \RequirePackage . . . . 3