diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/math-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/math-ini.lua | 216 |
1 files changed, 156 insertions, 60 deletions
diff --git a/Master/texmf-dist/tex/context/base/math-ini.lua b/Master/texmf-dist/tex/context/base/math-ini.lua index a122f722975..54452282bb0 100644 --- a/Master/texmf-dist/tex/context/base/math-ini.lua +++ b/Master/texmf-dist/tex/context/base/math-ini.lua @@ -8,9 +8,18 @@ if not modules then modules = { } end modules ['math-ext'] = { -- if needed we can use the info here to set up xetex definition files -- the "8000 hackery influences direct characters (utf) as indirect \char's +-- +-- isn't characters.data loaded already ... shortcut it here -local texsprint, format, utfchar, utfbyte = tex.sprint, string.format, utf.char, utf.byte +local format, utfchar, utfbyte = string.format, utf.char, utf.byte local setmathcode, setdelcode = tex.setmathcode, tex.setdelcode +local texattribute = tex.attribute +local floor = math.floor + +local context = context + +local contextsprint = context.sprint +local contextfprint = context.fprint -- a bit inefficient local allocate = utilities.storage.allocate @@ -25,7 +34,8 @@ mathematics.extrabase = 0xFE000 -- here we push some virtuals mathematics.privatebase = 0xFF000 -- here we push the ex local families = allocate { - tf = 0, it = 1, sl = 2, bf = 3, bi = 4, bs = 5, -- no longer relevant + mr = 0, + mb = 1, } local classes = allocate { @@ -53,8 +63,20 @@ local classes = allocate { nolop = 1, -- mathnolopcomm @@mathnolopcomm } -mathematics.families = families +local codes = allocate { + ordinary = 0, [0] = "ordinary", + largeoperator = 1, [1] = "largeoperator", + binaryoperator = 2, [2] = "binaryoperator", + relation = 3, [3] = "relation", + openingsymbol = 4, [4] = "openingsymbol", + closingsymbol = 5, [5] = "closingsymbol", + punctuation = 6, [6] = "punctuation", + variable = 7, [7] = "variable", +} + mathematics.classes = classes +mathematics.codes = codes +mathematics.families = families classes.alphabetic = classes.alpha classes.unknown = classes.nothing @@ -98,14 +120,8 @@ end local function mathtopaccent(class,family,slot) return format('\\Umathaccent "%X "%X "%X ',0,family,slot) -- no class end -if tex.luatexversion > 65 then -- this will disappear at 0.70 - local function mathbotaccent(class,family,slot) - return format('\\Umathaccent bottom "%X "%X "%X ',0,family,slot) -- no class - end -else - local function mathbotaccent(class,family,slot) - return format('\\Umathbotaccent "%X "%X "%X ',0,family,slot) -- no class - end +local function mathbotaccent(class,family,slot) + return format('\\Umathaccent bottom "%X "%X "%X ',0,family,slot) -- no class end local function mathtopdelimiter(class,family,slot) return format('\\Udelimiterover "%X "%X ',family,slot) -- no class @@ -118,16 +134,19 @@ local escapes = characters.filters.utf.private.escapes local setmathcharacter, setmathsynonym, setmathsymbol -- once updated we will inline them +-- beware ... we only set the math character once ... which is why we +-- have the 'done' checking below + if setmathcode then - setmathcharacter = function(class,family,slot,unicode,firsttime) - if not firsttime and class <= 7 then + setmathcharacter = function(class,family,slot,unicode) + if class <= 7 then setmathcode(slot,{class,family,unicode or slot}) end end - setmathsynonym = function(class,family,slot,unicode,firsttime) - if not firsttime and class <= 7 then + setmathsynonym = function(class,family,slot,unicode,setcode) + if setcode and class <= 7 then setmathcode(slot,{class,family,unicode}) end if class == classes.open or class == classes.close then @@ -137,69 +156,70 @@ if setmathcode then setmathsymbol = function(name,class,family,slot) -- hex is nicer for tracing if class == classes.accent then - texsprint(format([[\unexpanded\gdef\%s{\Umathaccent 0 "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Umathaccent 0 "%X "%X }]],name,family,slot)) elseif class == classes.topaccent then - texsprint(format([[\unexpanded\gdef\%s{\Umathaccent 0 "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Umathaccent 0 "%X "%X }]],name,family,slot)) elseif class == classes.botaccent then - texsprint(format([[\unexpanded\gdef\%s{\Umathbotaccent 0 "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Umathbotaccent 0 "%X "%X }]],name,family,slot)) elseif class == classes.over then - texsprint(format([[\unexpanded\gdef\%s{\Udelimiterover "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Udelimiterover "%X "%X }]],name,family,slot)) elseif class == classes.under then - texsprint(format([[\unexpanded\gdef\%s{\Udelimiterunder "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Udelimiterunder "%X "%X }]],name,family,slot)) elseif class == classes.open or class == classes.close then setdelcode(slot,{family,slot,0,0}) - texsprint(format([[\unexpanded\gdef\%s{\Udelimiter "%X "%X "%X }]],name,class,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Udelimiter "%X "%X "%X }]],name,class,family,slot)) elseif class == classes.delimiter then setdelcode(slot,{family,slot,0,0}) - texsprint(format([[\unexpanded\gdef\%s{\Udelimiter 0 "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Udelimiter 0 "%X "%X }]],name,family,slot)) elseif class == classes.radical then - texsprint(format([[\unexpanded\gdef\%s{\Uradical "%X "%X }]],name,family,slot)) + contextsprint(format([[\unexpanded\gdef\%s{\Uradical "%X "%X }]],name,family,slot)) else -- beware, open/close and other specials should not end up here - texsprint(format([[\unexpanded\gdef\%s{\Umathchar "%X "%X "%X }]],name,class,family,slot)) +-- contextsprint(format([[\unexpanded\gdef\%s{\Umathchar "%X "%X "%X }]],name,class,family,slot)) + contextsprint(format([[\Umathchardef\%s "%X "%X "%X ]],name,class,family,slot)) end end else - setmathcharacter = function(class,family,slot,unicode,firsttime) - if not firsttime and class <= 7 then - texsprint(mathcode(slot,class,family,unicode or slot)) + setmathcharacter = function(class,family,slot,unicode) + if class <= 7 then + contextsprint(mathcode(slot,class,family,unicode or slot)) end end - setmathsynonym = function(class,family,slot,unicode,firsttime) - if not firsttime and class <= 7 then - texsprint(mathcode(slot,class,family,unicode)) + setmathsynonym = function(class,family,slot,unicode,setcode) + if setcode and class <= 7 then + contextsprint(mathcode(slot,class,family,unicode)) end if class == classes.open or class == classes.close then - texsprint(delcode(slot,family,unicode)) + contextsprint(delcode(slot,family,unicode)) end end setmathsymbol = function(name,class,family,slot) if class == classes.accent then - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathaccent(class,family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,mathaccent(class,family,slot))) elseif class == classes.topaccent then - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathtopaccent(class,family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,mathtopaccent(class,family,slot))) elseif class == classes.botaccent then - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathbotaccent(class,family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,mathbotaccent(class,family,slot))) elseif class == classes.over then - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathtopdelimiter(class,family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,mathtopdelimiter(class,family,slot))) elseif class == classes.under then - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathbotdelimiter(class,family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,mathbotdelimiter(class,family,slot))) elseif class == classes.open or class == classes.close then - texsprint(delcode(slot,family,slot)) - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,delimiter(class,family,slot))) + contextsprint(delcode(slot,family,slot)) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,delimiter(class,family,slot))) elseif class == classes.delimiter then - texsprint(delcode(slot,family,slot)) - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,delimiter(0,family,slot))) + contextsprint(delcode(slot,family,slot)) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,delimiter(0,family,slot))) elseif class == classes.radical then - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,radical(family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,radical(family,slot))) else -- beware, open/close and other specials should not end up here - texsprint(format("\\unexpanded\\xdef\\%s{%s}",name,mathchar(class,family,slot))) + contextsprint(format([[\unexpanded\xdef\%s{%s}]],name,mathchar(class,family,slot))) end end @@ -216,7 +236,7 @@ local function report(class,family,unicode,name) end end --- there will be a combined \(math)chardef +-- there will be a combined \(math)chardef (tracker) function mathematics.define(family) family = family or 0 @@ -224,6 +244,7 @@ function mathematics.define(family) local data = characters.data for unicode, character in next, data do local symbol = character.mathsymbol + local setcode = true if symbol then local other = data[symbol] local class = other.mathclass @@ -232,7 +253,8 @@ function mathematics.define(family) if trace_defining then report(class,family,unicode,symbol) end - setmathsynonym(class,family,unicode,symbol) + setmathsynonym(class,family,unicode,symbol,setcode) + setcode = false end local spec = other.mathspec if spec then @@ -240,7 +262,8 @@ function mathematics.define(family) local class = m.class if class then class = classes[class] or class -- no real checks needed - setmathsynonym(class,family,unicode,symbol,i) + setmathsynonym(class,family,unicode,symbol,setcode) + setcode = false end end end @@ -271,7 +294,10 @@ function mathematics.define(family) end end end - setmathcharacter(class,family,unicode,unicode,i) + if setcode then + setmathcharacter(class,family,unicode,unicode) + setcode = false + end end end end @@ -303,37 +329,40 @@ end -- needed for mathml analysis -function mathematics.utfmathclass(chr, default) +local function utfmathclass(chr, default) local cd = characters.data[utfbyte(chr)] return (cd and cd.mathclass) or default or "unknown" end -function mathematics.utfmathstretch(chr, default) -- "h", "v", "b", "" + +local function utfmathstretch(chr, default) -- "h", "v", "b", "" local cd = characters.data[utfbyte(chr)] return (cd and cd.mathstretch) or default or "" end -function mathematics.utfmathcommand(chr, default) + +local function utfmathcommand(chr, default) local cd = characters.data[utfbyte(chr)] local cmd = cd and cd.mathname return cmd or default or "" end -function mathematics.utfmathfiller(chr, default) + +local function utfmathfiller(chr, default) local cd = characters.data[utfbyte(chr)] local cmd = cd and (cd.mathfiller or cd.mathname) return cmd or default or "" end --- xml +mathematics.utfmathclass = utfmathclass +mathematics.utfmathstretch = utfmathstretch +mathematics.utfmathcommand = utfmathcommand +mathematics.utfmathfiller = utfmathfiller -mathematics.xml = { entities = { } } +-- interfaced + +function commands.utfmathclass (chr) context(utfmathclass (chr)) end +function commands.utfmathstretch(chr) context(utfmathstretch(chr)) end +function commands.utfmathcommand(chr) context(utfmathcommand(chr)) end +function commands.utfmathfiller (chr) context(utfmathfiller (chr)) end -function mathematics.xml.registerentities() - local entities = xml.entities - for name, unicode in next, mathematics.xml.entities do - if not entities[name] then - entities[name] = utfchar(unicode) - end - end -end -- helpers @@ -365,3 +394,70 @@ function mathematics.big(tfmdata,unicode,n) return unicode end +-- experimental + +-- local categories = { } -- indexed + hashed +-- +-- local a_mathcategory = attributes.private("mathcategory") +-- +-- local function registercategory(category,tag,data) -- always same data for tag +-- local c = categories[category] +-- if not c then +-- c = { } +-- categories[category] = c +-- end +-- local n = c[tag] +-- if not n then +-- n = #c + 1 +-- c[n] = data +-- n = n * 1000 + category +-- c[tag] = n +-- end +-- return n +-- end +-- +-- function mathematics.getcategory(n) +-- local category = n % 1000 +-- return category, categories[category][floor(n/1000)] +-- end +-- +-- mathematics.registercategory = registercategory +-- +-- function commands.taggedmathfunction(tag,label) +-- if label then +-- texattribute[a_mathcategory] = registercategory(1,tag,tag) +-- context.mathlabeltext(tag) +-- else +-- texattribute[a_mathcategory] = 1 +-- context(tag) +-- end +-- end + +local categories = { } +mathematics.categories = categories + +local a_mathcategory = attributes.private("mathcategory") + +local functions = storage.allocate() +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 + texattribute[a_mathcategory] = noffunctions + delta + else + texattribute[a_mathcategory] = n + delta + end + context.mathlabeltext(tag) + else + texattribute[a_mathcategory] = 1000 + delta + context(tag) + end +end |