require'symmath'.setup{
implicitVars = true
, fixVariableNames = true
, env = symmath
}
local latex = symmath.export.MathJax
latex.openSymbol = ''
latex.closeSymbol = ''
local exp = export.MathJax
local gsub = mw.ustring.gsub
local mj = function (arg)
return gsub (gsub (exp (arg), '{{', '{ {'), '}}', '} }')
end
local p = {}
p ['производная'] = function (frame)
local func = frame.args[1]
local arg = symmath.var (frame.args[2] or 'x')
return mj (_G [func] (arg):diff (arg) ())
end
p ['ряд тейлора'] = function (frame)
local func = frame.args[1]
local arg = symmath.var (frame.args[2] or 'x')
return mj (_G [func] (arg):taylor (arg, 0, 4) ())
end
p ['интеграл'] = function (frame)
local func = frame.args[1]
local arg = symmath.var (frame.args[2] or 'x')
if frame.args[3] and frame.args[4] then
local from, to = symmath.var (frame.args[3]), symmath.var (frame.args[4])
return mj (_G [func] (arg):integrate (arg, from, to) ())
else
return mj (_G [func] (arg):integrate (arg) ()) .. ' + C'
end
end
return p