    %D \module
%D   [       file=math-tex,
%D        version=2001.04.12,
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=Definitions,
%D         author={Hans Hagen, Taco Hoekwater \& Aditya Mahajan},
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Math Macros / Definitions}

\unprotect

\pushoverloadmode % cap etc

\startluacode
    mathematics.define()
 -- mathematics.xml.registerentities()
\stopluacode

\popoverloadmode

% \activatemathcharacters

%D The \mfunction macro is an alternative for \hbox with a controlable font switch.

\definemathfunction [arccos]
\definemathfunction [arcsin]
\definemathfunction [arctan]
\definemathfunction [arccosh]
\definemathfunction [arcsinh]
\definemathfunction [arctanh]
\definemathfunction [acos]
\definemathfunction [asin]
\definemathfunction [atan]
\definemathfunction [arg]
\definemathfunction [cosh]
\definemathfunction [cos]
\definemathfunction [coth]
\definemathfunction [cot]
\definemathfunction [csc]
\definemathfunction [deg]
\definemathfunction [det]     [\c!mathlimits=\v!yes]
\definemathfunction [dim]
\definemathfunction [erf]
\definemathfunction [erfc]
\definemathfunction [erfi]
\definemathfunction [exp]
\definemathfunction [gcd]     [\c!mathlimits=\v!yes]
\definemathfunction [hom]
\definemathfunction [inf]     [\c!mathlimits=\v!auto]
\definemathfunction [inv]     [\c!mathlimits=\v!auto]
\definemathfunction [injlim]  [\c!mathlimits=\v!auto]
\definemathfunction [ker]
\definemathfunction [lg]
\definemathfunction [liminf]  [\c!mathlimits=\v!auto,\c!method=limits]
\definemathfunction [limsup]  [\c!mathlimits=\v!auto,\c!method=limits]
\definemathfunction [lim]     [\c!mathlimits=\v!auto,\c!method=limits]
\definemathfunction [ln]
\definemathfunction [log]
\definemathfunction [median]  [\c!mathlimits=\v!yes]
\definemathfunction [max]     [\c!mathlimits=\v!auto]
\definemathfunction [min]     [\c!mathlimits=\v!auto]
\definemathfunction [mod]     [\c!mathlimits=\v!yes]
%definemathfunction [div]     [\c!mathlimits=\v!yes]
\definemathfunction [projlim] [\c!mathlimits=\v!auto]
\definemathfunction [Pr]      [\c!mathlimits=\v!yes]
\definemathfunction [sec]
\definemathfunction [sinh]
\definemathfunction [sin]
\definemathfunction [sup]     [\c!mathlimits=\v!auto]
\definemathfunction [tanh]
\definemathfunction [tan]
\definemathfunction [diff]

\definemathfunction [adj]
\definemathfunction [coker]

% When [\c!command=] the label kicks in:

\definemathfunction [cs:median] [\c!command=\widetilde]
\definemathfunction [sk:median] [\c!command=\widetilde]

% Maybe set a method as well to signal the order

%definemathfunction[partial]              [class=differential]
%definemathfunction[gradient]             [class=differential]
\definemathfunction[adjoint]              [right=\adjointsymbol]
\definemathfunction[orthogonalcomplement] [right=\orthogonalcomplementsymbol]
\definemathfunction[transpose]            [right=\transposesymbol]
\definemathfunction[derivative]           [right=\derivativesymbol]
\definemathfunction[secondderivative]     [right=\secondderivativesymbol]
\definemathfunction[thirdderivative]      [right=\thirdderivativesymbol]
\definemathfunction[fourthderivative]     [right=\fourthderivativesymbol]
\definemathfunction[preimage]             [right=\preimagesymbol]
\definemathfunction[inverse]              [right=\inversesymbol]

% \definemathfunction[laplace]      [class=differential]
% \definemathfunction[crossproduct] [class=binary]
% \definemathfunction[scalarproduct][class=binary]
% \definemathfunction[complement]
\definemathfunction[neg]

\aliased\let\normalmatharg\arg % todo: maybe automatically

%D \macros
%D   {centercolon, colonminus, minuscolon, colonequals, equalscolon,
%D    colonapprox, approxcolon, colonsim, simcolon, coloncolon,
%D    coloncolonminus, minuscoloncolon, coloncolonequals,
%D    equalscoloncolon, coloncolonapprox, approxcoloncolon,
%D    colonsim, simcoloncolon}
%D
%D The following colon related definitions are provided by Aditya Mahajan who
%D derived them from \type {mathtools.sty} and \type {colonequals.sty}. This will be
%D redone as part of the overhaul and font updates.
%D
%D In $a := b$ the colon is not vertically centered with the equal to. Also the
%D distance between colon and equal to is a bit large. So, we define a vertically
%D centered colon \tex {centercolon} and a few macros for colon and double colon
%D relation symbols.
%D
%D \startlines
%D \formula {A \centercolon       B}
%D \formula {A \colonminus        B}
%D \formula {A \minuscolon        B}
%D \formula {A \colonequals       B}
%D \formula {A \equalscolon       B}
%D \formula {A \colonapprox       B}
%D \formula {A \approxcolon       B}
%D \formula {A \colonsim          B}
%D \formula {A \simcolon          B}
%D \formula {A \coloncolon        B}
%D \formula {A \coloncolonminus   B}
%D \formula {A \minuscoloncolon   B}
%D \formula {A \coloncolonequals  B}
%D \formula {A \equalscoloncolon  B}
%D \formula {A \coloncolonapprox  B}
%D \formula {A \approxcoloncolon  B}
%D \formula {A \colonsim          B}
%D \formula {A \simcoloncolon     B}
%D \stoplines
%D
%D The next macros take care of the space between the colon and the relation symbol,
%D but they are kind of weird and not in \UNICODE. Either we define them virtual or
%D we just keep these as bonus.

\pushoverloadmode

\protected\def\math_relation_atom_ordinary{\mathatom \s!class \mathrelationcode \s!all \mathordcode}

\definemathcommand [centercolon]      {\math_relation_atom_ordinary{\colon}}
\definemathcommand [colonminus]       {\math_relation_atom_ordinary{\colon\minus}}
\definemathcommand [colonapprox]      {\math_relation_atom_ordinary{\colon\approx}}
\definemathcommand [approxcolon]      {\math_relation_atom_ordinary{\approx\colon}}
\definemathcommand [colonsim]         {\math_relation_atom_ordinary{\colon\sim}}
\definemathcommand [simcolon]         {\math_relation_atom_ordinary{\sim\colon}}

\definemathcommand [coloncolon]       {\math_relation_atom_ordinary{\colon\colon}}
\definemathcommand [coloncolonminus]  {\math_relation_atom_ordinary{\colon\colon\minus}}
\definemathcommand [minuscoloncolon]  {\math_relation_atom_ordinary{\minus\colon\colon}}
\definemathcommand [coloncolonequals] {\math_relation_atom_ordinary{\colon\colon\eq}} % native char
\definemathcommand [equalscoloncolon] {\math_relation_atom_ordinary{\eq\colon\colon}}
\definemathcommand [coloncolonapprox] {\math_relation_atom_ordinary{\colon\colon\approx}}
\definemathcommand [approxcoloncolon] {\math_relation_atom_ordinary{\approx\colon\colon}}
\definemathcommand [coloncolonsim]    {\math_relation_atom_ordinary{\colon\colon\sim}}
\definemathcommand [simcoloncolon]    {\math_relation_atom_ordinary{\sim\colon\colon}}

% \definemathcommand [manycolons] [relation] [ordinary] {\colon\colon\colon\colon\colon\colon\colon}

\popoverloadmode

%D \macros
%D   {amedian}
%D
%D Something language specific, the arithmic median:
%D
%D \starttyping
%D                   \im {x + \amedian {x - a} + x}
%D \mainlanguage[cs] \im {x + \amedian {x - a} + x}
%D \stoptyping

\defcsname \s!en:amedian\endcsname#1{\widebar  {#1}}
\defcsname \s!cs:amedian\endcsname#1{\widetilde{#1}}
\defcsname \s!sk:amedian\endcsname#1{\widetilde{#1}}

\permanent\protected\def\amedian
  {\csname
     \ifcsname\currentmainlanguage:amedian\endcsname
       \currentmainlanguage\else\s!en
     \fi
     :amedian%
   \endcsname}

% \appendtoks
%     \def\over{\primitive\over}%
% \to \everymathematics

\protect \endinput
