summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luamaths
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-08-04 03:01:07 +0000
committerNorbert Preining <norbert@preining.info>2023-08-04 03:01:07 +0000
commit319c90e45fc96ba6f15edcf00b24e484d9d92f2b (patch)
tree7011e82643aff6842597d83574783a350142063c /macros/luatex/latex/luamaths
parent63c1aaa794cb47fe36ebe8010257ec8ad322efbb (diff)
CTAN sync 202308040301
Diffstat (limited to 'macros/luatex/latex/luamaths')
-rw-r--r--macros/luatex/latex/luamaths/README.txt9
-rw-r--r--macros/luatex/latex/luamaths/luamaths-complex.lua347
-rw-r--r--macros/luatex/latex/luamaths/luamaths-fractions.lua225
-rw-r--r--macros/luatex/latex/luamaths/luamaths.pdfbin176909 -> 145138 bytes
-rw-r--r--macros/luatex/latex/luamaths/luamaths.sty24
-rw-r--r--macros/luatex/latex/luamaths/luamaths.tex140
6 files changed, 705 insertions, 40 deletions
diff --git a/macros/luatex/latex/luamaths/README.txt b/macros/luatex/latex/luamaths/README.txt
index 02466225a8..926a94962c 100644
--- a/macros/luatex/latex/luamaths/README.txt
+++ b/macros/luatex/latex/luamaths/README.txt
@@ -1,10 +1,13 @@
+# The luamaths package
+# version 1.1
+# Authors: Chetan Shirore and Ajit Kumar
+# Email: mathsbeauty@gmail.com
+
# Introduction
The luamaths package is developed to perform standard mathematical operations inside LaTeX documents using Lua.
It provides an easy way to perform standard mathematical operations.
There is no particular environment in the package for performing mathematical operations.
-The package commands can be used in any environment (including the mathematics environment).
-
-
+
# License
The luamaths package is released under the LaTeX Project Public License v1.3c or later.
The complete license text is available at http://www.latex-project.org/lppl.txt.
diff --git a/macros/luatex/latex/luamaths/luamaths-complex.lua b/macros/luatex/latex/luamaths/luamaths-complex.lua
new file mode 100644
index 0000000000..68fd055b5e
--- /dev/null
+++ b/macros/luatex/latex/luamaths/luamaths-complex.lua
@@ -0,0 +1,347 @@
+--Version=1.3, Date=30-July-2023
+-- provides module for complex numbers
+--Contains a modified version of the file complex.lua. It is availalbe on the link https://github.com/davidm/lua-matrix/blob/master/lua/complex.lua. This is licensed under the same terms as Lua itself. This license allows to freely copy, modify and distribute the file for any purpose and without any restrictions.
+--Licensed under the same terms as Lua itself. This license allows to freely copy, modify and distribute the file for any purpose and without any restrictions.
+
+frac= require("luamaths-fractions")
+complex = {}
+complex_meta = {}
+
+local function parse_scalar(s, pos0)
+ local x, n, pos = s:match('^([+-]?[%d%.]+)(.?)()', pos0)
+ if not x then return end
+ if n == 'e' or n == 'E' then
+ local x2, n2, pos2 = s:match('^([+-]?%d+)(.?)()', pos)
+ if not x2 then error 'number format error' end
+ x = tonumber(x..n..x2)
+ if not x then error 'number format error' end
+ return x, n2, pos2
+ else
+ x = tonumber(x)
+ if not x then error 'number format error' end
+ return x, n, pos
+ end
+end
+local function parse_component(s, pos0)
+ local x, n, pos = parse_scalar(s, pos0)
+ if not x then
+ local x2, n2, pos2 = s:match('^([+-]?)(i)()$', pos0)
+ if not x2 then error 'number format error' end
+ return (x2=='-' and -1 or 1), n2, pos2
+ end
+ if n == '/' then
+ local x2, n2, pos2 = parse_scalar(s, pos)
+ x = x / x2
+ return x, n2, pos2
+ end
+ return x, n, pos
+end
+local function parse_complex(s)
+ local x, n, pos = parse_component(s, 1)
+ if n == '+' or n == '-' then
+ local x2, n2, pos2 = parse_component(s, pos)
+ if n2 ~= 'i' or pos2 ~= #s+1 then error 'number format error' end
+ if n == '-' then x2 = - x2 end
+ return x, x2
+ elseif n == '' then
+ return x, 0
+ elseif n == 'i' then
+ if pos ~= #s+1 then error 'number format error' end
+ return 0, x
+ else
+ error 'number format error'
+ end
+end
+
+function complex.to( num )
+ -- check for table type
+ if type( num ) == "table" then
+ -- check for a complex number
+ if getmetatable( num ) == complex_meta then
+ return num
+ end
+
+ if getmetatable( num) == frac_mt then
+ return setmetatable( { num, 0 }, complex_meta )
+ end
+
+ local real,imag = tonumber( num[1] ),tonumber( num[2] )
+ if real and imag then
+ return setmetatable( { real,imag }, complex_meta )
+ end
+ return
+ end
+ local isnum = tonumber( num )
+ if isnum then
+ return setmetatable( { isnum,0 }, complex_meta )
+ end
+ if type( num ) == "string" then
+ local real, imag = parse_complex(num)
+ return setmetatable( { real, imag }, complex_meta )
+ end
+end
+
+setmetatable( complex, { __call = function( _,num ) return complex.to( num ) end } )
+
+function complex.new( x,y)
+ return setmetatable( {x,y}, complex_meta )
+end
+
+lcomplex = complex.new
+function complex.type( arg )
+ if getmetatable( arg ) == complex_meta then
+ return "complex"
+ end
+end
+
+function complex.convpolar( radius, phi )
+ return setmetatable( { radius * math.cos( phi ), radius * math.sin( phi ) }, complex_meta )
+end
+
+function complex.convpolardeg( radius, phi )
+ phi = phi/180 * math.pi
+ return setmetatable( { radius * math.cos( phi ), radius * math.sin( phi ) }, complex_meta )
+end
+
+function complex.tostring( cx,formatstr )
+ imunit = "\\imUnit"
+ local real,imag = cx[1],cx[2]
+ if type(cx[1]) ~= "table" and type(cx[2]) ~= "table" then
+ if imag == 0 then
+ return real
+ elseif real == 0 then
+ return ((imag==1 and "") or (imag==-1 and "-") or imag)..imunit
+ elseif imag > 0 then
+ return real.."+"..(imag==1 and "" or imag)..imunit
+ end
+ return real..(imag==-1 and "-" or imag)..imunit
+ end
+
+ if type(cx[1]) == "table" and type(cx[2]) ~= "table" then
+ if cx[2] == 0 then
+ return frac.tostring(cx[1])
+ end
+ if cx[2] > 0 then
+ return frac.tostring(cx[1]).. "+"..(imag==1 and "" or imag)..imunit
+ end
+ if cx[2] < 0 then
+ return frac.tostring(cx[1])..(imag==-1 and "-" or imag)..imunit
+ end
+
+ end
+
+ if type(cx[1]) ~= "table" and type(cx[2]) == "table" then
+ if frac.toFnumber(cx[2])==0 then return cx[1] end
+ return cx[1].."+"..frac.tostring(cx[2])..imunit
+ end
+
+ if type(cx[1]) == "table" and type(cx[2]) == "table" then
+ if frac.toFnumber(cx[1]) == 0 and frac.toFnumber(cx[2]) ~= 0 then
+ return frac.tostring(cx[2])..imunit
+ end
+
+ if frac.toFnumber(cx[2]) == 0 then
+ return frac.tostring(cx[1] + 0)
+ end
+
+ if cx[2].d == 1 then
+ if cx[2].n > 0 then
+ return frac.tostring(cx[1]).. "+"..(cx[2].n==1 and "" or math.floor(cx[2].n))..imunit
+ end
+ if cx[2].n < 0 then
+ return frac.tostring(cx[1])..(cx[2].n==-1 and "-" or math.floor(cx[2].n))..imunit
+ end
+ end
+ end
+ return frac.tostring(cx[1]).. "+"..frac.tostring(cx[2])..imunit
+end
+
+function complex.print( ... )
+ print( complex.tostring( ... ) )
+end
+
+function complex.polar( cx )
+ return math.sqrt( cx[1]^2 + cx[2]^2 ), math.atan2( cx[2], cx[1] )
+end
+
+function complex.polardeg( cx )
+ return math.sqrt( cx[1]^2 + cx[2]^2 ), math.atan2( cx[2], cx[1] ) / math.pi * 180
+end
+
+function complex.norm2( cx )
+ return cx[1]^2 + cx[2]^2
+end
+
+function complex.abs( cx )
+ return math.sqrt( cx[1]^2 + cx[2]^2 )
+end
+
+function complex.get( cx )
+ return cx[1],cx[2]
+end
+
+function complex.set( cx,real,imag )
+ cx[1],cx[2] = real,imag
+end
+
+function complex.is( cx,real,imag )
+ if cx[1] == real and cx[2] == imag then
+ return true
+ end
+ return false
+end
+
+function complex.copy( cx )
+ return setmetatable( { cx[1],cx[2] }, complex_meta )
+end
+
+function complex.add( cx1,cx2 )
+ return setmetatable( { cx1[1]+cx2[1], cx1[2]+cx2[2] }, complex_meta )
+end
+
+function complex.sub( cx1,cx2 )
+ return setmetatable( { cx1[1]-cx2[1], cx1[2]-cx2[2] }, complex_meta )
+end
+
+function complex.mul( cx1,cx2 )
+ return setmetatable( { cx1[1]*cx2[1] - cx1[2]*cx2[2],cx1[1]*cx2[2] + cx1[2]*cx2[1] }, complex_meta )
+end
+
+function complex.mulnum( cx,num )
+ return setmetatable( { cx[1]*num,cx[2]*num }, complex_meta )
+end
+
+function complex.div( cx1,cx2 )
+ local val = cx2[1]*cx2[1] + cx2[2]*cx2[2]
+ return setmetatable( { (cx1[1]*cx2[1]+cx1[2]*cx2[2])/val,(cx1[2]*cx2[1]-cx1[1]*cx2[2])/val }, complex_meta )
+end
+
+function complex.divnum( cx,num )
+ return setmetatable( { cx[1]/num,cx[2]/num }, complex_meta )
+end
+
+function complex.pow( cx,num )
+ if math.floor( num ) == num then
+ if num < 0 then
+ local val = cx[1]^2 + cx[2]^2
+ cx = { cx[1]/val,-cx[2]/val }
+ num = -num
+ end
+ local real,imag = cx[1],cx[2]
+ for i = 2,num do
+ real,imag = real*cx[1] - imag*cx[2],real*cx[2] + imag*cx[1]
+ end
+ return setmetatable( { real,imag }, complex_meta )
+ end
+ local length,phi = math.sqrt( cx[1]^2 + cx[2]^2 )^num, math.atan2( cx[2], cx[1] )*num
+ return setmetatable( { length * math.cos( phi ), length * math.sin( phi ) }, complex_meta )
+end
+
+function complex.sqrt( cx )
+ local h
+ local k
+
+ if type(cx[1]) ~= "table" then h = cx[1] end
+ if type(cx[2]) ~= "table" then k = cx[2] end
+
+ if type(cx[1]) == "table" then h = frac.toFnumber(cx[1]) end
+ if type(cx[2]) == "table" then k = frac.toFnumber(cx[2]) end
+ local len = math.sqrt( h^2 + k^2 )
+ local sign = ( h<0 and -1) or 1
+ return setmetatable( { math.sqrt((h +len)/2), sign*math.sqrt((len-h)/2) }, complex_meta )
+end
+
+function complex.ln( cx )
+ return setmetatable( { math.log(math.sqrt( cx[1]^2 + cx[2]^2 )),
+ math.atan2( cx[2], cx[1] ) }, complex_meta )
+end
+
+function complex.exp( cx )
+ local expreal = math.exp(cx[1])
+ return setmetatable( { expreal*math.cos(cx[2]), expreal*math.sin(cx[2]) }, complex_meta )
+end
+
+function complex.conjugate( cx )
+ return setmetatable( { cx[1], -cx[2] }, complex_meta )
+end
+
+function Xround(num, numDecimalPlaces)
+ if type(num)=="number" then
+ if num==math.floor(num) then
+ return math.floor(num)
+ end
+ end
+ if type(num)=="number" then
+ local mult = 10^(numDecimalPlaces or 0)
+ return math.floor(num * mult + 0.5) / mult
+ end
+ return num
+end
+
+function complex.round( cx,idp )
+ local mult =10^( idp or 0 )
+ if type(cx[1]) ~= "table" and type(cx[2]) ~= "table" then
+ return setmetatable( {Xround(cx[1],idp), Xround(cx[2],idp)}, complex_meta )
+ end
+ if type(cx[1]) ~= "table" and type(cx[2]) == "table" then
+ return setmetatable( {Xround(cx[1],idp), cx[2]}, complex_meta )
+ end
+ if type(cx[1]) == "table" and type(cx[2]) ~= "table" then
+ return setmetatable({cx[1],Xround(cx[2],idp)}, complex_meta )
+ end
+ if type(cx[1]) == "table" and type(cx[2]) == "table" then
+ return setmetatable({cx[1],cx[2]}, complex_meta )
+ end
+end
+
+complex.zero = complex.new(0, 0)
+complex.one = complex.new(1, 0)
+
+complex_meta.__add = function( cx1,cx2 )
+local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+return complex.add( cx1,cx2 )
+end
+complex_meta.__sub = function( cx1,cx2 )
+local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+return complex.sub( cx1,cx2 )
+end
+complex_meta.__mul = function( cx1,cx2 )
+local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+return complex.mul( cx1,cx2 )
+end
+complex_meta.__div = function( cx1,cx2 )
+local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+return complex.div( cx1,cx2 )
+end
+complex_meta.__pow = function( cx,num )
+if num == "*" then
+return complex.conjugate( cx )
+end
+return complex.pow( cx,num )
+end
+complex_meta.__unm = function( cx )
+return setmetatable( { -cx[1], -cx[2] }, complex_meta )
+end
+complex_meta.__eq = function( cx1,cx2 )
+if cx1[1] == cx2[1] and cx1[2] == cx2[2] then
+return true
+end
+return false
+end
+complex_meta.__tostring = function( cx )
+return tostring( complex.tostring( cx ) )
+end
+complex_meta.__concat = function( cx,cx2 )
+return tostring(cx)..tostring(cx2)
+end
+-- cx( cx, formatstr )
+complex_meta.__call = function( ... )
+print( complex.tostring( ... ) )
+end
+complex_meta.__index = {}
+for k,v in pairs( complex ) do
+complex_meta.__index[k] = v
+end
+
+return complex
+
diff --git a/macros/luatex/latex/luamaths/luamaths-fractions.lua b/macros/luatex/latex/luamaths/luamaths-fractions.lua
new file mode 100644
index 0000000000..e4ab7a2329
--- /dev/null
+++ b/macros/luatex/latex/luamaths/luamaths-fractions.lua
@@ -0,0 +1,225 @@
+-- The luafractions module
+-- Authors: Chetan Shirore and Ajit Kumar
+-- version 1.0, Date=03-Aug-2023
+-- Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
+
+M = {} -- the module
+frac_mt = {} -- the metatable
+function M.new (n, d, mode)
+ mode = mode or 'fracs'
+ if mode == 'nofracs' then
+ return (n/d)
+ end
+ if mode == 'fracs' then
+ if n~=math.floor(n) or d~=math.floor(d) then
+ error('Only integers are expected.')
+ end
+ if d == 0 then
+ error('Invalid fraction')
+ end
+ local fr = {}
+ local g = M.lgcd(n,d)
+ fr = {n=n/g, d=d/g}
+ return setmetatable(fr,frac_mt)
+ end
+end
+lfrac = M.new
+
+function M.lgcd (a, b)
+ local r
+ while (b ~= 0) do
+ r = a % b
+ a = b
+ b = r
+ end
+ return a
+end
+
+function M.simp (num)
+ local cf = gcd(num[1], num[2])
+ return M.new(num[1] / cf, num2[2] / cf)
+end
+
+function M.toFnumber(c)
+ return c.n / c.d
+end
+
+function M.toFrac(x)
+ if type(x) == "number" then
+ if x==math.floor(x) then
+ return M.new(math.floor(x),1)
+ else
+ return x
+ end
+ end
+ return x
+end
+
+
+function addFracs (c1, c2)
+ return M.new(c1.n * c2.d + c1.d * c2.n, c1.d*c2.d)
+end
+
+function subFracs (c1, c2)
+ return M.new(c1.n * c2.d - c1.d * c2.n, c1.d*c2.d)
+end
+
+function mulFracs (c1, c2)
+ return M.new(c1.n * c2.n, c1.d*c2.d)
+end
+
+function divFracs (c1, c2)
+ return M.new(c1.n * c2.d, c1.d*c2.n)
+end
+
+function minusFracs (c1)
+ return M.new(-c1.n,c1.d)
+end
+
+function powerFracs (c1,m)
+ return M.new((c1.n)^m,(c1.d)^m)
+end
+
+
+function M.add(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return addFracs(M.new(a,1),b)
+ else
+ return a + M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return addFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) + b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a+b[1], b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { b+a[1], a[2] }, complex_meta )
+ end
+ end
+ return addFracs(a, b)
+end
+
+
+function M.sub(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return subFracs(M.new(a,1),b)
+ else
+ return a - M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return subFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) - b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a-b[1], b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { a[1]-b, a[2] }, complex_meta )
+ end
+ end
+ return subFracs(a, b)
+end
+
+
+function M.mul(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return mulFracs(M.new(a,1),b)
+ else
+ return a * M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return mulFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) * b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a*b[1], a*b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { b*a[1], b*a[2] }, complex_meta )
+ end
+ end
+ return mulFracs(a, b)
+end
+
+
+function M.div(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return divFracs(M.new(a,1),b)
+ else
+ return a / M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return divFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) / b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ b= setmetatable( { M.toFrac(b[1]), M.toFrac(b[2]) }, complex_meta )
+ return a*(1/b)
+ end
+ end
+ return divFracs(a, b)
+end
+
+function M.tostring (c)
+ if c.d == 1 then
+ return string.format("%g",c.n)
+ end
+ if c.d == -1 then
+ return string.format("%g",-c.n)
+ end
+ return string.format("\\frac{%g}{%g}", c.n, c.d)
+end
+
+--Setting Metatable operations.
+frac_mt.__add = M.add
+frac_mt.__sub = M.sub
+frac_mt.__mul = M.mul
+frac_mt.__div = M.div
+frac_mt.__unm = minusFracs
+frac_mt.__pow = powerFracs
+frac_mt.__tostring = M.tostring
+
+return M \ No newline at end of file
diff --git a/macros/luatex/latex/luamaths/luamaths.pdf b/macros/luatex/latex/luamaths/luamaths.pdf
index a9ffe78a82..0b5d310b1d 100644
--- a/macros/luatex/latex/luamaths/luamaths.pdf
+++ b/macros/luatex/latex/luamaths/luamaths.pdf
Binary files differ
diff --git a/macros/luatex/latex/luamaths/luamaths.sty b/macros/luatex/latex/luamaths/luamaths.sty
index c3bc4d51e0..524b36a210 100644
--- a/macros/luatex/latex/luamaths/luamaths.sty
+++ b/macros/luatex/latex/luamaths/luamaths.sty
@@ -1,19 +1,25 @@
-% luaset package
-% version 1.0
-% Authors: Chetan Shirore and Ajit Kumar
+% The luamaths package
+% version 1.1
% 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{luaset}[1.0]
+\ProvidesPackage{luamaths}[1.1]
\RequirePackage{xkeyval}
\RequirePackage{amsmath}
\RequirePackage{luacode}
\begin{luacode*}
+local complex = require "luamaths-complex"
+local lfrac = require "luamaths-fractions"
+
function mathop(...)
inf = math.huge
return ...
end
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
@@ -27,7 +33,7 @@ end
\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\mathHuge{\directlua{tex.sprint(math.huge)}}
+\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))}}
@@ -38,4 +44,12 @@ end
\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}}
+
+
\endinput
diff --git a/macros/luatex/latex/luamaths/luamaths.tex b/macros/luatex/latex/luamaths/luamaths.tex
index 0c5abbbe94..8e501abf14 100644
--- a/macros/luatex/latex/luamaths/luamaths.tex
+++ b/macros/luatex/latex/luamaths/luamaths.tex
@@ -1,11 +1,12 @@
\documentclass{article}
-\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol}
-\usepackage[ left=1in, right=1in]{geometry}
+\renewcommand{\baselinestretch}{1.2}
+\usepackage{float,listings,color,booktabs,longtable,array,hyperref,luamaths,amsmath,amssymb}
+\usepackage[top=1.1in, bottom=1.1in, left=1.1in, right=1.1in]{geometry}
\hypersetup{colorlinks,urlcolor=blue}
\lstset{frame=none,
language=[LaTeX]{TeX},
aboveskip=3mm,
- belowskip=3mm,
+ belowskip=2mm,
showstringspaces=false,
columns=flexible,
basicstyle={\ttfamily},
@@ -16,11 +17,12 @@
breakatwhitespace=true,
tabsize=1
}
+\usepackage{microtype,graphicx,amsmath,amssymb,float}
\usepackage[backend=bibtex]{biblatex}
\addbibresource{luamaths}
\begin{document}
-\title{The luamaths Package in LaTeX}
-\author{Chetan Shirore and Dr. Ajit Kumar}
+\title{The luamaths package in LaTeX}
+\author{Chetan Shirore\thanks{Email id: mathsbeauty@gmail.com} \space and Ajit Kumar}
\maketitle
\section{Introduction}\label{section:introduction}
The \verb|luamaths| package is developed to perform standard mathematical operations inside LaTeX documents using Lua. It provides an easy way to perform standard mathematical operations. There is no particular environment in the package for performing mathematical operations. The package commands can be used in any environment (including the mathematics environment). It is written in Lua, and tex file is to be compiled with LuaLatex engine. The time required for operations is not an issue while compiling with LuaLaTeX. There is no need to install Lua on the users system as tex distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. It is useful to perform standard operations (addition, subtraction, multiplication, division, powers, roots etc.) in tex file itself. The package supports the nesting of commands for multiple operations. It can be modified or extended by writing custom Lua programs.
@@ -28,6 +30,8 @@ The \verb|luamaths| package is developed to perform standard mathematical operat
The Lua \cite{online.luaorg} programming language is a scripting language that can be embedded across platforms. With\verb|LuaTeX| \cite{online.luatex} and\verb|luacode| \cite{online.luacode} packages, it is possible to use Lua in LaTeX. The TeX \cite{online.tex} or LaTeX has scope for programming \cite{online.texscript}. However, with the weird internals of TeX, there are several limitations, especially for performing calculations on numbers in LaTeX documents. There are packages like \emph{pgf} \cite{online.pgf} and \emph{xparse} \cite{online.xparse} in LaTeX which provides some programming capabilities inside LaTeX documents. However, such packages do not provide the complete programming structure that Lua programming languages provide. The \verb|luacode| \cite{online.luacode} package is used in its development apart from the \verb|luacode| package. There is no need to install Lua on users system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. The package can be modified or extended by writing custom Lua programs.
+
+
\section{Installation and License}
The installation of \verb|luamaths| package is similar to plain latex package, where the \texttt{.sty} file is in \LaTeX directory of texmf tree. The package can be included with \verb|\usepackage{luamaths}| command in the preamble of the LaTeX document. The TeX file is to be compiled using the LuaLaTeX engine.
@@ -179,13 +183,13 @@ Table \ref{tbl:opluamaths} lists operations in the \verb|luamaths| package.
\begin{lstlisting}
\mathTan{number}
\end{lstlisting} & Gives the tangent of a real number. Here the number is in radians.\\
-\bottomrule
+\bottomrule \\
\caption{Operations in the luamaths package}
\label{tbl:opluamaths}
\end{longtable}
\end{center}
Numbers can also be entered in scientific notation. For example, the number \(1860000\) can be entered as \(1.86e6\), and the number \(0.000186\) can be entered as \(1.86e-4\).
-\subsection{Illustrations of commands in the luamaths package}
+\subsection*{Illustrations of commands in the luamaths package}
Table \ref{tbl:illluamaths} illustrates operations in the \verb|luamaths| package with examples.
\begin{center}
\begin{longtable}{lc}
@@ -194,132 +198,204 @@ Table \ref{tbl:illluamaths} illustrates operations in the \verb|luamaths| packag
\toprule
\begin{lstlisting}
\mathOp{(3+3)^4-4}
-\end{lstlisting} & \(1292.0\)\\
+\end{lstlisting} & \(\mathOp{(3+3)^4-4}\)\\
\midrule
\begin{lstlisting}
\mathAbs{-6.96}
-\end{lstlisting} & \(6.96\)\\
+\end{lstlisting} & \(\mathAbs{-6.96}\)\\
\midrule
\begin{lstlisting}
\mathFloor{-6.9}
-\end{lstlisting} & \(-7\) \\
+\end{lstlisting} & \(\mathFloor{-6.9}\) \\
\midrule
\begin{lstlisting}
\mathFloor{9.9}
-\end{lstlisting} & \(9\)\\
+\end{lstlisting} & \(\mathFloor{9.9}\)\\
\midrule
\begin{lstlisting}
\mathCeil{-9.9}
-\end{lstlisting} & \(-9\) \\
+\end{lstlisting} & \(\mathCeil{-9.9}\) \\
\midrule
\begin{lstlisting}
\mathCeil{6.3}
-\end{lstlisting} &\(7\)\\
+\end{lstlisting} &\(\mathCeil{6.3}\)\\
\midrule
\begin{lstlisting}
\mathRound{9.678884}{3}
-\end{lstlisting} & \(9.679\)\\
+\end{lstlisting} & \(\mathRound{9.678884}{3}\)\\
\midrule
\begin{lstlisting}
\mathMax{20,30,100}
-\end{lstlisting} &\(100\) \\
+\end{lstlisting} &\(\mathMax{20,30,100}\) \\
\midrule
\begin{lstlisting}
\mathMin{20,30,100}
-\end{lstlisting} &\(20\)\\
+\end{lstlisting} &\(\mathMin{20,30,100}\)\\
\midrule
\begin{lstlisting}
\mathPi
-\end{lstlisting} & \(3.1415926535898\)\\
+\end{lstlisting} & \(\mathPi\)\\
\midrule
\begin{lstlisting}
\mathRound{\mathPi}{6}
-\end{lstlisting} & \(3.141593\)\\
+\end{lstlisting} & \(\mathRound{\mathPi}{6}\)\\
\midrule
\begin{lstlisting}
\mathInf
-\end{lstlisting} & \(Inf\)\\
+\end{lstlisting} & \(\mathInf\)\\
\midrule
\begin{lstlisting}
\mathOp{\mathInf/2}
-\end{lstlisting} &\(Inf\) \\
+\end{lstlisting} &\(\mathOp{\mathInf/2}\) \\
\midrule
\begin{lstlisting}
\mathSqrt{9}
-\end{lstlisting} & \(3.0\)\\
+\end{lstlisting} & \(\mathSqrt{9}\)\\
\midrule
\begin{lstlisting}
\mathLog{2}
-\end{lstlisting} & \(0.69314718055995\)\\
+\end{lstlisting} & \(\mathLog{2}\)\\
\midrule
\begin{lstlisting}
\mathExp{3}
-\end{lstlisting} & \(20.085536923188\) \\
+\end{lstlisting} & \(\mathExp{3}\) \\
\midrule
\begin{lstlisting}
\mathRad{1800}
-\end{lstlisting} & \(31.415926535898\)\\
+\end{lstlisting} & \(\mathRad{1800}\)\\
\midrule
\begin{lstlisting}
\mathSin{0}
-\end{lstlisting} &\(0.0\)\\
+\end{lstlisting} &\(\mathSin{0}\)\\
\midrule
\begin{lstlisting}
\mathCos{0}
-\end{lstlisting} & \(1.0\)\\
+\end{lstlisting} & \(\mathCos{0}\)\\
\midrule
\begin{lstlisting}
\mathTan{0}
-\end{lstlisting} & \(0.0\)\\
+\end{lstlisting} & \(\mathTan{0}\)\\
\midrule
\begin{lstlisting}
\mathAsin{0}
-\end{lstlisting} & \(0.0\)\\
+\end{lstlisting} & \(\mathAsin{0}\)\\
\midrule
\begin{lstlisting}
\mathAcos{0}
-\end{lstlisting} & \(1.5707963267949\)\\
+\end{lstlisting} & \(\mathAcos{0}\)\\
\midrule
\begin{lstlisting}
\mathAtan{0}
-\end{lstlisting} & \(0.0\)\\
+\end{lstlisting} & \(\mathAtan{0}\)\\
\midrule
\begin{lstlisting}
\mathRound{\mathOp{9+\mathSin{4}}}{6}
-\end{lstlisting} & \(8.243198\)\\
-\midrule
+\end{lstlisting} & \(\mathRound{\mathOp{9+\mathSin{4}}}{6}\)\\
+\bottomrule \\
\caption{Illustrations of commands in the luamaths package}
\label{tbl:illluamaths}
\end{longtable}
\end{center}
+The package supports fractions; numerators and denominators must be integers. A fraction can be specified with the Lua function: \verb|lfrac|. This function has the syntax \verb|lfrac(n,d,mode)|: \(n\) is an integer and \(d\) is a non-zero integer. The mode is optional. It can be \verb|fracs| or \verb|nofracs|. The default mode is \verb|fracs|. If fractions are input, the package will display vectors and matrices in fraction mode wherever possible. The package does not attempt to convert floats into fractions. If fractions are expected, then the input should contain fractions. If fractions are input and answers are expected in numbers, the mode can be specified as \verb|nofracs|.
+
+The Lua function \verb|lcomplex| defines the complex numbers. It has the syntax \verb|lcomplex(x,y)|, where \(x\) is a real part, and \(y\) is an imaginary part. \(x\) and \(y\) can also be fractions (numerators and denominators should be integers). The package has a command \verb|\imUnit| which provides typesetting for the imaginary unit. Its default value is \verb|\mathrm{i}|. It can be redefined. For example, one can redefine it as \verb|\renewcommand{\imUnit}{j}}|.
+
+Table \ref{tbl:illluamaths2} illustrates calculations on fractions and complex numbers using the \verb|luamaths| package. The numbers \(x, y, c\) and \(d\) are defined using the following commands.
+\begin{lstlisting}
+\def\x{lfrac(1,2)}
+\def\y{lfrac(-3,4)}
+\def\c{lcomplex(lfrac(3,4),6)}
+\def\d{lcomplex(3,-9)}
+\end{lstlisting}
+
+\subsection*{Some Illustrations}
+\def\x{lfrac(1,2)}
+\def\y{lfrac(-3,4)}
+\def\c{lcomplex(lfrac(3,4),6)}
+\def\d{lcomplex(3,-9)}
+\begin{center}
+\begin{longtable}{lc}
+\toprule
+\multicolumn{1}{c}{\textcolor{blue}{LaTeX input}} &\multicolumn{1}{c}{\textcolor{blue}{Output}} \\
+\toprule
+\begin{lstlisting}
+\(x + y = \mathOp{\x + \y}\)
+\end{lstlisting}
+& \(x + y = \mathOp{\x + \y}\) \\ \hline
+
+\begin{lstlisting}
+\(x - y = \mathOp{\x - \y}\)
+\end{lstlisting}
+& \(x - y = \mathOp{\x - \y}\) \\ \hline
+
+\begin{lstlisting}
+\(xy = \mathOp{\x*\y}\)
+\end{lstlisting}
+& \(xy = \mathOp{\x*\y}\) \\ \hline
+
+\begin{lstlisting}
+\(\frac{x}{y} = \mathOp{\x / \y}\)
+\end{lstlisting}
+& \(\frac{x}{y} = \mathOp{\x / \y}\) \\ \hline
+
+\begin{lstlisting}
+\(c + d = \mathOp{\c + \d}\)
+\end{lstlisting}
+& \(c + d = \mathOp{\c + \d}\) \\ \hline
+
+\begin{lstlisting}
+\(c - d = \mathOp{\c - \d}\)
+\end{lstlisting}
+& \(c - d = \mathOp{\c - \d}\) \\ \hline
+
+\begin{lstlisting}
+\(cd = \mathOp{\c*\d}\)
+\end{lstlisting}
+& \(cd = \mathOp{\c*\d}\) \\ \hline
+
+\begin{lstlisting}
+\(\frac{c}{d} = \mathOp{\c / \d}\)
+\end{lstlisting}
+& \(\frac{c}{d} = \mathOp{\c / \d}\) \\ \hline
+
+\begin{lstlisting}
+\(x + c - y + d = \mathOp{\x + \c - \y + \d}\)
+\end{lstlisting}
+& \(x + c - y + d = \mathOp{\x + \c - \y + \d}\) \\
+
+ \bottomrule \\
+\caption{Calculations on fractions and complex numbers}
+\label{tbl:illluamaths2}
+\end{longtable}
+\end{center}
\printbibliography
\end{document}