From d8b32263856c2f951bedec7f89adad3a412b7499 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 6 Nov 2020 20:46:53 +0100 Subject: 2020-11-06 20:26:00 --- tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkiv/back-out.mkxl | 10 +- tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/context.mkiv | 2 +- tex/context/base/mkiv/context.mkxl | 16 +- tex/context/base/mkiv/core-def.mkiv | 4 +- tex/context/base/mkiv/file-job.lmt | 1283 ++++++++++++++++++++ tex/context/base/mkiv/file-job.mklx | 348 ++++++ tex/context/base/mkiv/file-mod.mklx | 289 +++++ tex/context/base/mkiv/lang-ini.mkxl | 6 +- tex/context/base/mkiv/math-ini.mkxl | 24 +- tex/context/base/mkiv/mult-aux.mkxl | 65 +- tex/context/base/mkiv/mult-low.lua | 4 +- tex/context/base/mkiv/norm-ctx.mkxl | 87 ++ tex/context/base/mkiv/spac-ali.mkxl | 28 +- tex/context/base/mkiv/spac-chr.mkxl | 103 ++ tex/context/base/mkiv/status-files.pdf | Bin 29189 -> 29264 bytes tex/context/base/mkiv/status-lua.pdf | Bin 256569 -> 256558 bytes tex/context/base/mkiv/strc-blk.mkxl | 171 +++ tex/context/base/mkiv/strc-itm.mklx | 2 +- tex/context/base/mkiv/syst-ini.mkxl | 16 +- tex/context/base/mkiv/tabl-com.mkxl | 23 + tex/context/base/mkiv/tabl-ntb.mkxl | 18 +- tex/context/base/mkiv/tabl-nte.mkxl | 4 +- tex/context/base/mkiv/typo-scr.mkxl | 266 ++++ .../modules/common/s-abbreviations-logos.tex | 4 +- tex/context/modules/mkiv/s-system-macros.mkxl | 18 +- tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 29 files changed, 2695 insertions(+), 104 deletions(-) create mode 100644 tex/context/base/mkiv/file-job.lmt create mode 100644 tex/context/base/mkiv/file-job.mklx create mode 100644 tex/context/base/mkiv/file-mod.mklx create mode 100644 tex/context/base/mkiv/norm-ctx.mkxl create mode 100644 tex/context/base/mkiv/spac-chr.mkxl create mode 100644 tex/context/base/mkiv/strc-blk.mkxl create mode 100644 tex/context/base/mkiv/typo-scr.mkxl (limited to 'tex') diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 4dd19224c..b9725ecb6 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2020.11.05 22:57} +\newcontextversion{2020.11.06 20:23} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 1a3cd5512..d7c22dbca 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2020.11.05 22:57} +\edef\contextversion{2020.11.06 20:23} %D For those who want to use this: diff --git a/tex/context/base/mkiv/back-out.mkxl b/tex/context/base/mkiv/back-out.mkxl index 9e499a843..5cf79b2ea 100644 --- a/tex/context/base/mkiv/back-out.mkxl +++ b/tex/context/base/mkiv/back-out.mkxl @@ -13,10 +13,10 @@ \registerctxluafile{back-out}{autosuffix} -\let\normalopenout \openout -\let\normalwrite \write -\let\normalcloseout\closeout -\let\normallatelua \latelua -\let\normalspecial \special +% \let\normalopenout \openout +% \let\normalwrite \write +% \let\normalcloseout\closeout +% \let\normallatelua \latelua +% \let\normalspecial \special \endinput diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index b7ba71594..346d534e2 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -13,7 +13,7 @@ % \normalend % uncomment this to get the real base runtime -\newcontextversion{2020.11.05 22:57} +\newcontextversion{2020.11.06 20:23} %D This file is loaded at runtime, thereby providing an excellent place for hacks, %D patches, extensions and new features. There can be local overloads in cont-loc diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 18940ee57..bab10f2c2 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -45,7 +45,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2020.11.05 22:57} +\edef\contextversion{2020.11.06 20:23} %D Kind of special: diff --git a/tex/context/base/mkiv/context.mkxl b/tex/context/base/mkiv/context.mkxl index f2f29738d..4de6347f5 100644 --- a/tex/context/base/mkiv/context.mkxl +++ b/tex/context/base/mkiv/context.mkxl @@ -29,7 +29,7 @@ %D {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2020.11.05 22:57} +\edef\contextversion{2020.11.06 20:23} %overloadmode 1 % check frozen / warning %overloadmode 2 % check frozen / error @@ -85,7 +85,7 @@ %D Now the more fundamental code gets defined. -\loadmarkfile{norm-ctx} +\loadmkxlfile{norm-ctx} \loadmarkfile{syst-pln} \loadmarkfile{syst-mes} @@ -188,7 +188,7 @@ \loadmkxlfile{supp-mat} \loadmarkfile{core-uti} -\loadmkvifile{file-job} +\loadmklxfile{file-job} \loadmkxlfile{anch-pos} @@ -199,7 +199,7 @@ \loadmarkfile{typo-inj} \loadmklxfile{file-syn} -\loadmkvifile{file-mod} +\loadmklxfile{file-mod} \loadmarkfile{core-sys} \loadmkxlfile{core-con} @@ -221,7 +221,7 @@ \loadmarkfile{core-dat} \loadmkxlfile{colo-ini} -\loadmarkfile{colo-grp} % optional +\loadmkxlfile{colo-grp} % optional \loadmkxlfile{colo-ext} \loadmarkfile{node-bck} % overloads anch-pgr (experimental and undocumented) @@ -347,7 +347,7 @@ \loadmarkfile{buff-imp-parsed-xml} % optional %loadmarkfile{buff-imp-parsed-lua} % optional -\loadmarkfile{strc-blk} +\loadmkxlfile{strc-blk} \loadmarkfile{page-imp} \loadmkvifile{page-sel} % optional @@ -410,7 +410,7 @@ \loadmarkfile{lxml-css} -\loadmarkfile{spac-chr} % depends on fonts +\loadmkxlfile{spac-chr} % depends on fonts \loadmkxlfile{blob-ini} @@ -502,7 +502,7 @@ \loadmarkfile{chem-ini} \loadmkxlfile{chem-str} -\loadmarkfile{typo-scr} +\loadmkxlfile{typo-scr} \loadmarkfile{phys-dim} \loadmarkfile{node-rul} % beware, defined \underbar so after math diff --git a/tex/context/base/mkiv/core-def.mkiv b/tex/context/base/mkiv/core-def.mkiv index b1300d493..b1d984ae5 100644 --- a/tex/context/base/mkiv/core-def.mkiv +++ b/tex/context/base/mkiv/core-def.mkiv @@ -152,7 +152,9 @@ % temporary here: -\unexpanded\def\arg{\mathortext\normalmatharg\normaltextarg} +\pushoverloadmode + \frozen\unexpanded\def\arg{\mathortext\normalmatharg\normaltextarg} +\popoverloadmode % might move to \everydump or even disappear: diff --git a/tex/context/base/mkiv/file-job.lmt b/tex/context/base/mkiv/file-job.lmt new file mode 100644 index 000000000..95ad48e82 --- /dev/null +++ b/tex/context/base/mkiv/file-job.lmt @@ -0,0 +1,1283 @@ +if not modules then modules = { } end modules ['file-job'] = { + version = 1.001, + comment = "companion to file-job.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- in retrospect dealing it's not that bad to deal with the nesting +-- and push/poppign at the tex end + +local next, rawget, tostring, tonumber = next, rawget, tostring, tonumber +local gsub, match, find = string.gsub, string.match, string.find +local insert, remove, concat = table.insert, table.remove, table.concat +local validstring, formatters = string.valid, string.formatters +local sortedhash = table.sortedhash +local setmetatableindex, setmetatablenewindex = table.setmetatableindex, table.setmetatablenewindex + +local commands = commands +local resolvers = resolvers +local context = context + +local ctx_doifelse = commands.doifelse + +local implement = interfaces.implement + +local trace_jobfiles = false trackers.register("system.jobfiles", function(v) trace_jobfiles = v end) + +local report = logs.reporter("system") +local report_jobfiles = logs.reporter("system", "jobfiles") +local report_functions = logs.reporter("system", "functions") + +local texsetcount = tex.setcount +local elements = interfaces.elements +local constants = interfaces.constants +local variables = interfaces.variables +local settings_to_array = utilities.parsers.settings_to_array +local allocate = utilities.storage.allocate + +local nameonly = file.nameonly +local suffixonly = file.suffix +local basename = file.basename +local addsuffix = file.addsuffix +local removesuffix = file.removesuffix +local dirname = file.dirname +local is_qualified_path = file.is_qualified_path + +local cleanpath = resolvers.cleanpath +local toppath = resolvers.toppath +local resolveprefix = resolvers.resolve + +local hasscheme = url.hasscheme + +local jobresolvers = resolvers.jobs + +local registerextrapath = resolvers.registerextrapath +local resetextrapaths = resolvers.resetextrapaths +local getextrapaths = resolvers.getextrapath +local pushextrapath = resolvers.pushextrapath +local popextrapath = resolvers.popextrapath + +----- v_outer = variables.outer +local v_text = variables.text +local v_project = variables.project +local v_environment = variables.environment +local v_product = variables.product +local v_component = variables.component +local v_yes = variables.yes + +-- main code .. there is some overlap .. here we have loc:// + +local function findctxfile(name) -- loc ? any ? + if is_qualified_path(name) then -- maybe when no suffix do some test for tex + return name + elseif not hasscheme(name) then + return resolvers.finders.byscheme("loc",name) or "" + else + return resolvers.findtexfile(name) or "" + end +end + +resolvers.findctxfile = findctxfile + +implement { + name = "processfile", + arguments = "string", + public = true, + protected = true, + actions = function(name) + name = findctxfile(name) + if name ~= "" then + context.input(name) + end + end +} + +implement { + name = "doifelseinputfile", + arguments = "string", + public = true, + protected = true, + actions = function(name) + ctx_doifelse(findctxfile(name) ~= "") + end +} + +implement { + name = "locatefilepath", + arguments = "string", + actions = function(name) + context(dirname(findctxfile(name))) + end +} + +implement { + name = "usepath", + arguments = "optional", + public = true, + protected = true, + actions = function(paths) + report_jobfiles("using path: %s",paths) + registerextrapath(paths) + end +} + +implement { + name = "pushpath", + arguments = "optional", + public = true, + protected = true, + actions = function(paths) + report_jobfiles("pushing path: %s",paths) + pushextrapath(paths) + end +} + +implement { + name = "poppath", + public = true, + protected = true, + actions = function(paths) + popextrapath() + report_jobfiles("popping path") + end +} + +implement { + name = "usesubpath", + arguments = "optional", + public = true, + protected = true, + actions = function(subpaths) + report_jobfiles("using subpath: %s",subpaths) + registerextrapath(nil,subpaths) + end +} + +implement { + name = "resetpath", + public = true, + protected = true, + actions = function() + report_jobfiles("resetting path") + resetextrapaths() + end +} + +implement { + name = "allinputpaths", + public = true, + actions = function() + context(concat(getextrapaths(),",")) + end +} + +implement { + name = "usezipfile", + public = true, + protected = true, + arguments = { "optional", "optional" }, + actions = function(name,tree) + if tree and tree ~= "" then + resolvers.usezipfile(formatters["zip:///%s?tree=%s"](name,tree)) + else + resolvers.usezipfile(formatters["zip:///%s"](name)) + end + end +} + +-- moved from tex to lua: + +local texpatterns = { "%s.mkvi", "%s.mkiv", "%s.mklx", "%s.mkxl", "%s.tex" } +local luapatterns = { "%s" .. utilities.lua.suffixes.luc, "%s.lua", "%s.lmt" } +local cldpatterns = { "%s.cld" } +local xmlpatterns = { "%s.xml" } + +local uselibrary = resolvers.uselibrary +local input = context.input + +-- status +-- +-- these need to be synced with input stream: + +local processstack = { } +local processedfile = "" +local processedfiles = { } + +implement { + name = "processedfile", + actions = function() + context(processedfile) + end +} + +implement { + name = "processedfiles", + actions = function() + context(concat(processedfiles,",")) + end +} + +implement { + name = "dostarttextfile", + public = true, + protected = true, + arguments = "string", + actions = function(name) + insert(processstack,name) + processedfile = name + insert(processedfiles,name) + end +} + +implement { + name = "dostoptextfile", + public = true, + protected = true, + actions = function() + processedfile = remove(processstack) or "" + end +} + +local function startprocessing(name,notext) + if not notext then + -- report("begin file %a at line %a",name,status.linenumber or 0) + context.dostarttextfile(name) + end +end + +local function stopprocessing(notext) + if not notext then + context.dostoptextfile() + -- report("end file %a at line %a",name,status.linenumber or 0) + end +end + +-- + +local typestack = { } +local currenttype = v_text +local nofmissing = 0 +local missing = { + tex = setmetatableindex("number"), + lua = setmetatableindex("number"), + cld = setmetatableindex("number"), + xml = setmetatableindex("number"), +} + +local function reportfailure(kind,name) + nofmissing = nofmissing + 1 + missing[kind][name] = true + report_jobfiles("unknown %s file %a",kind,name) +end + +-- + +local function action(name,foundname) + input(foundname) +end +local function failure(name,foundname) + reportfailure("tex",name) +end +local function usetexfile(name,onlyonce,notext) + startprocessing(name,notext) + uselibrary { + name = name, + patterns = texpatterns, + action = action, + failure = failure, + onlyonce = onlyonce, + } + stopprocessing(notext) +end + +local function action(name,foundname) + dofile(foundname) +end +local function failure(name,foundname) + reportfailure("lua",name) +end +local function useluafile(name,onlyonce,notext) + uselibrary { + name = name, + patterns = luapatterns, + action = action, + failure = failure, + onlyonce = onlyonce, + } +end + +local function action(name,foundname) + dofile(foundname) +end +local function failure(name,foundname) + reportfailure("cld",name) +end +local function usecldfile(name,onlyonce,notext) + startprocessing(name,notext) + uselibrary { + name = name, + patterns = cldpatterns, + action = action, + failure = failure, + onlyonce = onlyonce, + } + stopprocessing(notext) +end + +local function action(name,foundname) + context.xmlprocess(foundname,"main","") +end +local function failure(name,foundname) + reportfailure("xml",name) +end +local function usexmlfile(name,onlyonce,notext) + startprocessing(name,notext) + uselibrary { + name = name, + patterns = xmlpatterns, + action = action, + failure = failure, + onlyonce = onlyonce, + } + stopprocessing(notext) +end + +local suffixes = { + mkvi = usetexfile, + mkiv = usetexfile, + mklx = usetexfile, + mkxl = usetexfile, + tex = usetexfile, + luc = useluafile, + lua = useluafile, + cld = usecldfile, + xml = usexmlfile, + [""] = usetexfile, +} + +local function useanyfile(name,onlyonce) + local s = suffixes[suffixonly(name)] + context(function() resolvers.pushpath(name) end) + if s then + -- s(removesuffix(name),onlyonce) + s(name,onlyonce) -- so, first with suffix, then without + else + usetexfile(name,onlyonce) -- e.g. ctx file + -- resolvers.readfilename(name) + end + context(resolvers.poppath) +end + +implement { name = "loadtexfile", public = true, protected = true, actions = usetexfile, arguments = "optional" } +implement { name = "loadluafile", public = true, protected = true, actions = useluafile, arguments = "optional" } +implement { name = "loadcldfile", public = true, protected = true, actions = usecldfile, arguments = "optional" } +implement { name = "loadxmlfile", public = true, protected = true, actions = usexmlfile, arguments = "optional" } + +implement { name = "loadtexfileonce", public = true, protected = true, actions = usetexfile, arguments = { "optional", true } } +implement { name = "loadluafileonce", public = true, protected = true, actions = useluafile, arguments = { "optional", true } } +implement { name = "loadcldfileonce", public = true, protected = true, actions = usecldfile, arguments = { "optional", true } } +implement { name = "loadxmlfileonce", public = true, protected = true, actions = usexmlfile, arguments = { "optional", true } } + +implement { name = "useanyfile", actions = useanyfile, arguments = "string" } +implement { name = "useanyfileonce", actions = useanyfile, arguments = { "string", true } } + +function jobresolvers.usefile(name,onlyonce,notext) + local s = suffixes[suffixonly(name)] + if s then + -- s(removesuffix(name),onlyonce,notext) + s(name,onlyonce,notext) -- so, first with suffix, then without + end +end + +-- document structure + +local textlevel = 0 -- inaccessible for user, we need to define counter textlevel at the tex end + +local function dummyfunction() end + +local function startstoperror() + report("invalid \\%s%s ... \\%s%s structure",elements.start,v_text,elements.stop,v_text) + startstoperror = dummyfunction +end + +local stopped + +local function starttext() + if textlevel == 0 then + if trace_jobfiles then + report_jobfiles("starting text") + end + context.dostarttext() + end + textlevel = textlevel + 1 + texsetcount("global","textlevel",textlevel) +end + +local function stoptext() + if not stopped then + if textlevel == 0 then + startstoperror() + elseif textlevel > 0 then + textlevel = textlevel - 1 + end + texsetcount("global","textlevel",textlevel) + if textlevel <= 0 then + if trace_jobfiles then + report_jobfiles("stopping text") + end + context.dostoptext() + stopped = true + end + end +end + +implement { + name = "starttext", + public = true, + protected = true, + actions = starttext +} + +implement { + name = "stoptext", + public = true, + protected = true, + actions = stoptext +} + +implement { + name = "forcequitjob", + arguments = "string", + public = true, + protected = true, + actions = function(reason) + if reason then + report("forcing quit: %s",reason) + else + report("forcing quit") + end + context.batchmode() + while textlevel >= 0 do + context.stoptext() + end + end +} + +implement { + name = "forceendjob", + public = true, + protected = true, + actions = function() + report([[don't use \end to finish a document]]) + context.stoptext() + end +} + +implement { + name = "autostarttext", + public = true, + protected = true, + actions = function() + if textlevel == 0 then + report([[auto \starttext ... \stoptext]]) + end + context.starttext() + end +} + +implement { + name = "autostoptext", + public = true, + protected = true, + actions = stoptext +} + +-- project structure + +implement { + name = "processfilemany", + public = true, + protected = true, + arguments = { "string", false }, + actions = useanyfile +} + +implement { + name = "processfileonce", + public = true, + protected = true, + arguments = { "string", true }, + actions = useanyfile +} + +implement { + name = "processfilenone", + arguments = "string", + public = true, + protected = true, + actions = dummyfunction, +} + +local tree = { type = "text", name = "", branches = { } } +local treestack = { } +local top = tree.branches +local root = tree + +local project_stack = { } +local product_stack = { } +local component_stack = { } +local environment_stack = { } + +local stacks = { + [v_project ] = project_stack, + [v_product ] = product_stack, + [v_component ] = component_stack, + [v_environment] = environment_stack, +} + +-- + +local function pushtree(what,name) + local t = { } + top[#top+1] = { type = what, name = name, branches = t } + insert(treestack,top) + top = t +end + +local function poptree() + top = remove(treestack) + -- inspect(top) +end + +do + + local function log_tree(report,top,depth) + report("%s%s: %s",depth,top.type,top.name) + local branches = top.branches + if #branches > 0 then + depth = depth .. " " + for i=1,#branches do + log_tree(report,branches[i],depth) + end + end + end + + logs.registerfinalactions(function() + root.name = environment.jobname + -- + logs.startfilelogging(report,"used files") + log_tree(report,root,"") + logs.stopfilelogging() + -- + if nofmissing > 0 and logs.loggingerrors() then + logs.starterrorlogging(report,"missing files") + for kind, list in sortedhash(missing) do + for name in sortedhash(list) do + report("%w%s %s",6,kind,name) + end + end + logs.stoperrorlogging() + end + end) + +end + +local jobstructure = job.structure or { } +job.structure = jobstructure +jobstructure.collected = jobstructure.collected or { } +jobstructure.tobesaved = root +jobstructure.components = { } + +local function initialize() + local function collect(root,result) + local branches = root.branches + if branches then + for i=1,#branches do + local branch = branches[i] + if branch.type == "component" then + result[#result+1] = branch.name + end + collect(branch,result) + end + end + return result + end + jobstructure.components = collect(jobstructure.collected,{}) +end + +job.register('job.structure.collected',root,initialize) + +-- component: small unit, either or not components itself +-- product : combination of components + +local ctx_processfilemany = context.processfilemany +local ctx_processfileonce = context.processfileonce +local ctx_processfilenone = context.processfilenone + +-- we need a plug in the nested loaded, push pop pseudo current dir + +local function processfilecommon(name,action) + -- experiment, might go away +-- if not hasscheme(name) then +-- local path = dirname(name) +-- if path ~= "" then +-- registerextrapath(path) +-- report_jobfiles("adding search path %a",path) +-- end +-- end + -- till here + action(name) +end + +local function processfilemany(name) processfilecommon(name,ctx_processfilemany) end +local function processfileonce(name) processfilecommon(name,ctx_processfileonce) end +local function processfilenone(name) processfilecommon(name,ctx_processfilenone) end + +local processors = utilities.storage.allocate { + -- [v_outer] = { + -- [v_text] = { "many", processfilemany }, + -- [v_project] = { "once", processfileonce }, + -- [v_environment] = { "once", processfileonce }, + -- [v_product] = { "once", processfileonce }, + -- [v_component] = { "many", processfilemany }, + -- }, + [v_text] = { + [v_text] = { "many", processfilemany }, + [v_project] = { "once", processfileonce }, -- dubious + [v_environment] = { "once", processfileonce }, + [v_product] = { "many", processfilemany }, -- dubious + [v_component] = { "many", processfilemany }, + }, + [v_project] = { + [v_text] = { "many", processfilemany }, + [v_project] = { "none", processfilenone }, + [v_environment] = { "once", processfileonce }, + [v_product] = { "none", processfilenone }, + [v_component] = { "none", processfilenone }, + }, + [v_environment] = { + [v_text] = { "many", processfilemany }, + [v_project] = { "none", processfilenone }, + [v_environment] = { "once", processfileonce }, + [v_product] = { "none", processfilenone }, + [v_component] = { "none", processfilenone }, + }, + [v_product] = { + [v_text] = { "many", processfilemany }, + [v_project] = { "once", processfileonce }, + [v_environment] = { "once", processfileonce }, + [v_product] = { "many", processfilemany }, + [v_component] = { "many", processfilemany }, + }, + [v_component] = { + [v_text] = { "many", processfilemany }, + [v_project] = { "once", processfileonce }, + [v_environment] = { "once", processfileonce }, + [v_product] = { "none", processfilenone }, + [v_component] = { "many", processfilemany }, + } +} + +local start = { + [v_text] = nil, + [v_project] = nil, + [v_environment] = context.startreadingfile, + [v_product] = context.starttext, + [v_component] = context.starttext, +} + +local stop = { + [v_text] = nil, + [v_project] = nil, + [v_environment] = context.stopreadingfile, + [v_product] = context.stoptext, + [v_component] = context.stoptext, +} + +jobresolvers.processors = processors + +local function topofstack(what) + local stack = stacks[what] + return stack and stack[#stack] or environment.jobname +end + +local function productcomponent() -- only when in product + local product = product_stack[#product_stack] + if product and product ~= "" then + local component = component_stack[1] + if component and component ~= "" then + return component + end + end +end + +local function justacomponent() + local product = product_stack[#product_stack] + if not product or product == "" then + local component = component_stack[1] + if component and component ~= "" then + return component + end + end +end + +jobresolvers.productcomponent = productcomponent +jobresolvers.justacomponent = justacomponent + +function jobresolvers.currentproject () return topofstack(v_project ) end +function jobresolvers.currentproduct () return topofstack(v_product ) end +function jobresolvers.currentcomponent () return topofstack(v_component ) end +function jobresolvers.currentenvironment() return topofstack(v_environment) end + +local done = { } +local tolerant = false -- too messy, mkii user with the wrong structure should adapt + +local function process(what,name) + local depth = #typestack + local process + -- + name = resolveprefix(name) + -- +-- if not tolerant then + -- okay, would be best but not compatible with mkii + process = processors[currenttype][what] +-- elseif depth == 0 then +-- -- could be a component, product or (brr) project +-- if trace_jobfiles then +-- report_jobfiles("%s : %s > %s (case 1)",depth,currenttype,v_outer) +-- end +-- process = processors[v_outer][what] +-- elseif depth == 1 and typestack[1] == v_text then +-- -- we're still not doing a component or product +-- if trace_jobfiles then +-- report_jobfiles("%s : %s > %s (case 2)",depth,currenttype,v_outer) +-- end +-- process = processors[v_outer][what] +-- else +-- process = processors[currenttype][what] +-- end + if process then + local method = process[1] + if method == "none" then + if trace_jobfiles then + report_jobfiles("%s : %s : %s %s %a in %s %a",depth,method,"ignoring",what,name,currenttype,topofstack(currenttype)) + end + elseif method == "once" and done[name] then + if trace_jobfiles then + report_jobfiles("%s : %s : %s %s %a in %s %a",depth,method,"skipping",what,name,currenttype,topofstack(currenttype)) + end + else + -- keep in mind that we also handle "once" at the file level + -- so there is a double catch + done[name] = true + local before = start[what] + local after = stop [what] + if trace_jobfiles then + report_jobfiles("%s : %s : %s %s %a in %s %a",depth,method,"processing",what,name,currenttype,topofstack(currenttype)) + end + if before then + before() + end + process[2](name) + if after then + after() + end + end + else + if trace_jobfiles then + report_jobfiles("%s : %s : %s %s %a in %s %a",depth,"none","ignoring",what,name,currenttype,topofstack(currenttype)) + end + end +end + +local scan_delimited = tokens.scanners.delimited + +local function getname() + return scan_delimited(91,93) or scan_delimited(0,32) -- [name] or name +end + +implement { name = "project", public = true, protected = true, actions = function() process(v_project, getname()) end } +implement { name = "environment", public = true, protected = true, actions = function() process(v_environment,getname()) end } +implement { name = "product", public = true, protected = true, actions = function() process(v_product, getname()) end } -- will be overloaded +implement { name = "component", public = true, protected = true, actions = function() process(v_component, getname()) end } + +implement { name = "useproject", public = true, protected = true, actions = function(name) process(v_project, name) end, arguments = "optional" } +implement { name = "useenvironment", public = true, protected = true, actions = function(name) process(v_environment,name) end, arguments = "optional" } +implement { name = "useproduct", public = true, protected = true, actions = function(name) process(v_product, name) end, arguments = "optional" } -- will be overloaded +implement { name = "usecomponent", public = true, protected = true, actions = function(name) process(v_component, name) end, arguments = "optional" } + +-- todo: setsystemmode to currenttype +-- todo: make start/stop commands at the tex end + +local start = { + [v_project] = context.startprojectindeed, + [v_product] = context.startproductindeed, + [v_component] = context.startcomponentindeed, + [v_environment] = context.startenvironmentindeed, +} + +local stop = { + [v_project] = context.stopprojectindeed, + [v_product] = context.stopproductindeed, + [v_component] = context.stopcomponentindeed, + [v_environment] = context.stopenvironmentindeed, +} + +local function gotonextlevel(what,name) -- todo: something with suffix name + insert(stacks[what],name) + insert(typestack,currenttype) + currenttype = what + pushtree(what,name) + if start[what] then + start[what]() + end +end + +local function gotopreviouslevel(what) + if stop[what] then + stop[what]() + end + poptree() + currenttype = remove(typestack) or v_text + remove(stacks[what]) -- not currenttype ... weak recovery +context.endinput() -- does not work +-- context.signalendofinput(what) +end + +local function autoname() + local name = scan_delimited(91,93) or scan_delimited(0,32) -- [name] or name + if name == "*" then + name = nameonly(toppath() or name) + end + return name +end + +implement { name = "startproject", public = true, protected = true, actions = function() gotonextlevel(v_project, autoname()) end } +implement { name = "startproduct", public = true, protected = true, actions = function() gotonextlevel(v_product, autoname()) end } +implement { name = "startcomponent", public = true, protected = true, actions = function() gotonextlevel(v_component, autoname()) end } +implement { name = "startenvironment", public = true, protected = true, actions = function() gotonextlevel(v_environment,autoname()) end } + +implement { name = "stopproject", public = true, protected = true, actions = function() gotopreviouslevel(v_project ) end } +implement { name = "stopproduct", public = true, protected = true, actions = function() gotopreviouslevel(v_product ) end } +implement { name = "stopcomponent", public = true, protected = true, actions = function() gotopreviouslevel(v_component ) end } +implement { name = "stopenvironment", public = true, protected = true, actions = function() gotopreviouslevel(v_environment) end } + +implement { name = "currentproject", public = true, actions = function() context(topofstack(v_project )) end } +implement { name = "currentproduct", public = true, actions = function() context(topofstack(v_product )) end } +implement { name = "currentcomponent", public = true, actions = function() context(topofstack(v_component )) end } +implement { name = "currentenvironment", public = true, actions = function() context(topofstack(v_environment)) end } + +-- -- -- this will move -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +-- +-- +-- +-- nee +-- standaard +-- +-- +-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +local report_examodes = logs.reporter("system","examodes") + +local function convertexamodes(str) + local x = xml.convert(str) + for e in xml.collected(x,"exa:variable") do + local label = e.at and e.at.label + if label and label ~= "" then + local data = xml.text(e) + local mode = match(label,"^mode:(.+)$") + if mode then + context.enablemode { formatters["%s:%s"](mode,data) } + end + context.setvariable("exa:variables",label,(gsub(data,"([{}])","\\%1"))) + end + end +end + +function environment.loadexamodes(filename) + if not filename or filename == "" then + filename = removesuffix(tex.jobname) + end + filename = resolvers.findfile(addsuffix(filename,'ctm')) or "" + if filename ~= "" then + report_examodes("loading %a",filename) -- todo: message system + convertexamodes(io.loaddata(filename)) + else + report_examodes("no mode file %a",filename) -- todo: message system + end +end + +implement { + name = "loadexamodes", + actions = environment.loadexamodes, + public = true, + protected = true, + arguments = "optional" +} + +-- changed in mtx-context +-- code moved from luat-ini + +-- todo: locals when mtx-context is changed + +document = document or { + arguments = allocate(), + files = allocate(), + variables = allocate(), -- for templates + options = { + commandline = { + environments = allocate(), + modules = allocate(), + modes = allocate(), + }, + ctxfile = { + environments = allocate(), + modules = allocate(), + modes = allocate(), + }, + }, + functions = table.setmetatablenewindex(function(t,k,v) + if rawget(t,k) then + report_functions("overloading document function %a",k) + end + rawset(t,k,v) + return v + end), +} + +function document.setargument(key,value) + document.arguments[key] = value +end + +function document.setdefaultargument(key,default) + local v = document.arguments[key] + if v == nil or v == "" then + document.arguments[key] = default + end +end + +function document.setfilename(i,name) + if name then + document.files[tonumber(i)] = name + else + document.files[#document.files+1] = tostring(i) + end +end + +function document.getargument(key,default) + local v = document.arguments[key] + if type(v) == "boolean" then + v = (v and "yes") or "no" + document.arguments[key] = v + end + return v or default or "" +end + +function document.getfilename(i) + return document.files[tonumber(i)] or "" +end + +implement { + name = "setdocumentargument", + actions = document.setargument, + arguments = "2 strings" +} + +implement { + name = "setdocumentdefaultargument", + actions = document.setdefaultargument, + arguments = "2 strings" +} + +implement { + name = "setdocumentfilename", + actions = document.setfilename, + arguments = { "integer", "string" } +} + +implement { + name = "getdocumentargument", + actions = { document.getargument, context }, + arguments = "2 strings" +} + +implement { + name = "getdocumentfilename", + actions = { document.getfilename, context }, + arguments = "integer" +} + +function document.setcommandline() -- has to happen at the tex end in order to expand + + -- the document[arguments|files] tables are copies + + local arguments = document.arguments + local files = document.files + local options = document.options + + for k, v in next, environment.arguments do + k = gsub(k,"^c:","") -- already done, but better be safe than sorry + if arguments[k] == nil then + arguments[k] = v + end + end + + -- in the new mtx=context approach we always pass a stub file so we need to + -- to trick the files table which actually only has one entry in a tex job + + if arguments.timing then + context.usemodule { "timing" } + end + + if arguments.usage then + trackers.enable("system.usage") + end + + if arguments.batchmode then + context.batchmode(false) + end + + if arguments.nonstopmode then + context.nonstopmode(false) + end + + if arguments.nostatistics then + directives.enable("system.nostatistics") + end + + if arguments.paranoid then + context.setvalue("maxreadlevel",1) + end + + if validstring(arguments.path) then + context.usepath { arguments.path } + end + + if arguments.export then + context.setupbackend { export = v_yes } + end + + local inputfile = validstring(arguments.input) + + if inputfile and dirname(inputfile) == "." and lfs.isfile(inputfile) then + -- nicer in checks + inputfile = basename(inputfile) + end + + local forcedruns = arguments.forcedruns + local kindofrun = arguments.kindofrun + local currentrun = arguments.currentrun + local maxnofruns = arguments.maxnofruns or arguments.runs + + -- context.setupsystem { + -- [constants.directory] = validstring(arguments.setuppath), + -- [constants.inputfile] = inputfile, + -- [constants.file] = validstring(arguments.result), + -- [constants.random] = validstring(arguments.randomseed), + -- -- old: + -- [constants.n] = validstring(kindofrun), + -- [constants.m] = validstring(currentrun), + -- } + + context.setupsystem { + directory = validstring(arguments.setuppath), + inputfile = inputfile, + file = validstring(arguments.result), + random = validstring(arguments.randomseed), + -- old: + n = validstring(kindofrun), + m = validstring(currentrun), + } + + forcedruns = tonumber(forcedruns) or 0 + kindofrun = tonumber(kindofrun) or 0 + maxnofruns = tonumber(maxnofruns) or 0 + currentrun = tonumber(currentrun) or 0 + + local prerollrun = forcedruns > 0 and currentrun > 0 and currentrun < forcedruns + + environment.forcedruns = forcedruns + environment.kindofrun = kindofrun + environment.maxnofruns = maxnofruns + environment.currentrun = currentrun + environment.prerollrun = prerollrun + + context.setconditional("prerollrun",prerollrun) + + if validstring(arguments.arguments) then + context.setupenv { arguments.arguments } + end + + if arguments.once then + directives.enable("system.runonce") + end + + if arguments.noarrange then + context.setuparranging { variables.disable } + end + + -- + + local commandline = options.commandline + + commandline.environments = table.append(commandline.environments,settings_to_array(validstring(arguments.environment))) + commandline.modules = table.append(commandline.modules, settings_to_array(validstring(arguments.usemodule))) + commandline.modes = table.append(commandline.modes, settings_to_array(validstring(arguments.mode))) + + -- + + if #files == 0 then + local list = settings_to_array(validstring(arguments.files)) + if list and #list > 0 then + files = list + end + end + + if #files == 0 then + files = { validstring(arguments.input) } + end + + -- + + document.arguments = arguments + document.files = files + +end + +-- commandline wins over ctxfile + +local function apply(list,action) + if list then + for i=1,#list do + action { list[i] } + end + end +end + +function document.setmodes() -- was setup: *runtime:modes + apply(document.options.ctxfile .modes,context.enablemode) + apply(document.options.commandline.modes,context.enablemode) +end + +function document.setmodules() -- was setup: *runtime:modules + apply(document.options.ctxfile .modules,context.usemodule) + apply(document.options.commandline.modules,context.usemodule) +end + +function document.setenvironments() -- was setup: *runtime:environments + apply(document.options.ctxfile .environments,context.environment) + apply(document.options.commandline.environments,context.environment) +end + +function document.setfilenames() + local initialize = environment.initializefilenames + if initialize then + initialize() + else + -- fatal error + end +end + +implement { name = "setdocumentcommandline", actions = document.setcommandline, onlyonce = true } +implement { name = "setdocumentmodes", actions = document.setmodes, onlyonce = true } +implement { name = "setdocumentmodules", actions = document.setmodules, onlyonce = true } +implement { name = "setdocumentenvironments", actions = document.setenvironments, onlyonce = true } +implement { name = "setdocumentfilenames", actions = document.setfilenames, onlyonce = true } + +do + + logs.registerfinalactions(function() + local foundintrees = resolvers.foundintrees() + if #foundintrees > 0 then + logs.startfilelogging(report,"used files") + for i=1,#foundintrees do + report("%4i: % T",i,foundintrees[i]) + end + logs.stopfilelogging() + end + end) + + logs.registerfinalactions(function() + local files = document.files -- or environment.files + local arguments = document.arguments -- or environment.arguments + -- + logs.startfilelogging(report,"commandline options") + if arguments and next(arguments) then + for argument, value in sortedhash(arguments) do + report("%s=%A",argument,value) + end + else + report("no arguments") + end + logs.stopfilelogging() + -- + logs.startfilelogging(report,"commandline files") + if files and #files > 0 then + for i=1,#files do + report("% 4i: %s",i,files[i]) + end + else + report("no files") + end + logs.stopfilelogging() + end) + +end + +if environment.initex then + + logs.registerfinalactions(function() + local startfilelogging = logs.startfilelogging + local stopfilelogging = logs.stopfilelogging + startfilelogging(report,"stored tables") + for k,v in sortedhash(storage.data) do + report("%03i %s",k,v[1]) + end + stopfilelogging() + startfilelogging(report,"stored modules") + for k,v in sortedhash(lua.bytedata) do + report("%03i %s %s",k,v.name) + end + stopfilelogging() + startfilelogging(report,"stored attributes") + for k,v in sortedhash(attributes.names) do + report("%03i %s",k,v) + end + stopfilelogging() + startfilelogging(report,"stored catcodetables") + for k,v in sortedhash(catcodes.names) do + report("%03i % t",k,v) + end + stopfilelogging() + startfilelogging(report,"stored corenamespaces") + for k,v in sortedhash(interfaces.corenamespaces) do + report("%03i %s",k,v) + end + stopfilelogging() + end) + +end + +implement { + name = "continueifinputfile", + public = true, + protected = true, + arguments = "string", + actions = function(inpname,basetoo) + local inpnamefull = addsuffix(inpname,"tex") + local inpfilefull = addsuffix(environment.inputfilename,"tex") + local continue = inpnamefull == inpfilefull + -- if basetoo and not continue then + if not continue then + continue = inpnamefull == basename(inpfilefull) + end + if continue then + report("continuing input file %a",inpname) + else + context.endinput() + end +-- ctx_doifelse(continue) + end +} diff --git a/tex/context/base/mkiv/file-job.mklx b/tex/context/base/mkiv/file-job.mklx new file mode 100644 index 000000000..6e8f8e83f --- /dev/null +++ b/tex/context/base/mkiv/file-job.mklx @@ -0,0 +1,348 @@ +%D \module +%D [ file=file-job, % copied from main-001, later core-job +%D version=1997.03.31, +%D title=\CONTEXT\ Core Macros, +%D subtitle=Job Handling, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt File Macros / Job Handling} + +\unprotect + +%D This module delegates most of the work to \LUA\ and therefore also let it +%D define the commands, which is more efficient. + +\registerctxluafile{file-job}{autosuffix} + +%D Here are some helpers for processing and path control. In the following example +%D the lookup order is \type {.}, {/foo}, \type {foo/bar} as one can always +%D explicitly prefix a wanted file. +%D +%D \starttyping +%D \pushpath[foo] +%D \pushpath[foo/bar] +%D \input test +%D \poppath +%D \poppath +%D \stoptyping + +% \usepath [#path] % defined at lua end +% \usesubpath [#path] % defined at lua end +% \pushpath [#path] % defined at lua end +% \poppath % defined at lua end +% \resetpath % defined at lua end (not the pushed paths) +% \allinputpaths % defined at lua end +% \doifelseinputfile #name % defined at lua end +% \processfile #name % defined at lua end + +\aliased\let\doifinputfileelse\doifelseinputfile + +% helper (not really needed nowadays) + +\mutable\let\locatedfilepath\empty + +\protected\def\locatefilepath#name{\edef\locatedfilepath{\clf_locatefilepath{#name}}} % todo: set at the lua end, catcodes and such + +% % maybe: +% +% % \dirlist{c:/data/temporary/foo}{images/bar.jpg} +% % \dirfile{c:/data/temporary/foo}{images/bar.jpg} +% +% \def\dirlist#1#2{dirlist://#1/**/#2} +% \def\dirfile#1#2{dirlist://#1/**/#2?option=fileonly} + +% zip files are tree'd +% exa stuff might become obsolete: + +% \usezipfile [#zipname]#spacer[#subtree] % defined at lua end +% \loadexamodes [#name] % defined at lua end + +\protected\def\syst_files_load + {\syst_files_load_indeed\f!newfilename % new code, to be integrated at some point, plus fixes posted on the list + \syst_files_load_indeed\f!locfilename % new code, somewhat experimental, not distributed (outside the dev group) + \syst_files_load_indeed\f!expfilename % new code, very experimental, can be engine specific, mostly for me only + \syst_files_load_indeed\f!sysfilename % local settings, but probably not that good an idea to use + %\syst_files_load_indeed\f!fntfilename % maybe some day, can load goodies and patches + } + +\def\syst_files_load_indeed#name% from now on we assume a suffix to be part of the name + {\readsysfile{#name}{\showmessage\m!system2{#name}}\donothing} + +% document structure + +\ifdefined\textlevel \else \newcount\textlevel \fi % might go away +\ifdefined\strc_pagenumbers_flush_final_page \else \let\strc_pagenumbers_flush_final_page\relax \fi % ugly + +\protected\def\dostarttext + {\enforced\glet\dostarttext\relax + \the\everystarttext + \global\everystarttext\emptytoks} + +\protected\def\dostoptext + {\enforced\glet\dostoptext\relax + \strc_pagenumbers_flush_final_page + \page % hm, bonus + \the\everystoptext + \global\everystoptext\emptytoks + \the\everybye + \global\everybye\emptytoks + \the\everygoodbye + \global\everygoodbye\emptytoks + \doifelsesometoks\everynotabene{\writeline\the\everynotabene\writeline}\donothing + % tex's \end: + \normalend} + +% \starttext % defined at lua end +% \stoptext % defined at lua end +% \forcequitjob % defined at lua end +% \autostarttext % defined at lua end +% \autostoptext % defined at lua end + +\pushoverloadmode + \aliased\let\end\forceendjob +\popoverloadmode + +\aliased\let\finishjob\stoptext % nicer in luatex call commandline + +\newtoks\everystartnotext +\newtoks\everystopnotext + +\protected\def\startnotext{\the\everystartnotext} +\protected\def\stopnotext {\the\everystopnotext\normalend} + +% protect structure + +% \processfilemany {#name} % defined at lua end +% \processfileonce {#name} % defined at lua end +% \processfilenone {#name} % defined at lua end + +% \useproject [#name] % defined at lua end +% \useproduct [#name] % defined at lua end +% \usecomponent [#name] % defined at lua end +% \useenvironment [#name] % defined at lua end + +% \project [#name] or #name % defined at lua end +% \product [#name] or #name % defined at lua end +% \component [#name] or #name % defined at lua end +% \environment [#name] or #name % defined at lua end + +% \startproject [#name] or #name % defined at lua end +% \startproduct [#name] or #name % defined at lua end +% \startcomponent [#name] or #name % defined at lua end +% \startenvironment [#name] or #name % defined at lua end + +\newconditional\endofinput % hack, needed because \endinput happens one level down in the input when we write from lua + +% \protected\def\signalendofinput#1% argument just for tracing +% {\global\settrue\endofinput} +% +% \protected\def\honorendofinput +% {\ifconditional\endofinput +% \global\setfalse\endofinput +% \endinput +% \fi} + +% \protected\def\stopproject {\clf_stopproject \honorendofinput} % todo +% \protected\def\stopproduct {\clf_stopproduct \honorendofinput} % todo +% \protected\def\stopcomponent {\clf_stopcomponent \honorendofinput} % todo +% \protected\def\stopenvironment {\clf_stopenvironment\honorendofinput} % todo + +% \currentproject % defined at lua end +% \currentproduct % defined at lua end +% \currentcomponent % defined at lua end +% \currentenvironment % defined at lua end +% \processedfile % defined at lua end +% \processedfiles % defined at lua end +% +% \dostarttextfile #name % defined at lua end +% \dostoptextfile % defined at lua end +% +% \loadtexfile [#name] % defined at lua end +% \loadluafile [#name] % defined at lua end +% \loadcldfile [#name] % defined at lua end +% \loadanyfile [#name] % defined at lua end +% +% \loadtexfileonce [#name] % defined at lua end +% \loadluafileonce [#name] % defined at lua end +% \loadcldfileonce [#name] % defined at lua end +% \loadanyfileonce [#name] % defined at lua end + +%D Handy for modules that have a test/demo appended (true added). + +% \permanent\protected\def\continueifinputfile#name{\clf_doifelsecontinuewithfile{#name}\relax\endinput} % we cannot do \endinput via lua + +% \continueifinputfile #name % defined at lua end + +% \startproject test +% 1: \startmode[*project] project \stopmode \endgraf +% 2: \startmode[*product] product \stopmode \endgraf +% \stopproject + +% A bit weird place: + +\neverypar\emptytoks + +%D Wrappers (the signal is a synchronization with lua hack): + +\newsystemmode\v!project +\newsystemmode\v!product +\newsystemmode\v!component +\newsystemmode\v!environment + +\permanent\protected\def\startprojectindeed + {%starttext + \pushsystemmode\v!project + \setsystemmode\v!project} + +\permanent\protected\def\stopprojectindeed + {\popsystemmode\v!project + %stoptext + }%\signalendofinput\v!project} + +\permanent\protected\def\startproductindeed + {\starttext + \pushsystemmode\v!product + \setsystemmode\v!product} + +\permanent\protected\def\stopproductindeed + {\popsystemmode\v!product + \stoptext + }%\signalendofinput\v!product} + +\permanent\protected\def\startcomponentindeed + {\starttext + \pushreferenceprefix\currentcomponent + \pushsystemmode\v!component + \setsystemmode\v!component} + +\permanent\protected\def\stopcomponentindeed + {\popsystemmode\v!component + \popreferenceprefix + \stoptext + }%\signalendofinput\v!component} + +\permanent\protected\def\startenvironmentindeed + {\pushsystemmode\v!environment + \setsystemmode\v!environment} + +\permanent\protected\def\stopenvironmentindeed + {\popsystemmode\v!environment + }%\signalendofinput\v!environment} + +%D Upgraded after the ctx 2020 meeting: +%D +%D \starttyping +%D \definedocument[thesis] +%D +%D \setupdocument[a=b,e=f] +%D \setupdocument[thesis][a=x,c=d] +%D +%D % \startsetups[thesis:start] +%D \startsetups[document:start] +%D START +%D \stopsetups +%D +%D \startsetups[thesis:stop] +%D % \startsetups[document:stop] +%D STOP +%D \stopsetups +%D +%D % \startdocument[thesis] +%D \startthesis +%D (\currentdocument/a): \documentvariable{a}\par +%D (\currentdocument/c): \documentvariable{c}\par +%D (\currentdocument/e): \documentvariable{e}\par +%D \stopthesis +%D % \stopdocument +%D \stoptyping + +\installcorenamespace {document} + +\installcommandhandler \??document \s!document \??document + +\setupdocument + [\c!before=\directsetup{\s!document:\v!start}, + \c!after =\directsetup{\s!document:\v!stop}] + +\def\syst_document_setup#1% + {\directsetup{\doifelsesetups{\currentdocument:\v!start}\currentdocument\s!document:\v!start}} + +\appendtoks + \normalexpanded {% + \startsetups[\currentdocument:\v!start]\noexpand\directsetup{\ifx\empty\currentdocumentparent\s!document\else\currentdocumentparent\fi:\v!start}\stopsetups + \startsetups[\currentdocument:\v!stop ]\noexpand\directsetup{\ifx\empty\currentdocumentparent\s!document\else\currentdocumentparent\fi:\v!stop }\stopsetups + \permanent\setvalue{\e!start\currentdocument}{\startdocument[\currentdocument]}% + \permanent\setvalue{\e!stop \currentdocument}{\stopdocument} + }% +\to \everydefinedocument + +% todo: dostarttagged\t!document + +\permanent\tolerant\protected\def\startdocument[#namespace]#spacer[#settings]% + {\pushmacro\currentdocument + \ifparameters + \or + \ifhastok={#namespace}% + \let\currentdocument\empty + \setupcurrentdocument[#namespace]% + \else + \edef\currentdocument{#namespace}% + \fi + \or + \edef\currentdocument{#namespace}% + \setupcurrentdocument[#settings]% + \fi + \ifempty\currentdocument\else\setmode\currentdocument\fi + \starttext + \the\everystartdocument + \documentvariable\c!before} + +\permanent\protected\def\stopdocument % todo: dostoptagged\t!document + {\documentvariable\c!after + \the\everystopdocument + \stoptext + \ifx\empty\currentdocument\else\resetmode\currentdocument\fi + \popmacro\currentdocument} + +\aliased \let\documentvariable \documentparameter +\aliased\protected\def\unexpandeddocumentvariable{\documentparameter} + +\permanent\protected\def\doifelsedocumentvariable#name{\doifelsesomething{\documentvariable{#name}}} +\permanent\protected\def\doifdocumentvariable #name{\doifsomething {\documentvariable{#name}}} +\permanent\protected\def\doifnotdocumentvariable #name{\doifnot {\documentvariable{#name}}} + +\aliased\let\doifdocumentvariableelse\doifelsedocumentvariable + +\permanent\tolerant\protected\def\presetdocument[#namespace]#spacer[#settings]% + {\pushmacro\currentdocument + \ifparameters + \or + \ifhastok={#namespace}% + \let\currentdocument\empty + \setupcurrentdocument[#namespace]% + \fi + \or + \edef\currentdocument{#namespace}% + \setupcurrentdocument[#settings]% + \fi + \popmacro\currentdocument} + +% Bonus: + +% \installcorenamespace{samplefile} +% +% \protected\def\samplefile#1% +% {\ifcsname\??samplefile#1\endcsname \else +% \setxvalue{\??samplefile#1}{\cldloadfile{#1}}% +% \fi +% \lastnamedcs} + +\permanent\protected\def\samplefile#1{\clf_samplefile{#1}} + +\protect \endinput diff --git a/tex/context/base/mkiv/file-mod.mklx b/tex/context/base/mkiv/file-mod.mklx new file mode 100644 index 000000000..60237ae26 --- /dev/null +++ b/tex/context/base/mkiv/file-mod.mklx @@ -0,0 +1,289 @@ +%D \module +%D [ file=file-mod, % was core-fil, +%D version=20110701, % 1997.11.15, +%D title=\CONTEXT\ File Macros, +%D subtitle=Module Support, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt File Macros / Modules} + +\unprotect + +\registerctxluafile{file-mod}{} + +%D \macros +%D {usemodule} +%D +%D Most of \CONTEXT is preloaded in the format file. Some very domain specific +%D typesetting topics are however dealt with in separate modules, e.g. typesetting +%D of chemical structure formulas. These modules are loaded by: +%D +%D \showsetup{usemodule} +%D +%D More information on the specific modules can be found in their dedicated manuals. +%D We use \type {\next} so that we can \type {\end} in modules. + +\installcorenamespace{module} + +\let\currentmodule \s!unknown +\let\currentmodulecategory \empty +\let\currentmoduleparameters\empty + +\installmacrostack\currentmodule +\installmacrostack\currentmodulecategory +\installmacrostack\currentmoduleparameters + +\permanent\tolerant\protected\def\usemodules[#category]#spacer[#name]#spacer[#parameters]% category=t|m|x|p|... + {\push_macro_currentmodule + \push_macro_currentmodulecategory + \push_macro_currentmoduleparameters + \ifparameters + \let\currentmodule\empty + \or + \let \currentmodulecategory \empty + \edef\currentmodule {#category}% + \let \currentmoduleparameters\empty + \or + \ifhastok={#name}% + \let\currentmodulecategory \empty + \edef\currentmodule {#category}% + \edef\currentmoduleparameters{#name}% + \else + \edef\currentmodulecategory {#category}% + \edef\currentmodule {#name}% + \let \currentmoduleparameters\empty + \fi + \or + \edef\currentmodulecategory {#category}% + \edef\currentmodule {#name}% + \def \currentmoduleparameters{#parameters}% + \fi + \processcommacommand[\currentmodule]{\strc_modules_use\currentmodulecategory}% + \pop_macro_currentmoduleparameters + \pop_macro_currentmodulecategory + \pop_macro_currentmodule} + +\def\strc_modules_use#category#name% + {\ifempty\currentmoduleparameters\else + \scratchtoks\expandafter{\currentmoduleparameters}% + \normalexpanded{\getparameters[\??module#name:][\the\scratchtoks]}% + \fi + \clf_usemodules{#category}{#name}} + +\aliased\let\usemodule \usemodules +\aliased\let\usetexmodule\usemodules + +\newcount\c_syst_modules_nesting +\newtoks \everysetupmodule + +\permanent\tolerant\protected\def\startmodule[#1]#;#2 % + {\global\advance\c_syst_modules_nesting\plusone + \push_macro_currentmodule + \push_macro_currentmoduleparameters + \def\currentmodule{#1#2}} + +\permanent\protected\def\stopmodule + {\ifcase\c_syst_modules_nesting + \writestatus\m!system{module wrapping error in '\currentmodule'}% + \else + \pop_macro_currentmoduleparameters + \pop_macro_currentmodule + \global\advance\c_syst_modules_nesting\minusone + \fi} + +\permanent\protected\def\setupmodule % to be lmtx'd + {\ifempty\currentmoduleparameters + \expandafter\syst_modules_setup_nop + \else + \expandafter\syst_modules_setup_yes + \fi} + +\tolerant\def\syst_modules_setup_nop[#name]#spacer[#parameters]% + {\ifarguments + % nothing + \or + \doifassignmentelse{#name}{\getparameters[\??module\currentmodule:][#name]}\donothing + \or + \getparameters[\??module#name:][#parameters]% internal (defaults) + \fi + \the\everysetupmodule} + +\def\syst_modules_setup_yes[#name]#spacer[#parameters]% + {\scratchtoks\expandafter{\currentmoduleparameters}% + \ifparameters + \normalexpanded{\getparameters[\??module\currentmodule:][\the\scratchtoks]}% + \or + \ifhastok={#name}% + \getparameters[\??module\currentmodule:][#name]% internal (defaults) + \normalexpanded{\getparameters[\??module\currentmodule:][\the\scratchtoks]}% loadtime (user) + \else + \normalexpanded{\getparameters[\??module#1:][\the\scratchtoks]}% loadtime (user) + \fi + \or + \getparameters[\??module#name:][#parameters]% internal (defaults) + \normalexpanded{\getparameters[\??module#name:][\the\scratchtoks]}% loadtime (user) + \fi + \let\currentmoduleparameters\empty + \the\everysetupmodule} + +\permanent\def\moduleparameter#name#parameter% should have been \namedmoduleparameter + {\begincsname\??module#name:#parameter\endcsname} + +\letvalue\??module\empty % so we default to empty as with all parameters + +\permanent\def\currentmoduleparameter{\moduleparameter\currentmodule} % no need for inlining + +%permanent\protected\def\useluamodule[#name]{\clf_loadluamodule{#1}} % why not use useluamodule + +\permanent\protected\def\useluamodule [#name]{\clf_useluamodule{#1}} +\permanent\protected\def\luaenvironment #name {\clf_loadluamodule{#1}} + +% \usemodule[newmml] +% \usemodule[newmml][a=b] +% \usemodule[x][newmml] +% \usemodule[x][newmml][a=b] +% +% \startmodule [mathml] +% \setupmodule[a=c] \relax [\currentmoduleparameter{a}] % user vars will be set afterwards +% \setupmodule[a=c] \relax [\currentmoduleparameter{a}] % user vars are now forgotten +% \stopmodule + +% one can introduce test sections with: +% +% \enablemode[newmml:test:\currentmoduleparameter{test}] +% \startmode[newmml:test:yes} ... \stopmode +% +% these will be ignored unless test=yes +% +% however, a better way is: + +\permanent\protected\def\startmoduletestsection + {\begingroup + \setupmodule % we need to make sure that the vars are set + \doifelse{\currentmoduleparameter\v!test}\v!yes + {\endgroup + \writestatus\currentmodule{loading experimental code}} + {\endgroup + \writestatus\currentmodule{skipping experimental code}% + \gobbleuntil\stopmoduletestsection}} + +\aliased\let\stopmoduletestsection\donothing + +% will become file-run + +%D To save memory, we implement some seldomly used commands in a lazy way. Nota +%D bene: such runtime definitions are to be defined global. +%D +%D \starttyping +%D \fetchruntimecommand \showaccents \f!file_run % last is a file name +%D \stoptyping + +\installcorenamespace{runtimeloaded} + +\permanent\protected\def\fetchruntimecommand#1#2% + {\protected\def#1{\dofetchruntimecommand#1{#2}}} + +\def\dofetchruntimecommand#1#2% actually a test on #1 being define would be ok as well + {\ifcsname\??runtimeloaded#2\endcsname + % already loaded + \else + \glet#1\undefined + \startreadingfile + \startnointerference % \bgroup + \cleanupfeatures % better \setnormalcatcodes / test first + \readfile{#2.\mksuffix}\donothing\donothing + \stopnointerference % \egroup + \stopreadingfile + \letgvalue{\??runtimeloaded#2}\empty + \fi + \ifx#1\undefined + \writestatus\m!system{command \string#1 not found in file #2}% + \protected\gdef#1{{\infofont[unknown command \string#1]}}% + \fi + #1} + +%D \macros +%D {doifolderversionelse} +%D +%D We start with a macro specially for Aditya who wants to be able +%D to use development versions of \MKIV\ for real documents. +%D +%D \starttyping +%D \doifolderversionelse\contextversion{1010.10.10} {OLDER} {OKAY} => OLDER +%D \doifolderversionelse\contextversion{2020.20.20} {OLDER} {OKAY} => OKAY +%D \doifolderversionelse\contextversion{2020} {OLDER} {OKAY} => OKAY +%D \stoptyping +%D +%D The version pattern is \type {yyyy.mm.dd} (with mm and dd being optional). + +\permanent\protected\def\doifelseolderversion#parent#child{\clf_doifelseolderversion{#parent}{#child}} +\permanent\protected\def\doifelseoldercontext #child{\clf_doifelseolderversion{#child}{}} + +\aliased\let\doifolderversionelse\doifelseolderversion +\aliased\let\doifoldercontextelse\doifelseoldercontext + +%D Relatively new (no need for a speedup here). Can't this now be done nicer? + +\permanent\protected\def\syst_modules_direct_lua#1#2% + {\edef\m_module_command_command {#1}% + \edef\m_module_command_function{#2}% + \directsetup{module:\m_module_command_command:start}% + \ctxlua{\m_module_command_function()}% + \directsetup{module:\m_module_command_command:stop}} + +\permanent\protected\def\syst_modules_single_lua#1#2% + {\edef\m_module_command_command {#1}% + \edef\m_module_command_function{#2}% + \dosingleempty\syst_modules_single_lua_indeed} + +\permanent\protected\def\syst_modules_single_lua_indeed[#1]% + {\directsetup{module:\m_module_command_command:start}% + \ctxlua{\m_module_command_function(\!!bs#1\!!es)}% + \directsetup{module:\m_module_command_command:stop}} + +\permanent\protected\def\syst_modules_double_lua#1#2% + {\edef\m_module_command_command {#1}% + \edef\m_module_command_function{#2}% + \dodoubleempty\syst_modules_double_lua_indeed} + +\permanent\protected\def\syst_modules_double_lua_indeed[#1][#2]% + {\directsetup{module:\m_module_command_command:start}% + \ctxlua{\m_module_command_function(\!!bs#1\!!es,\!!bs#2\!!es)}% + \directsetup{module:\m_module_command_command:stop}} + +\permanent\protected\def\installmodulecommandlua #1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_direct_lua{\csstring#1}{#2}}}} +\permanent\protected\def\installmodulecommandluasingle#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_single_lua{\csstring#1}{#2}}}} +\permanent\protected\def\installmodulecommandluadouble#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_double_lua{\csstring#1}{#2}}}} + +\unexpanded\def\syst_modules_one_lua#1#2#3% + {\directsetup{module:#1:start}% + \ctxlua{#2(\!!bs#3\!!es)}% + \directsetup{module:#1:stop}} + +\unexpanded\def\syst_modules_two_lua#1#2#3#4% + {\directsetup{module:#1:start}% + \ctxlua{#2(\!!bs#3\!!es,\!!bs#4\!!es)}% + \directsetup{module:#1:stop}} + +\permanent\protected\def\installmodulecommandluaone#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_one_lua{\csstring#1}{#2}}}} +\permanent\protected\def\installmodulecommandluatwo#1#2{\enforced\permanent\protected\def#1{\normalexpanded{\syst_modules_two_lua{\csstring#1}{#2}}}} + +% obsolete +% +% \def\documentresources{\@@erurl} +% +% \unexpanded\def\setupexternalresources +% {\dodoubleargument\getparameters[\??er]} +% +% \setupexternalresources +% [url=] + +% new: + +\protect \endinput diff --git a/tex/context/base/mkiv/lang-ini.mkxl b/tex/context/base/mkiv/lang-ini.mkxl index 5ae1ea35d..0565a7844 100644 --- a/tex/context/base/mkiv/lang-ini.mkxl +++ b/tex/context/base/mkiv/lang-ini.mkxl @@ -185,7 +185,7 @@ \expandafter\secondoftwoarguments \fi} -\let\doiflanguageelse\doifelselanguage +\aliased\let\doiflanguageelse\doifelselanguage \permanent\def\reallanguagetag#1% {\ifcsname\??languagelinked#1\endcsname\lastnamedcs\else#1\fi} @@ -533,11 +533,11 @@ \fi \fi} -\protected\def\uselanguageparameter#1% +\permanent\protected\def\uselanguageparameter#1% {\edef\askedlanguage{#1\c!language}% \ifempty\askedlanguage\else\lang_basics_switch_asked\fi} -\protected\def\douselanguageparameter#1% fast setter +\permanent\protected\def\douselanguageparameter#1% fast setter {\edef\askedlanguage{#1}% \ifempty\askedlanguage\else\lang_basics_switch_asked\fi} diff --git a/tex/context/base/mkiv/math-ini.mkxl b/tex/context/base/mkiv/math-ini.mkxl index 2859707e1..ad3ad4b20 100644 --- a/tex/context/base/mkiv/math-ini.mkxl +++ b/tex/context/base/mkiv/math-ini.mkxl @@ -98,14 +98,14 @@ %D A few compatibility helpers: -\def\Umathbotaccent{\Umathaccent \s!bottom } -\def\Umathtopaccent{\Umathaccent \s!top } -\def\Umathaccents {\Umathaccent \s!both } % strange highlighting +\permanent\def\Umathbotaccent{\Umathaccent \s!bottom } +\permanent\def\Umathtopaccent{\Umathaccent \s!top } +\permanent\def\Umathaccents {\Umathaccent \s!both } % strange highlighting \ifdefined\Umathcharclass \else - \def\Umathcharclass{\numexpr\cldcontext{tex.getmathcode(token.scan_int())[1]}\relax} - \def\Umathcharfam {\numexpr\cldcontext{tex.getmathcode(token.scan_int())[2]}\relax} - \def\Umathcharslot {\numexpr\cldcontext{tex.getmathcode(token.scan_int())[3]}\relax} + \permanent\def\Umathcharclass{\numexpr\cldcontext{tex.getmathcode(token.scan_int())[1]}\relax} + \permanent\def\Umathcharfam {\numexpr\cldcontext{tex.getmathcode(token.scan_int())[2]}\relax} + \permanent\def\Umathcharslot {\numexpr\cldcontext{tex.getmathcode(token.scan_int())[3]}\relax} \fi %D The attributes that we will use (todo: pack some into one but uglier code): @@ -683,18 +683,18 @@ \permanent\tolerant\protected\def\definemathcommand[#1]#*[#2]#*[#3]#:#*#4% command class args meaning {\ifparameter#3\or - \edef\nofmathcommandarguments{#3}% + \edef\nofmathcommandarguments{#3}% make this one m_arguments \ifx\nofmathcommandarguments\v!one - \setuvalue{\??mathcommand#1}##1{\mathcodecommand{#2}{#4{##1}}}% + \frozen\setuvalue{\??mathcommand#1}##1{\mathcodecommand{#2}{#4{##1}}}% \orelse\ifx\nofmathcommandarguments\v!two - \setuvalue{\??mathcommand#1}##1##2{\mathcodecommand{#2}{#4{##1}{##2}}}% + \frozen\setuvalue{\??mathcommand#1}##1##2{\mathcodecommand{#2}{#4{##1}{##2}}}% \else - \setuvalue{\??mathcommand#1}{\mathcodecommand{#2}{#4}}% + \frozen\setuvalue{\??mathcommand#1}{\mathcodecommand{#2}{#4}}% \fi \orelse\ifparameter#2\or - \setuvalue{\??mathcommand#1}{\mathcodecommand{#2}{#4}}% + \frozen\setuvalue{\??mathcommand#1}{\mathcodecommand{#2}{#4}}% \else - \setuvalue{\??mathcommand#1}{\mathcodecommand{nothing}{#4}}% + \frozen\setuvalue{\??mathcommand#1}{\mathcodecommand{nothing}{#4}}% \fi \ifparameter#1\or % safeguard \letcsnamecsname\csname#1\endcsname\csname\??mathcommand#1\endcsname diff --git a/tex/context/base/mkiv/mult-aux.mkxl b/tex/context/base/mkiv/mult-aux.mkxl index da86888c5..1b7a760cd 100644 --- a/tex/context/base/mkiv/mult-aux.mkxl +++ b/tex/context/base/mkiv/mult-aux.mkxl @@ -273,9 +273,8 @@ \def\mult_interfaces_detokenize{\expandafter\expandafter\expandafter\detokenize\expandafter\expandafter\expandafter} -\protected\def\mult_interfaces_install_parameter_handler#1#2#3#4#5#6#7#8#9% inlining \csname*\endcsname is more efficient (#3 and #6 only) - {\ifx#2\relax\mutable\let#2\empty\fi % it is hardly faster but produces less expansion tracing - \frozen\def#3##1{\csname\ifcsname#1#2:##1\endcsname#1#2:##1\else\expandafter#5\csname#1#2:\s!parent\endcsname{##1}\fi\endcsname}% +\protected\def\mult_interfaces_install_parameter_handler#1#2#3#4#5#6#7#8#9% + {\frozen\def#3##1{\csname\ifcsname#1#2:##1\endcsname#1#2:##1\else\expandafter#5\csname#1#2:\s!parent\endcsname{##1}\fi\endcsname}% \frozen\def#4##1##2{\ifcsname##1:##2\endcsname##1:##2\else\expandafter#5\csname##1:\s!parent\endcsname{##2}\fi}% \frozen\edef#5##1##2{\noexpand\ifx##1\relax\??empty\noexpand\else\noexpand#4##1{##2}\noexpand\fi}% is {} needed around ##1 ? \frozen\def#6##1##2{\csname\ifcsname#1##1:##2\endcsname#1##1:##2\else\expandafter#5\csname#1##1:\s!parent\endcsname{##2}\fi\endcsname}% @@ -285,7 +284,8 @@ \frozen\def#9##1##2{\expandafter\let\expandafter##1\csname\ifcsname#1#2:##2\endcsname#1#2:##2\else\expandafter#5\csname#1#2:\s!parent\endcsname{##2}\fi\endcsname}} \permanent\protected\def\installparameterhandler#1#2% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \normalexpanded {\mult_interfaces_install_parameter_handler {\noexpand#1}% \??aa \expandafter\noexpand\csname current#2\endcsname @@ -309,8 +309,7 @@ \expandafter\noexpand\csname root#2parameter\endcsname}} \protected\def\mult_interfaces_install_parameter_hash_handler#1#2#3#4#5#6#7#8#9% - {\ifx#2\relax\mutable\let#2\empty\fi - \frozen\def#3##1{#1#4{#1#2}{##1}:}% leading #1 was missing .. is this one used? + {\frozen\def#3##1{#1#4{#1#2}{##1}:}% leading #1 was missing .. is this one used? \frozen\def#4##1##2{\ifcsname##1:##2\endcsname##1\else\expandafter#5\csname##1:\s!parent\endcsname{##2}\fi}% \frozen\def#5##1##2{\ifx##1\relax\else#4##1{##2}\fi}% \frozen\def#6{#1#2:}% @@ -319,7 +318,8 @@ \frozen\protected\def#9##1{\edefcsname#1##1:\s!parent\endcsname{#1#2}}} \permanent\protected\def\installparameterhashhandler#1#2% - {\letcsname#2namespace\endcsname#1% + {\mutable\letcsname current#2\endcsname\empty + \letcsname#2namespace\endcsname#1% \normalexpanded {\mult_interfaces_install_parameter_hash_handler {\noexpand#1}% \??aa @@ -338,15 +338,15 @@ % \startinterface english \protected\def\mult_interfaces_install_parameter_set_handler#1#2#3#4#5#6% - {\ifx#2\relax\mutable\let#2\empty\fi - \frozen\protected\def#3##1{\defcsname#1#2:##1\endcsname}% ##1 {##2} (braces are mandate) + {\frozen\protected\def#3##1{\defcsname#1#2:##1\endcsname}% ##1 {##2} (braces are mandate) \frozen\protected\def#4##1{\edefcsname#1#2:##1\endcsname}% ##1 {##2} (braces are mandate) \frozen\protected\def#5##1{\letcsname#1#2:##1\endcsname}% ##1 ##2 \frozen\protected\def#6##1{\letcsname#1#2:##1\endcsname\empty}}% ##1 % \stopinterface \permanent\protected\def\installparametersethandler#1#2% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \normalexpanded {\mult_interfaces_install_parameter_set_handler {\noexpand#1}% \??aa \expandafter\noexpand\csname current#2\endcsname @@ -390,13 +390,16 @@ \edefcsname#1#4:\s!parent\endcsname{#2}% \fi} -\def\mult_interfaces_chain#1#2{\ifcsname#1#2:\s!chain\endcsname\lastnamedcs\space\fi} -\def\getparentchain #1#2{\begincsname#1#2:\s!chain\endcsname} -\def\getcurrentparentchain#1#2{\begincsname#1#2:\s!chain\endcsname} + \def\mult_interfaces_chain#1#2{\ifcsname#1#2:\s!chain\endcsname\lastnamedcs\space\fi} +\permanent\def\getparentchain #1#2{\begincsname#1#2:\s!chain\endcsname} +\permanent\def\getcurrentparentchain#1#2{\begincsname#1#2:\s!chain\endcsname} + +% we could have a \setcurrent... macro and then always make them a frozen +% but it might have a little impact on performance ... something to leave +% to when we're done with the transition (it's kind of massive) \protected\def\mult_interfaces_install_define_handler#1#2#3#4#5#6#7#8% why is \expanded still needed in clones - {\ifx#4\relax\mutable\let#4\empty\fi % see \defineregister - \newtoks#5% + {\newtoks#5% \newtoks#6% \frozen\tolerant\protected\def#2[##1]##*[##2]##*[##3]% [child][parent][settings] | [child][settings] | [child][parent] | [child] {\let#8#4% @@ -446,7 +449,9 @@ \let#4#8}} \permanent\protected\def\installdefinehandler#1#2#3% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \mutable\letcsname current#2parent\endcsname\empty + \normalexpanded {\mult_interfaces_install_define_handler {\noexpand#1}% \??aa \expandafter\noexpand\csname define#2\endcsname @@ -458,10 +463,9 @@ \expandafter\noexpand\csname saved_defined_#2\endcsname}} \protected\def\mult_interfaces_install_setup_handler#1#2#3#4#5#6#7#8% - {\ifx#3\relax\mutable\let#3\empty\fi - \protected\def#5{\mult_interfaces_get_parameters{#1#3:}}% no every ! don't change it - \newtoks#4% + {\newtoks#4% \newtoks#7% + \frozen\protected\def#5{\mult_interfaces_get_parameters{#1#3:}}% no every ! don't change it \frozen\tolerant\protected\def#2[##1]##*[##2]% maybe helper {\let#6#3% \ifnum\lastarguments=\plustwo @@ -479,7 +483,8 @@ \the#7}} \permanent\protected\def\installsetuphandler#1#2% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \normalexpanded {\mult_interfaces_install_setup_handler {\noexpand#1}% \??aa \expandafter\noexpand\csname setup#2\endcsname @@ -496,15 +501,13 @@ \let\doingrootsetroot \plusfour % \setuplayout \protected\def\mult_interfaces_install_switch_setup_handler_a#1#2#3% - {\ifx#2\relax\mutable\let#2\empty\fi - \frozen\protected\def#3{\mult_interfaces_get_parameters{#1#2:}}} + {\frozen\protected\def#3{\mult_interfaces_get_parameters{#1#2:}}} \protected\def\mult_interfaces_install_switch_setup_handler_b#1#2#3#4#5#6#7#8#9% {\newtoks#5% \newconstant#2% \newtoks#8% \newtoks#9% - \ifx#6\relax\let#6\empty\fi \frozen\tolerant\protected\def#4[##1]##*[##2]% maybe helper {\ifarguments % \setuplayout @@ -555,7 +558,9 @@ \the#9}} \permanent\protected\def\installswitchsetuphandler#1#2% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \mutable\letcsname previous#2\endcsname\empty + \normalexpanded {\mult_interfaces_install_switch_setup_handler_a {\noexpand#1}% \??aa \expandafter\noexpand\csname current#2\endcsname @@ -572,9 +577,8 @@ \expandafter\noexpand\csname everysetup#2root\endcsname}} \protected\def\mult_interfaces_install_auto_setup_handler#1#2#3#4#5#6#7#8% - {\ifx#3\relax\mutable\let#3\empty\fi + {\newtoks#4% \frozen\protected\def#5{\mult_interfaces_get_parameters{#1#3:}}% - \newtoks#4% \frozen\tolerant\protected\def#2[##1]##*[##2]##*[##3]% {\let#7#3% \ifarguments @@ -602,7 +606,8 @@ \let#3#7}} \permanent\protected\def\installautosetuphandler#1#2% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \normalexpanded {\mult_interfaces_install_auto_setup_handler {\noexpand#1}% \??aa \expandafter\noexpand\csname setup#2\endcsname @@ -668,7 +673,8 @@ \frozen\def#5##1{\begincsname#1##1\endcsname}} \permanent\protected\def\installdirectparameterhandler#1#2% - {\normalexpanded + {\mutable\letcsname current#2\endcsname\empty + \normalexpanded {\mult_interfaces_install_direct_parameter_handler {\noexpand#1}% \expandafter\noexpand\csname current#2\endcsname @@ -777,7 +783,8 @@ \endgroup}} \permanent\protected\def\installactionhandler#1% - {\normalexpanded + {\mutable\letcsname current#1\endcsname\empty + \normalexpanded {\mult_interfaces_install_action_handler {#1}% \expandafter\noexpand\csname current#1\endcsname diff --git a/tex/context/base/mkiv/mult-low.lua b/tex/context/base/mkiv/mult-low.lua index 8cf89c40a..0efd5d30c 100644 --- a/tex/context/base/mkiv/mult-low.lua +++ b/tex/context/base/mkiv/mult-low.lua @@ -387,7 +387,7 @@ return { "doloopovermatch", "doloopovermatched", "doloopoverlist", -- "newconstant", "setnewconstant", "setconstant", "setconstantvalue", - "newconditional", "settrue", "setfalse", "settruevalue", "setfalsevalue", + "newconditional", "settrue", "setfalse", "settruevalue", "setfalsevalue", "setconditional", -- "newmacro", "setnewmacro", "newfraction", "newsignal", @@ -488,7 +488,7 @@ return { -- "assumelongusagecs", -- - "Umathbotaccent", + "Umathbotaccent", "Umathtopaccent", -- "righttolefthbox", "lefttorighthbox", "righttoleftvbox", "lefttorightvbox", "righttoleftvtop", "lefttorightvtop", "rtlhbox", "ltrhbox", "rtlvbox", "ltrvbox", "rtlvtop", "ltrvtop", diff --git a/tex/context/base/mkiv/norm-ctx.mkxl b/tex/context/base/mkiv/norm-ctx.mkxl new file mode 100644 index 000000000..5cee04935 --- /dev/null +++ b/tex/context/base/mkiv/norm-ctx.mkxl @@ -0,0 +1,87 @@ +%D \module +%D [ file=norm-ctx, +%D version=2009.03.19, +%D title=\CONTEXT\ Normal Macros, +%D subtitle=\CONTEXT, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\unprotect + +%D A few more might end up here (like the weird ones in syst-ini). + +\let\normalreqno\normaleqno + +% more friendly in setups: + +\aliased\let\ordordspacing \Umathordordspacing +\aliased\let\ordopspacing \Umathordopspacing +\aliased\let\ordbinspacing \Umathordbinspacing +\aliased\let\ordrelspacing \Umathordrelspacing +\aliased\let\ordopenspacing \Umathordopenspacing +\aliased\let\ordclosespacing \Umathordclosespacing +\aliased\let\ordpunctspacing \Umathordpunctspacing +\aliased\let\ordinnerspacing \Umathordinnerspacing +\aliased\let\opordspacing \Umathopordspacing +\aliased\let\opopspacing \Umathopopspacing +\aliased\let\opbinspacing \Umathopbinspacing +\aliased\let\oprelspacing \Umathoprelspacing +\aliased\let\opopenspacing \Umathopopenspacing +\aliased\let\opclosespacing \Umathopclosespacing +\aliased\let\oppunctspacing \Umathoppunctspacing +\aliased\let\opinnerspacing \Umathopinnerspacing +\aliased\let\binordspacing \Umathbinordspacing +\aliased\let\binopspacing \Umathbinopspacing +\aliased\let\binbinspacing \Umathbinbinspacing +\aliased\let\binrelspacing \Umathbinrelspacing +\aliased\let\binopenspacing \Umathbinopenspacing +\aliased\let\binclosespacing \Umathbinclosespacing +\aliased\let\binpunctspacing \Umathbinpunctspacing +\aliased\let\bininnerspacing \Umathbininnerspacing +\aliased\let\relordspacing \Umathrelordspacing +\aliased\let\relopspacing \Umathrelopspacing +\aliased\let\relbinspacing \Umathrelbinspacing +\aliased\let\relrelspacing \Umathrelrelspacing +\aliased\let\relopenspacing \Umathrelopenspacing +\aliased\let\relclosespacing \Umathrelclosespacing +\aliased\let\relpunctspacing \Umathrelpunctspacing +\aliased\let\relinnerspacing \Umathrelinnerspacing +\aliased\let\openordspacing \Umathopenordspacing +\aliased\let\openopspacing \Umathopenopspacing +\aliased\let\openbinspacing \Umathopenbinspacing +\aliased\let\openrelspacing \Umathopenrelspacing +\aliased\let\openopenspacing \Umathopenopenspacing +\aliased\let\openclosespacing \Umathopenclosespacing +\aliased\let\openpunctspacing \Umathopenpunctspacing +\aliased\let\openinnerspacing \Umathopeninnerspacing +\aliased\let\closeordspacing \Umathcloseordspacing +\aliased\let\closeopspacing \Umathcloseopspacing +\aliased\let\closebinspacing \Umathclosebinspacing +\aliased\let\closerelspacing \Umathcloserelspacing +\aliased\let\closeopenspacing \Umathcloseopenspacing +\aliased\let\closeclosespacing\Umathcloseclosespacing +\aliased\let\closepunctspacing\Umathclosepunctspacing +\aliased\let\closeinnerspacing\Umathcloseinnerspacing +\aliased\let\punctordspacing \Umathpunctordspacing +\aliased\let\punctopspacing \Umathpunctopspacing +\aliased\let\punctbinspacing \Umathpunctbinspacing +\aliased\let\punctrelspacing \Umathpunctrelspacing +\aliased\let\punctopenspacing \Umathpunctopenspacing +\aliased\let\punctclosespacing\Umathpunctclosespacing +\aliased\let\punctpunctspacing\Umathpunctpunctspacing +\aliased\let\punctinnerspacing\Umathpunctinnerspacing +\aliased\let\innerordspacing \Umathinnerordspacing +\aliased\let\inneropspacing \Umathinneropspacing +\aliased\let\innerbinspacing \Umathinnerbinspacing +\aliased\let\innerrelspacing \Umathinnerrelspacing +\aliased\let\inneropenspacing \Umathinneropenspacing +\aliased\let\innerclosespacing\Umathinnerclosespacing +\aliased\let\innerpunctspacing\Umathinnerpunctspacing +\aliased\let\innerinnerspacing\Umathinnerinnerspacing + +\protect \endinput diff --git a/tex/context/base/mkiv/spac-ali.mkxl b/tex/context/base/mkiv/spac-ali.mkxl index 4f3e951fa..bc43db8ff 100644 --- a/tex/context/base/mkiv/spac-ali.mkxl +++ b/tex/context/base/mkiv/spac-ali.mkxl @@ -778,18 +778,18 @@ % Visible commands: -\let\notragged \spac_align_set_horizontal_none -\let\raggedleft \spac_align_set_horizontal_left -\let\raggedcenter \spac_align_set_horizontal_center -\let\raggedright \spac_align_set_horizontal_right -\let\veryraggedleft \spac_align_set_horizontal_very_left -\let\veryraggedcenter \spac_align_set_horizontal_very_center -\let\veryraggedright \spac_align_set_horizontal_very_right -\let\raggedwidecenter \spac_align_set_horizontal_wide_center -\let\centeredlastline \spac_align_set_horizontal_centered_last_line -\let\flushedrightlastline\spac_align_set_horizontal_flushedright_last_line -\let\ttraggedright \spac_align_set_horizontal_right_tt % a plain command -\let\forgetragged \spac_align_set_horizontal_none +\aliased\let\notragged \spac_align_set_horizontal_none +\aliased\let\raggedleft \spac_align_set_horizontal_left +\aliased\let\raggedcenter \spac_align_set_horizontal_center +\aliased\let\raggedright \spac_align_set_horizontal_right +\aliased\let\veryraggedleft \spac_align_set_horizontal_very_left +\aliased\let\veryraggedcenter \spac_align_set_horizontal_very_center +\aliased\let\veryraggedright \spac_align_set_horizontal_very_right +\aliased\let\raggedwidecenter \spac_align_set_horizontal_wide_center +\aliased\let\centeredlastline \spac_align_set_horizontal_centered_last_line +\aliased\let\flushedrightlastline\spac_align_set_horizontal_flushedright_last_line +\aliased\let\ttraggedright \spac_align_set_horizontal_right_tt % a plain command +\aliased\let\forgetragged \spac_align_set_horizontal_none \appendtoks \spac_align_set_horizontal_none @@ -892,8 +892,8 @@ % older (context) names: -\let\spaceamount \interwordspace -\let\emspaceamount\emwidth +\aliased\let\spaceamount \interwordspace +\aliased\let\emspaceamount\emwidth % tracing: diff --git a/tex/context/base/mkiv/spac-chr.mkxl b/tex/context/base/mkiv/spac-chr.mkxl new file mode 100644 index 000000000..8d7bba42e --- /dev/null +++ b/tex/context/base/mkiv/spac-chr.mkxl @@ -0,0 +1,103 @@ +%D \module +%D [ file=spac-chr, +%D version=2011.05.24, % code moved from core-spa.mkiv +%D title=\CONTEXT\ Spacing Macros, +%D subtitle=Characters, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Spacing Macros / Characters} + +\unprotect + +\registerctxluafile{spac-chr}{optimize} + +\definesystemattribute[characters][public] + +%D The nobreakspace is special as it needs to keep track of the space being +%D flexible. Another option is to use space (glue) nodes and tag them as characters +%D instead. No big deal but takes a moment of coding. So, as a prelude we +%D tag the nobreakspace only. Interesting is that it also fits better in the +%D tagging mechanism. +%D +%D But we need to do some checking as from then on we no longer can compare +%D them in a string. So this needs thinking. Not that we can compare the +%D nobreakspace now anyway. + +% \unexpanded\def\specialspacecharacter#1{\begingroup\c_attr_characters#1\ \endgroup} +% +% \unexpanded\edef\nobreakspace {\specialspacecharacter{"00A0}} % 1 = left +% \unexpanded\edef\ideographicspace {\specialspacecharacter{"2000}} +% \unexpanded\edef\ideographichalffillspace{\specialspacecharacter{"2001}} +% \unexpanded\edef\twoperemspace {\specialspacecharacter{"2002}} +% \unexpanded\edef\threeperemspace {\specialspacecharacter{"2004}} +% \unexpanded\edef\fourperemspace {\specialspacecharacter{"2005}} +% \unexpanded\edef\sixperemspace {\specialspacecharacter{"2006}} +% \unexpanded\edef\figurespace {\specialspacecharacter{"2007}} +% \unexpanded\edef\punctuationspace {\specialspacecharacter{"2008}} +% \unexpanded\edef\breakablethinspace {\specialspacecharacter{"2009}} +% \unexpanded\edef\hairspace {\specialspacecharacter{"200A}} +% \unexpanded\edef\zerowidthspace {\specialspacecharacter{"200B}} +% \unexpanded\edef\zwnj {\specialspacecharacter{"200C}} +% \unexpanded\edef\zwj {\specialspacecharacter{"200D}} +% \unexpanded\edef\narrownobreakspace {\specialspacecharacter{"202F}} + +% This does not work as spaceskip is only inserted in the case of raggedleft +% and we need to be able to figure out all of them. Which makes me wonder ... +% can't we just always set spaceskip to some value? + +% Making them active is also not an option unless we do that in every +% catcode vector. + +\pushoverloadmode + +%immutable\edef\nobreakspace {\begingroup\setalignstateattribute\normalUchar"00A0\endgroup} % 1 = left +\immutable\edef\nobreakspace {\normalUchar"00A0} % space +\immutable\edef\softhyphen {\normalUchar"00AD} % softhyohen +\immutable\edef\enquad {\normalUchar"2000} % quad/2 +\immutable\edef\emquad {\normalUchar"2001} % quad +\immutable\edef\twoperemspace {\normalUchar"2002} % quad/2 +% % "2003 % quad == \quad == \hskip\emwidth +\immutable\edef\threeperemspace {\normalUchar"2004} % quad/3 +\immutable\edef\fourperemspace {\normalUchar"2005} % quad/4 +%immutable\edef\fiveperemspace {\normalUchar"001E} % quad/5 (bonus) +\immutable\edef\sixperemspace {\normalUchar"2006} % quad/6 +\immutable\edef\figurespace {\normalUchar"2007} % width of zero +\immutable\edef\punctuationspace {\normalUchar"2008} % width of period +\immutable\edef\breakablethinspace {\normalUchar"2009} % quad/8 +\immutable\edef\hairspace {\normalUchar"200A} % quad/8 +\immutable\edef\zerowidthspace {\normalUchar"200B} % 0 +\immutable\edef\zerowidthnonjoiner {\normalUchar"200C} % 0 +\immutable\edef\zerowidthjoiner {\normalUchar"200D} % 0 +\immutable\edef\narrownobreakspace {\normalUchar"202F} % quad/8 +%immutable\edef\mediummathspace {\normalUchar"205F} % space/8 (math) +%immutable\edef\zerowidthnobreakspace{\normalUchar"FEFF} +%immutable\edef\fiveperemspace {\normalUchar"001E} + +\immutable\protected\def\zerowidthnobreakspace{\penalty\plustenthousand\kern\zeropoint} +\immutable\protected\def\fiveperemspace {\hskip\dimexpr\emwidth/5\relax} + +\aliased\let\ideographicspace \enquad +\aliased\let\ideographichalffillspace \emquad + +\immutable\let\zwnj \zerowidthnonjoiner +\immutable\let\zwj \zerowidthjoiner +\immutable\let\nbsp \nobreakspace + +\popoverloadmode + +\immutable\chardef\optionalspace"1F % will be space unless before punctuation + +% Shortcuts: + +% unexpanded as otherwise we need to intercept / cleanup a lot + +\protected\def~{\nobreakspace} + +\protect \endinput + diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index 46fb57d00..9889b2d8b 100644 Binary files a/tex/context/base/mkiv/status-files.pdf and b/tex/context/base/mkiv/status-files.pdf differ diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf index 0b613e4d1..6b354d351 100644 Binary files a/tex/context/base/mkiv/status-lua.pdf and b/tex/context/base/mkiv/status-lua.pdf differ diff --git a/tex/context/base/mkiv/strc-blk.mkxl b/tex/context/base/mkiv/strc-blk.mkxl new file mode 100644 index 000000000..4cfbd51eb --- /dev/null +++ b/tex/context/base/mkiv/strc-blk.mkxl @@ -0,0 +1,171 @@ +%D \module +%D [ file=strc-blk, +%D version=2008.10.20, +%D title=\CONTEXT\ Structure Macros, +%D subtitle=Blockmoves, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Structure Macros / Blockmoves} + +\registerctxluafile{strc-blk}{} + +\unprotect + +% we run on top of buffers and sections +% +% todo: prefix numbers (needs further integration elsewhere) +% check functionality +% alternative files (needs further integration elsewhere) +% +% order matters: \c!before (think of: \c!before=\startitemize) +% +% no \endgroups + +\installcorenamespace {block} +\installcorenamespace {blocktemp} + +\installcommandhandler \??block {block} \??block + +\appendtoks + \clf_definestructureblock{\currentblock}% + \frozen\setuevalue{\e!begin\currentblock}{\strc_blocks_begin{\currentblock}}% + \frozen\letvalue {\e!end \currentblock}\donothing +\to \everydefineblock + +% We need to prevent too much lookahead which will gobble newlines that are needed +% for buffers. See blocks-002.tex as example. + +% maybe: systemmode "block:" + +\let\m_block \empty +\let\m_subblock\empty + +\protected\def\strc_blocks_begin#1% + {\edef\m_block {#1}% + \let \m_subblock\empty + \doifelsenextoptionalcs\strc_blocks_begin_yes\strc_blocks_begin_nop} + +\protected\def\strc_blocks_begin_yes[#1]% + {\doifelseassignmentcs{#1}% + \strc_blocks_begin_indeed + \strc_blocks_begin_tagged + {#1}} + +\protected\def\strc_blocks_begin_tagged#1% + {\edef\m_subblock{#1}% + \doifelsenextoptionalcs\strc_blocks_begin_yes_yes\strc_blocks_begin_nop} + +\protected\def\strc_blocks_begin_yes_yes[#1]% + {\strc_blocks_begin_indeed{#1}} + +\protected\def\strc_blocks_begin_nop + {\strc_blocks_begin_indeed{}} + +\protected\def\strc_blocks_begin_indeed#1% + {\normalexpanded{\buff_pickup{\??block}{\e!begin\m_block}{\e!end\m_block}}% + {}% + {\clf_savestructureblock{\m_block}{\m_subblock}{#1}{\??block}}% + \plusone} + +\let\strc_blocks_setup\relax + +\newconstant \c_strc_blocks_index +\newconditional\c_strc_blocks_display + +\permanent\protected\def\dostarthiddenblock % called at lua end + {\begingroup + \visiblefalse % blocks float + \startnointerference + \strc_start_block} + +\permanent\protected\def\dostophiddenblock % called at lua end + {\strc_stop_block + \stopnointerference + \endgroup} + +\permanent\protected\def\dostartnormalblock % called at lua end + {\begingroup + \visibletrue + \strc_start_block} + +\permanent\protected\def\dostopnormalblock % called at lua end + {\strc_stop_block + \endgroup} + +\def\strc_start_block#1#2% + {\edef\currentblock{#2}% + \c_strc_blocks_index#1\relax + \strc_blocks_setup + \let\strc_blocks_setup\relax + \edef\p_alternative{\blockparameter\c!alternative}% + \ifx\p_alternative\v!text + \setfalse\c_strc_blocks_display + \else + \settrue\c_strc_blocks_display + \fi + \ifconditional\c_strc_blocks_display + \blockparameter\c!before + \fi + \begingroup + \usesetupsparameter\blockparameter\relax + \dostarttagged\t!block\currentblock + \useblockstyleandcolor\c!style\c!color + \blockparameter\c!inner % old + \ifconditional\c_strc_blocks_display + \usealignparameter\blockparameter + \else + \blockparameter\c!left + \fi + \ignorespaces} + +\def\strc_stop_block + {\removeunwantedspaces + \ifconditional\c_strc_blocks_display + \par + \else + \blockparameter\c!right + \fi + \dostoptagged + \endgroup + \ifconditional\c_strc_blocks_display + \blockparameter\c!after + \fi} + +\tolerant\def\strc_blocks_set_state[#1]#*[#2]#*[#3]% state name tag % todo: we could use the lua one directly + {\clf_setstructureblockstate{#1}{#2}{#3}} + +\tolerant\def\strc_blocks_select[#1]#*[#2]#*[#3]#*[#4]% state name tag setups + {\begingroup + \ifhastok={#3}% + \getparameters[\??blocktemp][\c!criterium=\v!text,#3]% + \def\strc_blocks_setup{\setupcurrentblock[#3]}% + \clf_selectstructureblock{#1}{#2}{}{\csname\??blocktemp\c!criterium\endcsname}% + \else + \getparameters[\??blocktemp][\c!criterium=\v!text,#4]% + \def\strc_blocks_setup{\setupcurrentblock[#4]}% + \clf_selectstructureblock{#1}{#2}{#3}{\csname\??blocktemp\c!criterium\endcsname}% + \fi + \endgroup} + +\permanent\def\blockuservariable#1% + {\clf_structureblockuservariable\c_strc_blocks_index{#1}} + +% hide : save, if [+] also hidden execute +% keep : save and normal execute +% use : normal execute unless [-] +% process: hidden execute unless [-] +% select : idem use + +\permanent\protected\def\hideblocks {\strc_blocks_set_state[hide]} +\permanent\protected\def\keepblocks {\strc_blocks_set_state[keep]} +\permanent\protected\def\useblocks {\strc_blocks_select [use]} +\permanent\protected\def\processblocks{\strc_blocks_select [process]} +\permanent\protected\def\selectblocks {\strc_blocks_select [use]} + +\protect \endinput diff --git a/tex/context/base/mkiv/strc-itm.mklx b/tex/context/base/mkiv/strc-itm.mklx index c167e24a4..b7f9cc6d5 100644 --- a/tex/context/base/mkiv/strc-itm.mklx +++ b/tex/context/base/mkiv/strc-itm.mklx @@ -830,7 +830,7 @@ \fi \begingroup % (2) \the\itemgroupcommands - \let\c_strc_itemgroups_text_saved\c_strc_itemgroups_text + \setconditional\c_strc_itemgroups_text_saved\c_strc_itemgroups_text \strc_itemgroups_initialize_local \strc_itemgroups_preset_stage_one\itemgroupoptions % diff --git a/tex/context/base/mkiv/syst-ini.mkxl b/tex/context/base/mkiv/syst-ini.mkxl index 202bc62f7..02202063c 100644 --- a/tex/context/base/mkiv/syst-ini.mkxl +++ b/tex/context/base/mkiv/syst-ini.mkxl @@ -751,11 +751,19 @@ \aliased\let\conditionalfalse\plusone % maybe we will have a dedicated count/chardef \aliased\let\conditionaltrue \zerocount % maybe we will have a dedicated count/chardef -\permanent\protected\def\settrue #1{\integerdef#1\conditionaltrue } -\permanent\protected\def\setfalse#1{\integerdef#1\conditionalfalse} +% \permanent\protected\def\settrue #1{\integerdef#1\conditionaltrue } +% \permanent\protected\def\setfalse#1{\integerdef#1\conditionalfalse} +% +% \permanent\protected\def\settruevalue #1{\expandafter\integerdef\csname#1\endcsname\conditionaltrue } +% \permanent\protected\def\setfalsevalue#1{\expandafter\integerdef\csname#1\endcsname\conditionalfalse} + +\permanent\protected\def\settrue #1{\enforced\let#1\conditionaltrue } +\permanent\protected\def\setfalse #1{\enforced\let#1\conditionalfalse} +\permanent\protected\def\setconditional#1{\enforced\let#1} + +\permanent\protected\def\settruevalue #1{\enforced\letcsname#1\endcsname\conditionaltrue } +\permanent\protected\def\setfalsevalue#1{\enforced\letcsname#1\endcsname\conditionalfalse} -\permanent\protected\def\settruevalue #1{\expandafter\integerdef\csname#1\endcsname\conditionaltrue } -\permanent\protected\def\setfalsevalue#1{\expandafter\integerdef\csname#1\endcsname\conditionalfalse} \aliased\let\newconditional\setfalse \aliased\let\ifconditional \ifcase diff --git a/tex/context/base/mkiv/tabl-com.mkxl b/tex/context/base/mkiv/tabl-com.mkxl index c6a0c14bc..791db656b 100644 --- a/tex/context/base/mkiv/tabl-com.mkxl +++ b/tex/context/base/mkiv/tabl-com.mkxl @@ -17,16 +17,26 @@ \pushoverloadmode +% maybe frozen instead + \permanent\let\AR\relax \permanent\let\BA\relax \permanent\let\BC\relax +\permanent\let\BH\relax \permanent\let\BL\relax +\permanent\let\BR\relax \permanent\let\CC\relax \permanent\let\CL\relax \permanent\let\CM\relax \permanent\let\CR\relax \permanent\let\DB\relax +\permanent\let\DC\relax +\permanent\let\DL\relax +\permanent\let\DR\relax +\permanent\let\DV\relax +\permanent\let\EH\relax \permanent\let\EQ\relax +\permanent\let\ER\relax \permanent\let\FB\relax \permanent\let\FL\relax \permanent\let\FR\relax @@ -35,8 +45,11 @@ \permanent\let\HQ\relax \permanent\let\HR\relax \permanent\let\LB\relax +\permanent\let\LC\relax +\permanent\let\LT\relax \permanent\let\LL\relax \permanent\let\LR\relax +\permanent\let\MC\relax \permanent\let\ML\relax \permanent\let\MR\relax \permanent\let\NA\relax @@ -53,9 +66,19 @@ \permanent\let\PB\relax \permanent\let\RC\relax \permanent\let\RQ\relax +\permanent\let\SL\relax +\permanent\let\SM\relax \permanent\let\SR\relax +\permanent\let\TB\relax \permanent\let\TL\relax +\permanent\let\TR\relax \permanent\let\VL\relax +\permanent\let\VC\relax +\permanent\let\VD\relax +\permanent\let\VN\relax +\permanent\let\VS\relax +\permanent\let\VT\relax +\permanent\let\XC\relax \popoverloadmode diff --git a/tex/context/base/mkiv/tabl-ntb.mkxl b/tex/context/base/mkiv/tabl-ntb.mkxl index ff8450f15..45e9236ff 100644 --- a/tex/context/base/mkiv/tabl-ntb.mkxl +++ b/tex/context/base/mkiv/tabl-ntb.mkxl @@ -467,7 +467,7 @@ \def\tabl_ntb_parameters_set[#1][#2]% {\ifappendTBLsetups \ifcsname\??naturaltableset\m_tabl_tbl_level:#1\endcsname - \def\tabl_ntb_parameters_get[##1]% + \enforced\def\tabl_ntb_parameters_get[##1]% {\setvalue{\??naturaltableset\m_tabl_tbl_level:#1}{\tabl_ntb_parameters_get[##1,#2]}}% \csname\??naturaltableset\m_tabl_tbl_level:#1\endcsname \enforced\let\tabl_ntb_parameters_get\setupcurrentnaturaltablelocal @@ -959,10 +959,10 @@ \let\currentTABLEcolumn\tabl_ntb_current_column \let\nofTABLErows \tabl_ntb_n_of_rows \let\nofTABLEcolumns \tabl_ntb_n_of_columns - \enforced\let\bTR\dobTR - \enforced\let\bTD\dobTD - \enforced\let\bTH\dobTH - \enforced\let\bTN\dobTN} + \enforced\let\bTR\tabl_ntb_bTR + \enforced\let\bTD\tabl_ntb_bTD + \enforced\let\bTH\tabl_ntb_bTH + \enforced\let\bTN\tabl_ntb_bTN} \def\tabl_ntb_current_row {\m_tabl_ntb_positive_row} \def\tabl_ntb_current_column{\m_tabl_ntb_positive_col} @@ -978,10 +978,10 @@ % todo with tolerant: -\permanent\protected\def\dobTR{\dosingleempty\tabl_ntb_tr} % also used in tabl-nte -\permanent\protected\def\dobTD{\dosingleempty\tabl_ntb_td} % also used in tabl-nte -\permanent\protected\def\dobTH{\dosingleempty\tabl_ntb_th} % also used in tabl-nte -\permanent\protected\def\dobTN{\dosingleempty\tabl_ntb_tn} % also used in tabl-nte +\permanent\protected\def\tabl_ntb_bTR{\dosingleempty\tabl_ntb_tr} % also used in tabl-nte +\permanent\protected\def\tabl_ntb_bTD{\dosingleempty\tabl_ntb_td} % also used in tabl-nte +\permanent\protected\def\tabl_ntb_bTH{\dosingleempty\tabl_ntb_th} % also used in tabl-nte +\permanent\protected\def\tabl_ntb_bTN{\dosingleempty\tabl_ntb_tn} % also used in tabl-nte % permits \expanded{\bTD ... \eTD} diff --git a/tex/context/base/mkiv/tabl-nte.mkxl b/tex/context/base/mkiv/tabl-nte.mkxl index 40213ad90..e79e2a004 100644 --- a/tex/context/base/mkiv/tabl-nte.mkxl +++ b/tex/context/base/mkiv/tabl-nte.mkxl @@ -88,9 +88,9 @@ \def\tabl_nte_start_nc_finish#1\NC {\ifconditional\c_tabl_nte_in_nc \else \settrue\c_tabl_nte_in_nc - \dobTR[]% + \tabl_ntb_bTR[]% \fi - \dobTD#1\eTD\NC} + \tabl_ntb_bTD#1\eTD\NC} %D The related structure commands are also available: diff --git a/tex/context/base/mkiv/typo-scr.mkxl b/tex/context/base/mkiv/typo-scr.mkxl new file mode 100644 index 000000000..7b72cb314 --- /dev/null +++ b/tex/context/base/mkiv/typo-scr.mkxl @@ -0,0 +1,266 @@ +%D \module +%D [ file=typo-scr, +%D version=2012.01.23, % very old ... 1995.10.10 .. moved from core-mis +%D title=\CONTEXT\ Typesetting Macros, +%D subtitle=Scripts, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Typesetting Macros / Scripts} + +\unprotect + +%D I addition to the commands implemented here, we have alternative commands +%D \type {shiftup} and \type {shiftdown} that can work across paragraphs. + +%D \macros +%D {low, high, definelow, definehigh, setuplow, setuphigh} +%D +%D Although \TEX\ is pretty well aware of super- and subscripts, its mechanism +%D is mainly tuned for math mode. The next few commands take care of script +%D texts both modes. +%D +%D \startbuffer +%D The higher\high{one goes} the lower\low{one drops}, or\lohi{yes}{no}? +%D \stopbuffer +%D +%D \typebuffer +%D \getbuffer +%D +%D Note the different placement of \type {\lohi}, where we need a bit more +%D space. The implementation looks a bit fuzzy, since some \type {\fontdimen}'s +%D are involved to determine the optimal placement. + +\installcorenamespace {low} +\installcorenamespace {high} + +\installcommandhandler \??low {low} \??low +\installcommandhandler \??high {high} \??high + +\setuplow [\c!style=\tx,\c!distance=\zeropoint,\c!down=.48\exheight] % historical +\setuphigh[\c!style=\tx,\c!distance=\zeropoint,\c!up =.86\exheight] % values + +\appendtoks \setuevalue\currentlow {\typo_scripts_low [\currentlow ]}\to \everydefinelow +\appendtoks \setuevalue\currenthigh{\typo_scripts_high[\currenthigh]}\to \everydefinehigh + +\protected\def\typo_scripts_low[#1]#2% + {\dontleavehmode + \begingroup + \edef\currentlow{#1}% + \kern\lowparameter\c!distance\relax + \setbox\scratchbox\runninghbox\bgroup + \lower\lowparameter\c!down\hbox\bgroup + \ifx\fontsize\empty + \ifmmode + \mr % no color yet + \else + \uselowstyleandcolor\c!style\c!color + \fi + \else + \uselowstyleandcolor\c!style\c!color + \fi + \dostarttagged\t!sub\currentlow + #2% + \dostoptagged + \egroup + \egroup + \ht\scratchbox\strutht + \dp\scratchbox\strutdp + \box\scratchbox + \endgroup} + +\protected\def\typo_scripts_high[#1]#2% + {\dontleavehmode + \begingroup + \edef\currenthigh{#1}% + \kern\highparameter\c!distance\relax + \setbox\scratchbox\runninghbox\bgroup + \raise\highparameter\c!up\hbox\bgroup + \ifx\fontsize\empty + \ifmmode + \mr % no color yet + \else + \usehighstyleandcolor\c!style\c!color + \fi + \else + \usehighstyleandcolor\c!style\c!color + \fi + \dostarttagged\t!sup\currenthigh + #2% + \dostoptagged + \egroup + \egroup + \ht\scratchbox\strutht + \dp\scratchbox\strutdp + \box\scratchbox + \endgroup} + +\permanent\protected\def\low {\typo_scripts_low []} +\permanent\protected\def\high{\typo_scripts_high[]} + +%D \macros +%D {lohi, hilo, definelohi, setuplohi} +%D +%D You can provide an optional keyword \type {left}, in which case the super and +%D subscripts will be aligned in a way that permits placement at the left of a word +%D (which means that it will be right aligned). +%D +%D \startbuffer +%D \lohi {aha} {ah} test \lohi {aha} {ah} test +%D \lohi [left] {aha} {ah} test \lohi [left] {aha} {ah} test +%D \lohi {aha} {ah} test \lohi {aha} {ah} test +%D \lohi [left] {aha} {ah}test \lohi [left] {aha} {ah} test +%D \stopbuffer +%D +%D \typebuffer +%D \getbuffer + +\installcorenamespace {lowhigh} + +\installcommandhandler \??lowhigh {lowhigh} \??lowhigh + +\setuplowhigh + [\c!style=\tx, + \c!distance=.1\exheight, % these are + \c!up=.96\exheight, % historical + \c!down=.58\exheight] % values + +\appendtoks + \frozen\setuevalue\currentlowhigh{\typo_scripts_lowhigh[\currentlowhigh]}% +\to \everydefinelowhigh + +\tolerant\protected\def\typo_scripts_lowhigh[#1]#*[#2]#:#3#4% todo: align .. [#1] is compatible hack + {\dontleavehmode + \runninghbox\bgroup + \edef\currentlowhigh{#1}% + \dostarttagged\t!subsup\currentlowhigh + \scratchdimen\lowhighparameter\c!distance\relax + \setbox\plusfour\hpack{\typo_scripts_lowhigh_low_high\lower\c!down\t!sub{#3}}% + \setbox\plussix \hpack{\typo_scripts_lowhigh_low_high\raise\c!up \t!sup{#4}}% + \edef\p_align{#2}% + \ifx\p_align\v!left + \ifdim\wd\plusfour<\wd\plussix + \setbox\plusfour\hpack to \wd\plussix {\hss\box\plusfour}% + \else + \setbox\plussix \hpack to \wd\plusfour{\hss\box\plussix }% + \fi + \fi + \ifdim\wd\plusfour<\wd\plussix + \wd\plusfour\zeropoint + \box\plusfour + \box\plussix + \else + \wd\plussix\zeropoint + \box\plussix + \box\plusfour + \fi + \dostoptagged + \egroup} + +\def\typo_scripts_lowhigh_low_high#1#2#3#4% + {\kern\scratchdimen + \setbox\scratchbox\hpack\bgroup + #1\lowhighparameter#2\hbox\bgroup + \ifx\fontsize\empty + \ifmmode + \mr % no color yet + \else + \uselowhighstyleandcolor\c!style\c!color + \fi + \else + \uselowhighstyleandcolor\c!style\c!color + \fi + \dostarttagged#3\empty + #4% + \dostoptagged + \egroup + \egroup + \ht\scratchbox\strutht + \dp\scratchbox\strutdp + \box\scratchbox} + +\permanent\tolerant\protected\def\typo_scripts_highlow_indeed[#1]#*[#2]#:#3#4% + {\typo_scripts_lowhigh_indeed[#1][#2]{#4}{#3}} + +\permanent\protected\def\lohi{\typo_scripts_lowhigh[]} +\permanent\protected\def\hilo{\typo_scripts_highlow[]} + +%D \macros +%D {lowmidhigh, definelowmidhigh, setuplowmidhigh} +%D +%D The previous command originally didn't have definers. These were introduced when +%D the next showed up: +%D +%D \startbuffer +%D \definelow [MyLow] [style=\txx] +%D \definehigh [MyHigh] [style=\txx] +%D \definelowhigh [MyLoHi] [style=\txx] +%D \definelowmidhigh[MyLoMiHi][style=\txx] +%D +%D We have +%D \ruledhbox{\low {L}} and \ruledhbox{\MyLow {L}} and +%D \ruledhbox{\high {H}} and \ruledhbox{\MyHigh {H}} and +%D \ruledhbox{\lohi {L}{H}} and \ruledhbox{\MyLoHi {L}{H}} and +%D \ruledhbox{\lomihi{L}{M}{H}} and \ruledhbox{\MyLoMiHi{L}{M}{H}}. +%D \stopbuffer +%D +%D \typebuffer \getbuffer + +\installcorenamespace {lowmidhigh} + +\installcommandhandler \??lowmidhigh {lowmidhigh} \??lowmidhigh + +\setuplowmidhigh + [\c!style=\tx, + \c!up=.8\struthtdp, + \c!down=.8\struthtdp] + +\appendtoks + \frozen\setuevalue\currentlowmidhigh{\typo_scripts_lowmidhigh[\currentlowmidhigh]}% +\to \everydefinelowmidhigh + +\protected\def\typo_scripts_lowmidhigh[#1]#2#3#4% + {\dontleavehmode + \runninghbox\bgroup + \edef\currentlowmidhigh{#1}% + \dostarttagged\t!subsup\currentlowmidhigh + \uselowmidhighstyleandcolor\c!style\c!color + \setstrut + \setbox\plustwo \hbox{\strut\dostarttagged\t!sub\empty#2\dostoptagged}% + \setbox\plusfour\hbox{\strut\dostarttagged\t!mid\empty#3\dostoptagged}% inefficient + \setbox\plussix \hbox{\strut\dostarttagged\t!sup\empty#4\dostoptagged}% + \scratchdimen \wd + \ifdim\wd\plustwo>\wd\plusfour + \ifdim\wd\plustwo>\wd\plussix + \plustwo + \else + \plussix + \fi + \else + \ifdim\wd\plusfour>\wd\plussix + \plusfour + \else + \plussix + \fi + \fi + \relax + \setbox\plustwo \hpack to \scratchdimen{\hss\lower\lowmidhighparameter\c!down\box\plustwo \hss}% + \setbox\plusfour\hpack to \scratchdimen{\hss \box\plusfour\hss}% + \setbox\plussix \hpack to \scratchdimen{\hss\raise\lowmidhighparameter\c!up \box\plussix \hss}% + \wd\plustwo \zeropoint + \wd\plusfour\zeropoint + \box\plusfour + \box\plustwo + \box\plussix + \dostoptagged + \egroup} + +\permanent\protected\def\lomihi {\typo_scripts_lowmidhigh[]} +\permanent\protected\def\himilo#1#2#3{\typo_scripts_lowmidhigh[]{#3}{#2}{#1}} + +\protect \endinput diff --git a/tex/context/modules/common/s-abbreviations-logos.tex b/tex/context/modules/common/s-abbreviations-logos.tex index 63677bc85..dfac57f0a 100644 --- a/tex/context/modules/common/s-abbreviations-logos.tex +++ b/tex/context/modules/common/s-abbreviations-logos.tex @@ -11,6 +11,8 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. +% avoid two character abbreviations + \startmodule[abbreviations-logos] \logo [MKI] {MkI} % joke @@ -369,6 +371,6 @@ \logo [KB] {KB} \logo [MB] {MB} \logo [GB] {GB} -\logo [TB] {TB} +% \logo [TB] {TB} \stopmodule diff --git a/tex/context/modules/mkiv/s-system-macros.mkxl b/tex/context/modules/mkiv/s-system-macros.mkxl index 48b0f5ed3..da0b4c2df 100644 --- a/tex/context/modules/mkiv/s-system-macros.mkxl +++ b/tex/context/modules/mkiv/s-system-macros.mkxl @@ -81,14 +81,16 @@ end) require("mtx-interface") - local data = scripts.interface.editor("data") + local data = scripts.interface.editor("data") local files = data and data.common and data.common.filenames or { } - local t = tex.hashtokens() - table.sort(t) + local okay = 0 + local list = tex.hashtokens() + table.sort(list) local function show(check) - context.starttabulate { "|l|l|l|lj2|l|l|l|l|l|l|l|l|" } - for i=1,#t do - local k = t[i] + -- context.starttabulate { "|l|l|l|lj2|l|l|l|l|l|l|l|l|" } + context.starttabulate { "|l|l|l|lj2|l|l|l|l|l|l|l|" } + for i=1,#list do + local k = list[i] if check(k) then local v = create(k) local frozen = v.frozen and "frozen" @@ -96,7 +98,7 @@ local immutable = v.immutable and "immutable" local primitive = v.primitive and "primitive" local mutable = v.mutable and "mutable" - local tolerant = v.tolerant and "tolerant" + -- local tolerant = v.tolerant and "tolerant" local noaligned = v.noaligned and "noaligned" local instance = v.instance and "instance" local parameters = v.parameters or 0 @@ -109,7 +111,7 @@ ctx_NC() if primitive then ctx_bold(csname) else context(csname) end ctx_NC() if parameters > 0 then context(parameters) end ctx_NC() context(cscommand) - ctx_NC() if tolerant then context(tolerant) end + -- ctx_NC() if tolerant then context(tolerant) end ctx_NC() if primitive then context(primitive) end ctx_NC() if permanent then context(permanent) end ctx_NC() if frozen then context(frozen) end diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 0ade30aed..ee65fb152 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 : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 2020-11-05 22:57 +-- merge date : 2020-11-06 20:23 do -- begin closure to overcome local limits and interference -- cgit v1.2.3