0% found this document useful (0 votes)
6 views

onlyamsmath

Uploaded by

wemakev293
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

onlyamsmath

Uploaded by

wemakev293
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

The onlyamsmath package

Harald Harders
[email protected]

Version v0.20, 2016/12/18, printed January 8, 2017

Abstract
This package inhibits the usage of plain TEX and on demand of standard
LATEX 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, 2012, 2016 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 l eft equations)
switched on:
a = b.
eqnarray 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.

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

a = b.

all The most brutal option is all that inhibits the writer to use any of the TEX and
LATEX 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].
error 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
LATEX generates an error message that reminds you to use the environments of the
amsmath package.
warning If using warning LATEX only produces warnings and proceeds.
nodollardollar If nodollardollar is used, the $ catcode is not changed. This way, the plain
TEX $$ macro can still be used. This option helps to avoid issues with recent
versions of TikZ/PGF but might have other side effects.

Acknowledgement
David Kastrup ([email protected]) 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.
Reinhard Kotucha has reported the problem with recent TikZ/PGF and
also identified that changing the $ catcode caused the issues. The class option
nodollardollar has been introduced to resolve this incompatibility.

2 The implementation
Package header:
1 hpackagei\ProvidesPackage{onlyamsmath}
2 hversioni\ProvidesFile{onlyamsmath-v.tex}
3 hpackage, versioni [2016/12/18 v0.20 Destroy the standard math environments]

Load amsmath package:


4 \RequirePackage{amsmath}

2.1 Options
All options set a boolean variable which is named simular to the option name.
Define the eqnarray option:
5 \newif\ifonlyams@eqnarray
6 \DeclareOption{eqnarray}{\onlyams@eqnarraytrue}

2
Define the all option:
7 \newif\ifonlyams@all
8 \DeclareOption{all}{
9 \onlyams@alltrue
10 \onlyams@eqnarraytrue
11 }

Define the error and warning options:


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

Define the nodollardollar option:


16 \newif\ifonlyams@nodollardollar
17 \DeclareOption{nodollardollar}{\onlyams@nodollardollartrue}
Set the default options:
18 \ExecuteOptions{error}
Process the options:
19 \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.
20 \newcommand{\onlyams@error}[1]{%
21 \ifonlyams@error
22 \PackageError{onlyamsmath}{Environment #1 used}{Please use only the
23 environments provided by the amsmath package.}%
24 \else
25 \PackageWarning{onlyamsmath}{Environment #1 used, please use
26 \MessageBreak only the environments provided by the amsmath
27 \MessageBreak package}%
28 \fi
29 }

Here follows the part that is only executed when one of the options eqnarray
or all is used:
30 \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:
31 \let\onlyams@eqnarray\eqnarray

eqnarray Redefine the \eqnarray command:


32 \def\eqnarray{%

3
First generate an error or warning message:
33 \onlyams@error{eqnarray or eqnarray*}%
Then call the original eqnarray environment:
34 \onlyams@eqnarray}
35 \fi

Here follows the part that is only executed when the option all is used:
36 \ifonlyams@all

displaymath Redefine the \displaymath command:


37 \def\displaymath{%
First generate an error or warning message:
38 \onlyams@error{displaymath}%
Then call the \[ environment which normally is called by the displaymath envi-
ronment:
39 \[}

40 \fi
Redefine the $$ environment. This part wass written by David Kastrup. Please
don’t ask me anything about it.
\dollarcode
41 \def\dollarcode{\ifx\protect\@typeset@protect
42 \expandafter\futurelet\expandafter\next\expandafter\checkdsp
43 \else \expandafter$\fi}
44 \begingroup
45 \lccode‘\~=‘\$
46 \lowercase{\endgroup\let~}\dollarcode

\defdsp
47 \def\checkdsp{\ifx\next\dollarcode\expandafter\dspcomplain
48 \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 $$.
49 \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 \]:
50 \ifmmode
51 \expandafter \]%
52 \else
If the mathmode isn’t active the first $$ of a mathematical environment has been
found. First generate the warning or error message:
53 \onlyams@error{$$ $$}%

4
Then start the mathmode by using \[:
54 \expandafter \[
55 \fi}

Activate the complaining behaviour at \begin{document} to ensure that packages


that internally use $$ can do that without an error:
56 \ifonlyams@nodollardollar
57 \else
58 \AtBeginDocument{\catcode‘\$=13 }
59 \fi

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

Change History

0.01 \[. . . \] . . . . . . . . . . . . . . . . . 3
General: First version . . . . . . . . . 1 0.10
0.02 General: Explicitly state date and
General: Added switch nodollardollar version in \ProvidesPackage
........................ 2 statement . . . . . . . . . . . . . . . . 1
0.03
Update documentation . . . . . . . 1
General: Changed definition of
\dollarcode, by David Kas- Update e-mail address . . . . . . . 1
trup . . . . . . . . . . . . . . . . . . . . 4 0.20
Removed switches dollardollar General: Added switch nodollardollar
and nodollardollar . . . . . . . . 2 again (prevent from changing
0.04 catcode to avoid issues with
General: Removed code that forbids TikZ/PGF) . . . . . . . . . . . . . . 1

Index
Numbers written in italic refer to the page where the corresponding entry is de-
scribed; numbers underlined refer to the code line of the definition; numbers in
roman refer to the code lines where the entry is used.

Symbols A D
\$ . . . . . . . . . . . . 45, 58 \all . . . . . . . . . . . . . . 2 \DeclareOption . . . .
\AtBeginDocument . . 58 . . . 6, 8, 14, 15, 17
\@typeset@protect . 41
\defdsp . . . . . . . . . . 47
\[ . . . . . . . . . . . . 39, 54 C \displaymath . . . . . . 37
\] . . . . . . . . . . . . . . 51 \catcode . . . . . . . . . 58 displaymath (environ-
\~ . . . . . . . . . . . . . . 45 \checkdsp . . . . . . 42, 47 ment) . . . . . . . 37

5
\dollarcode . . 41, 46, 47 \ifonlyams@eqnarray \onlyams@error . . . .
\dspcomplain . . . . 47, 49 . . . . . . . . . . 5, 30 . . . . 20, 33, 38, 53
\ifonlyams@error 12, 21 \onlyams@errorfalse 15
E \ifonlyams@nodollardollar \onlyams@errortrue .
\else . . 24, 43, 48, 52, 57 . . . . . . . . . 16, 56 . . . . . . . . . 13, 14
environments: \ifx . . . . . . . . . . . 41, 47 \onlyams@nodollardollartrue
displaymath . . . . 37
. . . . . . . . . . . . 17
eqnarray . . . . . . 32 L
\eqnarray . . . . 1, 31, 32 \lccode . . . . . . . . . . 45
P
eqnarray (environ- \lowercase . . . . . . . 46
ment) . . . . . . . 32 \PackageError . . . . . 22
\error . . . . . . . . . . . . 2 M \PackageWarning . . . 25
\ExecuteOptions . . . 18 \MessageBreak . . . 26, 27 \ProcessOptions . . . 19
\expandafter . . . 42, \protect . . . . . . . . . 41
43, 47, 48, 51, 54 N \ProvidesFile . . . . .. 2
\newif . . . . . 5, 7, 12, 16 \ProvidesPackage . .. 1
F \next . . . . . . . . . . 42, 47
\fi . . . . . . . . 28, 35, \nodollardollar . . . . 2
R
40, 43, 48, 55, 59
O \relax . . . . . . . . . . . 19
\futurelet . . . . . . . 42
\onlyams@alltrue . . . 9 \RequirePackage . . . . 4
I \onlyams@eqnarray 31, 34
\ifmmode . . . . . . . . . 50 \onlyams@eqnarraytrue W
\ifonlyams@all . . . 7, 36 . . . . . . . . . . 6, 10 \warning . . . . . . . . . . 2

You might also like