summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luamaths/luamaths.sty
blob: 59fd29f4345802cd622dba45debd77d487d46d14 (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
% The luamaths package
% version 1.6
% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
%Authors: Chetan Shirore and Ajit Kumar

\ProvidesPackage{luamaths}[1.6]
\RequirePackage{xkeyval}
\RequirePackage{amsmath}
\RequirePackage{luacode}
\begin{luacode*}
--load luamaths-complex and luamaths-fractions modules.
local complex = require "luamaths-complex"
local lfrac = require "luamaths-fractions"
--define lua function for evaluating expressions.
function mathop(...)
inf = math.huge
return ...
end
--define lua function for rounding numbers.
function mathround(num, numDecimalPlaces)
    if num==math.floor(num) then
     return math.floor(num)
    end
  local mult = 10^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
end
\end{luacode*}
\newcommand\mathOp[1]{\directlua{tex.sprint(tostring(mathop(#1)))}}
\newcommand\mathAbs[1]{\directlua{tex.sprint(math.abs(#1))}}
\newcommand\mathAcos[1]{\directlua{tex.sprint(math.acos(#1))}}
\newcommand\mathAsin[1]{\directlua{tex.sprint(math.asin(#1))}}
\newcommand\mathAtan[1]{\directlua{tex.sprint(math.atan(#1))}}
\newcommand\mathCeil[1]{\directlua{tex.sprint(math.ceil(#1))}}
\newcommand\mathCos[1]{\directlua{tex.sprint(math.cos(#1))}}
\newcommand\mathExp[1]{\directlua{tex.sprint(math.exp(#1))}}
\newcommand\mathFloor[1]{\directlua{tex.sprint(math.floor(#1))}}
\newcommand\mathInf{\directlua{tex.sprint(math.huge)}}
\newcommand\mathLog[1]{\directlua{tex.sprint(math.log(#1))}}
\newcommand\mathMax[1]{\directlua{tex.sprint(math.max(#1))}}
\newcommand\mathMin[1]{\directlua{tex.sprint(math.min(#1))}}
\newcommand\mathPi{\directlua{tex.sprint(math.pi)}}
\newcommand\mathRandom[1]{\directlua{tex.sprint(math.random(#1))}}
\newcommand\mathSin[1]{\directlua{tex.sprint(tostring(math.sin(#1)))}}
\newcommand\mathSqrt[1]{\directlua{tex.sprint(math.sqrt(#1))}}
\newcommand\mathTan[1]{\directlua{tex.sprint(math.tan(#1))}}
\newcommand\mathRad[1]{\directlua{tex.sprint(math.rad(#1))}}
\newcommand\mathRound[2]{\directlua{tex.sprint(mathround(#1,#2))}}
\newcommand\complexRound[2]{%
\directlua{%
tex.sprint(complex.tostring(complex.round(#1,#2)))
}%
}%
\newcommand{\imUnit}{\mathrm{i}}
\newcommand\luaChkeqnum[2]{%
\directlua{%
tex.sprint(tostring(lnumChqEql(#1,#2)))%
}%
}

\endinput