diff options
34 files changed, 635 insertions, 402 deletions
diff --git a/tex/context/base/char-ini.mkiv b/tex/context/base/char-ini.mkiv index 09e25f7fb..bb4483b75 100644 --- a/tex/context/base/char-ini.mkiv +++ b/tex/context/base/char-ini.mkiv @@ -42,7 +42,8 @@ % use \normalUchar when possible .. the next one is nice for documents and it also accepts % 0x prefixed numbers -\def\utfchar#1{\ctxcommand{utfchar(\number#1)}} +\def\utfchar #1{\clf_utfchar \numexpr#1\relax} +\def\safechar#1{\clf_safechar\numexpr#1\relax} \def\checkedchar {\relax\ifmmode\expandafter\checkedmathchar\else\expandafter\checkedtextchar\fi} % #1#2 \def\checkedmathchar#1#2{#2} @@ -68,21 +69,22 @@ % move to lua side -\ctxcommand{setlettercatcodes(\number\texcatcodes)} -\ctxcommand{setlettercatcodes(\number\ctxcatcodes)} -\ctxcommand{setlettercatcodes(\number\notcatcodes)} -%ctxcommand{setlettercatcodes(\number\mthcatcodes)} -\ctxcommand{setlettercatcodes(\number\vrbcatcodes)} -\ctxcommand{setlettercatcodes(\number\prtcatcodes)} -\ctxcommand{setlettercatcodes(\number\tpacatcodes)} -\ctxcommand{setlettercatcodes(\number\tpbcatcodes)} -\ctxcommand{setlettercatcodes(\number\txtcatcodes)} - -\ctxcommand{setactivecatcodes(\number\ctxcatcodes)} -\ctxcommand{setactivecatcodes(\number\notcatcodes)} -\ctxcommand{setactivecatcodes(\number\prtcatcodes)} - -\def\chardescription#1% - {\ctxcommand{chardescription(\number#1)}} +%clf_setcharactercodes + +\clf_setlettercatcodes\texcatcodes +\clf_setlettercatcodes\ctxcatcodes +\clf_setlettercatcodes\notcatcodes +%clf_setlettercatcodes\mthcatcodes +\clf_setlettercatcodes\vrbcatcodes +\clf_setlettercatcodes\prtcatcodes +\clf_setlettercatcodes\tpacatcodes +\clf_setlettercatcodes\tpbcatcodes +\clf_setlettercatcodes\txtcatcodes + +\clf_setactivecatcodes\ctxcatcodes +\clf_setactivecatcodes\notcatcodes +\clf_setactivecatcodes\prtcatcodes + +\def\chardescription#1{\clf_chardescription#1\relax} \protect \endinput diff --git a/tex/context/base/char-tex.lua b/tex/context/base/char-tex.lua index e1caa64b9..7d2579814 100644 --- a/tex/context/base/char-tex.lua +++ b/tex/context/base/char-tex.lua @@ -6,10 +6,8 @@ if not modules then modules = { } end modules ['char-tex'] = { license = "see context related readme files" } -local lpeg = lpeg -local context = context -local commands = commands +local lpeg = lpeg local next, type = next, type local format, find, gmatch = string.format, string.find, string.gmatch local utfchar, utfbyte = utf.char, utf.byte @@ -23,6 +21,10 @@ local utfchartabletopattern = lpeg.utfchartabletopattern local allocate = utilities.storage.allocate local mark = utilities.storage.mark +local context = context +local commands = commands +local implement = interfaces.implement + local characters = characters local texcharacters = { } characters.tex = texcharacters @@ -417,15 +419,6 @@ if not context or not commands then return end -function texcharacters.defineaccents() - for accent, group in next, accentmapping do - context.dodefineaccentcommand(accent) - for character, mapping in next, group do - context.dodefineaccent(accent,character,mapping) - end - end -end - -- all kind of initializations local tex = tex @@ -437,37 +430,49 @@ local texsetcatcode = tex.setcatcode local contextsprint = context.sprint local ctxcatcodes = catcodes.numbers.ctxcatcodes +function texcharacters.defineaccents() + local dodefineaccentcommand = context.dodefineaccentcommand + local dodefineaccent = context.dodefineaccent + for accent, group in next, accentmapping do + dodefineaccentcommand(accent) + for character, mapping in next, group do + dodefineaccent(accent,character,mapping) + end + end +end + +implement { -- a waste of scanner but consistent + name = "defineaccents", + actions = texcharacters.defineaccents +} + --[[ldx-- <p>Instead of using a <l n='tex'/> file to define the named glyphs, we use the table. After all, we have this information available anyway.</p> --ldx]]-- -function commands.makeactive(n,name) -- +function commands.makeactive(n,name) -- not used contextsprint(ctxcatcodes,format("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name)) -- context("\\catcode%s=13\\unexpanded\\def %s{\\%s}",n,utfchar(n),name) end -function commands.utfchar(c,n) - if n then - -- contextsprint(c,charfromnumber(n)) - contextsprint(c,utfchar(n)) - else - -- contextsprint(charfromnumber(c)) - contextsprint(utfchar(c)) - end -end +implement { + name = "utfchar", + actions = { utfchar, contextsprint }, + arguments = "integer" +} -function commands.safechar(n) - local c = data[n] - if c and c.contextname then - contextsprint("\\" .. c.contextname) -- context[c.contextname]() - else - contextsprint(utfchar(n)) - end -end +implement { + name = "safechar", + actions = { texcharacters.safechar, contextsprint }, + arguments = "integer" +} tex.uprint = commands.utfchar +-- in contect we don't use lc and uc codes (in fact in luatex we should have a hf code) +-- so at some point we might drop this + local forbidden = tohash { -- at least now 0x00A0, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x200C, 0x200D, @@ -478,13 +483,46 @@ local forbidden = tohash { -- at least now local csletters = characters.csletters -- also a signal that we have initialized local activated = { } +local sfmode = "unset" -- unset, traditional, normal +local block_too = false + +directives.register("characters.blockstoo",function(v) block_too = v end) + +-- If this is something that is not documentwide and used a lot, then we +-- need a more clever approach (trivial but not now). + +local function setuppersfcodes(v,n) + if sfstate ~= "unset" then + report_defining("setting uppercase sf codes to %a",n) + for u, chr in next, data do + if chr.category == "lu" then + texsetsfcode(u,n) + end + end + end + sfstate = v +end + +directives.register("characters.spaceafteruppercase",function(v) + if v == "traditional" then + setuppersfcodes(v,999) + elseif v == "normal" then + setuppersfcodes(v,1000) + end +end) if not csletters then csletters = allocate() characters.csletters = csletters - report_defining("setting up character related commands") + report_defining("setting up character related codes and commands") + + if sfstate == "unset" then + sfstate = "traditional" + end + + local traditional = sfstate == "traditional" for u, chr in next, data do -- will move up local fallback = chr.fallback @@ -494,10 +532,11 @@ if not csletters then else local contextname = chr.contextname local category = chr.category + local isletter = is_letter[category] if contextname then if is_character[category] then if chr.unicodeslot < 128 then - if is_letter[category] then + if isletter then -- setmacro local c = utfchar(u) contextsprint(ctxcatcodes,format("\\def\\%s{%s}",contextname,c)) -- has no s @@ -510,26 +549,72 @@ if not csletters then -- setmacro local c = utfchar(u) contextsprint(ctxcatcodes,format("\\def\\%s{%s}",contextname,c)) -- has no s - if is_letter[chr.category] and u >= 32 and u <= 65536 then + if isletter and u >= 32 and u <= 65536 then csletters[c] = u end end + -- + if isletter then + local lc, uc = chr.lccode, chr.uccode + if not lc then + chr.lccode, lc = u, u + elseif type(lc) == "table" then + lc = u + end + if not uc then + chr.uccode, uc = u, u + elseif type(uc) == "table" then + uc = u + end + texsetlccode(u,lc,uc) + if traditional and category == "lu" then + texsetsfcode(code,999) + end + end + -- elseif is_command[category] and not forbidden[u] then -- set contextsprint("{\\catcode",u,"=13\\unexpanded\\gdef ",utfchar(u),"{\\"..contextname,"}}") activated[#activated+1] = u + elseif is_mark[category] then + texsetlccode(u,u,u) -- for hyphenation end - elseif is_letter[chr.category] and u >= 32 and u <= 65536 then + elseif isletter and u >= 32 and u <= 65536 then csletters[utfchar(u)] = u + -- + local lc, uc = chr.lccode, chr.uccode + if not lc then + chr.lccode, lc = u, u + elseif type(lc) == "table" then + lc = u + end + if not uc then + chr.uccode, uc = u, u + elseif type(uc) == "table" then + uc = u + end + texsetlccode(u,lc,uc) + if traditional and category == "lu" then + texsetsfcode(code,999) + end + -- + elseif is_mark[category] then + -- + texsetlccode(u,u,u) -- for hyphenation + -- end end end - if false then + if blocks_too then + -- this slows down format generation by over 10 percent for k, v in next, blocks do if v.catcode == "letter" then for u=v.first,v.last do csletters[utfchar(u)] = u + -- + -- texsetlccode(u,u,u) -- self self + -- end end end @@ -595,86 +680,63 @@ end <p>Setting the lccodes is also done in a loop over the data table.</p> --ldx]]-- -local sfmode = "unset" -- unset, traditional, normal - -function characters.setcodes() - if trace_defining then - report_defining("defining lc and uc codes") - end - local traditional = sfstate == "traditional" or sfstate == "unset" - for code, chr in next, data do - local cc = chr.category - if is_letter[cc] then - local range = chr.range - if range then - for i=range.first,range.last do - texsetcatcode(i,11) -- letter - texsetlccode(i,i,i) -- self self - end - else - local lc, uc = chr.lccode, chr.uccode - if not lc then - chr.lccode, lc = code, code - elseif type(lc) == "table" then - lc = code - end - if not uc then - chr.uccode, uc = code, code - elseif type(uc) == "table" then - uc = code - end - texsetcatcode(code,11) -- letter - texsetlccode(code,lc,uc) - if traditional and cc == "lu" then - texsetsfcode(code,999) - end - end - elseif is_mark[cc] then - texsetlccode(code,code,code) -- for hyphenation - end - end - if traditional then - sfstate = "traditional" - end -end - --- If this is something that is not documentwide and used a lot, then we --- need a more clever approach (trivial but not now). - -local function setuppersfcodes(v,n) - if sfstate ~= "unset" then - report_defining("setting uppercase sf codes to %a",n) - for code, chr in next, data do - if chr.category == "lu" then - texsetsfcode(code,n) - end - end - end - sfstate = v -end - -directives.register("characters.spaceafteruppercase",function(v) - if v == "traditional" then - setuppersfcodes(v,999) - elseif v == "normal" then - setuppersfcodes(v,1000) - end -end) +-- function characters.setcodes() -- we could loop over csletters +-- if trace_defining then +-- report_defining("defining lc and uc codes") +-- end +-- local traditional = sfstate == "traditional" or sfstate == "unset" +-- for code, chr in next, data do +-- local cc = chr.category +-- if is_letter[cc] then +-- local range = chr.range +-- if range then +-- for i=range.first,range.last do +-- texsetlccode(i,i,i) -- self self +-- end +-- else +-- local lc, uc = chr.lccode, chr.uccode +-- if not lc then +-- chr.lccode, lc = code, code +-- elseif type(lc) == "table" then +-- lc = code +-- end +-- if not uc then +-- chr.uccode, uc = code, code +-- elseif type(uc) == "table" then +-- uc = code +-- end +-- texsetlccode(code,lc,uc) +-- if traditional and cc == "lu" then +-- texsetsfcode(code,999) +-- end +-- end +-- elseif is_mark[cc] then +-- texsetlccode(code,code,code) -- for hyphenation +-- end +-- end +-- if traditional then +-- sfstate = "traditional" +-- end +-- end -- tex -function commands.chardescription(slot) - local d = data[slot] - if d then - context(d.description) - end -end +implement { + name = "chardescription", + arguments = "integer", + actions = function(slot) + local d = data[slot] + if d then + context(d.description) + end + end, +} -- xml characters.activeoffset = 0x10000 -- there will be remapped in that byte range -function commands.remapentity(chr,slot) +function commands.remapentity(chr,slot) -- not used contextsprint(format("{\\catcode%s=13\\xdef%s{\\string%s}}",slot,utfchar(slot),chr)) end @@ -696,6 +758,6 @@ end -- entities.gt = utfchar(characters.activeoffset + utfbyte(">")) -- end -commands.setlettercatcodes = characters.setlettercatcodes -commands.setactivecatcodes = characters.setactivecatcodes -commands.setcharactercodes = characters.setcodes +implement { name = "setlettercatcodes", scope = "private", actions = characters.setlettercatcodes, arguments = "integer" } +implement { name = "setactivecatcodes", scope = "private", actions = characters.setactivecatcodes, arguments = "integer" } +--------- { name = "setcharactercodes", scope = "private", actions = characters.setcodes } diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index b3594bf1f..e09e4caaa 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2015.03.28 10:30} +\newcontextversion{2015.03.28 16:30} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 3d6722c68..cd34b5514 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index dad14f536..af1be861c 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -28,7 +28,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2015.03.28 10:30} +\edef\contextversion{2015.03.28 16:30} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/enco-ini.mkiv b/tex/context/base/enco-ini.mkiv index 29b0542da..7a1aef5cc 100644 --- a/tex/context/base/enco-ini.mkiv +++ b/tex/context/base/enco-ini.mkiv @@ -360,7 +360,7 @@ % \defineaccent u {\empty} {\textbreve} % \defineaccent v {\empty} {\textcaron} -\ctxlua{characters.tex.defineaccents()} +\clf_defineaccents % one time %D A smaller and bolder variant, more like the math and monospaced ones. diff --git a/tex/context/base/lang-dis.lua b/tex/context/base/lang-dis.lua index 7a7b3f5de..db19a0fc5 100644 --- a/tex/context/base/lang-dis.lua +++ b/tex/context/base/lang-dis.lua @@ -174,7 +174,7 @@ end local enabled = false -function commands.showdiscretionaries(v) +function languages.showdiscretionaries(v) if v == false then setattribute(a_visualize,unsetvalue) else -- also nil @@ -186,6 +186,11 @@ function commands.showdiscretionaries(v) end end +interfaces.implement { + name = "showdiscretionaries", + actions = languages.showdiscretionaries +} + local toutf = nodes.listtoutf function languages.serializediscretionary(d) -- will move to tracer diff --git a/tex/context/base/lang-hyp.lua b/tex/context/base/lang-hyp.lua index 7bd307f8e..ab6ab33df 100644 --- a/tex/context/base/lang-hyp.lua +++ b/tex/context/base/lang-hyp.lua @@ -70,6 +70,8 @@ local trace_visualize = false trackers.register("hyphenator.visualize",functi local report = logs.reporter("hyphenator") +local implement = interfaces and interfaces.implement or function() end + languages = languages or { } local hyphenators = languages.hyphenators or { } languages.hyphenators = hyphenators @@ -837,10 +839,7 @@ if context then return register(name,featureset) end - traditional.definefeatures = definefeatures - commands.definehyphenationfeatures = definefeatures - - function commands.sethyphenationfeatures(n) + local function setfeatures(n) if not n or n == v_reset then n = false else @@ -865,8 +864,46 @@ if context then texsetattribute(a_hyphenation,n or unsetvalue) end - commands.registerhyphenationpattern = traditional.registerpattern - commands.registerhyphenationexception = traditional.registerexception + traditional.definefeatures = definefeatures + traditional.setfeatures = setfeatures + + implement { + name = "definehyphenationfeatures", + actions = definefeatures, + arguments = { + "string", + { + { "characters" }, + { "hyphens" }, + { "joiners" }, + { "rightwordmin", "integer" }, + { "leftcharmin", "integer" }, + { "rightcharmin", "integer" }, + { "leftchar", "integer" }, + { "rightchar", "integer" }, + { "alternative" }, + { "rightedge" }, + } + } + } + + implement { + name = "sethyphenationfeatures", + actions = setfeatures, + arguments = "string" + } + + implement { + name = "registerhyphenationpattern", + actions = traditional.registerpattern, + arguments = { "string", "string", "boolean" } + } + + implement { + name = "registerhyphenationexception", + actions = traditional.registerexception, + arguments = { "string", "string" } + } -- This is a relative large function with local variables and local -- functions. A previous implementation had the functions outside but @@ -1484,22 +1521,25 @@ if context then directives.register("hyphenators.method",setmethod) - function commands.setuphyphenation(specification) + function hyphenators.setup(specification) local method = specification.method if method then setmethod(method) end end - commands.pushhyphenation = pushmethod - commands.pophyphenation = popmethod + implement { name = "sethyphenationmethod", actions = setmethod, arguments = "string" } + implement { name = "pushhyphenation", actions = pushmethod, arguments = "string" } + implement { name = "pophyphenation", actions = popmethod } + + -- can become a runtime loaded one: local context = context local ctx_NC = context.NC local ctx_NR = context.NR local ctx_verbatim = context.verbatim - function commands.showhyphenationtrace(language,word) + function hyphenators.showhyphenationtrace(language,word) if not word or word == "" then return end @@ -1525,6 +1565,12 @@ if context then end end + implement { + name = "showhyphenationtrace", + actions = hyphenators.showhyphenationtrace, + arguments = { "string", "string" } + } + function nodes.stripdiscretionaries(head) local h = tonut(head) for l in traverse_id(hlist_code,h) do diff --git a/tex/context/base/lang-hyp.mkiv b/tex/context/base/lang-hyp.mkiv index 24faed9cc..aed6f6c2c 100644 --- a/tex/context/base/lang-hyp.mkiv +++ b/tex/context/base/lang-hyp.mkiv @@ -70,18 +70,18 @@ \s!lefthyphenchar=0] % number \appendtoks - \ctxcommand{setuphyphenation{method="\hyphenationparameter\c!method"}}% + \clf_sethyphenationmethod{\hyphenationparameter\c!method}% \to \everysetuphyphenation %D These are mostly meant for manuals: \unexpanded\def\starthyphenation[#1]% {\begingroup - \ctxcommand{pushhyphenation("#1")}} + \clf_pushhyphenation{#1}} \unexpanded\def\stophyphenation {\ifhmode\par\fi - \ctxcommand{pophyphenation()}% + \clf_pophyphenation \endgroup} % This is a global setting, so we need to disable it when needed. However, as @@ -96,33 +96,36 @@ \unexpanded\def\lang_hyphenation_define_features[#1][#2]% {\begingroup - \letdummyparameter\c!characters\empty % maybe \s! - \letdummyparameter\c!hyphens\empty % maybe \s! - \letdummyparameter\c!joiners\empty % maybe \s! - \letdummyparameter\c!rightwords\!!zerocount % maybe \s! - \letdummyparameter\s!lefthyphenmin\!!zerocount - \letdummyparameter\s!righthyphenmin\!!zerocount - \letdummyparameter\s!lefthyphenchar\!!zerocount - \letdummyparameter\s!righthyphenchar\!!zerocount + \letdummyparameter\c!characters\empty % maybe \s! + \letdummyparameter\c!hyphens\empty % maybe \s! + \letdummyparameter\c!joiners\empty % maybe \s! + \letdummyparameter\c!rightwords\zerocount % maybe \s! + \letdummyparameter\s!lefthyphenmin\zerocount + \letdummyparameter\s!righthyphenmin\zerocount + \letdummyparameter\s!lefthyphenchar\zerocount + \letdummyparameter\s!righthyphenchar\zerocount \letdummyparameter\c!alternative\empty \letdummyparameter\c!rightedge\empty \getdummyparameters[#2]% - \ctxcommand{definehyphenationfeatures("#1",{ - characters = \!!bs\dummyparameter\c!characters\!!es, - hyphens = \!!bs\dummyparameter\c!hyphens\!!es, - joiners = \!!bs\dummyparameter\c!joiners\!!es, - rightwordmin = \number\dummyparameter\c!rightwords, - leftcharmin = \number\dummyparameter\s!lefthyphenmin, - rightcharmin = \number\dummyparameter\s!righthyphenmin, - leftchar = \number\dummyparameter\s!lefthyphenchar, - rightchar = \number\dummyparameter\s!righthyphenchar, - alternative = "\dummyparameter\c!alternative", - rightedge = "\dummyparameter\c!rightedge", - })}% + \clf_definehyphenationfeatures + {#1}% + { + characters {\dummyparameter\c!characters}% + hyphens {\dummyparameter\c!hyphens}% + joiners {\dummyparameter\c!joiners}% + rightwordmin \numexpr\dummyparameter\c!rightwords\relax + leftcharmin \numexpr\dummyparameter\s!lefthyphenmin\relax + rightcharmin \numexpr\dummyparameter\s!righthyphenmin\relax + leftchar \numexpr\dummyparameter\s!lefthyphenchar\relax + rightchar \numexpr\dummyparameter\s!righthyphenchar\relax + alternative {\dummyparameter\c!alternative}% + rightedge {\dummyparameter\c!rightedge}% + }% + \relax \endgroup} \unexpanded\def\sethyphenationfeatures[#1]% - {\ctxcommand{sethyphenationfeatures("#1")}} + {\cclf_sethyphenationfeatures{#1}} % todo: \start ... \stop too @@ -130,44 +133,19 @@ {\dodoubleempty\lang_hyphenation_register_pattern} \def\lang_hyphenation_register_pattern[#1][#2]% - {\ctxcommand{registerhyphenationpattern( - \ifsecondargument - \!!bs#1\!!es, - \!!bs#2\!!es - \else - \!!bs\currentlanguage\!!es, - \!!bs#1\!!es - \fi - )}} + {\clf_registerhyphenationpattern\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\s!true\relax} \unexpanded\def\unregisterhyphenationpattern {\dodoubleempty\lang_hyphenation_unregister_pattern} \def\lang_hyphenation_unregister_pattern[#1][#2]% - {\ctxcommand{registerhyphenationpattern( - \ifsecondargument - \!!bs#1\!!es, - \!!bs#2\!!es, - \else - \!!bs\currentlanguage\!!es, - \!!bs#1\!!es, - \fi - false - )}} + {\clf_registerhyphenationpattern\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\s!false\relax} \unexpanded\def\registerhyphenationexception {\dodoubleempty\lang_hyphenation_register_exception} \def\lang_hyphenation_register_exception[#1][#2]% - {\ctxcommand{registerhyphenationexception( - \ifsecondargument - \!!bs#1\!!es, - \!!bs#2\!!es - \else - \!!bs\currentlanguage\!!es, - \!!bs#1\!!es - \fi - )}} + {\clf_registerhyphenationexception\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\relax} \unexpanded\def\showhyphenationtrace {\dodoubleempty\lang_hyphenation_show_trace} @@ -175,15 +153,7 @@ \def\lang_hyphenation_show_trace[#1][#2]% {\begingroup \tt - \ctxcommand{showhyphenationtrace( - \ifsecondargument - \!!bs#1\!!es, - \!!bs#2\!!es - \else - \!!bs\currentlanguage\!!es, - \!!bs#1\!!es - \fi - )}% + \clf_showhyphenationtrace\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\relax \endgroup} % For old times sake: @@ -199,7 +169,7 @@ %D For me: \unexpanded\def\showdiscretionaries - {\ctxcommand{showdiscretionaries()}} + {\clf_showdiscretionaries} %D These are (at least now) not cummulative: diff --git a/tex/context/base/lang-ini.lua b/tex/context/base/lang-ini.lua index 27bab6129..d75a665e2 100644 --- a/tex/context/base/lang-ini.lua +++ b/tex/context/base/lang-ini.lua @@ -21,8 +21,9 @@ local utfbyte = utf.byte local format, gsub = string.format, string.gsub local concat, sortedkeys, sortedpairs = table.concat, table.sortedkeys, table.sortedpairs -local context = context -local commands = commands +local context = context +local commands = commands +local implement = interfaces.implement local settings_to_array = utilities.parsers.settings_to_array @@ -386,31 +387,58 @@ end) -- interface -local getnumber = languages.getnumber +implement { + name = "languagenumber", + actions = { languages.getnumber, context }, + arguments = { "string", "string", "string" } +} -function commands.languagenumber(tag,default,patterns) - context(getnumber(tag,default,patterns)) -end +implement { + name = "installedlanguages", + actions = { languages.installed, context }, +} -function commands.installedlanguages(separator) - context(languages.installed(separator)) -end +implement { + name = "definelanguage", + actions = languages.define, + arguments = { "string", "string" } +} -commands.definelanguage = languages.define -commands.setlanguagesynonym = languages.setsynonym -commands.unloadlanguage = languages.unload -commands.setlanguageexceptions = languages.setexceptions +implement { + name = "setlanguagesynonym", + actions = languages.setsynonym, + arguments = { "string", "string" } +} + +implement { + name = "unloadlanguage", + actions = languages.unload, + arguments = { "string" } +} -function commands.prehyphenchar(l) - local c = prehyphenchar(tolang(l)) - if c and c > 0 then - context.char(c) +implement { + name = "setlanguageexceptions", + actions = languages.setexceptions, + arguments = { "string", "string" } +} + + +implement { + name = "currentprehyphenchar", + actions = function() + local c = prehyphenchar(tolang()) + if c and c > 0 then + context.char(c) + end end -end +} -function commands.posthyphenchar(l) - local c = posthyphenchar(tolang(l)) - if c and c > 0 then - context.char(c) +implement { + name = "currentposthyphenchar", + actions = function() + local c = posthyphenchar(tolang()) + if c and c > 0 then + context.char(c) + end end -end +} diff --git a/tex/context/base/lang-ini.mkiv b/tex/context/base/lang-ini.mkiv index ddd7a8808..3391c6510 100644 --- a/tex/context/base/lang-ini.mkiv +++ b/tex/context/base/lang-ini.mkiv @@ -211,7 +211,7 @@ \newtoks \everysetuplanguage -\def\installedlanguages{\ctxcommand{installedlanguages()}} +\def\installedlanguages{\clf_installedlanguages} \unexpanded\def\doiflanguageelse#1% {\ifcsname\??language#1\c!state\endcsname @@ -236,10 +236,10 @@ \lang_basics_install_indeed{#1}{#1}% \getparameters[\??language#1][\c!state=\v!start,#2]}% \edef\currentsetuplanguage{#1}% - \ctxcommand{definelanguage("#1","\specificlanguageparameter{#1}\s!default")}% + \clf_definelanguage{#1}{\specificlanguageparameter{#1}\s!default}% \the\everysetuplanguage} {\setvalue{\??languagelinked#1}{#2}% - \ctxcommand{setlanguagesynonym("#1","#2")}% + \clf_setlanguagesynonym{#1}{#2}% \lang_basics_install_indeed{#1}{#2}}} \def\lang_basics_install_indeed#1#2% @@ -291,7 +291,7 @@ \lang_basics_synchronize} \appendtoks - \ctxcommand{unloadlanguage("\currentsetuplanguage")}% + \clf_unloadlanguage{\currentsetuplanguage}% \to \everysetuplanguage \setuplanguage @@ -413,11 +413,11 @@ \def\lang_basics_synchronize_yes {\zerocount % see below \global\expandafter\chardef\csname\??languagenumbers\currentlanguage\endcsname - \ctxcommand{languagenumber(% - "\currentlanguage",% - "\defaultlanguage\currentlanguage",% - "\languageparameter\s!patterns"% - )}\relax + \clf_languagenumber + {\currentlanguage}% + {\defaultlanguage\currentlanguage}% + {\languageparameter\s!patterns}% + \relax \normallanguage\csname\??languagenumbers\currentlanguage\endcsname} \let\lang_basics_synchronize_nop\zerocount % not loaded anyway @@ -733,7 +733,7 @@ \ifx\askedlanguage\empty \let\askedlanguage\currentlanguage \fi - \ctxcommand{setlanguageexceptions("\askedlanguage",\!!bs#2\!!es)}% + \clf_setlanguageexceptions{\askedlanguage}{#2}% \endgroup} %D For the moment here: @@ -749,8 +749,8 @@ \unexpanded\def\samplediscretionary {\traceddiscretionary - {pre\ctxcommand{prehyphenchar()}}% - {\ctxcommand{posthyphenchar()}post}% + {pre\clf_currentprehyphenchar}% + {\clf_currentposthyphenchar post}% {replace}} % todo: make this configurable diff --git a/tex/context/base/lang-lab.lua b/tex/context/base/lang-lab.lua index 1675146be..5ce1b7b01 100644 --- a/tex/context/base/lang-lab.lua +++ b/tex/context/base/lang-lab.lua @@ -111,7 +111,11 @@ end -- interface -commands.definelabels = labels.define +interfaces.implement { + name = "definelabels", + actions = labels.define, + arguments = { "string", "string", "boolean" } +} -- function commands.setstrippedtextprefix(str) -- context(string.strip(str)) diff --git a/tex/context/base/lang-lab.mkiv b/tex/context/base/lang-lab.mkiv index c5c2adc01..afa9f2b2b 100644 --- a/tex/context/base/lang-lab.mkiv +++ b/tex/context/base/lang-lab.mkiv @@ -265,10 +265,10 @@ \definelabelclass [mathlabel] [0] % functions \definelabelclass [taglabel] [2] % tags -\ctxcommand{definelabels("head", "titles", true )} -\ctxcommand{definelabels("label", "texts", true )} -\ctxcommand{definelabels("mathlabel", "functions",false)} -\ctxcommand{definelabels("taglabel", "tags", false)} +\clf_definelabels{head}{titles}\s!true\relax +\clf_definelabels{label}{texts}\s!true\relax +\clf_definelabels{mathlabel}{functions}\s!false\relax +\clf_definelabels{taglabel}{tags}\s!false\relax %D \macros %D {translate} diff --git a/tex/context/base/math-act.lua b/tex/context/base/math-act.lua index e767903a2..9c69a09de 100644 --- a/tex/context/base/math-act.lua +++ b/tex/context/base/math-act.lua @@ -473,21 +473,17 @@ setmetatableindex(extensibles,function(extensibles,font) return codes end) -function mathematics.extensiblecode(family,unicode) +local function extensiblecode(family,unicode) return extensibles[family_font(family or 0)][unicode][1] end -function commands.extensiblecode(family,unicode) - context(extensibles[family_font(family or 0)][unicode][1]) -end - -- left : [head] ... -- right : ... [head] -- horizontal : [head] ... [head] -- -- abs(right["start"] - right["end"]) | right.advance | characters[right.glyph].width -function commands.horizontalcode(family,unicode) +local function horizontalcode(family,unicode) local font = family_font(family or 0) local data = extensibles[font][unicode] local kind = data[1] @@ -511,13 +507,30 @@ function commands.horizontalcode(family,unicode) loffset = abs((left ["start"] or 0) - (left ["end"] or 0)) roffset = abs((right["start"] or 0) - (right["end"] or 0)) end - else end - texsetdimen("scratchleftoffset",loffset) - texsetdimen("scratchrightoffset",roffset) - context(kind) + return kind, loffset, roffset end +mathematics.extensiblecode = extensiblecode +mathematics.horizontalcode = horizontalcode + +interfaces.implement { + name = "extensiblecode", + arguments = { "integer", "integer" }, + actions = { extensiblecode, context } +} + +interfaces.implement { + name = "horizontalcode", + arguments = { "integer", "integer" }, + actions = function(family,unicode) + local kind, loffset, roffset = horizontalcode(family,unicode) + texsetdimen("scratchleftoffset", loffset) + texsetdimen("scratchrightoffset",roffset) + context(kind) + end +} + -- experiment -- check: when true, only set when present in font diff --git a/tex/context/base/math-dir.lua b/tex/context/base/math-dir.lua index 525d07831..0f871beed 100644 --- a/tex/context/base/math-dir.lua +++ b/tex/context/base/math-dir.lua @@ -162,4 +162,8 @@ function directions.setmath(n) end end -commands.setmathdirection = directions.setmath +interfaces.implement { + name = "setmathdirection", + actions = directions.setmath, + arguments = "integer" +} diff --git a/tex/context/base/math-frc.lua b/tex/context/base/math-frc.lua index a663fb3ec..1485c2159 100644 --- a/tex/context/base/math-frc.lua +++ b/tex/context/base/math-frc.lua @@ -28,8 +28,8 @@ end) local ctx_normalatop = context.normalatop local ctx_normalover = context.normalover -function commands.math_frac(how,left,right,width) - if how == v_no then +local function mathfraction(how,left,right,width) -- of course we could use the scanners directly here which + if how == v_no then -- is faster but also less abstract ... maybe some day if left == 0x002E and right == 0x002E then ctx_normalatop() else @@ -49,3 +49,9 @@ function commands.math_frac(how,left,right,width) end end end + +interfaces.implement { + name = "mathfraction", + actions = mathfraction, + arguments = { "string", "integer", "dimen", "dimen" } +} diff --git a/tex/context/base/math-frc.mkiv b/tex/context/base/math-frc.mkiv index 932053f8f..36004b842 100644 --- a/tex/context/base/math-frc.mkiv +++ b/tex/context/base/math-frc.mkiv @@ -221,12 +221,12 @@ % we use utfchar anyway so we can as well do all at the lua end \def\math_frac_command - {\ctxcommand{math_frac(% - "\mathfractionparameter\c!rule",% - \number\mathfractionparameter\c!left,% - \number\mathfractionparameter\c!right,% - \number\dimexpr\mathfractionparameter\c!rulethickness% - )}} + {\cclf_mathfraction + {\mathfractionparameter\c!rule}% + \numexpr\mathfractionparameter\c!left\relax + \numexpr\mathfractionparameter\c!right\relax + \dimexpr\mathfractionparameter\c!rulethickness\relax + \relax} % Having a \withmarginornot{#1}{#2} makes not much sense nor do 4 tests or 4 redundant % kerns (longer node lists plus possible interference). A split in normal and margin 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 +} diff --git a/tex/context/base/math-ini.mkiv b/tex/context/base/math-ini.mkiv index a194b7348..2002834b1 100644 --- a/tex/context/base/math-ini.mkiv +++ b/tex/context/base/math-ini.mkiv @@ -101,7 +101,7 @@ \setnewconstant\defaultmathfamily \zerocount % 255 -\unexpanded\def\resetmathattributes{\ctxcommand{resetmathattributes()}} +\unexpanded\def\resetmathattributes{\clf_resetmathattributes} % handy @@ -143,9 +143,9 @@ \unexpanded\def\rawmathematics#1% slow but only for tracing {\begingroup \ifmmode - \resetmathattributes#1% + \clf_resetmathattributes#1% \else - \startimath\resetmathattributes#1\stopimath + \startimath\clf_resetmathattributes#1\stopimath \fi \endgroup} @@ -195,7 +195,7 @@ \unexpanded\def\math_set_attribute #1#2{\ifmmode\clf_setmathattribute{#1}{#2}\fi} \unexpanded\def\math_set_alphabet #1{\ifmmode\clf_setmathalphabet{#1}\fi} \unexpanded\def\math_set_font_style #1{\ifmmode\clf_setmathstyle{#1}\fi} -\unexpanded\def\math_set_font_alternate#1{\ifmmode\ctxcommand{setmathalternate(\number\defaultmathfamily,"#1")}\fi} +\unexpanded\def\math_set_font_alternate#1{\ifmmode\clf_setmathalternate\defaultmathfamily{#1}\fi} \installcorenamespace{mathstylealternate} % might become a setuphandler @@ -309,7 +309,7 @@ \newcount\c_math_renderings_attribute \appendtoks - \c_math_renderings_attribute\ctxcommand{mathrenderset("\mathematicsparameter\c!symbolset")}\relax + \c_math_renderings_attribute\clf_mathrenderset{\mathematicsparameter\c!symbolset}\relax \to \everysetupmathematics % only in mathematics \appendtoks @@ -331,27 +331,21 @@ \unexpanded\def\boldsymbol {\mathortext\mathboldsymbol\bold} -%D Helpers: +%D Helpers (assume {} being used): -\def\utfmathclass #1{\ctxcommand{utfmathclass (\!!bs#1\!!es)}} -\def\utfmathstretch#1{\ctxcommand{utfmathstretch(\!!bs#1\!!es)}} -\def\utfmathcommand#1{\ctxcommand{utfmathcommand(\!!bs#1\!!es)}} -\def\utfmathfiller #1{\ctxcommand{utfmathfiller (\!!bs#1\!!es)}} +\let\utfmathclass \clf_utfmathclass +\let\utfmathstretch \clf_utfmathstretch +\let\utfmathcommand \clf_utfmathcommand +\let\utfmathfiller \clf_utfmathfiller -\def\utfmathclassfiltered #1#2{\ctxcommand{utfmathclass (\!!bs#1\!!es,nil,\!!bs#2\!!es)}} -\def\utfmathcommandfiltered#1#2{\ctxcommand{utfmathcommand(\!!bs#1\!!es,nil,\!!bs#2\!!es)}} +\let\utfmathcommandabove \clf_utfmathcommandabove +\let\utfmathcommandbelow \clf_utfmathcommandbelow +\let\utfmathcommandfiller\clf_utfmathcommandfiller -\def\utfmathcommandabove #1{\ctxcommand{utfmathcommandabove (\!!bs#1\!!es)}} -\def\utfmathcommandbelow #1{\ctxcommand{utfmathcommandbelow (\!!bs#1\!!es)}} -\def\utfmathcommandfiller#1{\ctxcommand{utfmathcommandfiller(\!!bs#1\!!es)}} - -\unexpanded\def\doifelseutfmathaccent #1{\ctxcommand{doifelseutfmathaccent(\!!bs#1\!!es)}} -\unexpanded\def\doifelseutfmathaccentfiltered#1#2{\ctxcommand{doifelseutfmathaccent(\!!bs#1\!!es,\!!bs#2\!!es)}} - -\unexpanded\def\doifelseutfmathabove #1{\ctxcommand{doifelseutfmathabove(\!!bs#1\!!es)}} -\unexpanded\def\doifelseutfmathbelow #1{\ctxcommand{doifelseutfmathbelow(\!!bs#1\!!es)}} - -\unexpanded\def\doifelseutfmathfiller #1{\ctxcommand{doifelseutfmathfiller(\!!bs#1\!!es)}} +\unexpanded\def\doifelseutfmathaccent{\clf_doifelseutfmathaccent} +\unexpanded\def\doifelseutfmathabove {\clf_doifelseutfmathabove } +\unexpanded\def\doifelseutfmathbelow {\clf_doifelseutfmathbelow } +\unexpanded\def\doifelseutfmathfiller{\clf_doifelseutfmathfiller} %D Not used that much: @@ -531,8 +525,8 @@ % Once this is stable we can store the number at the tex end which is % faster. Functions getnumbers >= 1000. -\expanded\def\math_tags_mathfunction_indeed #1{\ctxcommand{taggedmathfunction("#1",false,\ifconditional\c_apply_function true\else false\fi)}} -\expanded\def\math_tags_mathfunctionlabeltext_indeed#1{\ctxcommand{taggedmathfunction("#1",true ,\ifconditional\c_apply_function true\else false\fi)}} +\expanded\def\math_tags_mathfunction_indeed #1{\clf_taggedmathfunction{#1}{false}{\ifconditional\c_apply_function true\else false\fi}} +\expanded\def\math_tags_mathfunctionlabeltext_indeed#1{\clf_taggedmathfunction{#1} {true}{\ifconditional\c_apply_function true\else false\fi}} \expanded\def\math_tags_mo_indeed#1{\begingroup \attribute\mathcategoryattribute\plusone #1\endgroup} \expanded\def\math_tags_mi_indeed#1{\begingroup \attribute\mathcategoryattribute\plustwo #1\endgroup} @@ -954,8 +948,8 @@ \newcount\c_math_bidi -\setvalue{\??mathbidi\v!no }{\ctxcommand{setmathdirection(0)}\c_math_bidi\attributeunsetvalue} -\setvalue{\??mathbidi\v!yes}{\ctxcommand{setmathdirection(1)}\c_math_bidi\plusone} +\setvalue{\??mathbidi\v!no }{\clf_setmathdirection\zerocount\relax\c_math_bidi\attributeunsetvalue} +\setvalue{\??mathbidi\v!yes}{\clf_setmathdirection\plusone \relax\c_math_bidi\plusone} \appendtoks \edef\p_bidi{\mathematicsparameter\c!bidi}% @@ -1037,7 +1031,7 @@ \def\math_italics_initialize {\ifnum\c_math_italics_attribute=\attributeunsetvalue \else - \ctxcommand{setmathitalics()}% one time + \clf_setmathitalics % one time \global\let\math_italics_initialize\relax \fi} @@ -1920,11 +1914,8 @@ % this should be a primitive: -% \def\mathextensiblecode#1#2% -% {\cldcontext{mathematics.extensiblecode(\number#1,\number#2)}} - -\def\mathextensiblecode#1#2{\ctxcommand{extensiblecode(\number#1,\number#2)}} -\def\mathhorizontalcode#1#2{\ctxcommand{horizontalcode(\number#1,\number#2)}} +\def\mathextensiblecode#1#2{\clf_extensiblecode\numexpr#1\relax\numexpr#2\relax} +\def\mathhorizontalcode#1#2{\clf_horizontalcode\numexpr#1\relax\numexpr#2\relax} % experimental: diff --git a/tex/context/base/math-noa.lua b/tex/context/base/math-noa.lua index be1f4a9b5..412d18d05 100644 --- a/tex/context/base/math-noa.lua +++ b/tex/context/base/math-noa.lua @@ -1234,6 +1234,20 @@ end) -- interface -commands.setmathalternate = mathematics.setalternate -commands.setmathitalics = mathematics.setitalics -commands.resetmathitalics = mathematics.resetitalics +local implement = interfaces.implement + +implement { + name = "setmathalternate", + actions = mathematics.setalternate, + arguments = { "integer", "string" } +} + +implement { + name = "setmathitalics", + actions = mathematics.setitalics +} + +implement { + name = "resetmathitalics", + actions = mathematics.resetitalics +} diff --git a/tex/context/base/math-ren.lua b/tex/context/base/math-ren.lua index 5c4c13369..4628ffe55 100644 --- a/tex/context/base/math-ren.lua +++ b/tex/context/base/math-ren.lua @@ -60,6 +60,8 @@ end mathematics.renderset = renderset -function commands.mathrenderset(list) - context(renderset(list)) -end +interfaces.implement { + name = "mathrenderset", + actions = { renderset, context }, + arguments = "string", +} diff --git a/tex/context/base/node-aux.lua b/tex/context/base/node-aux.lua index 8f1146857..f705e4774 100644 --- a/tex/context/base/node-aux.lua +++ b/tex/context/base/node-aux.lua @@ -314,7 +314,7 @@ nuts .firstcharinbox = firstcharinbox nodes.firstcharinbox = firstcharinbox nodes.firstcharacter = vianuts(firstcharacter) -function commands.buildtextaccent(n) +function commands.buildtextaccent(n) -- Is this crap really used? Or was it an experiment? local char = firstcharinbox(n) if char > 0 then -- context.accent(false,char) diff --git a/tex/context/base/pack-rul.lua b/tex/context/base/pack-rul.lua index 0c29eb5f1..5229987ea 100644 --- a/tex/context/base/pack-rul.lua +++ b/tex/context/base/pack-rul.lua @@ -24,6 +24,8 @@ local line_code = nodes.listcodes.line local texsetdimen = tex.setdimen local texsetcount = tex.setcount +local implement = interfaces.implement + local nuts = nodes.nuts local getfield = nuts.getfield @@ -39,7 +41,7 @@ local hpack = nuts.hpack local traverse_id = nuts.traverse_id local node_dimensions = nuts.dimensions -function commands.doreshapeframedbox(n) +local function doreshapeframedbox(n) local box = getbox(n) local noflines = 0 local firstheight = nil @@ -128,7 +130,7 @@ function commands.doreshapeframedbox(n) texsetdimen("global","framedaveragewidth",averagewidth) end -function commands.doanalyzeframedbox(n) +local function doanalyzeframedbox(n) local box = getbox(n) local noflines = 0 local firstheight = nil @@ -156,6 +158,8 @@ function commands.doanalyzeframedbox(n) texsetdimen("global","framedlastdepth",lastdepth or 0) end +implement { name = "doreshapeframedbox", actions = doreshapeframedbox, arguments = "integer" } +implement { name = "doanalyzeframedbox", actions = doanalyzeframedbox, arguments = "integer" } function nodes.maxboxwidth(box) local boxwidth = getfield(box,"width") diff --git a/tex/context/base/pack-rul.mkiv b/tex/context/base/pack-rul.mkiv index 72e86b545..2875f0f18 100644 --- a/tex/context/base/pack-rul.mkiv +++ b/tex/context/base/pack-rul.mkiv @@ -2287,8 +2287,8 @@ \framedmaxwidth \zeropoint \framedaveragewidth\zeropoint} -\def\pack_framed_reshape_process{\ifvbox\b_framed_normal\ctxcommand{doreshapeframedbox(\number\b_framed_normal)}\fi} -\def\pack_framed_reshape_analyze{\ifvbox\b_framed_normal\ctxcommand{doanalyzeframedbox(\number\b_framed_normal)}\fi} +\def\pack_framed_reshape_process{\ifvbox\b_framed_normal\clf_doreshapeframedbox\b_framed_normal\relax\fi} +\def\pack_framed_reshape_analyze{\ifvbox\b_framed_normal\clf_doanalyzeframedbox\b_framed_normal\relax\fi} % torture test / strange case (much depth) / method 2 needed % diff --git a/tex/context/base/phys-dim.lua b/tex/context/base/phys-dim.lua index db0b5740d..7430b62d7 100644 --- a/tex/context/base/phys-dim.lua +++ b/tex/context/base/phys-dim.lua @@ -50,12 +50,11 @@ local utfchar = utf.char physics = physics or { } physics.units = physics.units or { } -local variables = interfaces.variables -local v_reverse = variables.reverse local allocate = utilities.storage.allocate local context = context local commands = commands +local implement = interfaces.implement local trace_units = false local report_units = logs.reporter("units") @@ -173,8 +172,8 @@ local p_c = (ddigitspace^1 * dskipperiod)^0 -- ___. local p_c_dparser = math_one + math_two + dleader * p_c * dtrailer * dfinal local c_p_dparser = math_one + math_two + dleader * c_p * dtrailer * dfinal -function commands.digits(str,p_c) - if p_c == v_reverse then +local function makedigits(str,reverse) + if reverse then matchlpeg(p_c_dparser,str) else matchlpeg(c_p_dparser,str) @@ -877,7 +876,7 @@ local p_c_parser = nil local c_p_parser = nil local dirty = true -function commands.unit(str,p_c) +local function makeunit(str,reverse) if dirty then if trace_units then report_units("initializing parser") @@ -886,7 +885,7 @@ function commands.unit(str,p_c) dirty = false end local ok - if p_c == v_reverse then + if reverse then ok = matchlpeg(p_c_parser,str) else ok = matchlpeg(c_p_parser,str) @@ -932,7 +931,7 @@ local mapping = { packaged = "packaged", } -function commands.registerunit(category,list) +local function registerunit(category,list) if not list or list == "" then list = category category = "unit" @@ -945,3 +944,11 @@ function commands.registerunit(category,list) end -- inspect(tables) end + +physics.units.registerunit = registerunit + +implement { name = "digits_normal", actions = makedigits, arguments = "string" } +implement { name = "digits_reverse", actions = makedigits, arguments = { "string", true } } +implement { name = "unit_normal", actions = makeunit, arguments = "string"} +implement { name = "unit_reverse", actions = makeunit, arguments = { "string", true } } +implement { name = "registerunit", actions = registerunit, arguments = { "string", "string" } } diff --git a/tex/context/base/phys-dim.mkiv b/tex/context/base/phys-dim.mkiv index 3de6b2344..d3aae0114 100644 --- a/tex/context/base/phys-dim.mkiv +++ b/tex/context/base/phys-dim.mkiv @@ -246,7 +246,7 @@ \unexpanded\def\phys_digits_indeed#1% {\dontleavehmode \begingroup - \ctxcommand{digits(\!!bs\detokenize{#1}\!!es,"\ifcase\c_phys_digits_order \v!normal\else\v!reverse\fi")}% + \ifcase\c_phys_digits_order\expandafter\clf_digits_normal\else\expandafter\clf_digits_reverse\fi{\detokenize{#1}}% \endgroup \settrue\c_phys_units_dospace} @@ -500,7 +500,8 @@ \to \everyunits \unexpanded\def\phys_units_indeed#1% - {\ctxcommand{unit(\!!bs\detokenize{#1}\!!es,"\unitparameter\c!order")}} + {\edef\p_order{\unitparameter\c!order}% + \ifx\p_order\v!reverse\expandafter\clf_unit_reverse\else\expandafter\clf_unit_normal\fi{\detokenize{#1}}} \unexpanded\def\unitsPUS#1#2#3{\phys_units_next\prefixtext{#1}\unittext{#2}\unitsraise{\suffixtext{#3}}\c_phys_units_state\plusone} % suffix \unexpanded\def\unitsPU #1#2{\phys_units_next\prefixtext{#1}\unittext{#2}\c_phys_units_state\plusthree} % unit @@ -682,10 +683,10 @@ \definelabelclass [prefix] [2] \definelabelclass [suffix] [2] % This is only a label because we want to show them in a table. -\ctxcommand{definelabels("prefix", "prefixes" )} -\ctxcommand{definelabels("unit", "units" )} -\ctxcommand{definelabels("operator","operators")} -\ctxcommand{definelabels("suffix", "suffixes" )} +\clf_definelabels{prefix}{prefixes}\s!false\relax +\clf_definelabels{unit}{units}\s!false\relax +\clf_definelabels{operator}{operators}\s!false\relax +\clf_definelabels{suffix}{suffixes}\s!false\relax %D You can define additional units: %D @@ -716,7 +717,7 @@ {\dodoubleempty\phys_units_register} \def\phys_units_register[#1][#2]% - {\ctxcommand{registerunit(\!!bs#1\!!es,\!!bs#2\!!es)}} + {\clf_registerunit{#1}{#2}} %D You can generate a list as follows: %D diff --git a/tex/context/base/publ-ini.mkiv b/tex/context/base/publ-ini.mkiv index a7494058e..958397ca9 100644 --- a/tex/context/base/publ-ini.mkiv +++ b/tex/context/base/publ-ini.mkiv @@ -826,6 +826,7 @@ \else\ifx\currentbtxnumbering\v!no % nothing \else + \usebtxstyleandcolor\c!style\c!color % new, needed? \btxparameter\c!left \ifconditional\c_publ_prefixed\btxlistprefixednumber\fi \clf_btxlistvariant % some can go @@ -1561,20 +1562,28 @@ % \btxusecommand[btx:apa:list:article:title]{foo} % \btxstopstyle +\let\savedcurrentbtx\empty + \unexpanded\def\btxstartstyle[#1]% {\begingroup + \let\savedcurrentbtx\currentbtx \def\currentbtx{#1}% - \usebtxstyle\c!style} + \usebtxstyle\c!style + \let\currentbtx\savedcurrentbtx} \unexpanded\def\btxstartcolor[#1]% {\begingroup + \let\savedcurrentbtx\currentbtx \def\currentbtx{#1}% - \usebtxcolor\c!color} + \usebtxcolor\c!color + \let\currentbtx\savedcurrentbtx} \unexpanded\def\btxstartstyleandcolor[#1]% {\begingroup + \let\savedcurrentbtx\currentbtx \def\currentbtx{#1}% - \usebtxstyleandcolor\c!style\c!color} + \usebtxstyleandcolor\c!style\c!color + \let\currentbtx\savedcurrentbtx} \let\btxstopstyle \endgroup \let\btxstopcolor \endgroup diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 59fe33bbe..d01aedc28 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex a805ed2f4..1d06b44bb 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/strc-sec.mkiv b/tex/context/base/strc-sec.mkiv index 759941c85..b9560162f 100644 --- a/tex/context/base/strc-sec.mkiv +++ b/tex/context/base/strc-sec.mkiv @@ -310,10 +310,6 @@ \def\getsomefullstructurenumber#1#2{\clf_getsomefullstructurenumber #1{#2}} % level, what \def\getspecificstructuretitle #1{\clf_getspecificstructuretitle {#1}{\headparameter\s!catcodes}} -% will be: -% -% \def\getfullstructurenumber #1{\ctxcommand{structurenumber(\thenamedheadlevel{#1})}} - % structure heads (like \startchapter) % \c!deeptextcommand, \c!deepnumbercommand: undefined ! diff --git a/tex/context/base/syst-lua.lua b/tex/context/base/syst-lua.lua index 37353c74e..8fa43588f 100644 --- a/tex/context/base/syst-lua.lua +++ b/tex/context/base/syst-lua.lua @@ -40,6 +40,16 @@ function commands.doifelse(b) end end +function commands.doifelsesomething(b) + if b and b ~= "" then + ctx_firstoftwoarguments() +-- csprint(prtcatcodes,[[\ui_ft]]) -- ctx_firstoftwoarguments + else + ctx_secondoftwoarguments() +-- csprint(prtcatcodes,[[\ui_st]]) -- ctx_secondoftwoarguments + end +end + function commands.doif(b) if b then ctx_firstofoneargument() @@ -50,6 +60,16 @@ function commands.doif(b) end end +function commands.doifsomething(b) + if b and b ~= "" then + ctx_firstofoneargument() +-- context.__flushdirect(prtcatcodes,[[\ui_fo]]) -- ctx_firstofonearguments + else + ctx_gobbleoneargument() +-- context.__flushdirect(prtcatcodes,[[\ui_go]]) -- ctx_gobbleonearguments + end +end + function commands.doifnot(b) if b then ctx_gobbleoneargument() @@ -60,6 +80,16 @@ function commands.doifnot(b) end end +function commands.doifnotthing(b) + if b and b ~= "" then + ctx_gobbleoneargument() +-- csprint(prtcatcodes,[[\ui_go]]) -- ctx_gobbleonearguments + else + ctx_firstofoneargument() +-- csprint(prtcatcodes,[[\ui_fo]]) -- ctx_firstofonearguments + end +end + commands.testcase = commands.doifelse -- obsolete function commands.boolcase(b) diff --git a/tex/context/base/tabl-tbl.lua b/tex/context/base/tabl-tbl.lua index b088a1008..13d899de6 100644 --- a/tex/context/base/tabl-tbl.lua +++ b/tex/context/base/tabl-tbl.lua @@ -25,7 +25,7 @@ local pattern = Ct((separator * (C(nested) + Cc("")) * C((1-separator)^0))^0 local ctx_settabulatelastentry = context.settabulatelastentry local ctx_settabulateentry = context.settabulateentry -function commands.presettabulate(preamble) +local function presettabulate(preamble) preamble = gsub(preamble,"~","d") -- let's get rid of ~ mess here if find(preamble,"*",1,true) then -- todo: lpeg but not now @@ -43,3 +43,10 @@ function commands.presettabulate(preamble) end ctx_settabulatelastentry(t[m+1]) end + +interfaces.implement { + name = "presettabulate", + actions = presettabulate, + arguments = "string", + scope = "private", +} diff --git a/tex/context/base/tabl-tbl.mkiv b/tex/context/base/tabl-tbl.mkiv index 59ac85ed3..c1dcef46f 100644 --- a/tex/context/base/tabl-tbl.mkiv +++ b/tex/context/base/tabl-tbl.mkiv @@ -331,7 +331,7 @@ {\dowithnextboxcs\tabl_tabulate_shaped_par_finish\vbox\bgroup} \def\tabl_tabulate_shaped_par_finish - {\ctxcommand{doreshapeframedbox(\number\nextbox)}% + {\clf_doreshapeframedbox\nextbox\relax \ifvmode\unvbox\else\box\fi\nextbox} \let\tabl_tabulate_shaped_par_end\egroup @@ -2099,7 +2099,7 @@ \c_tabl_tabulate_nofcolumns \zerocount \c_tabl_tabulate_has_rule_spec_first\zerocount \c_tabl_tabulate_has_rule_spec_last \zerocount - \ctxcommand{presettabulate(\!!bs\detokenizedtabulationparameter\c!format\!!es)}% + \clf_presettabulate{\detokenizedtabulationparameter\c!format}% % % \edef\totaltabulatecolumns{\the\numexpr3*\c_tabl_tabulate_columns+\plusfour}% \d_tabl_tabulate_width\zeropoint diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index c03d650a5..8b045da09 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 03/28/15 10:30:56 +-- merge date : 03/28/15 16:30:32 do -- begin closure to overcome local limits and interference |