% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 13.1.4, p. II-158.
% Original source in file "math1.TEX", starting line 211.
\wlog{L: "mathenv.tip" ["math1.TEX," l. 211, p. II-158]}%
% This file DOES belong to format "texip."
\def\BeginMath{%
    \ifmath
        \ifinner
            \errmessage{\string\BeginMath: already in math
                mode, \string\BeginMath ignored.}%
        \else
            \errmessage{\string\BeginMath: in display math
                mode, terminated and math mode started.}%
            $$
            $
        \fi
    \else
        $\relax
    \fi
}
\def\EndMath{%
    \ifmath
        \ifinner
            $%
        \else
            \errmessage{\string\EndMath: you are in display math
                mode! Should have used \string\EndDisplayMath!}%
            $$
        \fi
    \else
        \errmessage{\string\EndMath: already in math
            mode, \string\EndMath ignored.}%
    \fi
}
\def\BeginDisplayMath{%
    \ifmath
        \ifinner
            \errmessage{\string\BeginDisplayMath: in inline
                math mode, terminate it, start display math.}%
            $
            $$
        \else
            \errmessage{\string\BeginDisplayMath: already in math
                mode, \string\BeginDisplayMath ignored.}%
        \fi
    \else
        $$
    \fi
}
\def\EndDisplayMath{%
    \ifmath
        \ifinner
            \errmessage{\string\EndDisplayMath: inline
                math mode in effect, did you intend to
                write \string\EndMath?}%
            $%
        \else
            $$
        \fi
    \else
        \errmessage{\string\EndDisplayMath: not in math
            mode, \string\EndDisplayMath ignored.}%
    \fi
}