diff options
Diffstat (limited to 'tex/context/base/math-ini.lua')
-rw-r--r-- | tex/context/base/math-ini.lua | 174 |
1 files changed, 103 insertions, 71 deletions
diff --git a/tex/context/base/math-ini.lua b/tex/context/base/math-ini.lua index 4cfa02e4e..78ccf1779 100644 --- a/tex/context/base/math-ini.lua +++ b/tex/context/base/math-ini.lua @@ -18,31 +18,33 @@ if not modules then modules = { } end modules ['math-ini'] = { local formatters, find = string.formatters, string.find local utfchar, utfbyte, utflength = utf.char, utf.byte, utf.length local floor = math.floor +local toboolean = toboolean -local context = context -local commands = commands +local context = context +local commands = commands +local implement = interfaces.implement -local context_sprint = context.sprint ------ context_fprint = context.fprint -- a bit inefficient -local ctx_doifelse = commands.doifelse +local context_sprint = context.sprint +----- context_fprint = context.fprint -- a bit inefficient +local ctx_doifelsesomething = commands.doifelsesomething -local trace_defining = false trackers.register("math.defining", function(v) trace_defining = v end) +local trace_defining = false trackers.register("math.defining", function(v) trace_defining = v end) -local report_math = logs.reporter("mathematics","initializing") +local report_math = logs.reporter("mathematics","initializing") -mathematics = mathematics or { } -local mathematics = mathematics +mathematics = mathematics or { } +local mathematics = mathematics -mathematics.extrabase = 0xFE000 -- here we push some virtuals -mathematics.privatebase = 0xFF000 -- here we push the ex +mathematics.extrabase = 0xFE000 -- here we push some virtuals +mathematics.privatebase = 0xFF000 -- here we push the ex -local unsetvalue = attributes.unsetvalue -local allocate = utilities.storage.allocate -local chardata = characters.data +local unsetvalue = attributes.unsetvalue +local allocate = utilities.storage.allocate +local chardata = characters.data -local texsetattribute = tex.setattribute -local setmathcode = tex.setmathcode -local setdelcode = tex.setdelcode +local texsetattribute = tex.setattribute +local setmathcode = tex.setmathcode +local setdelcode = tex.setdelcode local families = allocate { mr = 0, @@ -477,51 +479,72 @@ mathematics.utfmathaccent = utfmathaccent -- interfaced -function commands.utfmathclass (...) context(utfmathclass (...)) end -function commands.utfmathstretch(...) context(utfmathstretch(...)) end -function commands.utfmathcommand(...) context(utfmathcommand(...)) end -function commands.utfmathfiller (...) context(utfmathfiller (...)) end +implement { + name = "utfmathclass", + actions = { utfmathclass, context }, + arguments = "string" +} -function commands.utfmathcommandabove(asked) - local c = utfmathcommand(asked,nil,"topaccent","over" ) - if c ~= "" then - context(c) - end -end +implement { + name = "utfmathstretch", + actions = { utfmathstretch, context }, + arguments = "string" +} -function commands.utfmathcommandbelow (asked) - local c = utfmathcommand(asked,nil,"botaccent","under") - if c ~= "" then - context(c) - end -end +implement { + name = "utfmathcommand", + actions = { utfmathcommand, context }, + arguments = "string" +} -function commands.utfmathcommandfiller(asked) - local c = utfmathfiller(asked,nil) - if c ~= "" then - context(c) - end -end +implement { + name = "utfmathfiller", + actions = { utfmathfiller, context }, + arguments = "string" +} -function commands.doifelseutfmathabove(chr) - local c = utfmathaccent(chr,nil,"topaccent","over") - ctx_doifelse(c and c ~= "") -end +implement { + name = "utfmathcommandabove", + actions = { utfmathcommand, context }, + arguments = { "string", false, "'topaccent'","'over'" } +} -function commands.doifelseutfmathbelow(chr) - local c = utfmathaccent(chr,nil,"botaccent","under") - ctx_doifelse(c and c ~= "") -end +implement { + name = "utfmathcommandbelow", + actions = { utfmathcommand, context }, + arguments = { "string", false, "'botaccent'","'under'" } +} +implement { + name = "utfmathcommandfiller", + actions = { utfmathfiller, context }, + arguments = "string" +} -function commands.doifelseutfmathaccent(chr,asked) - local c = utfmathaccent(chr,nil,asked) - ctx_doifelse(c and c ~= "") -end +-- todo: make this a helper: -function commands.doifelseutfmathfiller(chr) - local c = utfmathfiller(chr,nil) - ctx_doifelse(c and c ~= "") -end +implement { + name = "doifelseutfmathabove", + actions = { utfmathaccent, ctx_doifelsesomething }, + arguments = { "string", false, "'topaccent'", "'over'" } +} + +implement { + name = "doifelseutfmathbelow", + actions = { utfmathaccent, ctx_doifelsesomething }, + arguments = { "string", false, "'botaccent'", "'under'" } +} + +implement { + name = "doifelseutfmathaccent", + actions = { utfmathaccent, ctx_doifelsesomething }, + arguments = "string", +} + +implement { + name = "doifelseutfmathfiller", + actions = { utfmathfiller, ctx_doifelsesomething }, + arguments = "string", +} -- helpers -- @@ -631,30 +654,34 @@ local noffunctions = 1000 -- offset categories.functions = functions -function commands.taggedmathfunction(tag,label,apply) - local delta = apply and 1000 or 0 - if label then - local n = functions[tag] - if not n then - noffunctions = noffunctions + 1 - functions[noffunctions] = tag - functions[tag] = noffunctions - texsetattribute(a_mathcategory,noffunctions + delta) +implement { + name = "taggedmathfunction", + arguments = { "string", "string", "string" }, + actions = function(tag,label,apply) + local delta = toboolean(apply) and 1000 or 0 + if toboolean(label) then + local n = functions[tag] + if not n then + noffunctions = noffunctions + 1 + functions[noffunctions] = tag + functions[tag] = noffunctions + texsetattribute(a_mathcategory,noffunctions + delta) + else + texsetattribute(a_mathcategory,n + delta) + end + context.mathlabeltext(tag) else - texsetattribute(a_mathcategory,n + delta) + texsetattribute(a_mathcategory,1000 + delta) + context(tag) end - context.mathlabeltext(tag) - else - texsetattribute(a_mathcategory,1000 + delta) - context(tag) end -end +} -- local list -function commands.resetmathattributes() +function mathematics.resetattributes() if not list then list = { } for k, v in next, attributes.numbers do @@ -667,3 +694,8 @@ function commands.resetmathattributes() texsetattribute(list[i],unsetvalue) end end + +implement { + name = "resetmathattributes", + actions = mathematics.resetattributes +} |