summaryrefslogtreecommitdiff
path: root/tex/context/modules/mkiv/x-calcmath.mkiv
blob: dda88bb3ee53cb6247fa7fe6da541ee38a88ed4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
%D \module
%D   [       file=m-calcmath,
%D        version=2006.04.24, % 1999.11.06,
%D          title=\CONTEXT\ Modules,
%D       subtitle=Calculator Math,
%D         author=Hans Hagen,
%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.

%D Lua code.

\registerctxluafile{x-calcmath}{}

\def\ctxmodulecalcmath#1{\ctxlua{moduledata.calcmath.#1}}

%D Interface:

\unprotect

\unexpanded\def\inlinecalcmath #1{\mathematics{\ctxmodulecalcmath{tex("#1",1)}}}
\unexpanded\def\displaycalcmath#1{\startformula\ctxmodulecalcmath{tex("#1",2)}\stopformula}

\let\calcmath\inlinecalcmath

\let\icm\inlinecalcmath
\let\dcm\displaycalcmath

\startxmlsetups xml:cam:define
    \xmlsetsetup {\xmldocument} {cam:*}     {*}
    \xmlsetsetup {\xmldocument} {(icm|dcm)} {cam:*}
\stopxmlsetups

\xmlregisterns{cam}{calcmath}

\xmlregistersetup{xml:cam:define}

% tex -> lua -> tex -> lua -> tex
%   \mathematics{\ctxmodulecalcmath{xml(\!!bs\xmlflush{#1}\!!es,1)}}
% tex -> lua -> tex
%   \mathematics{\ctxmodulecalcmath{xml("#1",1)}}%

\startxmlsetups cam:i
    \mathematics{\ctxmodulecalcmath{xml("#1",1)}}%
\stopxmlsetups

\startxmlsetups cam:d
    \startformula\ctxmodulecalcmath{xml("#1",2)}\stopformula
\stopxmlsetups

\startxmlsetups cam:icm
    \mathematics{\ctxmodulecalcmath{xml("#1",1)}}
\stopxmlsetups

\startxmlsetups cam:dcm
    \startformula\ctxmodulecalcmath{xml("#1",2)}\stopformula
\stopxmlsetups

\protect \endinput

\starttext

% \calcmath{sin(x) + x^2 + x^(1+x) + 1/x^2 + mean(x+mean(y))}
% \calcmath{int(a,b,c)}
% \calcmath{(1+x)/(1+x) + (1+x)/(1+(1+x)/(1+x))}
% \calcmath{10E-2}
% \calcmath{(1+x)/x}
% \calcmath{(1+x)/12}
% \calcmath{(1+x)/-12}
% \calcmath{1/-12}
% \calcmath{12x/(1+x)}
% \calcmath{exp(x+exp(x+1))}
% \calcmath{abs(x+abs(x+1)) + pi + inf}
% \calcmath{Dx Dy}
% \calcmath{D(x+D(y))}
% \calcmath{Df(x)}
% \calcmath{g(x)}