summaryrefslogtreecommitdiff
path: root/tex/context/base
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2020-11-03 18:03:10 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2020-11-03 18:03:10 +0100
commit10148cf24f5cdb6a67c8ba46ff62cea67affc44c (patch)
treefc1d1d1f9beb6f96cfa740a4ede46e14538aa98d /tex/context/base
parent7043cd3b7046f6a11112a5d49c4ae5e2dc0c6896 (diff)
downloadcontext-10148cf24f5cdb6a67c8ba46ff62cea67affc44c.tar.gz
2020-11-03 16:53:00
Diffstat (limited to 'tex/context/base')
-rw-r--r--tex/context/base/mkii/cont-new.mkii2
-rw-r--r--tex/context/base/mkii/context.mkii2
-rw-r--r--tex/context/base/mkii/mult-nl.mkii5
-rw-r--r--tex/context/base/mkiv/anch-pos.lmt1633
-rw-r--r--tex/context/base/mkiv/anch-pos.mkxl504
-rw-r--r--tex/context/base/mkiv/anch-tab.mkxl375
-rw-r--r--tex/context/base/mkiv/char-utf.mkxl44
-rw-r--r--tex/context/base/mkiv/chem-str.mkxl6
-rw-r--r--tex/context/base/mkiv/colo-ext.mkxl99
-rw-r--r--tex/context/base/mkiv/colo-grp.mkiv4
-rw-r--r--tex/context/base/mkiv/colo-grp.mkxl163
-rw-r--r--tex/context/base/mkiv/cont-new.mkiv2
-rw-r--r--tex/context/base/mkiv/context.mkiv3
-rw-r--r--tex/context/base/mkiv/context.mkxl121
-rw-r--r--tex/context/base/mkiv/core-env.mkxl12
-rw-r--r--tex/context/base/mkiv/enco-ini.mkiv2
-rw-r--r--tex/context/base/mkiv/enco-ini.mkxl10
-rw-r--r--tex/context/base/mkiv/font-aux.mklx26
-rw-r--r--tex/context/base/mkiv/font-chk.mkxl29
-rw-r--r--tex/context/base/mkiv/font-col.mklx148
-rw-r--r--tex/context/base/mkiv/font-fea.mklx2
-rw-r--r--tex/context/base/mkiv/font-ini.mklx6
-rw-r--r--tex/context/base/mkiv/grph-inc.mkiv26
-rw-r--r--tex/context/base/mkiv/grph-inc.mkxl1076
-rw-r--r--tex/context/base/mkiv/grph-pat.mkxl8
-rw-r--r--tex/context/base/mkiv/l-package.lua24
-rw-r--r--tex/context/base/mkiv/lang-imp-serbian.lua38
-rw-r--r--tex/context/base/mkiv/lang-mis.mkxl2
-rw-r--r--tex/context/base/mkiv/lang-rep.lua2
-rw-r--r--tex/context/base/mkiv/lang-tra.lua123
-rw-r--r--tex/context/base/mkiv/lang-tra.mkiv98
-rw-r--r--tex/context/base/mkiv/lxml-ini.mkxl4
-rw-r--r--tex/context/base/mkiv/math-ali.mkxl14
-rw-r--r--tex/context/base/mkiv/math-frc.mkxl34
-rw-r--r--tex/context/base/mkiv/pack-box.mkxl12
-rw-r--r--tex/context/base/mkiv/pack-com.mkxl10
-rw-r--r--tex/context/base/mkiv/pack-mrl.mkxl10
-rw-r--r--tex/context/base/mkiv/page-bck.mkxl12
-rw-r--r--tex/context/base/mkiv/page-ini.mkxl8
-rw-r--r--tex/context/base/mkiv/page-lay.mkxl26
-rw-r--r--tex/context/base/mkiv/page-spr.mkxl4
-rw-r--r--tex/context/base/mkiv/regi-ini.mkxl37
-rw-r--r--tex/context/base/mkiv/spac-hor.mkxl8
-rw-r--r--tex/context/base/mkiv/status-files.pdfbin28808 -> 29127 bytes
-rw-r--r--tex/context/base/mkiv/status-lua.pdfbin244626 -> 267806 bytes
-rw-r--r--tex/context/base/mkiv/strc-con.mklx34
-rw-r--r--tex/context/base/mkiv/strc-des.mklx2
-rw-r--r--tex/context/base/mkiv/strc-enu.mklx12
-rw-r--r--tex/context/base/mkiv/strc-ini.mklx81
-rw-r--r--tex/context/base/mkiv/strc-itm.mklx6
-rw-r--r--tex/context/base/mkiv/strc-lab.mkxl4
-rw-r--r--tex/context/base/mkiv/strc-mar.mkxl135
-rw-r--r--tex/context/base/mkiv/strc-not.mklx24
-rw-r--r--tex/context/base/mkiv/strc-num.mkxl675
-rw-r--r--tex/context/base/mkiv/strc-sbe.mkxl2
-rw-r--r--tex/context/base/mkiv/strc-sec.mkxl140
-rw-r--r--tex/context/base/mkiv/strc-syn.mkxl4
-rw-r--r--tex/context/base/mkiv/supp-ran.mkiv1
-rw-r--r--tex/context/base/mkiv/symb-ini.mkxl345
-rw-r--r--tex/context/base/mkiv/syst-aux.mkxl2
-rw-r--r--tex/context/base/mkiv/syst-fnt.mkxl47
-rw-r--r--tex/context/base/mkiv/tabl-frm.mkxl12
-rw-r--r--tex/context/base/mkiv/tabl-ltb.mkxl28
-rw-r--r--tex/context/base/mkiv/tabl-tab.mkxl3
-rw-r--r--tex/context/base/mkiv/tabl-xtb.mklx16
-rw-r--r--tex/context/base/mkiv/toks-ini.lmt110
-rw-r--r--tex/context/base/mkiv/toks-ini.mkxl20
-rw-r--r--tex/context/base/mkiv/toks-scn.mkxl26
-rw-r--r--tex/context/base/mkiv/unic-ini.mkiv2
69 files changed, 6100 insertions, 405 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii
index 10383d3a2..d6a945518 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.10.30 22:24}
+\newcontextversion{2020.11.03 16:50}
%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 d1f827650..7646f3f3e 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.10.30 22:24}
+\edef\contextversion{2020.11.03 16:50}
%D For those who want to use this:
diff --git a/tex/context/base/mkii/mult-nl.mkii b/tex/context/base/mkii/mult-nl.mkii
index 287f47814..1247c7b4b 100644
--- a/tex/context/base/mkii/mult-nl.mkii
+++ b/tex/context/base/mkii/mult-nl.mkii
@@ -283,6 +283,7 @@
\setinterfacevariable{intermezzo}{intermezzo}
\setinterfacevariable{intext}{intekst}
\setinterfacevariable{intro}{intro}
+\setinterfacevariable{invertedshort}{invertedshort}
\setinterfacevariable{italic}{italic}
\setinterfacevariable{italicbold}{italicvet}
\setinterfacevariable{item}{som}
@@ -386,6 +387,7 @@
\setinterfacevariable{nonumber}{geennummer}
\setinterfacevariable{norepeat}{norepeat}
\setinterfacevariable{normal}{normaal}
+\setinterfacevariable{normalshort}{normalshort}
\setinterfacevariable{nospacing}{geenspatiering}
\setinterfacevariable{nostopper}{geenafsluiter}
\setinterfacevariable{not}{niet}
@@ -453,6 +455,7 @@
\setinterfacevariable{rectangular}{recht}
\setinterfacevariable{reference}{referentie}
\setinterfacevariable{referral}{kenmerk}
+\setinterfacevariable{region}{gebied}
\setinterfacevariable{register}{register}
\setinterfacevariable{regular}{regular}
\setinterfacevariable{relative}{relatief}
@@ -1805,7 +1808,7 @@
\setinterfacecommand{resetpath}{resetpath}
\setinterfacecommand{resetperiodkerning}{resetperiodkerning}
\setinterfacecommand{resetsystemmode}{resetsystemmode}
-\setinterfacecommand{resettext}{resettekstinhoud}
+\setinterfacecommand{resettextcontent}{resettekstinhoud}
\setinterfacecommand{resetvisualizers}{resetvisualizers}
\setinterfacecommand{restoreglobalbodyfont}{restoreglobalbodyfont}
\setinterfacecommand{retestfeature}{retestfeature}
diff --git a/tex/context/base/mkiv/anch-pos.lmt b/tex/context/base/mkiv/anch-pos.lmt
new file mode 100644
index 000000000..e1d9bd752
--- /dev/null
+++ b/tex/context/base/mkiv/anch-pos.lmt
@@ -0,0 +1,1633 @@
+if not modules then modules = { } end modules ['anch-pos'] = {
+ version = 1.001,
+ comment = "companion to anch-pos.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+--[[ldx--
+<p>We save positional information in the main utility table. Not only
+can we store much more information in <l n='lua'/> but it's also
+more efficient.</p>
+--ldx]]--
+
+-- plus (extra) is obsolete but we will keep it for a while
+--
+-- maybe replace texsp by our own converter (stay at the lua end)
+-- eventually mp will have large numbers so we can use sp there too
+--
+-- this is one of the first modules using scanners and we need to replace it by
+-- implement and friends
+--
+-- we could have namespaces, like p, page, region, columnarea, textarea but then
+-- we need virtual table accessors as well as have tag/id accessors ... we don't
+-- save much here (at least not now)
+--
+-- This was the last module that got rid of directly setting scanners, with a little
+-- performance degradation but not that noticeable.
+
+local tostring, next, setmetatable, tonumber = tostring, next, setmetatable, tonumber
+local sort = table.sort
+local format, gmatch = string.format, string.gmatch
+local lpegmatch = lpeg.match
+local insert, remove = table.insert, table.remove
+local allocate = utilities.storage.allocate
+
+local report = logs.reporter("positions")
+
+local scanners = tokens.scanners
+local scanstring = scanners.string
+local scaninteger = scanners.integer
+local scandimen = scanners.dimen
+
+local implement = interfaces.implement
+
+local commands = commands
+local context = context
+
+local ctx_latelua = context.latelua
+
+local tex = tex
+local texgetcount = tex.getcount
+local texgetinteger = tex.getintegervalue or tex.getcount
+local texsetcount = tex.setcount
+local texget = tex.get
+local texsp = tex.sp
+----- texsp = string.todimen -- because we cache this is much faster but no rounding
+
+local setmetatableindex = table.setmetatableindex
+local setmetatablenewindex = table.setmetatablenewindex
+
+local nuts = nodes.nuts
+
+local setlink = nuts.setlink
+local getlist = nuts.getlist
+local setlist = nuts.setlist
+local getbox = nuts.getbox
+local getid = nuts.getid
+local getwhd = nuts.getwhd
+
+local hlist_code = nodes.nodecodes.hlist
+
+local find_tail = nuts.tail
+----- hpack = nuts.hpack
+
+local new_latelua = nuts.pool.latelua
+
+local variables = interfaces.variables
+local v_text = variables.text
+local v_column = variables.column
+
+local pt = number.dimenfactors.pt
+local pts = number.pts
+local formatters = string.formatters
+
+local collected = allocate()
+local tobesaved = allocate()
+
+local jobpositions = {
+ collected = collected,
+ tobesaved = tobesaved,
+}
+
+job.positions = jobpositions
+
+local default = { -- not r and paragraphs etc
+ __index = {
+ x = 0, -- x position baseline
+ y = 0, -- y position baseline
+ w = 0, -- width
+ h = 0, -- height
+ d = 0, -- depth
+ p = 0, -- page
+ n = 0, -- paragraph
+ ls = 0, -- leftskip
+ rs = 0, -- rightskip
+ hi = 0, -- hangindent
+ ha = 0, -- hangafter
+ hs = 0, -- hsize
+ pi = 0, -- parindent
+ ps = false, -- parshape
+ dir = 0,
+ }
+}
+
+local f_b_tag = formatters["b:%s"]
+local f_e_tag = formatters["e:%s"]
+local f_p_tag = formatters["p:%s"]
+local f_w_tag = formatters["w:%s"]
+
+local f_region = formatters["region:%s"]
+
+local f_tag_three = formatters["%s:%s:%s"]
+local f_tag_two = formatters["%s:%s"]
+
+local nofregular = 0
+local nofspecial = 0
+local splitter = lpeg.splitat(":",true)
+
+local pagedata = { }
+local columndata = setmetatableindex("table") -- per page
+local freedata = setmetatableindex("table") -- per page
+
+local function initializer()
+ tobesaved = jobpositions.tobesaved
+ collected = jobpositions.collected
+ for tag, data in next, collected do
+ local prefix, rest = lpegmatch(splitter,tag)
+ if prefix == "p" then
+ nofregular = nofregular + 1
+ elseif prefix == "page" then
+ nofregular = nofregular + 1
+ pagedata[tonumber(rest) or 0] = data
+ elseif prefix == "free" then
+ nofspecial = nofspecial + 1
+ local t = freedata[data.p or 0]
+ t[#t+1] = data
+ elseif prefix == "columnarea" then
+ columndata[data.p or 0][data.c or 0] = data
+ end
+ setmetatable(data,default)
+ end
+ --
+ local pages = structures.pages.collected
+ if pages then
+ local last = nil
+ for p=1,#pages do
+ local region = "page:" .. p
+ local data = pagedata[p]
+ local free = freedata[p]
+ if free then
+ sort(free,function(a,b) return b.y < a.y end) -- order matters !
+ end
+ if data then
+ last = data
+ last.free = free
+ elseif last then
+ local t = setmetatableindex({ free = free, p = p },last)
+ if not collected[region] then
+ collected[region] = t
+ else
+ -- something is wrong
+ end
+ pagedata[p] = t
+ end
+ end
+ end
+ jobpositions.pagedata = pagedata
+end
+
+function jobpositions.used()
+ return next(collected) -- we can safe it
+end
+
+function jobpositions.getfree(page)
+ return freedata[page]
+end
+
+-- we can gain a little when we group positions but then we still have to
+-- deal with regions and cells so we either end up with lots of extra small
+-- tables pointing to them and/or assembling/disassembling so in the end
+-- it makes no sense to do it (now) and still have such a mix
+--
+-- proof of concept code removed ... see archive
+
+local function finalizer()
+ -- We make the (possible extensive) shape lists sparse working
+ -- from the end. We could also drop entries here that have l and
+ -- r the same which saves testing later on.
+ for k, v in next, tobesaved do
+ local s = v.s
+ if s then
+ for p, data in next, s do
+ local n = #data
+ if n > 1 then
+ local ph = data[1][2]
+ local pd = data[1][3]
+ local xl = data[1][4]
+ local xr = data[1][5]
+ for i=2,n do
+ local di = data[i]
+ local h = di[2]
+ local d = di[3]
+ local l = di[4]
+ local r = di[5]
+ if r == xr then
+ di[5] = nil
+ if l == xl then
+ di[4] = nil
+ if d == pd then
+ di[3] = nil
+ if h == ph then
+ di[2] = nil
+ else
+ ph = h
+ end
+ else
+ pd, ph = d, h
+ end
+ else
+ ph, pd, xl = h, d, l
+ end
+ else
+ ph, pd, xl, xr = h, d, l, r
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+job.register('job.positions.collected', tobesaved, initializer, finalizer)
+
+local regions = { }
+local nofregions = 0
+local region = nil
+
+local columns = { }
+local nofcolumns = 0
+local column = nil
+
+local nofpages = nil
+
+-- beware ... we're not sparse here as lua will reserve slots for the nilled
+
+local getpos, gethpos, getvpos
+
+function jobpositions.registerhandlers(t)
+ getpos = t and t.getpos or function() return 0, 0 end
+ getrpos = t and t.getrpos or function() return 0, 0, 0 end
+ gethpos = t and t.gethpos or function() return 0 end
+ getvpos = t and t.getvpos or function() return 0 end
+end
+
+function jobpositions.getpos () return getpos () end
+function jobpositions.getrpos() return getrpos() end
+function jobpositions.gethpos() return gethpos() end
+function jobpositions.getvpos() return getvpos() end
+
+-------- jobpositions.getcolumn() return column end
+
+jobpositions.registerhandlers()
+
+local function setall(name,p,x,y,w,h,d,extra)
+ tobesaved[name] = {
+ p = p,
+ x = x ~= 0 and x or nil,
+ y = y ~= 0 and y or nil,
+ w = w ~= 0 and w or nil,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ e = extra ~= "" and extra or nil,
+ r = region,
+ c = column,
+ r2l = texgetinteger("inlinelefttoright") == 1 and true or nil,
+ }
+end
+
+local function enhance(data)
+ if not data then
+ return nil
+ end
+ if data.r == true then -- or ""
+ data.r = region
+ end
+ if data.x == true then
+ if data.y == true then
+ local x, y = getpos()
+ data.x = x ~= 0 and x or nil
+ data.y = y ~= 0 and y or nil
+ else
+ local x = gethpos()
+ data.x = x ~= 0 and x or nil
+ end
+ elseif data.y == true then
+ local y = getvpos()
+ data.y = y ~= 0 and y or nil
+ end
+ if data.p == true then
+ data.p = texgetcount("realpageno") -- we should use a variable set in otr
+ end
+ if data.c == true then
+ data.c = column
+ end
+ if data.w == 0 then
+ data.w = nil
+ end
+ if data.h == 0 then
+ data.h = nil
+ end
+ if data.d == 0 then
+ data.d = nil
+ end
+ return data
+end
+
+-- analyze some files (with lots if margindata) and then when one key optionally
+-- use that one instead of a table (so, a 3rd / 4th argument: key, e.g. "x")
+
+local function set(name,index,value) -- ,key
+ -- officially there should have been a settobesaved
+ local data = enhance(value or {})
+ if value then
+ container = tobesaved[name]
+ if not container then
+ tobesaved[name] = {
+ [index] = data
+ }
+ else
+ container[index] = data
+ end
+ else
+ tobesaved[name] = data
+ end
+end
+
+local function setspec(specification)
+ local name = specification.name
+ local index = specification.index
+ local value = specification.value
+ local data = enhance(value or {})
+ if value then
+ container = tobesaved[name]
+ if not container then
+ tobesaved[name] = {
+ [index] = data
+ }
+ else
+ container[index] = data
+ end
+ else
+ tobesaved[name] = data
+ end
+end
+
+local function get(id,index)
+ if index then
+ local container = collected[id]
+ return container and container[index]
+ else
+ return collected[id]
+ end
+end
+
+------------.setdim = setdim
+jobpositions.setall = setall
+jobpositions.set = set
+jobpositions.setspec = setspec
+jobpositions.get = get
+
+implement {
+ name = "dosaveposition",
+ public = true,
+ protected = true,
+ arguments = { "argument", "integerargument", "dimenargument", "dimenargument" },
+ actions = setall, -- name p x y
+}
+
+implement {
+ name = "dosavepositionwhd",
+ public = true,
+ protected = true,
+ arguments = { "argument", "integerargument", "dimenargument", "dimenargument", "dimenargument", "dimenargument", "dimenargument" },
+ actions = setall, -- name p x y w h d
+}
+
+implement {
+ name = "dosavepositionplus",
+ public = true,
+ protected = true,
+ arguments = { "argument", "integerargument", "dimenargument", "dimenargument", "dimenargument", "dimenargument", "dimenargument", "argument" },
+ actions = setall, -- name p x y w h d extra
+}
+
+-- will become private table (could also become attribute driven but too nasty
+-- as attributes can bleed e.g. in margin stuff)
+
+-- not much gain in keeping stack (inc/dec instead of insert/remove)
+
+local function b_column(specification)
+ local tag = specification.tag
+ local x = gethpos()
+ tobesaved[tag] = {
+ r = true,
+ x = x ~= 0 and x or nil,
+ -- w = 0,
+ }
+ insert(columns,tag)
+ column = tag
+end
+
+local function e_column()
+ local t = tobesaved[column]
+ if not t then
+ -- something's wrong
+ else
+ local x = gethpos() - t.x
+ t.w = x ~= 0 and x or nil
+ t.r = region
+ end
+ remove(columns)
+ column = columns[#columns]
+end
+
+jobpositions.b_column = b_column
+jobpositions.e_column = e_column
+
+implement {
+ name = "bposcolumn",
+ arguments = "string",
+ actions = function(tag)
+ insert(columns,tag)
+ column = tag
+ end
+}
+
+implement {
+ name = "bposcolumnregistered",
+ arguments = "string",
+ actions = function(tag)
+ insert(columns,tag)
+ column = tag
+ ctx_latelua { action = b_column, tag = tag }
+ end
+}
+
+implement {
+ name = "eposcolumn",
+ actions = function()
+ remove(columns)
+ column = columns[#columns]
+ end
+}
+
+implement {
+ name = "eposcolumnregistered",
+ actions = function()
+ ctx_latelua { action = e_column }
+ remove(columns)
+ column = columns[#columns]
+ end
+}
+
+-- regions
+
+local function b_region(specification)
+ local tag = specification.tag or specification
+ local last = tobesaved[tag]
+ local x, y = getpos()
+ last.x = x ~= 0 and x or nil
+ last.y = y ~= 0 and y or nil
+ last.p = texgetcount("realpageno")
+ insert(regions,tag) -- todo: fast stack
+ region = tag
+end
+
+local function e_region(specification)
+ local last = tobesaved[region]
+ local y = getvpos()
+ local x, y = getpos()
+ if specification.correct then
+ local h = (last.y or 0) - y
+ last.h = h ~= 0 and h or nil
+ end
+ last.y = y ~= 0 and y or nil
+ remove(regions) -- todo: fast stack
+ region = regions[#regions]
+end
+
+jobpositions.b_region = b_region
+jobpositions.e_region = e_region
+
+local lastregion
+
+local function setregionbox(n,tag,k,lo,ro,to,bo,column) -- kind
+ if not tag or tag == "" then
+ nofregions = nofregions + 1
+ tag = f_region(nofregions)
+ end
+ local box = getbox(n)
+ local w, h, d = getwhd(box)
+ tobesaved[tag] = {
+ -- p = texgetcount("realpageno"), -- we copy them
+ x = 0,
+ y = 0,
+ w = w ~= 0 and w or nil,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ k = k ~= 0 and k or nil,
+ lo = lo ~= 0 and lo or nil,
+ ro = ro ~= 0 and ro or nil,
+ to = to ~= 0 and to or nil,
+ bo = bo ~= 0 and bo or nil,
+ c = column or nil,
+ }
+ lastregion = tag
+ return tag, box
+end
+
+local function markregionbox(n,tag,correct,...) -- correct needs checking
+ local tag, box = setregionbox(n,tag,...)
+ -- todo: check if tostring is needed with formatter
+ local push = new_latelua { action = b_region, tag = tag }
+ local pop = new_latelua { action = e_region, correct = correct }
+ -- maybe we should construct a hbox first (needs experimenting) so that we can avoid some at the tex end
+ local head = getlist(box)
+ -- no, this fails with \framed[region=...] .. needs thinking
+ -- if getid(box) ~= hlist_code then
+ -- -- report("mark region box assumes a hlist, fix this for %a",tag)
+ -- head = hpack(head)
+ -- end
+ if head then
+ local tail = find_tail(head)
+ setlink(push,head)
+ setlink(tail,pop)
+ else -- we can have a simple push/pop
+ setlink(push,pop)
+ end
+ setlist(box,push)
+end
+
+jobpositions.markregionbox = markregionbox
+jobpositions.setregionbox = setregionbox
+
+function jobpositions.enhance(name)
+ enhance(tobesaved[name])
+end
+
+function jobpositions.gettobesaved(name,tag)
+ local t = tobesaved[name]
+ if t and tag then
+ return t[tag]
+ else
+ return t
+ end
+end
+
+function jobpositions.settobesaved(name,tag,data)
+ local t = tobesaved[name]
+ if t and tag and data then
+ t[tag] = data
+ end
+end
+
+local nofparagraphs = 0
+
+implement {
+ name = "parpos",
+ actions = function()
+ nofparagraphs = nofparagraphs + 1
+ texsetcount("global","c_anch_positions_paragraph",nofparagraphs)
+ local box = getbox("strutbox")
+ local w, h, d = getwhd(box)
+ local t = {
+ p = true,
+ c = true,
+ r = true,
+ x = true,
+ y = true,
+ h = h,
+ d = d,
+ hs = texget("hsize"), -- never 0
+ }
+ local leftskip = texget("leftskip",false)
+ local rightskip = texget("rightskip",false)
+ local hangindent = texget("hangindent")
+ local hangafter = texget("hangafter")
+ local parindent = texget("parindent")
+ local parshape = texget("parshape")
+ if leftskip ~= 0 then
+ t.ls = leftskip
+ end
+ if rightskip ~= 0 then
+ t.rs = rightskip
+ end
+ if hangindent ~= 0 then
+ t.hi = hangindent
+ end
+ if hangafter ~= 1 and hangafter ~= 0 then -- can not be zero .. so it needs to be 1 if zero
+ t.ha = hangafter
+ end
+ if parindent ~= 0 then
+ t.pi = parindent
+ end
+ if parshape and #parshape > 0 then
+ t.ps = parshape
+ end
+ local name = f_p_tag(nofparagraphs)
+ tobesaved[name] = t
+ ctx_latelua { action = enhance, specification = t }
+ end
+}
+
+implement {
+ name = "dosetposition",
+ arguments = "argument",
+ public = true,
+ protected = true,
+ actions = function(name)
+ local spec = {
+ p = true,
+ c = column,
+ r = true,
+ x = true,
+ y = true,
+ n = nofparagraphs > 0 and nofparagraphs or nil,
+ r2l = texgetinteger("inlinelefttoright") == 1 or nil,
+ }
+ tobesaved[name] = spec
+ ctx_latelua { action = enhance, specification = spec }
+ end
+}
+
+implement {
+ name = "dosetpositionwhd",
+ arguments = { "argument", "dimenargument", "dimenargument", "dimenargument" },
+ public = true,
+ protected = true,
+ actions = function(name,w,h,d)
+ local spec = {
+ p = true,
+ c = column,
+ r = true,
+ x = true,
+ y = true,
+ w = w ~= 0 and w or nil,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ n = nofparagraphs > 0 and nofparagraphs or nil,
+ r2l = texgetinteger("inlinelefttoright") == 1 or nil,
+ }
+ tobesaved[name] = spec
+ ctx_latelua { action = enhance, specification = spec }
+ end
+}
+
+implement {
+ name = "dosetpositionbox",
+ arguments = { "argument", "integerargument" },
+ public = true,
+ protected = true,
+ actions = function(name,n)
+ local box = getbox(n)
+ local w, h, d = getwhd(box)
+ local spec = {
+ p = true,
+ c = column,
+ r = true,
+ x = true,
+ y = true,
+ w = w ~= 0 and w or nil,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ n = nofparagraphs > 0 and nofparagraphs or nil,
+ r2l = texgetinteger("inlinelefttoright") == 1 or nil,
+ }
+ tobesaved[name] = spec
+ ctx_latelua { action = enhance, specification = spec }
+ end
+}
+
+implement {
+ name = "dosetpositionplus",
+ arguments = { "argument", "dimenargument", "dimenargument", "dimenargument" },
+ public = true,
+ protected = true,
+ actions = function(name,w,h,d)
+ local spec = {
+ p = true,
+ c = column,
+ r = true,
+ x = true,
+ y = true,
+ w = w ~= 0 and w or nil,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ n = nofparagraphs > 0 and nofparagraphs or nil,
+ e = scanstring(),
+ r2l = texgetinteger("inlinelefttoright") == 1 or nil,
+ }
+ tobesaved[name] = spec
+ ctx_latelua { action = enhance, specification = spec }
+ end
+}
+
+implement {
+ name = "dosetpositionstrut",
+ arguments = "argument",
+ public = true,
+ protected = true,
+ actions = function(name)
+ local box = getbox("strutbox")
+ local w, h, d = getwhd(box)
+ local spec = {
+ p = true,
+ c = column,
+ r = true,
+ x = true,
+ y = true,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ n = nofparagraphs > 0 and nofparagraphs or nil,
+ r2l = texgetinteger("inlinelefttoright") == 1 or nil,
+ }
+ tobesaved[name] = spec
+ ctx_latelua { action = enhance, specification = spec }
+ end
+}
+
+implement {
+ name = "dosetpositionstrutkind",
+ arguments = { "argument", "integerargument" },
+ public = true,
+ protected = true,
+ actions = function(name,kind)
+ local box = getbox("strutbox")
+ local w, h, d = getwhd(box)
+ local spec = {
+ k = kind,
+ p = true,
+ c = column,
+ r = true,
+ x = true,
+ y = true,
+ h = h ~= 0 and h or nil,
+ d = d ~= 0 and d or nil,
+ n = nofparagraphs > 0 and nofparagraphs or nil,
+ r2l = texgetinteger("inlinelefttoright") == 1 or nil,
+ }
+ tobesaved[name] = spec
+ ctx_latelua { action = enhance, specification = spec }
+ end
+}
+
+function jobpositions.getreserved(tag,n)
+ if tag == v_column then
+ local fulltag = f_tag_three(tag,texgetcount("realpageno"),n or 1)
+ local data = collected[fulltag]
+ if data then
+ return data, fulltag
+ end
+ tag = v_text
+ end
+ if tag == v_text then
+ local fulltag = f_tag_two(tag,texgetcount("realpageno"))
+ return collected[fulltag] or false, fulltag
+ end
+ return collected[tag] or false, tag
+end
+
+function jobpositions.copy(target,source)
+ collected[target] = collected[source]
+end
+
+function jobpositions.replace(id,p,x,y,w,h,d)
+ collected[id] = { p = p, x = x, y = y, w = w, h = h, d = d } -- c g
+end
+
+local function getpage(id)
+ local jpi = collected[id]
+ return jpi and jpi.p
+end
+
+local function getcolumn(id)
+ local jpi = collected[id]
+ return jpi and jpi.c or false
+end
+
+local function getparagraph(id)
+ local jpi = collected[id]
+ return jpi and jpi.n
+end
+
+local function getregion(id)
+ local jpi = collected[id]
+ if jpi then
+ local r = jpi.r
+ if r then
+ return r
+ end
+ local p = jpi.p
+ if p then
+ return "page:" .. p
+ end
+ end
+ return false
+end
+
+jobpositions.page = getpage
+jobpositions.column = getcolumn
+jobpositions.paragraph = getparagraph
+jobpositions.region = getregion
+
+jobpositions.p = getpage -- not used, kind of obsolete
+jobpositions.c = getcolumn -- idem
+jobpositions.n = getparagraph -- idem
+jobpositions.r = getregion -- idem
+
+function jobpositions.x(id)
+ local jpi = collected[id]
+ return jpi and jpi.x
+end
+
+function jobpositions.y(id)
+ local jpi = collected[id]
+ return jpi and jpi.y
+end
+
+function jobpositions.width(id)
+ local jpi = collected[id]
+ return jpi and jpi.w
+end
+
+function jobpositions.height(id)
+ local jpi = collected[id]
+ return jpi and jpi.h
+end
+
+function jobpositions.depth(id)
+ local jpi = collected[id]
+ return jpi and jpi.d
+end
+
+function jobpositions.whd(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.h, jpi.h, jpi.d
+ end
+end
+
+function jobpositions.leftskip(id)
+ local jpi = collected[id]
+ return jpi and jpi.ls
+end
+
+function jobpositions.rightskip(id)
+ local jpi = collected[id]
+ return jpi and jpi.rs
+end
+
+function jobpositions.hsize(id)
+ local jpi = collected[id]
+ return jpi and jpi.hs
+end
+
+function jobpositions.parindent(id)
+ local jpi = collected[id]
+ return jpi and jpi.pi
+end
+
+function jobpositions.hangindent(id)
+ local jpi = collected[id]
+ return jpi and jpi.hi
+end
+
+function jobpositions.hangafter(id)
+ local jpi = collected[id]
+ return jpi and jpi.ha or 1
+end
+
+function jobpositions.xy(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.x, jpi.y
+ else
+ return 0, 0
+ end
+end
+
+function jobpositions.lowerleft(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.x, jpi.y - jpi.d
+ else
+ return 0, 0
+ end
+end
+
+function jobpositions.lowerright(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.x + jpi.w, jpi.y - jpi.d
+ else
+ return 0, 0
+ end
+end
+
+function jobpositions.upperright(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.x + jpi.w, jpi.y + jpi.h
+ else
+ return 0, 0
+ end
+end
+
+function jobpositions.upperleft(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.x, jpi.y + jpi.h
+ else
+ return 0, 0
+ end
+end
+
+function jobpositions.position(id)
+ local jpi = collected[id]
+ if jpi then
+ return jpi.p, jpi.x, jpi.y, jpi.w, jpi.h, jpi.d
+ else
+ return 0, 0, 0, 0, 0, 0
+ end
+end
+
+local splitter = lpeg.splitat(",")
+
+function jobpositions.extra(id,n,default) -- assume numbers
+ local jpi = collected[id]
+ if jpi then
+ local e = jpi.e
+ if e then
+ local split = jpi.split
+ if not split then
+ split = lpegmatch(splitter,jpi.e)
+ jpi.split = split
+ end
+ return texsp(split[n]) or default -- watch the texsp here
+ end
+ end
+ return default
+end
+
+local function overlapping(one,two,overlappingmargin) -- hm, strings so this is wrong .. texsp
+ one = collected[one]
+ two = collected[two]
+ if one and two and one.p == two.p then
+ if not overlappingmargin then
+ overlappingmargin = 2
+ end
+ local x_one = one.x
+ local x_two = two.x
+ local w_two = two.w
+ local llx_one = x_one - overlappingmargin
+ local urx_two = x_two + w_two + overlappingmargin
+ if llx_one > urx_two then
+ return false
+ end
+ local w_one = one.w
+ local urx_one = x_one + w_one + overlappingmargin
+ local llx_two = x_two - overlappingmargin
+ if urx_one < llx_two then
+ return false
+ end
+ local y_one = one.y
+ local y_two = two.y
+ local d_one = one.d
+ local h_two = two.h
+ local lly_one = y_one - d_one - overlappingmargin
+ local ury_two = y_two + h_two + overlappingmargin
+ if lly_one > ury_two then
+ return false
+ end
+ local h_one = one.h
+ local d_two = two.d
+ local ury_one = y_one + h_one + overlappingmargin
+ local lly_two = y_two - d_two - overlappingmargin
+ if ury_one < lly_two then
+ return false
+ end
+ return true
+ end
+end
+
+local function onsamepage(list,page)
+ for id in gmatch(list,"(, )") do
+ local jpi = collected[id]
+ if jpi then
+ local p = jpi.p
+ if not p then
+ return false
+ elseif not page then
+ page = p
+ elseif page ~= p then
+ return false
+ end
+ end
+ end
+ return page
+end
+
+local function columnofpos(realpage,xposition)
+ local p = columndata[realpage]
+ if p then
+ for i=1,#p do
+ local c = p[i]
+ local x = c.x or 0
+ local w = c.w or 0
+ if xposition >= x and xposition <= (x + w) then
+ return i
+ end
+ end
+ end
+ return 1
+end
+
+jobpositions.overlapping = overlapping
+jobpositions.onsamepage = onsamepage
+jobpositions.columnofpos = columnofpos
+
+-- interface
+
+implement {
+ name = "replacepospxywhd",
+ arguments = { "argument", "integerargument", "dimenargument", "dimenargument", "dimenargument", "dimenargument", "dimenargument" },
+ public = true,
+ protected = true,
+ actions = function(name,page,x,y,w,h,d)
+ collected[name] = {
+ p = page,
+ x = x,
+ y = y,
+ w = w,
+ h = h,
+ d = d,
+ }
+ end
+}
+
+implement {
+ name = "copyposition",
+ arguments = "2 arguments",
+ public = true,
+ protected = true,
+ actions = function(target,source)
+ collected[target] = collected[source]
+ end
+}
+
+implement {
+ name = "MPp",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local p = jpi.p
+ if p and p ~= true then
+ context(p)
+ return
+ end
+ end
+ context('0')
+ end
+}
+
+implement {
+ name = "MPx",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local x = jpi.x
+ if x and x ~= true and x ~= 0 then
+ context("%.5Fpt",x*pt)
+ return
+ end
+ end
+ context('0pt')
+ end
+}
+
+implement {
+ name = "MPy",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local y = jpi.y
+ if y and y ~= true and y ~= 0 then
+ context("%.5Fpt",y*pt)
+ return
+ end
+ end
+ context('0pt')
+ end
+}
+
+implement {
+ name = "MPw",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local w = jpi.w
+ if w and w ~= 0 then
+ context("%.5Fpt",w*pt)
+ return
+ end
+ end
+ context('0pt')
+ end
+}
+
+implement {
+ name = "MPh",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local h = jpi.h
+ if h and h ~= 0 then
+ context("%.5Fpt",h*pt)
+ return
+ end
+ end
+ context('0pt')
+ end
+}
+
+implement {
+ name = "MPd",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local d = jpi.d
+ if d and d ~= 0 then
+ context("%.5Fpt",d*pt)
+ return
+ end
+ end
+ context('0pt')
+ end
+}
+
+implement {
+ name = "MPxy",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context('(%.5Fpt,%.5Fpt)',
+ jpi.x*pt,
+ jpi.y*pt
+ )
+ else
+ context('(0,0)')
+ end
+ end
+}
+
+implement {
+ name = "MPwhd",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local w = jpi.w or 0
+ local h = jpi.h or 0
+ local d = jpi.d or 0
+ if w ~= 0 or h ~= 0 or d ~= 0 then
+ context("%.5Fpt,%.5Fpt,%.5Fpt",w*pt,h*pt,d*pt)
+ return
+ end
+ end
+ context('0pt,0pt,0pt')
+ end
+}
+
+implement {
+ name = "MPll",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context('(%.5Fpt,%.5Fpt)',
+ jpi.x *pt,
+ (jpi.y-jpi.d)*pt
+ )
+ else
+ context('(0,0)') -- for mp only
+ end
+ end
+}
+
+implement {
+ name = "MPlr",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context('(%.5Fpt,%.5Fpt)',
+ (jpi.x + jpi.w)*pt,
+ (jpi.y - jpi.d)*pt
+ )
+ else
+ context('(0,0)') -- for mp only
+ end
+ end
+}
+
+implement {
+ name = "MPur",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context('(%.5Fpt,%.5Fpt)',
+ (jpi.x + jpi.w)*pt,
+ (jpi.y + jpi.h)*pt
+ )
+ else
+ context('(0,0)') -- for mp only
+ end
+ end
+}
+
+implement {
+ name = "MPul",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context('(%.5Fpt,%.5Fpt)',
+ jpi.x *pt,
+ (jpi.y + jpi.h)*pt
+ )
+ else
+ context('(0,0)') -- for mp only
+ end
+ end
+}
+
+local function MPpos(id)
+ local jpi = collected[id]
+ if jpi then
+ local p = jpi.p
+ if p then
+ context("%s,%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt",
+ p,
+ jpi.x*pt,
+ jpi.y*pt,
+ jpi.w*pt,
+ jpi.h*pt,
+ jpi.d*pt
+ )
+ return
+ end
+ end
+ context('0,0,0,0,0,0') -- for mp only
+end
+
+implement {
+ name = "MPpos",
+ arguments = "argument",
+ public = true,
+ actions = MPpos
+}
+
+implement {
+ name = "MPn",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local n = jpi.n
+ if n then
+ context(n)
+ return
+ end
+ end
+ context(0)
+ end
+}
+
+implement {
+ name = "MPc",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local c = jpi.c
+ if c and c ~= true then
+ context(c)
+ return
+ end
+ end
+ context('0') -- okay ?
+ end
+}
+
+implement {
+ name = "MPr",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ local r = jpi.r
+ if r and r ~= true then
+ context(r)
+ return
+ end
+ local p = jpi.p
+ if p and p ~= true then
+ context("page:" .. p)
+ end
+ end
+ end
+}
+
+local function MPpardata(id)
+ local t = collected[id]
+ if not t then
+ local tag = f_p_tag(id)
+ t = collected[tag]
+ end
+ if t then
+ context("%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt,%s,%.5Fpt",
+ t.hs*pt,
+ t.ls*pt,
+ t.rs*pt,
+ t.hi*pt,
+ t.ha,
+ t.pi*pt
+ )
+ else
+ context("0,0,0,0,0,0") -- for mp only
+ end
+end
+
+implement {
+ name = "MPpardata",
+ arguments = "argument",
+ public = true,
+ actions = MPpardata
+}
+
+implement {
+ name = "MPposset",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local b = f_b_tag(name)
+ local e = f_e_tag(name)
+ local w = f_w_tag(name)
+ local p = f_p_tag(getparagraph(b))
+ MPpos(b) context(",") MPpos(e) context(",") MPpos(w) context(",") MPpos(p) context(",") MPpardata(p)
+ end
+}
+
+implement {
+ name = "MPls",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context("%.5Fpt",jpi.ls*pt)
+ else
+ context("0pt")
+ end
+ end
+}
+
+implement {
+ name = "MPrs",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context("%.5Fpt",jpi.rs*pt)
+ else
+ context("0pt")
+ end
+ end
+}
+
+local splitter = lpeg.tsplitat(",")
+
+implement {
+ name = "MPplus",
+ arguments = { "argument", "integerargument", "argument" },
+ public = true,
+ actions = function(name,n,default)
+ local jpi = collected[name]
+ if jpi then
+ local e = jpi.e
+ if e then
+ local split = jpi.split
+ if not split then
+ split = lpegmatch(splitter,jpi.e)
+ jpi.split = split
+ end
+ context(split[n] or default)
+ return
+ end
+ end
+ context(default)
+ end
+}
+
+implement {
+ name = "MPrest",
+ arguments = { "argument", "argument" },
+ public = true,
+ actions = function(name,default)
+ local jpi = collected[name]
+ context(jpi and jpi.e or default)
+ end
+}
+
+implement {
+ name = "MPxywhd",
+ arguments = "argument",
+ public = true,
+ actions = function(name)
+ local jpi = collected[name]
+ if jpi then
+ context("%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt,%.5Fpt",
+ jpi.x*pt,
+ jpi.y*pt,
+ jpi.w*pt,
+ jpi.h*pt,
+ jpi.d*pt
+ )
+ else
+ context("0,0,0,0,0") -- for mp only
+ end
+ end
+}
+
+local doif = commands.doif
+local doifelse = commands.doifelse
+
+implement {
+ name = "doifelseposition",
+ arguments = "argument",
+ public = true,
+ protected = true,
+ actions = function(name)
+ doifelse(collected[name])
+ end
+}
+
+implement {
+ name = "doifposition",
+ arguments = "argument",
+ public = true,
+ protected = true,
+ actions = function(name)
+ doif(collected[name])
+ end
+}
+
+implement {
+ name = "doifelsepositiononpage",
+ arguments = { "string", "integerargument" },
+ public = true,
+ protected = true,
+ actions = function(name,p)
+ local c = collected[name]
+ doifelse(c and c.p == p)
+ end
+}
+
+implement {
+ name = "doifelseoverlapping",
+ arguments = { "argument", "argument" },
+ public = true,
+ protected = true,
+ actions = function(one,two)
+ doifelse(overlapping(one,two))
+ end
+}
+
+implement {
+ name = "doifelsepositionsonsamepage",
+ arguments = "argument", -- string
+ public = true,
+ protected = true,
+ actions = function(list)
+ doifelse(onsamepage(list))
+ end
+}
+
+implement {
+ name = "doifelsepositionsonthispage",
+ arguments = "argument", -- string
+ public = true,
+ protected = true,
+ actions = function(list)
+ doifelse(onsamepage(list,tostring(texgetcount("realpageno"))))
+ end
+}
+
+implement {
+ name = "doifelsepositionsused",
+ public = true,
+ protected = true,
+ actions = function()
+ doifelse(next(collected))
+ end
+}
+
+implement {
+ name = "markregionbox",
+ arguments = "integer",
+ actions = markregionbox
+}
+
+implement {
+ name = "setregionbox",
+ arguments = "integer",
+ actions = setregionbox
+}
+
+implement {
+ name = "markregionboxtagged",
+ arguments = { "integer", "string" },
+ actions = markregionbox
+}
+
+implement {
+ name = "markregionboxtaggedn",
+ arguments = { "integer", "string", "integer" },
+ actions = function(box,tag,n)
+ markregionbox(box,tag,nil,nil,nil,nil,nil,nil,n)
+ end
+}
+
+implement {
+ name = "setregionboxtagged",
+ arguments = { "integer", "string" },
+ actions = setregionbox
+}
+
+implement {
+ name = "markregionboxcorrected",
+ arguments = { "integer", "string", true },
+ actions = markregionbox
+}
+
+implement {
+ name = "markregionboxtaggedkind",
+ arguments = { "integer", "string", "integer", "dimen", "dimen", "dimen", "dimen" },
+ actions = function(box,tag,n,d1,d2,d3,d4)
+ markregionbox(box,tag,nil,n,d1,d2,d3,d4)
+ end
+}
+
+implement {
+ name = "reservedautoregiontag",
+ public = true,
+ actions = function()
+ nofregions = nofregions + 1
+ context(f_region(nofregions))
+ end
+}
+
+-- statistics (at least for the moment, when testing)
+
+-- statistics.register("positions", function()
+-- local total = nofregular + nofusedregions + nofmissingregions
+-- if total > 0 then
+-- return format("%s collected, %s regulars, %s regions, %s unresolved regions",
+-- total, nofregular, nofusedregions, nofmissingregions)
+-- else
+-- return nil
+-- end
+-- end)
+
+statistics.register("positions", function()
+ local total = nofregular + nofspecial
+ if total > 0 then
+ return format("%s collected, %s regular, %s special",total,nofregular,nofspecial)
+ else
+ return nil
+ end
+end)
+
+-- We support the low level positional commands too:
+
+local newsavepos = nodes.pool.savepos
+
+implement { name = "savepos", actions = function() context(newsavepos()) end }
+implement { name = "lastxpos", actions = function() context(gethpos()) end }
+implement { name = "lastypos", actions = function() context(getvpos()) end }
diff --git a/tex/context/base/mkiv/anch-pos.mkxl b/tex/context/base/mkiv/anch-pos.mkxl
new file mode 100644
index 000000000..e232d9cd3
--- /dev/null
+++ b/tex/context/base/mkiv/anch-pos.mkxl
@@ -0,0 +1,504 @@
+%D \module
+%D [ file=anch-pos, % was core-pos
+%D version=1999.08.01,
+%D title=\CONTEXT\ Anchoring Macros,
+%D subtitle=Positioning 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 Anchoring Macros / Positioning}
+
+%D In \MKIV\ there was already a different housekeeping model for positions quite
+%D early, but starting in 2012 more dramatic changes started to happen, especially
+%D in relation to background graphics. It will probably take some time to settle.
+
+\registerctxluafile{anch-pos}{autosuffix}
+
+\unprotect
+
+%D The first application of positional information was embedded graphics. Since we
+%D are interacting with text, it made sense to take the current line height and
+%D depth into account too. This is why we have position macros for simple positions
+%D and one boxes.
+%D
+%D \starttyping
+%D \dosetposition {identifier}
+%D \dosetpositionwhd {identifier} {width} {height} {depth}
+%D \dosetpositionplus {identifier} {width} {height} {depth} {list}
+%D \stoptyping
+
+% \dosaveposition #1#2#3#4 % defined at lua end
+% \dosavepositionwhd #1#2#3#4#5#6#7 % defined at lua end
+% \dosavepositionplus #1#2#3#4#5#6#7#8 % defined at lua end
+
+% \dosetposition #1 % defined at lua end
+% \dosetpositionwhd #1#2#3#4 % defined at lua end
+% \dosetpositionplus #1#2#3#4#5 % defined at lua end
+% \dosetpositionbox #1#2 % defined at lua end
+% \dosetpositionstrut #1 % defined at lua end
+% \dosetpositionstrutkind #1#2 % defined at lua end
+
+\newbox\b_anch_position
+\newif \ifpositioning % sort of public
+
+%D Sometimes we want to trick the position handler a bit:
+
+% \replacepospxywhd #1#2#3#4#5#6#7 % defined at lua end
+
+%D \macros
+%D {MPp, MPx, MPy, MPw, MPh, MPd, MPxy, MPll, MPlr, MPur, MPul, MPpos, MPanchor}
+%D
+%D Access to the positional information is provided by macros with short names
+%S that are clearly meant for \METAPOST\ but nowadays also used for other purposes.
+
+% \MPp : defined at lua end
+% \MPr : defined at lua end
+% \MPc : defined at lua end
+% \MPn : defined at lua end
+% \MPx : defined at lua end
+% \MPy : defined at lua end
+% \MPw : defined at lua end
+% \MPh : defined at lua end
+% \MPd : defined at lua end
+% \MPxy : defined at lua end
+% \MPwhd : defined at lua end
+% \MPll : defined at lua end
+% \MPlr : defined at lua end
+% \MPur : defined at lua end
+% \MPul : defined at lua end
+% \MPpos : defined at lua end
+% \MPls : defined at lua end
+% \MPrs : defined at lua end
+% \MPpardata : defined at lua end
+% \MPxywhd : defined at lua end
+% \MPposset : defined at lua end
+
+\aliased\let\MPpage \MPp
+\aliased\let\MPregion \MPr
+\aliased\let\MPcolumn \MPc
+\aliased\let\MPparagraph\MPn
+
+ \let\MPanchor \MPpos % overloaded locally when needed (todo: LMTX)
+
+\aliased\let\MPleftskip \MPls % compatible feature
+\aliased\let\MPrightkip \MPrs % compatible feature
+
+%D \macros
+%D {MPplus, MPrest, MPv, MPvv}
+%D
+%D Since we will probably keep on extending, we provide a general extension
+%D macro. The plus alternative takes an extra argument, denoting what additional
+%D parameter to pick up. So, the third extra is fetched with,
+%D
+%D \starttyping
+%D \MPplus{identifier}{3}{default}
+%D \stoptyping
+%D
+%D All extras (comma separated) are fetched with:
+%D
+%D \starttyping
+%D \MPrest{identifier}
+%D \stoptyping
+%D
+%D The extra parameters are not treated.
+
+% \MPplus #1#2#3 % defined at lua end
+% \MPrest #1 % defined at lua end
+
+\aliased\let\MPv \MPplus
+\aliased\let\MPvv\MPrest
+
+%D There are two low level positioning macros. Both store the position as well
+%D as execute an action associated with that position.
+
+\let\dopositionaction\gobbleoneargument % implemented later
+
+\def\anch_positions_initialize
+ {\ifpositioning \else
+ \global\positioningtrue
+ \fi}
+
+\permanent\protected\def\setpositiononly
+ {\iftrialtypesetting
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\anch_positions_set_only_indeed
+ \fi}
+
+\def\anch_positions_set_only_indeed#1%
+ {\anch_positions_initialize
+ \edef\currentposition{#1}%
+ \dosetposition\currentposition}
+
+\permanent\protected\def\setposition
+ {\iftrialtypesetting
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\anch_positions_set_indeed
+ \fi}
+
+\def\anch_positions_set_indeed#1%
+ {\anch_positions_initialize
+ \edef\currentposition{#1}%
+ \dosetposition\currentposition
+ \anch_positions_trace_left
+ \dopositionaction\currentposition}
+
+\permanent\protected\def\setpositiondata
+ {\iftrialtypesetting
+ \expandafter\gobblefourarguments
+ \else
+ \expandafter\anch_positions_set_data_indeed
+ \fi}
+
+\def\anch_positions_set_data_indeed#1#2#3#4%
+ {\anch_positions_initialize
+ \hbox % \hpack
+ {\edef\currentposition{#1}%
+ \dosetpositionwhd\currentposition{#2}{#3}{#4}% already \the\dimexpr
+ \anch_positions_trace_left
+ \dopositionaction\currentposition
+ \hss}}
+
+\permanent\protected\def\setpositionbox
+ {\iftrialtypesetting
+ \expandafter\anch_positions_set_box_nop
+ \else
+ \expandafter\anch_positions_set_box_yes
+ \fi}
+
+\def\anch_positions_set_box_nop#1%
+ {\dowithnextboxcs\flushnextbox}
+
+\def\anch_positions_set_box_yes#1%
+ {\dowithnextbox{\anch_positions_set_box_finish{#1}}}
+
+\def\anch_positions_set_box_finish#1%
+ {\anch_positions_initialize
+ \hbox to \wd\nextbox % \hpack
+ {\edef\currentposition{#1}%
+ \dosetpositionbox\currentposition\nextbox
+ \anch_positions_trace_left
+ \setbox\b_anch_position\box\nextbox
+ \dopositionaction\currentposition
+ \box\b_anch_position
+ \hss}}
+
+\permanent\protected\def\setpositionstrut
+ {\iftrialtypesetting
+ \expandafter\anch_positions_set_strut_nop
+ \else
+ \expandafter\anch_positions_set_strut_yes
+ \fi}
+
+\def\anch_positions_set_strut_nop#1%
+ {\strut}
+
+\def\anch_positions_set_strut_yes#1%
+ {\anch_positions_initialize
+ \hbox to \zeropoint % \hpack
+ {\edef\currentposition{#1}%
+ \dosetpositionstrut\currentposition
+ \anch_positions_trace_left
+ \dopositionaction\currentposition
+ \strut
+ \hss}}
+
+\permanent\protected\def\setpositionstrutkind
+ {\iftrialtypesetting
+ \expandafter\anch_positions_set_strut_kind_nop
+ \else
+ \expandafter\anch_positions_set_strut_kind_yes
+ \fi}
+
+\def\anch_positions_set_strut_kind_yes#1#2%
+ {\anch_positions_initialize
+ \hbox to \zeropoint % \hpack
+ {\edef\currentposition{#1}%
+ \dosetpositionstrutkind\currentposition{#2}%
+ \anch_positions_trace_left
+ \dopositionaction\currentposition
+ \strut
+ \hss}}
+
+\def\anch_positions_set_strut_kind_nop#1#2%
+ {\strut}
+
+\permanent\protected\def\setpositiondataplus
+ {\iftrialtypesetting
+ \expandafter\gobblefivearguments
+ \else
+ \expandafter\anch_positions_set_plus_indeed
+ \fi}
+
+\def\anch_positions_set_plus_indeed#1#2#3#4#5%
+ {\anch_positions_initialize
+ \hbox % \hpack
+ {\edef\currentposition{#1}%
+ \dosetpositionplus\currentposition{#2}{#3}{#4}{#5}% already \the\dimexpr
+ \anch_positions_trace_right
+ \dopositionaction\currentposition
+ \hss}}
+
+\permanent\protected\def\setpositionplus
+ {\iftrialtypesetting
+ \expandafter\anch_positions_set_plus_nop
+ \else
+ \expandafter\anch_positions_set_plus_yes
+ \fi}
+
+\def\anch_positions_set_plus_nop#1#2%
+ {\dowithnextboxcs\flushnextbox}
+
+\def\anch_positions_set_plus_yes#1#2%
+ {\dowithnextbox{\anch_positions_set_plus_yes_finish{#1}{#2}}}
+
+\def\anch_positions_set_plus_yes_finish#1#2%
+ {\anch_positions_initialize
+ \hbox to \nextboxwd % \hpack
+ {\edef\currentposition{#1}%
+ \dosetpositionplus\currentposition{\wd\nextbox}{\ht\nextbox}{\dp\nextbox}{#2}%
+ \anch_positions_trace_right
+ \setbox\b_anch_position\flushnextbox
+ \dopositionaction\currentposition
+ \box\b_anch_position
+ \hss}}
+
+\let\currentposition\s!unknown
+
+%D A few special ones .. will be cleaned up
+
+\def\pageanchor {page:\the\realpageno} % for the moment only one pagesize
+\def\textanchor {text:\the\realpageno}
+\def\regionanchor{region:0}
+
+\newcount\c_anch_column % will be delegated to lua
+\newcount\c_anch_text % will be delegated to lua
+
+% beware we need to pass \somethingexpanded or { }
+
+\protected\def\anch_mark_column_box#1#2% box n
+ {\global\advance\c_anch_column\plusone
+ \clf_markregionboxtaggedn#1{columnarea:\the\c_anch_column}#2\relax} % extra height
+
+\protected\def\anch_mark_region_box
+ {\iftrialtypesetting
+ \expandafter\gobbleoneargument
+ \orelse\ifpositioning
+ \expandafter\anch_mark_region_box_indeed
+ \else
+ \expandafter\gobbleoneargument
+ \fi}
+
+\protected\def\anch_mark_region_box_indeed#1%
+ {\clf_markregionbox#1\relax}
+
+\protected\def\anch_mark_flow_box#1% will be extended / renamed
+ {\hpack\bgroup
+ \global\advance\c_anch_text\plusone
+ \clf_markregionboxtagged#1{textarea:\the\c_anch_text}%
+ \box#1%
+ \egroup}
+
+\protected\def\anch_mark_tagged_box#1#2%
+ {\clf_markregionboxtagged#1{#2}}
+
+\protected\def\anch_mark_flow_only#1% will be extended / renamed
+ {\global\advance\c_anch_text\plusone
+ \clf_markregionboxcorrected#1{textarea:\the\c_anch_text}}
+
+\protected\def\anch_make_page_box#1% maybe like text
+ {\clf_setregionboxtagged#1{page:\the\realpageno}}
+
+\protected\def\anch_mark_text_box#1%
+ {\clf_markregionboxtagged#1{text:\the\realpageno}} % needs an hbox
+
+\newcount\c_anch_free
+
+\protected\def\anch_mark_tagged_box_free#1#2#3#4#5#6% only needed when positions
+ {\ifpositioning
+ \global\advance\c_anch_free\plusone % could be done at the lua end
+ \clf_markregionboxtaggedkind
+ #1%
+ {free:\number\c_anch_free}%
+ #2\space % kind
+ #3\space % leftoffset
+ #4\space % rightoffset
+ #5\space % topoffset
+ #6\relax % bottomoffset
+ \fi}
+
+% \reservedautoregiontag % define at lua end
+
+%D We can copy a position with:
+%D
+%D \starttyping
+%D \copyposition {to} {from}
+%D \stoptyping
+%D
+%D Again, this is a global operation.
+
+% \copyposition #1#2 % defined at lua end
+
+%D The fact that handling positions is a two pass operation, is one of the
+%D reasons why we need to be able to test for existence, using:
+%D
+%D \starttyping
+%D \doifpositionelse {identifier} {found action} {not found action}
+%D \stoptyping
+
+% \doifposition #1 % defined at lua end
+% \doifelseposition #1#2 % defined at lua end
+% \doifelsepositiononpage #1#2 % defined at lua end
+
+\aliased\let\doifpositionelse \doifelseposition
+\aliased\let\doifpositiononpageelse\doifelsepositiononpage
+
+%D \macros
+%D {xypos}
+%D
+%D We have several macros available to save positions. Later we will see
+%D applications.
+%D
+%D \starttabulate[|l|l||]
+%D \NC \type {\xypos} \NC \NC simple position with no dimensions \NC \NR
+%D \NC \type {\hpos} \NC \NC position and characteristics of a \type {\hbox} \NC \NR
+%D \NC \type {\vpos} \NC \NC position and characteristics of a \type {\vbox} \NC \NR
+%D \NC \type {\bpos} \NC b: \NC begin point in a line \NC \NR
+%D \NC \type {\epos} \NC e: \NC end point in a line \NC \NR
+%D \stoptabulate
+%D
+%D Each macro takes an identifier as argument, and the \type {\hpos} and
+%D \type {\vpos} also expect box content.
+
+\aliased\let\xypos\setpositiononly
+
+\permanent\protected\def\hpos #1{\dontleavehmode\setpositionbox{#1}\hbox}
+\permanent\protected\def\vpos #1{\setpositionbox{#1}\vbox}
+\permanent\protected\def\bpos #1{\dontleavehmode\setpositionstrut{b:#1}\ignorespaces}
+\permanent\protected\def\epos #1{\removeunwantedspaces\setpositionstrut{e:#1}}
+\permanent\protected\def\bposkind#1#2{\dontleavehmode\setpositionstrutkind{b:#1}{#2}\ignorespaces} % not public, used in backgrounds
+\permanent\protected\def\eposkind#1#2{\removeunwantedspaces\setpositionstrutkind{e:#1}{#2}} % not public, used in backgrounds
+
+%D When we want to calculate more complex backgrounds, we need to know what the
+%D current indentation scheme is. At the cost of many positions and memory, we
+%D can keep track of them. This mechanism is activated automatically based on
+%D information collected in the previous pass.
+
+\newtoks \t_anch_positions_tracers
+\newcount\c_anch_positions_paragraph
+
+\permanent\protected\def\tracepositions
+ {\the\t_anch_positions_tracers}
+
+\permanent\protected\def\enableparpositions % global
+ {\glet\registerparoptions\doregisterparoptions
+ \global\positioningtrue}
+
+\permanent\let\disableparpositions\relax
+
+\let\registerparoptions\relax
+
+\protected\def\doregisterparoptions
+ {\iftrialtypesetting \else
+ \ifinpagebody \else \ifmmode \else \ifinformula \else
+ \anch_positions_register_par_options
+ \fi \fi \fi
+ \fi}
+
+\def\anch_positions_register_par_options_normal
+ {\dontleavehmode\clf_parpos}
+
+\def\anch_positions_register_par_options_traced
+ {\anch_positions_register_par_options_normal
+ \smashedhbox to \zeropoint
+ {\hss
+ \startcolor[blue]%
+ \llap{\infofont\number\c_anch_positions_paragraph}%
+ \vrule
+ \s!width 4\onepoint
+ \s!height2\onepoint
+ \s!depth 2\onepoint
+ \stopcolor
+ \hss}}
+
+\let\anch_positions_register_par_options\anch_positions_register_par_options_normal
+
+\appendtoks
+ \let\anch_positions_register_par_options\anch_positions_register_par_options_traced
+\to \t_anch_positions_tracers
+
+\protected\def\anch_positions_trace#1#2#3%
+ {\smashedhbox
+ {#1{\infofont#2#3}%
+ \kern-\onepoint
+ \vrule\s!width2\onepoint\s!height\halfapoint\s!depth\halfapoint}}
+
+\protected\def\anch_positions_trace_left_indeed
+ {\anch_positions_trace\llap\darkmagenta{\currentposition>}}
+
+\protected\def\anch_positions_trace_right_indeed
+ {\anch_positions_trace\rlap\darkcyan{<\currentposition}}
+
+\let\anch_positions_trace_left \relax
+\let\anch_positions_trace_right\relax
+
+\appendtoks
+ \let\anch_positions_trace_left \anch_positions_trace_left_indeed
+ \let\anch_positions_trace_right \anch_positions_trace_right_indeed
+\to \t_anch_positions_tracers
+
+% \appendtoks \registerparoptions \to \everypar
+
+%D \macros
+%D {doifoverlappingelse}
+%D
+%D A first application of positional information, is to determine if two boxes do
+%D overlap:
+%D
+%D \starttyping
+%D \doifoverlappingelse{point a}{point b}
+%D {action when overlapping}
+%D {action when not overlapping}
+%D \stoptyping
+
+% \doifelseoverlapping #1#2#3#4 % defined at lua end
+
+\aliased\let\doifoverlappingelse\doifelseoverlapping
+
+%D \macros
+%D {doifpositionsonsamepageelse,
+%D doifpositionsonthispageelse}
+%D
+%D Instead of letting the user handle fuzzy expansion, we provide a simple test on
+%D positions being on the same page.
+%D
+%D \starttyping
+%D \doifpositionsonsamepageelse{point a}{point b}
+%D {action when on same page}
+%D {action when not on same page}
+%D \doifpositionsonthispageelse{point a}{point b}
+%D {action when on this page}
+%D {action when not on this page}
+%D \stoptyping
+
+% \doifelsepositionsonsamepage #1 % defined at lua end
+% \doifelsepositionsonthispage #1 % defined at lua end
+% \doifelsepositionsused % defined at lua end
+
+\aliased\let\doifpositionsonsamepageelse\doifelsepositionsonsamepage
+\aliased\let\doifpositionsonthispageelse\doifelsepositionsonthispage
+\aliased\let\doifpositionsusedelse \doifelsepositionsused
+
+%D Moved here:
+
+\permanent\protected\def\savepos {\clf_savepos}
+\permanent\protected\def\lastxpos{\numexpr\clf_lastxpos\relax}
+\permanent\protected\def\lastypos{\numexpr\clf_lastypos\relax}
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/anch-tab.mkxl b/tex/context/base/mkiv/anch-tab.mkxl
new file mode 100644
index 000000000..075668ab7
--- /dev/null
+++ b/tex/context/base/mkiv/anch-tab.mkxl
@@ -0,0 +1,375 @@
+%D \module
+%D [ file=anch-pgr, % moved from anch-pgr (1999.08.01)
+%D version=2011.12.19, % 1999.08.01,
+%D title=\CONTEXT\ Anchoring Macros,
+%D subtitle=Table Extensions,
+%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 Anchoring Macros / Table Extensions}
+
+%D This is just a playground and functionality might change or even dissappear in
+%D favour of better solutions. Anyway, it now has been aroudn too long to bother.
+
+\unprotect
+
+\newcount\c_anch_tabs
+
+\protected\def\tabl_tabulate_hook_b
+ {\iftrialtypesetting\else
+ \ifpositioning
+ \ifconditional\tablehaspositions
+ \ifcase\c_tabl_tabulate_noflines % \ifnum\c_tabl_tabulate_noflines=\c_tabl_tabulate_totalnoflines
+ \tabl_tabulate_hook_b_first
+ \else
+ \tabl_tabulate_hook_b_next
+ \fi
+ \fi
+ \fi
+ \fi}
+
+\protected\def\tabl_tabulate_hook_e
+ {\iftrialtypesetting\else
+ \ifpositioning
+ \ifconditional\tablehaspositions
+ \ifcase\c_tabl_tabulate_noflines % \ifnum\c_tabl_tabulate_noflines=\c_tabl_tabulate_totalnoflines
+ \tabl_tabulate_hook_e_first
+ \else
+ \tabl_tabulate_hook_e_next
+ \fi
+ \fi
+ \fi
+ \fi}
+
+\protected\def\tabl_tabulate_hook_b_first{\clf_bposcolumnregistered{tabulate:\the\c_anch_tabs:\the\c_tabl_tabulate_column}}
+\protected\def\tabl_tabulate_hook_b_next {\clf_bposcolumn{tabulate:\the\c_anch_tabs:\the\c_tabl_tabulate_column}}
+\protected\def\tabl_tabulate_hook_e_first{\clf_eposcolumnregistered}
+\protected\def\tabl_tabulate_hook_e_next {\clf_eposcolumn}
+
+% \appendtoks \registerparoptions \to \everypar
+
+\appendtoks
+ \global\advance\c_anch_tabs\plusone
+\to \everytabulate
+
+% for text backgrounds
+
+\appendtoks
+ \settrue\c_anch_backgrounds_pos_no_shape
+\to \everytabulate
+
+%D Beware, the following code is somewhat weird and experimental and might be
+%D dropped or become a loadable module.
+
+%D \macros
+%D {GFC, GTC, GSC}
+%D
+%D The next macros extend tables and tabulation with backgrounds and position
+%D related features. Areas are specified with symbolic names, and symbolic
+%D references to the graphics involved. Each table has its own namespace.
+
+\newconditional\tablehaspositions
+\newcount \noftabpositions
+\newtoks \posXCtoks
+
+\protected\def\anch_tabulate_bpos{\bpos}
+\protected\def\anch_tabulate_epos{\epos}
+
+\installcorenamespace{positiontables}
+
+\permanent\def\tbPOSprefix{\??positiontables\number\noftabpositions:}
+
+\protected\def\tablepos
+ {\normalexpanded{\global\posXCtoks\emptytoks\the\posXCtoks}}
+
+\permanent\tolerant\protected\def\tbXC [#1]{\anch_table_check_state\iffirstargument\anch_tables_indeed_XC [#1]\else\expandafter\NC\fi}
+\permanent\tolerant\protected\def\tbGSC[#1]{\anch_table_check_state\iffirstargument\anch_tables_indeed_GSC[#1]\else\expandafter\NC\fi}
+\permanent\tolerant\protected\def\tbGFC[#1]{\anch_table_check_state\iffirstargument\anch_tables_indeed_GFC[#1]\else\expandafter\NC\fi}
+\permanent\tolerant\protected\def\tbGTC[#1]{\anch_table_check_state\iffirstargument\anch_tables_indeed_GTC[#1]\else\expandafter\NC\fi}
+
+\def\anch_table_check_state
+ {\iftrialtypesetting
+ \global\settrue\tablehaspositions
+ \firstargumentfalse
+ \fi}
+
+\def\anch_tables_indeed_XC[#1]%
+ {{\overloaded\let\NC\relax\processcommalist[#1]\anch_tables_step_XC}}
+
+\def\anch_tables_step_XC#1%
+ {\anch_tables_step_indeed_XC[#1]}
+
+\def\anch_tables_step_indeed_XC[#1#2]%
+ {\if#1>\anch_tables_indeed_GFC[#2:#2]\orelse
+ \if#1+\anch_tables_indeed_GFC[#2:#2]\orelse
+ \if#1<\anch_tables_indeed_GTC[#2:#2]\orelse
+ \if#1-\anch_tables_indeed_GTC[#2:#2]\orelse
+ \if#1=\anch_tables_indeed_GSC[#2:#2]\orelse
+ \anch_tables_indeed_GSC[#1#2:#1#2]\fi}
+
+\def\anch_tables_indeed_GSC[#1]%
+ {\processcommalist[#1]\anch_tables_step_GSC}
+
+\def\anch_tables_step_GSC#1%
+ {\anch_tables_append_GSC[#1:#1]}
+
+\def\anch_tables_append_GSC[#1:#2:#3]%
+% {\doglobal\appendtoks\anch_tables_process_GSC[#1:#2]\to\posXCtoks\NC}
+ {\gtoksapp\posXCtoks{\anch_tables_process_GSC[#1:#2]}\NC}
+
+\def\anch_tables_process_GSC[#1:#2]%
+ {\remappositionframed{#2}{\tbPOSprefix#1}%
+ \anch_tabulate_bpos{\tbPOSprefix#1}%
+ \doglobal\appendtoks\expandafter\anch_tabulate_epos\expandafter{\tbPOSprefix#1}\to\posXCtoks}
+% \xtoksapp\posXCtoks{\anch_tabulate_epos{\tbPOSprefix#1}}}
+
+\def\anch_tables_indeed_GFC[#1]%
+ {\doglobal\appendtoks\anch_tables_delayed_GFC[#1]\to\posXCtoks\NC}
+% {\gtoksapp\posXCtoks{\anch_tables_delayed_GFC[#1]}\NC}
+
+\def\anch_tables_delayed_GFC[#1]%
+ {\processcommalist[#1]\anch_tables_step_GFC}
+
+\def\anch_tables_step_GFC#1%
+ {\anch_tables_process_GFC[#1:#1]}
+
+\def\anch_tables_process_GFC[#1:#2:#3]%
+ {\remappositionframed{#2}{\tbPOSprefix#1}%
+ \anch_tabulate_bpos{\tbPOSprefix#1}}
+
+\def\anch_tables_indeed_GTC[#1]%
+ {\doglobal\appendtoks\anch_tables_delayed_GTC[#1]\to\posXCtoks\NC}
+% {\gtoksapp\posXCtoks{\anch_tables_delayed_GTC[#1]}\NC}
+
+\def\anch_tables_delayed_GTC[#1]%
+ {\doglobal\appendtoks\anch_tables_process_GTC[#1]\to\posXCtoks}
+% {\gtoksapp\posXCtoks{\anch_tables_process_GTC[#1]}\NC}
+
+\def\anch_tables_process_GTC[#1]%
+ {\processcommalist[#1]\anch_tables_step_GTC}
+
+\def\anch_tables_step_GTC#1%
+ {\anch_tables_step_indeed_GTC[#1:#1]}
+
+\def\anch_tables_step_indeed_GTC[#1:#2]%
+ {\anch_tabulate_epos{\tbPOSprefix#1}}
+
+%D The amount of code to support tables and tabulation is rather minimalistic.
+
+\aliased\let\tabulatepos\tablepos
+
+\def\tabulatenormalpos
+ {\iftrialtypesetting
+ % nothing
+ \orelse\ifconditional\tablehaspositions
+ \hss\tabulatepos\hss
+ \else
+ % nothing
+ \fi}
+
+\def\tabulateequalpos
+ {\iftrialtypesetting
+ \tabulateEQ
+ \orelse\ifconditional\tablehaspositions
+ \tabulateEQpos
+ \else
+ \tabulateEQ
+ \fi}
+
+\def\tabulateEQpos
+ {\setbox\scratchbox\hbox{\tabulateEQ}%
+ \hbox to \wd\scratchbox{\hss\kern\zeropoint\tabulatepos\hss}% hpack
+ \kern-\wd\scratchbox
+ \box\scratchbox}
+
+\appendtoks
+ \global\advance\noftabpositions\plusone
+ \global\setfalse\tablehaspositions
+\to \everytabulate
+
+% We need to handle paragraphs as well.
+
+\let\anch_tabulate_flush_epos\relax
+
+\protected\def\anch_tabulate_bpos_indeed
+ {\bpos}
+
+\protected\def\anch_tabulate_epos_indeed#1%
+ {\ifvoid\b_tabl_tabulate_current\c_tabl_tabulate_column
+ \epos{#1}%
+ \glet\anch_tabulate_flush_epos\relax
+ \else
+ \gdef\anch_tabulate_flush_epos{\epos{#1}}%
+ \fi}
+
+\permanent\def\flushtabulatesplitbox
+ {\box\b_tabl_tabulate
+ \iftrialtypesetting\orelse\ifconditional\tablehaspositions\anch_tabulate_flush_epos\fi}
+
+\appendtoks
+ \let\anch_tabulate_bpos\anch_tabulate_bpos_indeed % ?
+ \let\anch_tabulate_epos\anch_tabulate_epos_indeed % ?
+ \glet\anch_tabulate_flush_epos\relax
+\to \everytabulate
+
+%D In order to prevent potential clashes with abbreviations, postpone the mapping.
+
+\appendtoks
+ \enforced\let\GSC\tbGSC
+ \enforced\let\GFC\tbGFC
+ \enforced\let\GTC\tbGTC
+ \enforced\let\XC \tbXC
+\to \everytabulate
+
+%D \macros
+%D {definepositionframed}
+%D
+%D The next example show how to provide backgrounds to table cells. First we define
+%D some framed backgrounds.
+%D
+%D \startbuffer
+%D \definepositionframed[x][background=color,backgroundcolor=red]
+%D \definepositionframed[y][background=color,backgroundcolor=green]
+%D \definepositionframed[z][background=color,backgroundcolor=blue]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D % \getbuffer
+%D
+%D \startbuffer
+%D \starttabulate[|c|c|c|]
+%D \GFC[f:x] this is a small \NC table \NC in which we \NC \FR
+%D \NC will demonstrate \GFC[g:z] that this \GTC[g] positioning \NC \MR
+%D \GSC[e:y] mechanism also \GTC[f] works quite well \NC in tables \NC \LR
+%D \stoptabulate
+%D \stopbuffer
+%D
+%D The table itself defines three areas (a, b and~c) using these frames.
+%D
+%D \typebuffer
+%D % \getbuffer
+%D
+%D Tables (based on \TABLE) are supported by:
+
+\permanent\def\normalTABLEsimplebar {\unskip\!ttRightGlue&\tablepos&} % |
+\permanent\def\normalTABLEcomplexbar{\unskip\!ttRightGlue&\omit\tablepos\!ttAlternateVrule} % \|
+\permanent\def\normalTABLEquote {\unskip\!ttRightGlue&\omit\tablepos&} % "
+
+\appendtoks
+ \global\advance\noftabpositions\plusone
+ \global\setfalse\tablehaspositions
+\to \everytable
+
+%D Since we don't want nameclashes:
+
+\appendtoks
+ \enforced\let\GSC\tbGSC
+ \enforced\let\GFC\tbGFC
+ \enforced\let\GTC\tbGTC
+ \enforced\let\XC \tbXC
+\to \everytable
+
+%D In the previous example, we could have provided an overlay to the framed definition.
+%D A more direct approach is demonstrated below:
+%D
+%D \startbuffer
+%D \def\cw#1{\color[white]{#1}}
+%D
+%D \startMPpositiongraphic{tableshade}
+%D initialize_area(\MPpos{\MPvar{from}},\MPpos{\MPvar{to}}) ;
+%D color c ; c := \MPvar{color} ;
+%D linear_shade(pxy,0,.4c,.9c) ;
+%D anchor_area(\MPanchor{\MPvar{from}}) ;
+%D \stopMPpositiongraphic
+%D
+%D \setMPpositiongraphic{b:x}{tableshade}{from=b:x,to=e:x,color=red}
+%D \setMPpositiongraphic{b:y}{tableshade}{from=b:y,to=e:y,color=green}
+%D \setMPpositiongraphic{b:z}{tableshade}{from=b:z,to=e:z,color=blue}
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+%D
+%D The definition of the table looks about the same as the previous one:
+%D
+%D \startbuffer
+%D \starttable[|c|c|c|]
+%D \GFC[b:z] \cw{this is a small} \NC \cw{table} \NC in which we \NC \FR
+%D \NC \cw{will demonstrate} \GFC[c:y] \cw{that this} \GTC[c] \cw{positioning} \NC \MR
+%D \GSC[a:x] \cw{mechanism also} \GTC[b] \cw{works quite well} \NC in tables \NC \LR
+%D \stoptable
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \getbuffer
+
+% \definepositionframed[w][background=color,backgroundcolor=yellow]
+% \definepositionframed[x][background=color,backgroundcolor=red]
+% \definepositionframed[y][background=color,backgroundcolor=green]
+% \definepositionframed[z][background=color,backgroundcolor=blue]
+%
+% \starttabulate[|c|c|c|]
+% \NC this is a small \NC table \NC in which we \NC \FR
+% \NC will demonstrate \NC that this \NC positioning \NC \MR
+% \NC mechanism also \NC works quite well \NC in tables \NC \LR
+% \stoptabulate
+%
+% \starttabulate[|c|c|c|]
+% \GFC[f:x] this is a small \GTC table \NC in which we \NC \FR
+% \NC will demonstrate \GFC[g:z] that this \GTC[g] positioning \NC \MR
+% \GSC[e:y] mechanism also \GTC[f] works quite well \NC in tables \NC \LR
+% \stoptabulate
+%
+% \starttabulate[|c|c|c|]
+% \GFC[f:x,d:w] this is a small \GTC[d] table \NC in which we \NC \FR
+% \NC will demonstrate \GFC[g:z] that this \GTC[g] positioning \NC \MR
+% \GSC[e:y] mechanism also \GTC[f] works quite well \NC in tables \NC \LR
+% \stoptabulate
+%
+% \starttabulate[|c|c|c|]
+% \XC[+f:x] this is a small \XC table \NC in which we \NC \FR
+% \NC will demonstrate \XC[+g:z] that this \XC[-g] positioning \NC \MR
+% \XC[=e:y] mechanism also \XC[-f] works quite well \NC in tables \NC \LR
+% \stoptabulate
+%
+% \starttabulate[|c|c|c|]
+% \XC[+f:x,+d:w] this is a small \XC[-d] table \NC in which we \NC \FR
+% \NC will demonstrate \XC[+g:z] that this \XC[-g] positioning \NC \MR
+% \XC[=e:y] mechanism also \XC[-f] works quite well \NC in tables \NC \LR
+% \stoptabulate
+
+% evt [b:x]
+%
+% \definepositionframed[x][background=color,fillcolor=red]
+% \definepositionframed[y][background=color,fillcolor=green]
+% \definepositionframed[z][background=color,fillcolor=blue]
+
+\permanent\protected\def\remappositionframed#1#2% from to
+ {\copyposition{b:#1}{b:#2}%
+ \copyposition{e:#1}{e:#2}%
+ \anch_positions_set_action{b:#2}{\dopositionaction{b:#1}}}
+
+\permanent\tolerant\protected\def\definepositionframed[#1]#*[#2]%
+ {\anch_positions_set_action{b:#1}{\anch_framed_handle[#1][#2]}}
+
+\protected\def\anch_framed_handle
+ {\bgroup
+ \anch_framed_indeed}
+
+\permanent\tolerant\protected\def\positionframed[#1]#*[#2]%
+ {\setbox\scratchbox\hpack
+ {\scratchwidth \dimexpr\MPx{e:#1}-\MPx{b:#1}\relax
+ \scratchdepth \dimexpr\MPy{b:#1}-\MPy{e:#1}+\MPd{e:#1}\relax
+ \scratchheight\dimexpr\scratchdepth+\MPh{b:#1}\relax
+ \lower\scratchdepth\hpack
+ {\framed[\c!width=\scratchwidth,\c!height=\scratchheight,\c!offset=\v!overlay,#2]{}}}%
+ \smashedbox\scratchbox
+ \egroup}
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/char-utf.mkxl b/tex/context/base/mkiv/char-utf.mkxl
new file mode 100644
index 000000000..a7cbab345
--- /dev/null
+++ b/tex/context/base/mkiv/char-utf.mkxl
@@ -0,0 +1,44 @@
+%D \module
+%D [ file=char-utf,
+%D version=2006.12.05,
+%D title=\CONTEXT\ Character Support,
+%D subtitle=Unicode UTF,
+%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 Character Support / Unicode UTF}
+
+%D After a bit of experimenting we reached a clean state where \UTF\ 8, 16 and 32
+%D were supported as well as collapsing (combining sequences). Writing the code was
+%D a relaxed experience, not in the last place because it was accompanied by
+%D listening to those nice Vienna Teng cd's (who decided that making music was more
+%D fun than programming, but then, she may not know \TEX\ and \LUA).
+
+\unprotect
+
+\registerctxluafile{char-def}{}
+\registerctxluafile{char-ini}{}
+\registerctxluafile{char-utf}{}
+\registerctxluafile{char-cjk}{}
+
+%D We enable collapsing (combining characters) by default, but since the source
+%D files are rather simple, we postpone the initialization till runtime.
+
+% \appendtoks
+% \clf_enableutf % not needed when we create a format so we do it now
+% \to \everyjob
+
+%D The next one influences input parsing.
+%D
+%D \starttyping
+%D \definecomposedutf 318 108 126 % lcaron
+%D \stoptyping
+
+\permanent\protected\def\definecomposedutf#1 #2 #3 {\clf_addgrapheme{#1}{#2}{#3}}
+
+\protect
diff --git a/tex/context/base/mkiv/chem-str.mkxl b/tex/context/base/mkiv/chem-str.mkxl
index 853887678..036b1f5da 100644
--- a/tex/context/base/mkiv/chem-str.mkxl
+++ b/tex/context/base/mkiv/chem-str.mkxl
@@ -157,11 +157,11 @@
{\setupcurrentchemical[#1]}% same as \currentchemical
{\edef\currentchemical{#1}%
\setupcurrentchemical[#2]}%
- \else\iffirstargument
+ \orelse\iffirstargument
\doifelseassignment{#1}
{\setupcurrentchemical[#1]}% same as \currentchemical
{\edef\currentchemical{#1}}%
- \fi\fi
+ \fi
\the\everystructurechemical
\setbox\b_chem_result\hpack\bgroup
\clf_startchemical
@@ -254,7 +254,7 @@
\appendtoks
\edef\chemicalbodyfont{\chemicalparameter\c!bodyfont}% public?
- \ifx\chemicalbodyfont\empty
+ \ifempty\chemicalbodyfont
\switchtobodyfont[\chemicalbodyfont]%
\fi
\getvalue{\??chemicalsize\chemicalparameter\c!size}%
diff --git a/tex/context/base/mkiv/colo-ext.mkxl b/tex/context/base/mkiv/colo-ext.mkxl
new file mode 100644
index 000000000..df2d9d768
--- /dev/null
+++ b/tex/context/base/mkiv/colo-ext.mkxl
@@ -0,0 +1,99 @@
+%D \module
+%D [ file=colo-ext, % mostof thsi code used to be in colo-ini.tex
+%D version=1997.04.01,
+%D title=\CONTEXT\ Color Macros,
+%D subtitle=Extras,
+%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 Color Macros / Extras}
+
+\unprotect
+
+%D \macros
+%D {negatecolorcomponent, negativecolorbox}
+%D
+%D Sometimes, especially when we deal with typesetting devices, we want to reverse
+%D the color scheme. Instead of recalculating all those colors, we use a quick and
+%D dirty approach:
+%D
+%D \starttyping
+%D \negativecolorbox0
+%D \stoptyping
+%D
+%D will negate the colors in box zero.
+
+\permanent\protected\def\negatecolorbox#1% or just set attr of #1
+ {\setbox#1\hpack to \wd#1%
+ {\scratchdimen\wd#1\relax
+ \startnegative % might change
+ \blackrule[\c!color=\s!white,\c!height=\ht#1,\c!depth=\dp#1,\c!width=\scratchdimen]%
+ \hskip-\scratchdimen
+ \leaders\box#1\hfill% this triggers application to the box .. a real dirty hack!
+ \stopnegative}}
+
+%D There are in principle two ways to handle overprint: bound to colors or
+%D independent. For the moment we only support independent overprint handling. Here
+%D we deal with a per-document setting.
+
+%D We can move the stack and attribute setting to the \LUA\ end.
+
+\installcorenamespace{colorintent}
+
+\permanent\protected\def\registercolorintent#1#2% \relax is needed !
+ {\setevalue{\??colorintent#1}{\c_attr_colorintent\clf_registercolorintent{#2}\relax}}
+
+\protected\def\colo_intents_set
+ {\clf_enablecolorintents
+ \protected\gdef\colo_intents_set##1{\csname\??colorintent##1\endcsname}%
+ \colo_intents_set}
+
+\registercolorintent{knockout} {knockout}
+\registercolorintent{overprint}{overprint}
+
+\installattributestack\colorintentattribute
+
+\setevalue{\??colorintent\v!none}{\c_attr_colorintent\attributeunsetvalue} % or reset? used at all?
+
+\permanent\protected\def\startcolorintent[#1]%
+ {\pushattribute\colorintentattribute
+ \colo_intents_set{#1}}
+
+\permanent\protected\def\stopcolorintent
+ {\popattribute\colorintentattribute}
+
+\permanent\protected\def\startoverprint{\startcolorintent[\v!overprint]}
+\permanent\protected\def\startknockout {\startcolorintent[\v!knockout ]}
+
+\aliased\let\stopoverprint\stopcolorintent
+\aliased\let\stopknockout \stopcolorintent
+
+\aliased\let\starttextcolorintent\relax
+\aliased\let\stoptextcolorintent \relax
+
+\appendtoks
+ \colo_intents_set_text
+\to \everysetupcolors
+
+\let\p_colo_intent\empty
+
+\def\colo_intents_set_text
+ {\edef\p_colo_intent{\colorsparameter\c!intent}%
+ \ifx\p_colo_intent\v!none \else
+ \enforced\protected\xdef\starttextcolorintent{\colo_intents_set{\p_colo_intent}}%
+ \glet\colo_intents_set_text\relax
+ \colo_intents_set\p_colo_intent
+ \fi}
+
+\appendtoks \starttextcolorintent \to \everystarttextproperties
+\appendtoks \stoptextcolorintent \to \everystoptextproperties
+
+\setupcolors
+ [\c!intent=\v!none]
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/colo-grp.mkiv b/tex/context/base/mkiv/colo-grp.mkiv
index fddf65c79..a1b3333cc 100644
--- a/tex/context/base/mkiv/colo-grp.mkiv
+++ b/tex/context/base/mkiv/colo-grp.mkiv
@@ -68,8 +68,8 @@
{\doifelseinstring{:}{#2}
{\colo_groups_define_normal[#1][\v!rgb][#2]}
{\doloop % inherited
- {\ifcsname\??colorgroup#2:\recurselevel\endcsname
- \setevalue{\??colorgroup#1:\recurselevel}{\csname\??colorgroup#2:\recurselevel\endcsname}%
+ {\ifcsname#2:##1\endcsname
+ \definecolor[#1:##1][#2:##1]%
\else
\exitloop
\fi}}}
diff --git a/tex/context/base/mkiv/colo-grp.mkxl b/tex/context/base/mkiv/colo-grp.mkxl
new file mode 100644
index 000000000..82dd67959
--- /dev/null
+++ b/tex/context/base/mkiv/colo-grp.mkxl
@@ -0,0 +1,163 @@
+%D \module
+%D [ file=colo-grp,
+%D version=2011.12.27, % moved from colo-ini
+%D title=\CONTEXT\ Color Macros,
+%D subtitle=Groups,
+%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.
+
+%D Regular colors and palets are used most, contrary to groups which is why we
+%D define their support in a separate module.
+
+\writestatus{loading}{ConTeXt Color Macros / Groups}
+
+\unprotect
+
+%D \macros
+%D {definecolorgroup}
+%D
+%D The naming of the colors in this palet suggests some ordening, which in turn is
+%D suported by color grouping.
+%D
+%D \starttyping
+%D \definecolorgroup
+%D [red]
+%D [1.00:0.90:0.90,
+%D 1.00:0.80:0.80,
+%D 1.00:0.70:0.70,
+%D 1.00:0.55:0.55,
+%D 1.00:0.40:0.40,
+%D 1.00:0.25:0.25,
+%D 1.00:0.15:0.15,
+%D 0.90:0.00:0.00]
+%D \stoptyping
+%D
+%D In such a color group colors are numbered from~$1$ to~$n$.
+%D
+%D \showsetup{definecolorgroup}
+%D
+%D This kind of specification is not only more compact than defining each color
+%D separate, it also loads faster and takes less bytes.
+
+\installcorenamespace{colorgroup}
+\installcorenamespace{colorgroupsetter}
+
+\newcount\c_colo_groups_n % scratch counter
+
+\permanent\tolerant\protected\def\definecolorgroup[#1]#*[#2]#*[#3]% % sort of obsolete, just use palets directly
+ {\ifarguments\or\or
+ \ifhastok:{#2}%
+ \colo_groups_define_normal[#1][\v!rgb][#2]
+ \else
+ \colo_groups_define_checked[#1][#2][]%
+ \fi
+ \else
+ \colo_groups_define_normal[#1][#2][#3]%
+ \fi}
+
+\def\colo_groups_define_normal[#1][#2][#3]%
+ {\c_colo_groups_n\zerocount
+ \processcommalist[#3]{\colo_groups_define_entry{#1}{#2}}}
+
+\def\colo_groups_define_checked[#1][#2][#3]%
+ {\doloop % inherited
+ {\ifcsname#2:##1\endcsname
+ \definecolor[#1:##1][#2:##1]%
+ \else
+ \exitloop
+ \fi}}
+
+\def\colo_groups_define_entry#1#2#3% name mode specification
+ {\advance\c_colo_groups_n\plusone
+ \csname\??colorgroupsetter\ifcsname\??colorgroupsetter#2\endcsname#2\else\s!rgb\fi\endcsname[#1:\the\c_colo_groups_n][#3:0:0:0:0]}
+
+\setvalue{\??colorgroupsetter\s!gray}[#1][#2:#3]{\definecolor[#1][s=#2]}
+\setvalue{\??colorgroupsetter\s!rgb }[#1][#2:#3:#4:#5]{\definecolor[#1][r=#2,g=#3,b=#4]}
+\setvalue{\??colorgroupsetter\s!cmyk}[#1][#2:#3:#4:#5:#6]{\definecolor[#1][c=#2,m=#3=,y=#4,k=#5]}
+\setvalue{\??colorgroupsetter\s!spot}[#1][#2:#3:#4]{\definespotcolor[#1][#2][p=#3]}
+
+%D \macros
+%D {showcolorgroup}
+%D
+%D We can show the group by:
+%D
+%D \startbuffer
+%D \showcolorgroup [blue] [horizontal,name,number,value]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D or in color:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D which uses:
+%D
+%D \showsetup{showcolorgroup}
+
+\fetchruntimecommand \showcolorgroup \f!colo_run
+
+%D There are ten predefined color groups, like \color [green] {\em groen}, \color
+%D [red] {\em rood}, \color [blue] {\em blauw}, \color [cyan] {\em cyaan}, \color
+%D [magenta] {\em magenta} and \color [yellow] {\em geel}.
+%D
+%D \startlinecorrection
+%D \hbox to \hsize
+%D {\hss
+%D \showcolorgroup [red] [vertical,name,number]\hss
+%D \showcolorgroup [green] [vertical,name]\hss
+%D \showcolorgroup [blue] [vertical,name]\hss
+%D \showcolorgroup [cyan] [vertical,name]\hss
+%D \showcolorgroup [magenta][vertical,name]\hss
+%D \showcolorgroup [yellow] [vertical,name]\hss}
+%D \stoplinecorrection
+%D
+%D These groups are used to define palets {\em alfa} upto {\em zeta}. As long as we
+%D don't use colors from the same row, we get ourselves distinctive palets. By
+%D activating such a palet one gains access to its members {\em top} to {\em charm}
+%D (of course one should use more suitable names than these).
+%D
+%D \startlinecorrection
+%D \hbox to \hsize
+%D {\showpalet [alfa] [vertical,name,number]\hss
+%D \showpalet [beta] [vertical,name]\hss
+%D \showpalet [gamma] [vertical,name]\hss
+%D \showpalet [delta] [vertical,name]\hss
+%D \showpalet [epsilon] [vertical,name]\hss
+%D \showpalet [zeta] [vertical,name]}
+%D \stoplinecorrection
+%D
+%D By using the keyword \type {value} the individual color components are shown too.
+%D When printed in color, these showcases show both the colors and the gray value.
+
+%D \macros
+%D {comparecolorgroup}
+%D
+%D The similar command:
+%D
+%D \startbuffer
+%D \comparecolorgroup [blue]
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D shows color groups:
+%D
+%D \startlinecorrection
+%D \getbuffer
+%D \stoplinecorrection
+%D
+%D this commands are defined as:
+%D
+%D \showsetup{comparecolorgroup}
+
+\fetchruntimecommand \comparecolorgroup \f!colo_run
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv
index d14c6b9c7..1baddfe32 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.10.30 22:24}
+\newcontextversion{2020.11.03 16:50}
%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 d22459a4b..63d4b8bde 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.10.30 22:24}
+\edef\contextversion{2020.11.03 16:50}
%D Kind of special:
@@ -458,6 +458,7 @@
\loadmarkfile{symb-emj}
+\loadmarkfile{lang-tra}
\loadmarkfile{lang-wrd} % can be optional (discussion with mm sideeffect)
\loadmarkfile{lang-rep} % can be optional (bt 2013 side effect)
diff --git a/tex/context/base/mkiv/context.mkxl b/tex/context/base/mkiv/context.mkxl
index 793fc4d14..c89e37ade 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.10.30 22:24}
+\edef\contextversion{2020.11.03 16:50}
%overloadmode 1 % check frozen / warning
%overloadmode 2 % check frozen / error
@@ -61,7 +61,7 @@
%D First we load the system modules. These implement a lot of manipulation macros.
%D We start with setting up some basic \TEX\ machinery.
-\loadmkxlfile{syst-ini} % LMTX
+\loadmkxlfile{syst-ini}
%D We just quit if new functionality is expected.
@@ -100,7 +100,7 @@
\loadmkxlfile{catc-ctx}
\loadmarkfile{catc-sym}
-\loadmarkfile{toks-ini}
+\loadmkxlfile{toks-ini}
\loadmarkfile{cldf-ini}
% \tracecatcodetables
@@ -109,13 +109,13 @@
%D \type {\unexpanded} long before etex came around.
\loadmarkfile{luat-ini}
-\loadmarkfile{toks-scn}
+\loadmkxlfile{toks-scn}
-\loadmkxlfile{syst-aux} % LMTX
-\loadmkxlfile{syst-lua} % LMTX
-\loadmkxlfile{syst-con} % LMTX
+\loadmkxlfile{syst-aux}
+\loadmkxlfile{syst-lua}
+\loadmkxlfile{syst-con}
-\loadmarkfile{syst-fnt}
+\loadmkxlfile{syst-fnt}
\loadmarkfile{syst-rtp}
\loadmarkfile{luat-usr}
@@ -124,7 +124,7 @@
\loadmkvifile{file-res}
\loadmkvifile{file-lib}
-\loadmkxlfile{core-lmt} % LMTX
+\loadmkxlfile{core-lmt}
%D This needs more checking for clashes:
%D
@@ -134,13 +134,13 @@
\loadmarkfile{supp-dir}
-\loadmarkfile{char-utf}
+\loadmkxlfile{char-utf}
\loadmkxlfile{char-ini}
\loadmarkfile{char-act}
\loadmkxlfile{mult-ini}
\loadmkxlfile{mult-sys}
-\loadmkxlfile{mult-aux} % LMTX
+\loadmkxlfile{mult-aux}
\loadmarkfile{mult-def}
\loadmarkfile{mult-chk}
\loadmkvifile{mult-dim}
@@ -166,12 +166,12 @@
\loadmkxlfile{node-mig}
%loadmarkfile{node-pag}
-\loadmkxlfile{driv-ini} % LMTX
+\loadmkxlfile{driv-ini}
-\loadmkxlfile{back-ini} % LMTX
+\loadmkxlfile{back-ini}
\loadmarkfile{back-res}
\loadmarkfile{back-trf}
-\loadmkxlfile{back-out} % LMTX
+\loadmkxlfile{back-out}
\loadmarkfile{attr-col}
\loadmarkfile{attr-lay}
@@ -182,7 +182,7 @@
\loadmarkfile{trac-tex}
\loadmarkfile{trac-deb} % will move up
-\loadmkxlfile{supp-box} % LMTX
+\loadmkxlfile{supp-box}
\loadmarkfile{supp-ran}
\loadmarkfile{supp-mat}
@@ -190,7 +190,7 @@
\loadmarkfile{core-uti}
\loadmkvifile{file-job}
-\loadmarkfile{anch-pos}
+\loadmkxlfile{anch-pos}
\loadmarkfile{typo-ini}
\loadmarkfile{typo-lin}
@@ -206,13 +206,13 @@
\loadmarkfile{cont-fil}
-\loadmarkfile{regi-ini}
+\loadmkxlfile{regi-ini}
\loadmkxlfile{enco-ini}
\loadmkxlfile{hand-ini}
-\loadmkxlfile{lang-ini} % LMTX
+\loadmkxlfile{lang-ini}
\loadmarkfile{lang-hyp} % also loads dis
-\loadmkxlfile{lang-lab} % LMTX
+\loadmkxlfile{lang-lab}
\loadmarkfile{unic-ini}
@@ -220,28 +220,28 @@
\loadmarkfile{core-two}
\loadmarkfile{core-dat}
-\loadmkxlfile{colo-ini} % LMTX
+\loadmkxlfile{colo-ini}
\loadmarkfile{colo-grp} % optional
-\loadmarkfile{colo-ext}
+\loadmkxlfile{colo-ext}
\loadmarkfile{node-bck} % overloads anch-pgr (experimental and undocumented)
\loadmarkfile{pack-cut}
-\loadmkxlfile{lang-mis} % LMTX
+\loadmkxlfile{lang-mis}
\loadmarkfile{lang-url}
\loadmarkfile{lang-def}
% \loadmkvifile{file-job} % why so late?
-\loadmarkfile{symb-ini} % brrr depends on fonts
+\loadmkxlfile{symb-ini} % brrr depends on fonts
\loadmarkfile{sort-ini}
\loadmkvifile{pack-mis}
-\loadmkxlfile{pack-ori} % LMTX
-\loadmkxlfile{pack-rul} % LMTX
-\loadmkxlfile{pack-mrl} % LMTX
+\loadmkxlfile{pack-ori}
+\loadmkxlfile{pack-rul}
+\loadmkxlfile{pack-mrl}
\loadmkvifile{pack-bck}
\loadmarkfile{pack-fen}
@@ -251,13 +251,11 @@
\loadmkvifile{typo-prc}
\loadmkivfile{typo-plc}
-% \loadmarkfile{anch-pos}
-
-\loadmkvifile{strc-ini}
+\loadmklxfile{strc-ini}
\loadmarkfile{strc-tag}
\loadmarkfile{strc-doc}
-\loadmarkfile{strc-num}
-\loadmarkfile{strc-mar}
+\loadmkxlfile{strc-num}
+\loadmkxlfile{strc-mar}
\loadmkxlfile{strc-sbe}
\loadmkvifile{strc-lst}
\loadmkxlfile{strc-sec}
@@ -272,7 +270,7 @@
\loadmkxlfile{spac-hor}
\loadmkxlfile{spac-ali}
\loadmarkfile{spac-flr}
-\loadmkxlfile{spac-ver} % LMTX beware, hooks into strc-sec
+\loadmkxlfile{spac-ver} % beware, hooks into strc-sec
\loadmarkfile{spac-lin}
\loadmarkfile{spac-pag}
\loadmkxlfile{spac-par}
@@ -280,14 +278,12 @@
\loadmkvifile{spac-prf}
\loadmkxlfile{spac-grd}
-%loadmarkfile{anch-pos}
-
\loadmkvifile{scrn-ini}
\loadmkvifile{scrn-ref}
\loadmarkfile{pack-obj}
-\loadmklxfile{strc-itm} % LMTX
+\loadmklxfile{strc-itm}
\loadmklxfile{strc-con}
\loadmklxfile{strc-des}
@@ -313,7 +309,7 @@
\loadmarkfile{page-one}
\loadmkxlfile{page-lay}
\loadmkvifile{page-box}
-\loadmklxfile{page-txt} % LMTX
+\loadmklxfile{page-txt}
\loadmarkfile{page-sid} % when
\loadmkvifile{strc-flt}
@@ -326,10 +322,10 @@
%loadmarkfile{page-set} % \usecolumns[old-columnsets]
\loadmarkfile{page-cst}
\loadmarkfile{page-pcl} % new
-\loadmkxlfile{pack-lyr} % LMTX
+\loadmkxlfile{pack-lyr}
\loadmarkfile{pack-pos}
\loadmkvifile{page-mak}
-\loadmkxlfile{page-mcl} % LMTX
+\loadmkxlfile{page-mcl}
\loadmarkfile{strc-reg} % uses mixed columns
@@ -340,7 +336,7 @@
\loadmarkfile{typo-itm}
\loadmarkfile{buff-ini}
-\loadmkxlfile{buff-ver} % LMTX
+\loadmkxlfile{buff-ver}
\loadmkvifile{buff-par}
\loadmarkfile{buff-imp-tex} % optional as also runtime if not loaded
@@ -371,26 +367,26 @@
\loadmkvifile{scrn-fld}
\loadmkvifile{scrn-hlp}
-\loadmarkfile{char-enc} % will move up
+\loadmarkfile{char-enc} % will move up, can be in char-utf
\loadmkvifile{font-lib} % way too late but after language
-\loadmklxfile{font-fil} % LMTX
+\loadmklxfile{font-fil}
\loadmkvifile{font-var}
\loadmklxfile{font-fea}
-\loadmklxfile{font-mat} % LMTX
-\loadmklxfile{font-ini} % LMTX
-\loadmklxfile{font-sym} % LMTX
-\loadmklxfile{font-sty} % LMTX
+\loadmklxfile{font-mat}
+\loadmklxfile{font-ini}
+\loadmklxfile{font-sym}
+\loadmklxfile{font-sty}
\loadmkvifile{font-set}
-\loadmklxfile{font-emp} % LMTX
+\loadmklxfile{font-emp}
\loadmarkfile{font-pre}
\loadmarkfile{font-unk}
\loadmarkfile{font-tra}
-\loadmarkfile{font-chk}
+\loadmkxlfile{font-chk}
\loadmarkfile{font-uni}
-\loadmkvifile{font-col}
+\loadmklxfile{font-col}
\loadmkvifile{font-gds}
-\loadmkvifile{font-aux}
+\loadmklxfile{font-aux}
\loadmkvifile{font-sel}
\loadmarkfile{typo-tal}
@@ -401,8 +397,8 @@
\loadmkxlfile{tabl-tab} % thrd-tab stripped and merged
-\loadmkxlfile{tabl-tbl} % LMTX
-\loadmkxlfile{tabl-ntb} % LMTX
+\loadmkxlfile{tabl-tbl}
+\loadmkxlfile{tabl-ntb}
\loadmkxlfile{tabl-nte}
\loadmkxlfile{tabl-ltb}
\loadmkxlfile{tabl-frm}
@@ -441,21 +437,22 @@
\loadmkivfile{typo-fkr}
\loadmkivfile{typo-pnc}
-\loadmklxfile{type-ini} % LMTX
+\loadmklxfile{type-ini}
\loadmarkfile{type-set}
\loadmarkfile{scrp-ini}
\loadmarkfile{symb-emj}
+\loadmarkfile{lang-tra} % can be optional (discussion with mm sideeffect)
\loadmarkfile{lang-wrd} % can be optional (discussion with mm sideeffect)
\loadmarkfile{lang-rep} % can be optional (bt 2013 side effect)
\loadmarkfile{prop-ini} % only for downward compatibility
-\loadmkxlfile{mlib-ctx} % LMTX % messy order
+\loadmkxlfile{mlib-ctx} % messy order
-\loadmkxlfile{meta-ini} % LMTX
+\loadmkxlfile{meta-ini}
\loadmarkfile{meta-tex}
\loadmarkfile{meta-fun}
\loadmkxlfile{meta-pag}
@@ -463,7 +460,7 @@
\loadmarkfile{meta-fnt}
\loadmarkfile{meta-nod}
\loadmarkfile{meta-lua}
-\loadmkxlfile{meta-mac} % LMTX
+\loadmkxlfile{meta-mac}
\loadmarkfile{page-mrk} % depends on mp
@@ -474,7 +471,7 @@
\loadmarkfile{anch-pgr} % can be moved up (nicer for dependencies)
\loadmkvifile{anch-bck}
-\loadmarkfile{anch-tab} % overloads tabl-tbl
+\loadmkxlfile{anch-tab} % overloads tabl-tbl
\loadmarkfile{anch-bar}
%loadmarkfile{anch-snc} % when needed this one will be redone
@@ -520,7 +517,7 @@
\loadmarkfile{typo-del}
\loadmarkfile{grph-trf}
-\loadmarkfile{grph-inc}
+\loadmkxlfile{grph-inc}
\loadmarkfile{grph-fig}
\loadmarkfile{grph-raw}
\loadmarkfile{grph-rul}
@@ -570,14 +567,14 @@
% now we hook in backend code (needs checking)
-\loadmkxlfile{driv-shp} % LMTX
+\loadmkxlfile{driv-shp}
\loadmarkfile{back-exp}
-\loadmkxlfile{back-pdf} % LMTX
-\loadmkxlfile{back-mps} % LMTX
-\loadmkxlfile{back-lua} % LMTX
+\loadmkxlfile{back-pdf}
+\loadmkxlfile{back-mps}
+\loadmkxlfile{back-lua}
-\loadmkxlfile{mlib-pdf} % LMTX
+\loadmkxlfile{mlib-pdf}
\loadmarkfile{mlib-pps}
\loadmarkfile{meta-pdf}
\loadmarkfile{meta-blb}
diff --git a/tex/context/base/mkiv/core-env.mkxl b/tex/context/base/mkiv/core-env.mkxl
index 2d7c22afd..8b22275e1 100644
--- a/tex/context/base/mkiv/core-env.mkxl
+++ b/tex/context/base/mkiv/core-env.mkxl
@@ -378,13 +378,13 @@
\def\doprocesslocalsetups#1% sort of public, fast local variant
{\edef\m_syst_setups_asked{#1}%
- \ifx\m_syst_setups_asked\empty\else
+ \ifempty\m_syst_setups_asked\else
\expandafter\syst_setups_process_local
\fi}
\protected\def\usesetupsparameter#1%
{\edef\m_syst_setups_asked{#1\c!setups}%
- \ifx\m_syst_setups_asked\empty\else
+ \ifempty\m_syst_setups_asked\else
\expandafter\syst_setups_process_local
\fi}
@@ -692,7 +692,7 @@
\def\syst_variables_check_value#1#2#3%
{\ifcsname\??variables#1:#2\endcsname
\edef\m_syst_variables_temp{\lastnamedcs}%
- \ifx\m_syst_variables_temp\empty
+ \ifempty\m_syst_variables_temp
\expandafter\def\csname\??variables#1:#2\endcsname{#3}%
\fi
\else
@@ -734,7 +734,7 @@
\permanent\protected\def\doifelseemptyvariable#1#2%
{\edef\m_syst_string_one{\begincsname\??variables#1:#2\endcsname}%
- \ifx\m_syst_string_one\empty
+ \ifempty\m_syst_string_one
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
@@ -744,7 +744,7 @@
\permanent\protected\def\doifemptyvariable#1#2%
{\edef\m_syst_string_one{\begincsname\??variables#1:#2\endcsname}%
- \ifx\m_syst_string_one\empty
+ \ifempty\m_syst_string_one
\expandafter\firstofoneargument
\else
\expandafter\gobbleoneargument
@@ -752,7 +752,7 @@
\permanent\protected\def\doifnotemptyvariable#1#2%
{\edef\m_syst_string_one{\begincsname\??variables#1:#2\endcsname}%
- \ifx\m_syst_string_one\empty
+ \ifempty\m_syst_string_one
\expandafter\gobbleoneargument
\else
\expandafter\firstofoneargument
diff --git a/tex/context/base/mkiv/enco-ini.mkiv b/tex/context/base/mkiv/enco-ini.mkiv
index e4343ba2d..26f218b03 100644
--- a/tex/context/base/mkiv/enco-ini.mkiv
+++ b/tex/context/base/mkiv/enco-ini.mkiv
@@ -427,7 +427,7 @@
{\char \iffontchar\font"2012 "2012 % figuredash
\else\iffontchar\font"2013 "2013 % endash
\else\iffontchar\font"2212 "2212 % math minus
- "002D % hyphen
+ \else "002D % hyphen
\fi\fi\fi}
\unexpanded\def\textplus
diff --git a/tex/context/base/mkiv/enco-ini.mkxl b/tex/context/base/mkiv/enco-ini.mkxl
index 609aa28da..dfd6075c9 100644
--- a/tex/context/base/mkiv/enco-ini.mkxl
+++ b/tex/context/base/mkiv/enco-ini.mkxl
@@ -421,11 +421,11 @@
\pushoverloadmode
\permanent\protected\def\textminus
- {\char \iffontchar\font"2012 "2012 % figuredash
- \else\iffontchar\font"2013 "2013 % endash
- \else\iffontchar\font"2212 "2212 % math minus
- "002D % hyphen
- \fi\fi\fi}
+ {\char
+ \iffontchar\font"2012 "2012 \orelse % figuredash
+ \iffontchar\font"2013 "2013 \orelse % endash
+ \iffontchar\font"2212 "2212 \else % math minus
+ "002D \fi} % hyphen
\permanent\protected\def\textplus
{\char"002B } % plus
diff --git a/tex/context/base/mkiv/font-aux.mklx b/tex/context/base/mkiv/font-aux.mklx
new file mode 100644
index 000000000..caf32510e
--- /dev/null
+++ b/tex/context/base/mkiv/font-aux.mklx
@@ -0,0 +1,26 @@
+%D \module
+%D [ file=font-gds,
+%D version=2012.06.26,
+%D title=\CONTEXT\ Font Support,
+%D subtitle=Helpers,
+%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 Font Support / Helpers}
+
+%D Here we collect code moved from other files, like some of the
+%D support modules.
+
+\unprotect
+
+%D Leftovers:
+
+\permanent\protected\def\xbox {\bgroup\aftergroup\egroup\hbox\bgroup\tx \let\next=}
+\permanent\protected\def\xxbox{\bgroup\aftergroup\egroup\hbox\bgroup\txx\let\next=}
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/font-chk.mkxl b/tex/context/base/mkiv/font-chk.mkxl
new file mode 100644
index 000000000..b84056e4e
--- /dev/null
+++ b/tex/context/base/mkiv/font-chk.mkxl
@@ -0,0 +1,29 @@
+%D \module
+%D [ file=font-chk,
+%D version=2009.01.02, % moved from font-tra
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=Checking,
+%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 Font Macros / Checking}
+
+\registerctxluafile{font-chk}{}
+
+\tracinglostchars\zerocount
+
+% Use this instead:
+%
+% \definefontfeature[default][default][missing=yes]
+% \enabletrackers[fonts.missing=replace]
+
+\permanent\protected\def\checkcharactersinfont {\enabletrackers[fonts.missing]}
+\permanent\protected\def\removemissingcharacters {\enabletrackers[fonts.missing=remove]}
+\permanent\protected\def\replacemissingcharacters{\enabletrackers[fonts.missing=replace]}
+
+\endinput
diff --git a/tex/context/base/mkiv/font-col.mklx b/tex/context/base/mkiv/font-col.mklx
new file mode 100644
index 000000000..1dd5b25c6
--- /dev/null
+++ b/tex/context/base/mkiv/font-col.mklx
@@ -0,0 +1,148 @@
+%D \module
+%D [ file=font-col,
+%D version=2008.06.11,
+%D title=\CONTEXT\ Font Macros,
+%D subtitle=Fallbacks (collections),
+%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.
+
+% todo : missing only, force always, multiple fallbacks with test, scale
+% beware : only english key/values
+%
+% \resetfontfallback [whatever]
+%
+% \definefontfallback [whatever] [Slanted] [0x0060-0x007F] [force=yes]
+% \definefontfallback [whatever] [Bold] [0x0080-0x00FF,0x00A0-0x00AF] [rscale=1.2]
+% \definefontfallback [whatever] [BoldSlanted] [0x00C0-0x00C7] [check=yes,force=yes]
+%
+% \definefontfeature [emboldened] [effect={width=0.1,delta=0.4,factor=0.3}]
+% \definefontsynonym [SansEmboldened] [Sans] [features=emboldened]
+% \definefontfallback[FakeSansCaps] [SansEmboldened] [0x0000-0xFFFF] [rscale=.8,method=uppercase]
+% \definefontsynonym [SansCaps] [file:MyriadPro-Regular.otf] [fallbacks=FakeSansCaps]
+
+\writestatus{loading}{ConTeXt Font Macros / Collections}
+
+\registerctxluafile{font-col}{}
+
+\unprotect
+
+\permanent\tolerant\protected\def\definefontfallback[#name]#spacer[#font]#spacer[#ranges]#spacer[#settings]%
+ {\let\mathsizesuffix\relax
+ \clf_fontcollectiondefine{#name}{#font}{#ranges}{#settings}%
+ \let\mathsizesuffix\empty}
+
+\permanent\tolerant\protected\def\resetfontfallback[#name]#spacer[#font]%
+ {\clf_fontcollectionreset{#name}{#font}}
+
+\def\font_fallbacks_prepare#name%
+ {\clf_fontcollectionprepare{#name}} % add fallbacks to last font
+
+% we might as well move the handling to lua but then we need to pass the
+% fallbacks, skewchar etc.
+
+\newconditional\c_font_fallbacks_in_progress
+
+\def\font_fallbacks_prepare_indeed#fallbacks%
+ {\begingroup
+ \settrue\c_font_fallbacks_in_progress
+ \lastrawfontcall % sets current font id
+ \font_fallbacks_prepare#fallbacks%
+ \endgroup}
+
+\let\m_font_fallbacks\empty % set in the font-ini
+
+\appendtoks
+ \ifconditional\c_font_fallbacks_in_progress\else
+ \ifempty\m_font_fallbacks
+ \ifempty\m_font_class_fallbacks\else
+ \font_fallbacks_prepare_indeed\m_font_class_fallbacks
+ \fi
+ \else
+ \font_fallbacks_prepare_indeed\m_font_fallbacks
+ \fi
+ \fi
+\to\everydefinefont
+
+\def\font_fallbacks_start_cloning
+ {\begingroup
+ \let\savedfontspec\somefontspec}
+
+\def\font_fallbacks_stop_cloning
+ {\endgroup}
+
+\def\font_fallbacks_clone_unique#specification#scale% kind of dododefinefont
+ {\clf_fontcollectionreport{defining #specification (relative scale: #scale)}% brrr
+ \setfalse\c_font_auto_size
+ \let\lastfontidentifier\s!dummy
+ \def\v_font_size_relative{#scale}%
+ \let\v_font_size_absolute\fontbody
+ \font_helpers_low_level_define{#specification}\v_font_identifier_basic
+ \csname\v_font_identifier_basic\endcsname
+ \setfalse\c_font_auto_size} % no \setfontcharacteristics and \the\everyfontswitch needed
+
+\def\font_fallbacks_clone_inherited#font% also a second argument
+ {\font_fallbacks_clone_unique{#font \savedfontspec}}
+
+\def\font_fallbacks_register_main #name{\clf_fontcollectionregister{#name}}
+\def\font_fallbacks_prepare_clone_vectors#name{\clf_fontcollectionclone{#name}}
+
+% math (experiment, todo clf_)
+
+\def\font_fallbacks_register_math#1#2#3#4%
+ {\doifelsenothing{#3}%
+ {\definedfont[#2 at #4sp]}%
+ {\definedfont[#2*#3\space at #4\scaledpoint]}%
+ \clf_registerfontfallbackid#1\space\fontid\font\space{#2}}
+
+% \def\font_fallbacks_finish_math
+% {\ctxlua{mathematics.finishfallbacks()}}
+
+% check : only replace when present in replacement font (default: no)
+% force : force replacent even when basefont has glyph (default: yes)
+
+% \definefontfallback [whatever] [Slanted] [0x0060-0x007F] [force=yes]
+% \definefontfallback [whatever] [Bold] [0x0080:0x00FF,0x00A0:0x00AF] [rscale=2.0]
+% \definefontfallback [whatever] [BoldSlanted] ["00C0-"00C7] [check=yes,force=yes]
+% \definefontfallback [whatever] [Mono] [latinextendeda] [force=yes] % 0x0100:0x017F
+% \definefontfallback [whatever] [Mono] [latin extended a] [force=yes] % 0x0100:0x017F
+%
+% \definefontsynonym[SerifPlus][Serif][fallbacks=whatever]
+%
+% \showfont[SerifPlus][all]
+
+% \definefontfeature[zh][mode=node,script=hang,lang=zhs]
+% \definefontfallback[serifwhatever] [lmroman10-regular] [0x0000-0x0400][force=yes]
+% \definefontfallback[serifboldwhatever] [lmroman10-bold] [0x0000-0x0400][force=yes]
+% \definefontfallback[serifitalicwhatever] [lmroman10-italic] [0x0000-0x0400][force=yes]
+% \definefontfallback[serifbolditalicwhatever][lmroman10-bolditalic][0x0000-0x0400][force=yes]
+%
+% \starttypescript [serif] [zhfont]
+% \definefontsynonym [zhserif] [AdobeSongStd-Light] [features=zh,fallbacks=serifwhatever]
+% \definefontsynonym [zhserifbold] [AdobeHeitiStd-Regular][features=zh,fallbacks=serifboldwhatever]
+% \definefontsynonym [zhserifitalic] [AdobeKaitiStd-Regular][features=zh,fallbacks=serifitalicwhatever]
+% \definefontsynonym [zhserifbolditalic][AdobeHeitiStd-Regular][features=zh,fallbacks=serifbolditalicwhatever]
+% \stoptypescript
+%
+% \starttypescript [serif][zhfont][name]
+% \definefontsynonym[Serif] [zhserif] % [fallbacks=serifwhatever]
+% \definefontsynonym[SerifBold] [zhserifbold] % [fallbacks=serifboldwhatever]
+% \definefontsynonym[SerifItalic] [zhserifitalic] % [fallbacks=serifitalicwhatever]
+% \definefontsynonym[SerifBoldItalic] [zhserifbolditalic] % [fallbacks=serifbolditalicwhatever]
+% \stoptypescript
+%
+% \starttypescript[myfont]
+% \definetypeface[myfont][rm][serif][zhfont]
+% \stoptypescript
+%
+% \usetypescript[myfont] \setupbodyfont[myfont,rm,12pt]
+%
+% \starttext
+% fonts {\bf fonts} {\bi fonts} {\it fonts}
+% \stoptext
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/font-fea.mklx b/tex/context/base/mkiv/font-fea.mklx
index 010f95500..c92bc21eb 100644
--- a/tex/context/base/mkiv/font-fea.mklx
+++ b/tex/context/base/mkiv/font-fea.mklx
@@ -345,7 +345,7 @@
\permanent\protected\def\useaddfontfeatureparameter#namespace% faster local variant
{\edef\m_font_feature_asked{#namespace\c!features}%
- \ifx\m_font_feature_asked\empty\else
+ \ifempty\m_font_feature_asked\else
\font_feature_add
\fi}
diff --git a/tex/context/base/mkiv/font-ini.mklx b/tex/context/base/mkiv/font-ini.mklx
index a9e01e7ec..af1414b14 100644
--- a/tex/context/base/mkiv/font-ini.mklx
+++ b/tex/context/base/mkiv/font-ini.mklx
@@ -428,9 +428,9 @@
\def\thenormalizedbodyfontsize#body%
{\clf_nbfs\dimexpr#body\relax}
-\protected\edef\normalizedglobalbodyfontsize{\thenormalizedbodyfontsize\bodyfontsize}
-\protected\edef\normalizedlocalbodyfontsize {\thenormalizedbodyfontsize\bodyfontsize}
-\protected\edef\normalizedbodyfontsize {\thenormalizedbodyfontsize\bodyfontsize}
+\edef\normalizedglobalbodyfontsize{\thenormalizedbodyfontsize\bodyfontsize}
+\edef\normalizedlocalbodyfontsize {\thenormalizedbodyfontsize\bodyfontsize}
+\edef\normalizedbodyfontsize {\thenormalizedbodyfontsize\bodyfontsize}
%D \macros
%D {mapfontsize}
diff --git a/tex/context/base/mkiv/grph-inc.mkiv b/tex/context/base/mkiv/grph-inc.mkiv
index 693e55d2f..0b8065989 100644
--- a/tex/context/base/mkiv/grph-inc.mkiv
+++ b/tex/context/base/mkiv/grph-inc.mkiv
@@ -23,11 +23,6 @@
\registerctxluafile{grph-img}{}
\registerctxluafile{grph-inc}{}
-\ifcase\contextlmtxmode \else
- \registerctxluafile{grph-bmp}{}
- \registerctxluafile{grph-chk}{}
-\fi
-
\registerctxluafile{grph-con}{}
\registerctxluafile{grph-fil}{}
\registerctxluafile{grph-mem}{}
@@ -416,7 +411,7 @@
\else\ifx\p_crossreference\v!no
% nothing
\else\ifx\p_crossreference\v!yes
- \ifassignment
+ \ifcondition\validassignment{#2}%
\scratchcounter\clf_figure_register_page{#1}{}{#2}\relax
\else
\scratchcounter\clf_figure_register_page{#1}{#2}{#3}\relax
@@ -903,25 +898,6 @@
\unexpanded\def\overlayfigure#1%
{\externalfigure[#1][\c!width=\d_overlay_width,\c!height=\d_overlay_height]}
-% Experimental (will become cleaner):
-
-\ifcase\contextlmtxmode \else
-
- \unexpanded\def\includesvgfile {\dontleavehmode\begingroup\dodoubleempty\grph_include_svg_file}
- \unexpanded\def\includesvgbuffer{\dontleavehmode\begingroup\dodoubleempty\grph_include_svg_buffer}
-
- \def\grph_include_svg_file[#1][#2]%
- {\getdummyparameters[\c!offset=\zeropoint,#2]%
- \clf_includesvgfile{#1}\dimexpr\dummyparameter\c!offset\relax
- \endgroup}
-
- \def\grph_include_svg_buffer[#1][#2]%
- {\getdummyparameters[\c!offset=\zeropoint,#2]%
- \clf_includesvgbuffer{#1}\dimexpr\dummyparameter\c!offset\relax
- \endgroup}
-
-\fi
-
% Bonus:
\useexternalfigure
diff --git a/tex/context/base/mkiv/grph-inc.mkxl b/tex/context/base/mkiv/grph-inc.mkxl
new file mode 100644
index 000000000..1e6d614a6
--- /dev/null
+++ b/tex/context/base/mkiv/grph-inc.mkxl
@@ -0,0 +1,1076 @@
+%D \module
+%D [ file=grph-inc, % moved from core-fig
+%D version=2006.08.26, % overhaul of 1997.03.31
+%D title=\CONTEXT\ Graphic Macros,
+%D subtitle=Figure Inclusion,
+%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.
+
+% \enabledirectives[graphics.conversion.eps.cleanup.ai]
+
+% \setupexternalfigures[directory=dirfile://./test/**]
+% \externalfigure[crappname(2).eps][frame=on]
+
+% todo: messages
+
+\writestatus{loading}{ConTeXt Graphic Macros / Figure Inclusion}
+
+\registerctxluafile{grph-img}{}
+\registerctxluafile{grph-inc}{}
+\registerctxluafile{grph-bmp}{}
+\registerctxluafile{grph-chk}{}
+\registerctxluafile{grph-con}{}
+\registerctxluafile{grph-fil}{}
+\registerctxluafile{grph-mem}{}
+\registerctxluafile{grph-u3d}{} % this will become a module
+\registerctxluafile{grph-swf}{} % this will become a module
+
+\unprotect
+
+%D Including graphics is complicated by the fact that we need to locate them first,
+%D optionally manipulate them and scale then next. Lookups are to be done as efficient
+%D as possible and inclusion of the data might happens only once. In \MKIV\ much of this
+%D is delegated to the \LUA\ end. There is not so much less code as in \MKII\ but it's
+%D more powerful, flexible, pluggable and some of the extended functionality has been
+%D moved from modules to the core. The overall functionality is rather stable and has
+%D not changed much over the years.
+
+\ifdefined\dotagfigure \else \let\dotagfigure\relax \fi
+
+\installcorenamespace{externalfigure}
+\installcorenamespace{externalfigureinstance}
+\installcorenamespace{externalfigurecollection}
+
+\installframedcommandhandler \??externalfigure {externalfigure} \??externalfigure
+
+\aliased\let\setupexternalfigures\setupexternalfigure
+
+\setupexternalfigures[% we really need the defaults
+ \c!method =,
+ \c!label =,
+ \c!size =,
+ \c!conversion =,
+ \c!resolution =,
+ \c!prefix =,
+ \c!cache =,
+ \c!page =\zerocount,
+ \c!file =,
+ \c!display =,
+ \c!mask =,
+ \c!preset =\v!yes,
+ \c!split =,
+ \c!color =,
+ \c!arguments =,
+ \c!symbol =\v!no,
+ \c!controls =\v!no,
+ \c!resources =,
+ \c!preview =\v!no,
+ \c!repeat =\v!no,
+ \c!foregroundcolor=,
+ \c!interaction =\v!none,
+ \c!hfactor =,
+ \c!wfactor =,
+ \c!factor =,
+ \c!maxwidth =\externalfigureparameter\c!width,
+ \c!maxheight =\externalfigureparameter\c!height,
+ \c!xscale =,
+ \c!yscale =,
+ \c!scale =,
+ \c!sx =\externalfigureparameter\c!s,
+ \c!sy =\externalfigureparameter\c!s,
+ \c!s =1,
+ \c!width =,
+ \c!height =,
+ \c!lines =,
+ \c!grid =,
+ \c!bodyfont =\bodyfontsize,
+ \c!object =\v!yes,
+ \c!corner =\v!rectangular,
+ \c!frame =\v!off,
+ \c!option =,
+ \c!reset =\v!no,
+ \c!directory =,
+ \c!radius =.5\bodyfontsize,
+ \c!background =,
+ \c!splitcolor =\s!white,
+ \c!order =,
+ \c!equalwidth =,
+ \c!equalheight =,
+ \c!location ={\v!local,\v!global},
+ \c!frames =\v!off,
+ \c!ymax =24,
+ \c!xmax =,
+ \c!align =\v!none, % New, for Tacos extremely large graphics.
+ \c!crossreference =\v!no,
+ \c!transform =\v!auto,
+ \c!userpassword =,
+ \c!ownerpassword =,
+ \c!compact =,
+ \c!cmyk =,
+ ]
+
+%D Defining figures.
+
+\newcount\c_grph_include_nesting
+
+\newtoks \everyexternalfigureresets % for the moment still public
+\newtoks \everyexternalfigurechecks % for the moment still public
+
+% \useexternalfigure[alpha][cow]
+% \useexternalfigure[beta] [cow] [width=1cm]
+% \useexternalfigure[gamma][cow][alpha]
+% \useexternalfigure[delta][cow][alpha][width=2cm]
+%
+% full width : \externalfigure[cow] \par
+% 3cm width : \externalfigure[cow] [width=3cm] \par
+% full width : \externalfigure[alpha] \par
+% 1cm width : \externalfigure[beta] \par
+% full width : \externalfigure[gamma] \par
+% 2cm width : \externalfigure[delta] \par
+% 4cm width : \externalfigure[beta] [width=4cm] \par
+% 5cm width : \externalfigure[gamma][width=5cm] \par
+%
+% \defineexternalfigure[a][width=10cm]
+% \defineexternalfigure[b][width=5cm]
+% \externalfigure[cow][a]
+% \externalfigure[cow][b][height=8cm]
+%
+% \useexternalfigure[x][cow][width=10cm,height=1cm]
+% \externalfigure[x]
+% \externalfigure[x][width=3cm]
+%
+% [label] [filename]
+% [label] [filename] [parent]
+% [label] [filename] [parent] [settings]
+% [label] [filename] [settings]
+%
+% new: more convenient/efficient than
+%
+% \use..[a][a][setting] \externalfigure[b][a]
+%
+% is equivalent to:
+%
+% \def..[a][setting] \externalfigure[b][a]
+%
+% see x-res modules for usage:
+%
+% \defineexternalfigure[name][settings]
+
+%D Defining is persistent, i.e.\ when you redefine an instance, the already set
+%D parameters need to be set again or otherwise the old values will be used.
+%D
+%D New: \type {method=auto}: strips suffix and uses \quote {order} which is handy in
+%D some of four workflows where sources are used for web and print and where the web
+%D tools need a suffix (like gif) which we don't want as we want a high quality
+%D format.
+
+\newconditional\c_grph_include_trace_inheritance
+
+\installtextracker
+ {graphics.inheritance}
+ {\settrue \c_grph_include_trace_inheritance}
+ {\setfalse\c_grph_include_trace_inheritance}
+
+\installcorenamespace{externalfiguredefinition}
+
+% \protected\def\defineexternalfigure
+% {\dodoubleargument\grph_include_define}
+%
+% \def\grph_include_define[#1][#2]%
+% {\setvalue{\??externalfiguredefinition#1}{\setupcurrentexternalfigure[#2]}}
+
+\aliased\let\defineexternalfigures\defineexternalfigure
+
+% label file parent settings
+% label file settings
+% label file parent
+
+\permanent\tolerant\protected\def\useexternalfigure[#1]#*[#2]#*[#3]#*[#4]%
+ {\iftok{#1}\emptytoks
+ \iftok{#2}\emptytoks\else
+ \ifhastok={#3}%
+ \grph_include_use_indeed{#2}{#2}{#3}{#4}%
+ \else
+ \grph_include_use_indeed{#2}{#2}\empty{#4}%
+ \fi
+ \fi
+ \orelse\iftok{#2}\emptytoks
+ \ifhastok={#3}%
+ \grph_include_use_indeed{#1}{#1}\empty{#3}%
+ \else
+ \grph_include_use_indeed{#1}{#1}{#3}{#4}%
+ \fi
+ \else
+ \ifhastok={#3}%
+ \grph_include_use_indeed{#1}{#2}\empty{#3}
+ \else
+ \grph_include_use_indeed{#1}{#2}{#3}{#4}%
+ \fi
+ \fi}
+
+\def\grph_include_use_indeed#1#2#3#4%
+ {\dodoglobal\setvalue{\??externalfigureinstance#1}{\grph_include_setup{#2}{#3}{#4}}%
+ \grph_include_analyze_collection[#2][#4]}
+
+% inclusion
+
+\permanent\tolerant\protected\def\externalfigure[#1]#*[#2]#*[#3]%
+ {\ifhastok={#2}%
+ \grph_include_place[#1][][#2]%
+ \else
+ \grph_include_place[#1][#2][#3]%
+ \fi}
+
+% todo: chain them
+
+\def\grph_include_setup#1#2#3% name parent settings
+ {\edef\m_grph_include_name {#1}%
+ \edef\m_grph_include_parent{#2}%
+ \ifempty\m_grph_include_name \else
+ \let\p_grph_include_name\m_grph_include_name
+ \fi
+ \ifempty\m_grph_include_parent \else
+ \grph_include_inherit_from_parent\m_grph_include_parent
+ \fi
+ \setupcurrentexternalfigure[#3]}
+
+\def\grph_include_inherit_from_parent#1%
+ {\ifcsname\??externalfigure#1:\s!parent\endcsname
+ \let\currentexternalfigure#1%
+ \fi
+ \ifcsname\??externalfigureinstance#1\endcsname
+ \ifconditional\c_grph_include_trace_inheritance\writestatus\m!figures{inheriting from instance: #1}\fi
+ \csname\??externalfigureinstance#1\endcsname
+ \fi}
+
+\newtoks\t_grph_include_local_settings
+
+\appendtoks
+ \let\textunderscore\letterunderscore % {\string _} % space needed as _ is now letter in unprotected mode (probably no longer needed)
+ %
+ \dontcomplain
+ \restorecatcodes
+ \forgetall
+\to \t_grph_include_local_settings
+
+\def\grph_include_place_inherit
+ {\ifconditional\c_grph_include_trace_inheritance
+ \writestatus\m!figures{label: \p_grph_include_label, name: \p_grph_include_name, parent: \p_grph_include_parent}%
+ \fi
+ \ifempty\p_grph_include_parent
+ % nothing to be done
+ \orelse\ifx\p_grph_include_parent\p_grph_include_label
+ % redundant
+ \else
+ \grph_include_inherit_from_parent\p_grph_include_parent
+ \fi
+ \ifempty\p_grph_include_label
+ % nothing to be done
+ \else
+ \grph_include_inherit_from_parent\p_grph_include_label
+ \fi}
+
+\def\grph_include_place[#1][#2][#3]% [label][file][settings] | [file][settings] | [file][parent][settings]
+ {\bgroup
+ \advance\c_grph_include_nesting\plusone
+ \edef\currentexternalfigure{\the\c_grph_include_nesting}%
+ \checkexternalfigureparent % each inherits from the root
+ %
+ \the\everyexternalfigureresets
+ %
+ \edef\p_grph_include_label{#1}%
+ \let\p_grph_include_name\p_grph_include_label
+ \ifhastok={#2}%
+ % [label] [settings]
+ \let\p_grph_include_parent\p_grph_include_label
+ \grph_include_place_inherit
+ \setupcurrentexternalfigure[#2]%
+ \else
+ % [label] [parent] [settings]
+ \edef\p_grph_include_parent{#2}%
+ \ifempty\p_grph_include_parent
+ \let\p_grph_include_parent\p_grph_include_label
+ \fi
+ \grph_include_place_inherit
+ \setupcurrentexternalfigure[#3]%
+ \fi
+ %
+ \the\everyexternalfigurechecks
+ %
+ \the\t_grph_include_local_settings
+ %
+ \edef\p_width {\externalfigureparameter\c!width}%
+ \edef\p_height {\externalfigureparameter\c!height}%
+ \edef\p_label {\externalfigureparameter\c!label}%
+ \edef\p_reference{\externalfigureparameter\c!reference}%
+ %
+ \dostarttagged\t!image\empty
+ \clf_figure_push {
+ name {\p_grph_include_name}%
+ label {\ifempty\p_label\p_grph_include_label\else\p_label\fi}%
+ page {\externalfigureparameter\c!page}%
+ file {\externalfigureparameter\c!file}%
+ size {\externalfigureparameter\c!size}%
+ object {\externalfigureparameter\c!object}%
+ prefix {\externalfigureparameter\c!prefix}%
+ cache {\externalfigureparameter\c!cache}%
+ format {\externalfigureparameter\c!method}%
+ preset {\externalfigureparameter\c!prefix}%
+ controls {\externalfigureparameter\c!controls}%
+ resources {\externalfigureparameter\c!resources}%
+ preview {\externalfigureparameter\c!preview}%
+ display {\externalfigureparameter\c!display}%
+ mask {\externalfigureparameter\c!mask}%
+ conversion {\externalfigureparameter\c!conversion}%
+ resolution {\externalfigureparameter\c!resolution}%
+ color {\externalfigureparameter\c!color}% unprocessed raw key
+ cmyk {\externalfigureparameter\c!cmyk}% kind of special
+ arguments {\externalfigureparameter\c!arguments}% used for converters
+ repeat {\externalfigureparameter\c!repeat}%
+ transform {\externalfigureparameter\c!transform}%
+ compact {\externalfigureparameter\c!compact}% experiment, share fonts
+ userpassword {\externalfigureparameter\c!userpassword}%
+ ownerpassword{\externalfigureparameter\c!ownerpassword}%
+ \ifempty\p_width \else
+ width \dimexpr\p_width\relax
+ \fi
+ \ifempty\p_height \else
+ height \dimexpr\p_height\relax
+ \fi
+ }%\relax
+ \clf_figure_identify
+ \relax
+ \ifconditional\c_grph_include_test_only
+ \ifcase\figurestatus \else
+ \clf_figure_check
+ \clf_figure_dummy
+ \clf_figure_scale
+ \clf_figure_done
+ \fi
+ \grph_include_set_mode
+ \else
+ \ifcase\figurestatus
+ \clf_figure_dummy
+ \clf_figure_scale
+ \else
+ \clf_figure_check
+ \clf_figure_include
+ \clf_figure_scale
+ \fi
+ \clf_figure_done
+ \grph_include_set_mode
+ \grph_include_finalize
+ \fi
+ \clf_figure_pop
+ \dotagfigure
+ %
+ \scratchcounter\zerocount
+ \edef\p_crossreference{\externalfigureparameter\c!crossreference}%
+ \iflocation\iftrialtypesetting\else
+ \ifempty\p_crossreference
+ % nothing
+ \orelse\ifx\p_crossreference\v!no
+ % nothing
+ \orelse\ifx\p_crossreference\v!yes
+ \ifhastok={#2}%
+ \scratchcounter\clf_figure_register_page{#1}{}{#2}\relax
+ \else
+ \scratchcounter\clf_figure_register_page{#1}{#2}{#3}\relax
+ \fi
+ \else
+ \scratchcounter-\p_crossreference % passed by repeater
+ \fi
+ \fi\fi
+ \naturalvpack
+ attr \imageattribute \plustwo
+ \ifnum\scratchcounter>\zerocount
+ {\strc_references_cross_forward {ex:\number \scratchcounter}{\box\foundexternalfigure}}%
+ \orelse\ifnum\scratchcounter<\zerocount
+ {\strc_references_cross_backward{ex:\number-\scratchcounter}{\box\foundexternalfigure}}%
+ \else
+ {\box\foundexternalfigure}%
+ \fi
+ %
+ % \naturalvpack attr \imageattribute \plustwo \bgroup
+ % \ifcmpnum\scratchcounter\zerocount
+ % \strc_references_cross_backward{ex:\number-\scratchcounter}{\box\foundexternalfigure}%
+ % \or % equal
+ % \box\foundexternalfigure%
+ % \or % more
+ % \strc_references_cross_forward {ex:\number \scratchcounter}{\box\foundexternalfigure}%
+ % \fi
+ % \egroup
+ %
+ \dostoptagged
+ \egroup}
+
+%D Next we provide a cross referenced scale-up mechanism:
+
+\def\strc_references_cross_forward#1#2%
+ {\begingroup
+ \strc_references_set_simple_internal_reference{cross:b:#1}%
+ \naturalhpack
+ attr \destinationattribute\number\lastdestinationattribute
+ {\naturalhpack{\strc_references_flush_destination_nodes\directgotodumbbox{#2}[cross:f:#1]}}%
+ \endgroup}
+
+\def\strc_references_cross_backward#1#2%
+ {\begingroup
+ \strc_references_set_simple_internal_reference{cross:f:#1}%
+ \naturalhpack
+ attr \destinationattribute\number\lastdestinationattribute
+ {\naturalhpack{\strc_references_flush_destination_nodes\directgotodumbbox{#2}[cross:b:#1]}}%
+ \endgroup}
+
+\let\doexternalfigurerepeat\gobblefourarguments % called from lua end
+
+\permanent\tolerant\protected\def\placeregisteredexternalfigures[#1]%
+ {\page
+ \begingroup
+ \protected\def\doexternalfigurerepeat{\grph_include_place_registered_indeed{#1}}%
+ \dorecurse\clf_figure_nof_registered_pages
+ {\page
+ \clf_figure_flush_registered_pages\recurselevel
+ \page}%
+ \endgroup
+ \page}
+
+\protected\def\grph_include_place_registered_indeed#1#2#3#4#5% called from lua end
+ {\grph_include_place[#2][#3][#4,%
+ \c!hfactor=,\c!wfactor=,\c!factor=,%
+ \c!maxwidth=,\c!maxheight=,%
+ \c!xscale=,\c!yscale=,\c!scale=,%
+ \c!sx=,\c!sy=,\c!s=,%
+ \c!width=,\c!height=,%
+ \c!crossreference=#5,%
+ #1]}
+
+%D Scaling:
+
+\let\dowithfigure\relax % name might change (into a proper hook)
+
+\permanent\protected\def\doscalefigure % used at lua end
+ {\global\setbox\foundexternalfigure\vpack{\scale[\v!figure]{\dowithfigure{\box\foundexternalfigure}}}}
+
+\definescale % some day we will inherit
+ [\v!figure]
+ [\c!hfactor =\externalfigureparameter\c!hfactor,
+ \c!wfactor =\externalfigureparameter\c!wfactor,
+ \c!factor =\externalfigureparameter\c!factor,
+ \c!maxwidth =\externalfigureparameter\c!maxwidth ,
+ \c!maxheight =\externalfigureparameter\c!maxheight,
+ \c!equalwidth =\externalfigureparameter\c!equalwidth ,
+ \c!equalheight=\externalfigureparameter\c!equalheight,
+ \c!xscale =\externalfigureparameter\c!xscale,
+ \c!yscale =\externalfigureparameter\c!yscale,
+ \c!scale =\externalfigureparameter\c!scale,
+ \c!sx =\externalfigureparameter\c!sx,
+ \c!sy =\externalfigureparameter\c!sy,
+ \c!s =\externalfigureparameter\c!s,
+ \c!width =\externalfigureparameter\c!width,
+ \c!height =\externalfigureparameter\c!height,
+ \c!lines =\externalfigureparameter\c!lines]
+
+%D You can register additional suffixes with the following command:
+%D
+%D \starttyping
+%D \definegraphictypesynonym[jbig] [jb2]
+%D \definegraphictypesynonym[jbig2][jb2]
+%D \definegraphictypesynonym[jbg] [jb2]
+%D \stoptyping
+
+\permanent\tolerant\protected\def\definegraphictypesynonym[#1]#*[#2]%
+ {\clf_registerfiguresuffix{#1}{#2}}
+
+%D Additional paths can be installed with the regular setup command. The next
+%D macro picks up the list.
+
+\permanent\protected\def\setfigurepathlist
+ {\clf_setfigurepaths{\externalfigureparameter\c!location}{\externalfigureparameter\c!directory}}
+
+%D Variables:
+
+\newbox \foundexternalfigure
+\newtoks\externalfigurepostprocessors
+
+\def\defaultfigurewidth {8\lineheight} % permanent ? frozen ?
+\def\defaultfigureheight {6\lineheight} % permanent ? frozen ?
+
+\permanent\def\figurestatus {\numexpr\clf_figurestatus{status}{0}\relax} % number: 0 = not found
+\permanent\def\figurewidth {\clf_figurestatus{width}{0}sp}
+\permanent\def\figureheight {\clf_figurestatus{height}{0}sp}
+\permanent\def\figurexscale {\clf_figurestatus{xscale}{1}}
+\permanent\def\figureyscale {\clf_figurestatus{yscale}{1}}
+
+\permanent\def\figuresize {\clf_figurerequest{size}{}}
+\permanent\def\figurelabel {\clf_figurerequest{label}{}}
+\permanent\def\figurefileoriginal {\clf_figurerequest{name}{}}
+\permanent\def\figurefilepage {\clf_figurerequest{page}{1}}
+\permanent\def\figurefileoptions {\clf_figurerequest{options}{}}
+\permanent\def\figurefileconversion{\clf_figurerequest{conversion}{}}
+\permanent\def\figurefileresolution{\clf_figurerequest{resolution}{}}
+\permanent\def\figurefilecolor {\clf_figurerequest{color}{}}
+\permanent\def\figurefilearguments {\clf_figurerequest{arguments}{}}
+\permanent\def\figurefilecache {\clf_figurerequest{cache}{}}
+\permanent\def\figurefileprefix {\clf_figurerequest{prefix}{}}
+
+\permanent\def\figurenaturalwidth {\clf_figureused{width}{\number\dimexpr\defaultfigurewidth\relax}sp}
+\permanent\def\figurenaturalheight {\clf_figureused{height}{\number\dimexpr\defaultfigureheight\relax}sp}
+\permanent\def\figurexresolution {\clf_figureused{xresolution}{0}}
+\permanent\def\figureyresolution {\clf_figureused{yresolution}{0}}
+\permanent\def\figureorientation {\clf_figureused{orientation}{1}}
+\permanent\def\figurerotation {\clf_figureused{rotation}{0}}
+\permanent\def\figurexsize {\clf_figureused{xsize}{0}}
+\permanent\def\figureysize {\clf_figureused{ysize}{0}}
+\permanent\def\figurecolordepth {\clf_figureused{colordepth}{0}}
+\permanent\def\figuredepth {\clf_figureused{depth}{0}}
+
+\permanent\def\figurefullname {\clf_figureused{fullname}{}}
+\permanent\def\noffigurepages {\clf_figureused{pages}{0}}
+
+% \permanent\def\figurefilepath {\clf_figurefilepath} % public in lua
+% \permanent\def\figurefilename {\clf_figurefilename} % public in lua
+% \permanent\def\figurefiletype {\clf_figurefiletype} % public in lua
+
+\permanent\let\naturalfigurewidth \figurenaturalwidth
+\permanent\let\naturalfigureheight \figurenaturalheight
+
+\aliased\let\figurescalewidth \figurewidth
+\aliased\let\figurescaleheight \figureheight
+\aliased\let\figurescalexscale \figurexscale
+\aliased\let\figurescaleyscale \figureyscale
+
+%D Abuse:
+%D
+%D \starttyping
+%D \externalfigure[rubish.pdf] \ifcase\figurestatus\relax \ctxlua{os.exit(999)} \fi
+%D \stoptyping
+
+%D Calculating:
+
+% \enabletrackers[figures.conversion]
+% \externalfigure[demo.svg]
+% \externalfigure[demo.svg][conversion=png]
+
+%D The following registers are used (if only to be downward compatible).
+
+\newconditional\c_grph_include_skip
+\newconditional\c_grph_include_test_only
+\newconditional\c_grph_include_level \setfalse\c_grph_include_level % true=background false=normal
+\newconditional\c_grph_include_flush \settrue \c_grph_include_flush % true=place false=ignore
+
+\newsystemmode\v!figure
+
+\def\grph_include_set_mode
+ {\ifcase\figurestatus
+ \globalresetsystemmode\v!figure % todo, also: \v!resource
+ \else
+ \globalsetsystemmode \v!figure % todo, also: \v!resource
+ \fi}
+
+\appendtoks
+ \clf_setfigurepaths
+ {\externalfigureparameter\c!location}%
+ {\externalfigureparameter\c!directory}%
+ \clf_figure_reset
+ \foundexternalfigure
+ \defaultfigurewidth
+ \defaultfigureheight
+ \relax
+\to \everyexternalfigureresets
+
+\appendtoks
+ \edef\p_option{\externalfigureparameter\c!option}%
+ \ifx\p_option\v!frame
+ \setfalse\c_grph_include_skip
+ \letexternalfigureparameter\c!frame\v!on
+ \else\ifx\p_option\v!empty
+ \settrue\c_grph_include_skip
+ \letexternalfigureparameter\c!frame\v!off
+ \else
+ \setfalse\c_grph_include_skip
+ \fi\fi
+ % fake color in gray bitmaps, assumes that
+ % a transparent color is used
+ \edef\p_foregroundcolor{\externalfigureparameter\c!foregroundcolor}%
+ \ifempty\p_foregroundcolor \else
+ \setexternalfigureparameter\c!background{\v!foreground,\v!color}%
+ \letexternalfigureparameter\c!backgroundcolor\p_foregroundcolor
+ \fi
+\to \everyexternalfigurechecks
+
+%D Internal graphics are handled at the \TEX\ end:
+
+\def\grph_include_process_tex#1%
+ {\framed
+ [\c!strut=\v!no,\c!align=\v!normal,\c!frame=\v!off,
+ \c!offset=\v!overlay,\c!width=\v!fit,\c!height=\v!fit]
+ {\blank[\v!disable]#1\endgraf\removelastskip}} % disable should stay here!
+
+% used al lua end:
+
+\permanent\protected\def\docheckfigurebuffer #1{\global\setbox\foundexternalfigure\vpack{\grph_include_process_tex{\getbuffer[#1]}}}
+\permanent\protected\def\docheckfiguretex #1{\global\setbox\foundexternalfigure\vpack{\grph_include_process_tex{\input{#1}}}}
+\permanent\protected\def\docheckfigurecld #1{\global\setbox\foundexternalfigure\vbox {\cldprocessfile{#1}}}
+\permanent\protected\def\docheckfiguremps #1{\global\setbox\foundexternalfigure\vpack{\convertMPtoPDF{#1}11}}
+\permanent\protected\def\docheckfiguremprun #1#2{\global\setbox\foundexternalfigure\vpack{\useMPrun{#1}{#2}}}
+
+\permanent\protected\def\relocateexternalfigure
+ {\global\setbox\foundexternalfigure\vpack to \ht\foundexternalfigure\bgroup
+ %
+ % The \vss can (!) introduce 1 sp excess visible in xform which in itself
+ % is not that important but some don't like these cosmetic side effects, for
+ % instance we can get:
+ %
+ % vss : \vbox(845.1575+0.0)x597.23125, glue set 845.15747fil, direction TLT
+ % vskip : \vbox(845.1575+0.0)x597.23125, direction TLT
+ %
+ % or
+ %
+ % 1 0 0 1 0 0.00003 cm
+ % 1 0 0 1 0 0 cm
+ %
+ % This is a known property of using glue and can even depend on the architecture
+ % (float implementation). Anyway, let's for now use a skip. Of course this can
+ % shift the issue elsewhere, as vss is used a lot elsewhere.
+ %
+ % \vss
+ \vkern\ht\foundexternalfigure
+ %
+ \ht\foundexternalfigure\zeropoint
+ \dp\foundexternalfigure\zeropoint
+ \hpack to \wd\foundexternalfigure\bgroup
+ \box\foundexternalfigure
+ \hss
+ \egroup
+ \egroup}
+
+\permanent\protected\def\startfoundexternalfigure#1#2% ht wd
+ {\global\setbox\foundexternalfigure\vbox to #2\bgroup\vss\hbox to #1\bgroup}
+
+\permanent\protected\def\stopfoundexternalfigure
+ {\hss\egroup\egroup}
+
+\permanent\protected\def\emptyfoundexternalfigure % sort of obsolete
+ {\startfoundexternalfigure\defaultfigurewidth\defaultfigureheight
+ \stopfoundexternalfigure}
+
+% \doifmodeelse{*\v!last}
+% {\settrue \c_grph_include_flush}
+% {\setfalse\c_grph_include_flush}%
+
+\def\grph_include_finalize
+ {\global\setbox\foundexternalfigure\vbox
+ {\ifcase\figurestatus
+ \letexternalfigureparameter\c!frame\v!on
+ \fi
+ \ifconditional\c_grph_include_flush
+ \ifconditional\c_grph_include_level % probably background
+ \ifconditional\c_grph_include_skip
+ % nothing
+ \fakebox\foundexternalfigure
+ \orelse\ifcase\figurestatus
+ % nothing
+ \else
+ \the\externalfigurepostprocessors
+ \box\foundexternalfigure
+ \fi
+ \else
+ \iftrialtypesetting \else \feedbackexternalfigure \fi
+ \settrue\c_grph_include_level
+ \ifconditional\c_grph_include_skip
+ \ifcase\figurestatus
+ \grph_include_replacement\figurelabel\figurefileoriginal{unknown}%
+ \else
+ \grph_include_replacement\figurelabel\figurefullname{skipped}%
+ \fi
+ \orelse\ifcase\figurestatus
+ \grph_include_replacement\figurelabel\figurefileoriginal{unknown}%
+ \else
+ \the\externalfigurepostprocessors
+ \edef\p_reset{\externalfigureparameter\c!reset}%
+ \ifx\p_reset\v!yes
+ \wd\foundexternalfigure\figurewidth
+ \ht\foundexternalfigure\figureheight
+ \dp\foundexternalfigure\zeropoint
+ \box\foundexternalfigure
+ \else
+ \letexternalfigureparameter\c!offset\v!overlay
+ \letexternalfigureparameter\c!width \figurewidth
+ \letexternalfigureparameter\c!height\figureheight
+ \inheritedexternalfigureframed{\box\foundexternalfigure}%
+ \fi
+ \fi
+ \fi
+ \else
+ % maybe also \the\externalfigurepostprocessors
+ \iftrialtypesetting \else \feedbackexternalfigure \fi
+ \fi}}
+
+\let\feedbackexternalfigure\relax % hook
+
+\permanent\protected\def\getfiguredimensions
+ {\dodoubleempty\grph_include_get_dimensions}
+
+\def\grph_include_get_dimensions[#1][#2]%
+ {\startnointerference
+ \settrue\c_grph_include_test_only
+ \externalfigure[#1][#2,\c!display=,\c!mask=,\c!object=\v!no]%
+ \stopnointerference}
+
+\permanent\protected\def\doifelsefigure#1%
+ {\getfiguredimensions[#1]% so data is available !
+ \ifcase\figurestatus
+ \expandafter\secondoftwoarguments
+ \else
+ \expandafter\firstoftwoarguments
+ \fi}
+
+\aliased\let\doiffigureelse\doifelsefigure
+
+% No placement, handy for preprocessing:
+
+\permanent\tolerant\protected\def\registerexternalfigure[#1]#*[#2]#*[#3]%
+ {\startnointerference
+ \c_grph_include_test_only
+ \setfalse\c_grph_include_flush % == test ?
+ \externalfigure[#1][#2][#3]% or
+ \externalfigure[#1][#2,\c!display=,\c!mask=,\c!object=\v!no]%
+ \stopnointerference}
+
+% Helpers will be replaced when xforms are accessible at the lua end but then
+% we need to do the object offset there too.
+
+\permanent\protected\def\dosetfigureobject#1#2%
+ {\setobject{#1}{#2}\vpack{\box\foundexternalfigure}}
+
+\permanent\protected\def\doboxfigureobject#1#2%
+ {\global\setbox\foundexternalfigure\vpack{\getobject{#1}{#2}}} % probably one vbox too many
+
+% Figure bases
+
+\permanent\protected\def\usefigurebase[#1]%
+ {\clf_usefigurebase{#1}}
+
+\appendtoks
+ \setfigurepathlist % the path may be used elsewhere too (as in x-res-04)
+\to \everysetupexternalfigure
+
+\appendtoks
+ \clf_setfigurelookuporder{\externalfigureparameter\c!order}%
+\to \everysetupexternalfigure
+
+\definecolor[missingfigurecolor][s=.8]
+
+\def\grph_include_replacement#1#2#3%
+ {\bgroup
+ \letexternalfigureparameter\c!width\figurewidth
+ \letexternalfigureparameter\c!height\figureheight
+ \letexternalfigureparameter\c!background\v!color
+ \setexternalfigureparameter\c!backgroundcolor{missingfigurecolor}%
+ \setexternalfigureparameter\c!align{\v!middle,\v!lohi}% we default to \v!none
+ \inheritedexternalfigureframed
+ {\tt\tfxx \nohyphens
+ name: \expanded{\verbatimstring{#1}}\\%
+ file: \expanded{\verbatimstring{#2}}\\%
+ state: \expanded{\verbatimstring{#3}}}%
+ \egroup}
+
+% maybe setuphandler
+
+\newconditional\c_grph_include_in_collection
+
+\newdimen\d_grph_include_collection_minwidth
+\newdimen\d_grph_include_collection_maxwidth
+\newdimen\d_grph_include_collection_minheight
+\newdimen\d_grph_include_collection_maxheight
+
+\def\grph_include_analyze_collection[#1][#2]%
+ {\ifconditional\c_grph_include_in_collection
+ \setfalse\c_grph_include_in_collection
+ \getfiguredimensions[#1][#2]%
+ \settrue\c_grph_include_in_collection
+ \scratchdimen\naturalfigurewidth
+ \ifdim\scratchdimen>\d_grph_include_collection_maxwidth \d_grph_include_collection_maxwidth \scratchdimen \fi
+ \ifdim\scratchdimen<\d_grph_include_collection_minwidth \d_grph_include_collection_minwidth \scratchdimen \fi
+ \scratchdimen\naturalfigureheight
+ \ifdim\scratchdimen>\d_grph_include_collection_maxheight \d_grph_include_collection_maxheight\scratchdimen \fi
+ \ifdim\scratchdimen<\d_grph_include_collection_minheight \d_grph_include_collection_minheight\scratchdimen \fi
+ \fi}
+
+\permanent\protected\def\startexternalfigurecollection[#1]%
+ {\begingroup
+ \def\currentexternalfigurecollection{#1}%
+ \settrue\c_grph_include_in_collection
+ \d_grph_include_collection_minwidth \maxdimen
+ \d_grph_include_collection_maxwidth \zeropoint
+ \d_grph_include_collection_minheight\maxdimen
+ \d_grph_include_collection_maxheight\zeropoint}
+
+\permanent\protected\def\stopexternalfigurecollection
+ {\setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!minwidth }{\the\d_grph_include_collection_minwidth }%
+ \setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!maxwidth }{\the\d_grph_include_collection_maxwidth }%
+ \setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!minheight}{\the\d_grph_include_collection_minheight}%
+ \setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!maxheight}{\the\d_grph_include_collection_maxheight}%
+ \endgroup}
+
+\permanent\def\externalfigurecollectionparameter#1#2%
+ {\csname
+ \ifcsname\??externalfigurecollection#1:#2\endcsname
+ \??externalfigurecollection#1:#2%
+ \else
+ \s!empty
+ \fi
+ \endcsname}
+
+\permanent\def\externalfigurecollectionminwidth #1{\externalfigurecollectionparameter{#1}\c!minwidth }
+\permanent\def\externalfigurecollectionmaxwidth #1{\externalfigurecollectionparameter{#1}\c!maxwidth }
+\permanent\def\externalfigurecollectionminheight#1{\externalfigurecollectionparameter{#1}\c!minheight}
+\permanent\def\externalfigurecollectionmaxheight#1{\externalfigurecollectionparameter{#1}\c!maxheight}
+
+\aliased\let\efcparameter\externalfigurecollectionparameter % still needed ?
+\aliased\let\efcminwidth \externalfigurecollectionminwidth % still needed ?
+\aliased\let\efcmaxwidth \externalfigurecollectionmaxwidth % still needed ?
+\aliased\let\efcminheight\externalfigurecollectionminheight % still needed ?
+\aliased\let\efcmaxheight\externalfigurecollectionmaxheight % still needed ?
+
+% \startexternalfigurecollection[name]
+% \useexternalfigure[cow] [cow.pdf]
+% \useexternalfigure[mill][mill.png]
+% \stopexternalfigurecollection
+% \starttext
+% \bTABLE
+% \bTR
+% \bTD \externalfigure[cow] [height=\externalfigurecollectionmaxheight{name}] \eTD
+% \bTD \externalfigure[mill][height=\externalfigurecollectionmaxheight{name}] \eTD
+% \eTR
+% \eTABLE
+% \stoptext
+
+\permanent\protected\def\overlayfigure#1%
+ {\externalfigure[#1][\c!width=\d_overlay_width,\c!height=\d_overlay_height]}
+
+% Experimental (will become cleaner):
+
+\permanent\tolerant\protected\def\includesvgfile[#1]#*[#2]%
+ {\dontleavehmode\begingroup
+ \getdummyparameters[\c!offset=\zeropoint,#2]%
+ \clf_includesvgfile{#1}\dimexpr\dummyparameter\c!offset\relax
+ \endgroup}
+
+\permanent\tolerant\protected\def\includesvgbuffer[#1]#*[#2]%
+ {\dontleavehmode\begingroup
+ \getdummyparameters[\c!offset=\zeropoint,#2]%
+ \clf_includesvgbuffer{#1}\dimexpr\dummyparameter\c!offset\relax
+ \endgroup}
+
+% Bonus:
+
+\useexternalfigure
+ [\v!buffer]
+ [\jobname.buffer]
+ [\c!object=\v!no]
+
+% Another two:
+
+\defineexternalfigure
+ [\v!inline]
+ [\c!height=\lineheight]
+
+\definemeasure
+ [\v!combination]
+ [(\textwidth
+ -\effectiveleftskip
+ -\effectiverightskip
+ -\numexpr\combinationparameter\c!nx-\plusone\relax\dimexpr\combinationparameter\c!distance\relax
+ )/\combinationparameter\c!nx]
+
+\defineexternalfigure
+ [\v!combination]
+ [\c!width=\measure{\v!combination}]
+
+% \startcombination[nx=2,ny=1]
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% \stopcombination
+
+% \startcombination[nx=2,ny=1]
+% {\externalfigure[dummy][width=\measure{combination}]} {}
+% {\externalfigure[dummy][width=\measure{combination}]} {}
+% \stopcombination
+
+% \startcombination[nx=2,ny=2]
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% \stopcombination
+
+% \startcombination[nx=3,ny=1]
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% \stopcombination
+
+% \startcombination[nx=4,ny=1]
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% {\externalfigure[dummy][combination]} {}
+% \stopcombination
+
+\permanent\protected\def\inlinefigure[#1]%
+ {\dontleavehmode
+ \sbox{\externalfigure[#1][\v!inline]}}
+
+%D Needs to be done global:
+
+\definelayer[epdfcontent]
+
+\protect \endinput
+
+%D Moved here because this already old code is nowhere documents (so I need to check
+%D it:
+%
+% \starttyping
+% \starttext
+%
+% \startluaparameterset [u3d:myset:controls:1]
+% view = {
+% name = 'default',
+% bg = {1,1,1},
+% mag = 100,
+% coo = {0,0,0},
+% c2c = {0,0,1},
+% rot = {40,0,60},
+% roo = 6,
+% lights = 'CAD'
+% },
+% js = 'cloudq.js'
+% \stopluaparameterset
+%
+% \startluaparameterset [u3d:myset:controls:2]
+% views = {
+% {
+% name = 'AnglePositioning',
+% bg = {1,1,1},
+% azimuth = 45,
+% altitude = 45,
+% roo = 50,
+% aac = 2.5,
+% lights = 'Artwork'
+% },
+% {
+% name = 'RotationPositioning',
+% bg = {1,1,1},
+% rot = {0,45,45},
+% roo = 50,
+% aac = 2.5,
+% lights = 'Artwork'
+% },
+% {
+% name = 'VectorPositioning',
+% bg = {1,0,0},
+% c2c = {1,1,math.sqrt(2)},
+% roo = 50,
+% aac = 2.5,
+% lights = 'CAD'
+% },
+% {
+% name = 'PositionPositioning',
+% bg = {1,0,0},
+% pos = {1+25,1+25,1+50/math.sqrt(2)},
+% aac = 2.5,
+% lights = 'CAD'
+% },
+% {
+% name = 'ortho',
+% bg = {1,1,1},
+% mag = 300,
+% lights = 'CAD',
+% crossection = {}
+% }
+% },
+% view = {
+% name = 'default',
+% bg = {1,1,1},
+% c2c = {-1,-1,0},
+% roo = 50,
+% aac = 2.5,
+% roll = 45,
+% lights = 'CAD',
+% crossection = {
+% normal = {-1,-1,-1},
+% transparent = true
+% },
+% nodes = {
+% {
+% name = 'xlabel',
+% visible = false
+% },
+% {
+% name = 'ylabel',
+% opacity = 0.5
+% },
+% {
+% name = 'zlabel',
+% rendermode = 'Wireframe'
+% }
+% }
+% }
+% \stopluaparameterset
+%
+% \useexternalfigure
+% [cloudq]
+% [cloudq.u3d]
+% [width=0.7\textwidth,
+% height=.7\textwidth,
+% display=u3d:myset:display:1,
+% controls=u3d:myset:controls:1]
+%
+% \useexternalfigure
+% [axes]
+% [axes.u3d]
+% [width=0.7\textwidth,
+% height=.7\textwidth,
+% controls=u3d:myset:controls:1]
+%
+% \startluaparameterset[u3d:myset:display:2]
+% toolbar = true,
+% preview = 'cloudq.png'
+% \stopluaparameterset
+% \startluaparameterset[u3d:myset:display:3]
+% toolbar = true,
+% tree = false,
+% preview = 'axes.png'
+% \stopluaparameterset
+% \startluaparameterset[u3d:myset:display:4]
+% toolbar = true,
+% tree = false,
+% view = {
+% name = 'view',
+% bg = {0.1,0.1,0.1},
+% c2c = {-1,-1,0},
+% roo = 50,
+% aac = 2.5,
+% roll = 45,
+% lights = 'Red'
+% }
+% \stopluaparameterset
+% \startluaparameterset[u3d:myset:display:5]
+% toolbar = true,
+% tree = false,
+% view = 'ortho'
+% \stopluaparameterset
+%
+% \placefigure[here]{none}{\externalfigure[cloudq][frame=on,display=u3d:myset:display:2]}
+% \placefigure[here]{none}{\externalfigure[axes] [frame=on,display=u3d:myset:display:3]}
+% \placefigure[here]{none}{\externalfigure[axes] [frame=on,display=u3d:myset:display:4]}
+% \placefigure[here]{none}{\externalfigure[axes] [frame=on,display=u3d:myset:display:5,width=0.5\textwidth,height=.5\textwidth]}
+%
+% \stoptext
diff --git a/tex/context/base/mkiv/grph-pat.mkxl b/tex/context/base/mkiv/grph-pat.mkxl
index df30258bc..92fd5ad74 100644
--- a/tex/context/base/mkiv/grph-pat.mkxl
+++ b/tex/context/base/mkiv/grph-pat.mkxl
@@ -49,10 +49,10 @@
\edef\p_height {\dummyparameter\c!height}%
\edef\p_hoffset{\dummyparameter\c!hoffset}%
\edef\p_voffset{\dummyparameter\c!voffset}%
- \scratchwidth \dimexpr\ifx\p_width \v!auto\wd \nextbox \else\p_width \fi\relax
- \scratchheight \dimexpr\ifx\p_height \v!auto\htdp\nextbox \else\p_height \fi\relax
- \scratchhoffset\dimexpr\ifx\p_hoffset\v!auto\scratchwidth /2\else\ifx\p_hoffset\v!auto_m-\scratchwidth /2\else\p_hoffset\fi\fi\relax
- \scratchvoffset\dimexpr\ifx\p_voffset\v!auto\scratchheight/2\else\ifx\p_voffset\v!auto_m-\scratchheight/2\else\p_voffset\fi\fi\relax
+ \scratchwidth \dimexpr\ifx\p_width \v!auto\wd \nextbox\else\p_width \fi\relax
+ \scratchheight \dimexpr\ifx\p_height \v!auto\htdp\nextbox\else\p_height \fi\relax
+ \scratchhoffset\dimexpr\ifx\p_hoffset\v!auto\scratchwidth /2\orelse\ifx\p_hoffset\v!auto_m-\scratchwidth /2\else\p_hoffset\fi\relax
+ \scratchvoffset\dimexpr\ifx\p_voffset\v!auto\scratchheight/2\orelse\ifx\p_voffset\v!auto_m-\scratchheight/2\else\p_voffset\fi\relax
\clf_registerpattern
name {\dummyparameter\c!name}
number \nextbox
diff --git a/tex/context/base/mkiv/l-package.lua b/tex/context/base/mkiv/l-package.lua
index 94607d436..a35ec3e2a 100644
--- a/tex/context/base/mkiv/l-package.lua
+++ b/tex/context/base/mkiv/l-package.lua
@@ -300,7 +300,10 @@ methods["already loaded"] = function(name)
end
methods["preload table"] = function(name)
- return builtin["preload table"](name)
+ local f = builtin["preload table"]
+ if f then
+ return f(name)
+ end
end
methods["qualified path"]=function(name)
@@ -316,17 +319,26 @@ methods["lib extra list"] = function(name)
end
methods["path specification"] = function(name)
- getluapaths() -- triggers list building and tracing
- return builtin["path specification"](name)
+ local f = builtin["path specification"]
+ if f then
+ getluapaths() -- triggers list building and tracing
+ return f(name)
+ end
end
methods["cpath specification"] = function(name)
- getlibpaths() -- triggers list building and tracing
- return builtin["cpath specification"](name)
+ local f = builtin["cpath specification"]
+ if f then
+ getlibpaths() -- triggers list building and tracing
+ return f(name)
+ end
end
methods["all in one fallback"] = function(name)
- return builtin["all in one fallback"](name)
+ local f = builtin["all in one fallback"]
+ if f then
+ return f(name)
+ end
end
methods["not loaded"] = function(name)
diff --git a/tex/context/base/mkiv/lang-imp-serbian.lua b/tex/context/base/mkiv/lang-imp-serbian.lua
new file mode 100644
index 000000000..377d6dfde
--- /dev/null
+++ b/tex/context/base/mkiv/lang-imp-serbian.lua
@@ -0,0 +1,38 @@
+return {
+ transliterations = {
+ ["serbian to latin"] = {
+ mapping = {
+ ["А"] = "A", ["а"] = "a",
+ ["Б"] = "B", ["б"] = "b",
+ ["В"] = "V", ["в"] = "v",
+ ["Г"] = "G", ["г"] = "g",
+ ["Д"] = "D", ["д"] = "d",
+ ["Е"] = "E", ["е"] = "e",
+ ["Ж"] = "Ž", ["ж"] = "ž",
+ ["З"] = "Z", ["з"] = "z",
+ ["И"] = "I", ["и"] = "i",
+ ["Й"] = "J", ["й"] = "j",
+ ["К"] = "K", ["к"] = "k",
+ ["Л"] = "L", ["л"] = "l",
+ ["М"] = "M", ["м"] = "m",
+ ["Н"] = "N", ["н"] = "n",
+ ["О"] = "O", ["о"] = "o",
+ ["П"] = "P", ["п"] = "p",
+ ["Р"] = "R", ["р"] = "r",
+ ["С"] = "S", ["с"] = "s",
+ ["Т"] = "T", ["т"] = "t",
+ ["У"] = "U", ["у"] = "u",
+ ["Ф"] = "F", ["ф"] = "f",
+ ["Х"] = "Ch", ["х"] = "ch",
+ ["Ц"] = "C", ["ц"] = "c",
+ ["Ч"] = "Č", ["ч"] = "č",
+ ["Ш"] = "Š", ["ш"] = "š",
+ ["Щ"] = "Št", ["щ"] = "št",
+ ["Ъ"] = "Ă", ["ъ"] = "ă",
+ ["Ь"] = "′", ["ь"] = "′",
+ ["Ю"] = "Ju", ["ю"] = "ju",
+ ["Я"] = "Ja", ["я"] = "ja",
+ }
+ }
+ }
+}
diff --git a/tex/context/base/mkiv/lang-mis.mkxl b/tex/context/base/mkiv/lang-mis.mkxl
index 9515a1f8e..853a7a7c2 100644
--- a/tex/context/base/mkiv/lang-mis.mkxl
+++ b/tex/context/base/mkiv/lang-mis.mkxl
@@ -276,7 +276,7 @@
{\edef\discretionarytoken{\detokenize{#2}}%
\def\textmodediscretionary{\handletextmodediscretionary{#1}}%
\lang_discretionaries_check_after
- \ifx\discretionarytoken\empty
+ \ifempty\discretionarytoken
\ifx#1\nexttoken % takes care of ||| and +++ and ......
\ifcsname\??discretionaryaction\string#1\endcsname
\lastnamedcs
diff --git a/tex/context/base/mkiv/lang-rep.lua b/tex/context/base/mkiv/lang-rep.lua
index 2a3c8a7fa..9f89fa248 100644
--- a/tex/context/base/mkiv/lang-rep.lua
+++ b/tex/context/base/mkiv/lang-rep.lua
@@ -87,7 +87,7 @@ local replacements = languages.replacements or { }
languages.replacements = replacements
local a_replacements = attributes.private("replacements")
-local a_noligature = attributes.private("noligature")
+local a_noligature = attributes.private("noligature") -- to be adapted to lmtx !
local lists = { }
local last = 0
diff --git a/tex/context/base/mkiv/lang-tra.lua b/tex/context/base/mkiv/lang-tra.lua
new file mode 100644
index 000000000..5fd123349
--- /dev/null
+++ b/tex/context/base/mkiv/lang-tra.lua
@@ -0,0 +1,123 @@
+if not modules then modules = { } end modules ['lang-tra'] = {
+ version = 1.001,
+ comment = "companion to lang-tra.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local utfbyte, utfsplit = utf.byte, utf.split
+
+local nuts = nodes.nuts
+
+local nextchar = nuts.traversers.char
+
+local getattr = nuts.getattr
+local setchar = nuts.setchar
+
+local insert_before = nuts.insert_before
+local copy_node = nuts.copy
+
+local texsetattribute = tex.setattribute
+
+local transliteration = { }
+languages.transliteration = transliteration
+
+local a_transliteration = attributes.private("transliteration")
+local unsetvalue = attributes.unsetvalue
+
+local lastmapping = 0
+local loadedmappings = { }
+
+function transliteration.define(name,vector)
+ local m = loadedmappings[vector]
+ if m == nil then
+ lastmapping = lastmapping + 1
+ local data = require("lang-imp-" .. name)
+ if data then
+ local transliterations = data.transliterations
+ if transliterations then
+ for name, d in next, transliterations do
+ local vector = d.vector
+ if not vector then
+ local mapping = d.mapping
+ if mapping then
+ vector = { }
+ for k, v in next, mapping do
+ local vv = utfsplit(v)
+ for i=1,#vv do
+ vv[i] = utfbyte(vv[i])
+ end
+ vector[utfbyte(k)] = vv
+ end
+ d.vector = vector
+ end
+ end
+ d.attribute = lastmapping
+ loadedmappings[name] = d
+ loadedmappings[lastmapping] = d
+ end
+ end
+ end
+ m = loadedmappings[vector] or false
+ end
+end
+
+local enabled = false
+
+function transliteration.set(vector)
+ if not enabled then
+ nodes.tasks.enableaction("processors", "languages.transliteration.handler")
+ enabled = true
+ end
+ local m = loadedmappings[vector]
+ texsetattribute(a_transliteration,m and m.attribute or unsetvalue)
+end
+
+function transliteration.handler(head)
+ local aprev = nil
+ local vector = nil
+ for current, char in nextchar, head do
+ local a = getattr(current,a_transliteration)
+ if a then
+ if a ~= aprev then
+ aprev = a
+ vector = loadedmappings[a]
+ if vector then
+ vector = vector.vector
+ end
+ end
+ if vector then
+ local t = vector[char]
+ if t then
+ local n = #t
+ setchar(current,t[n])
+ local p = current
+ if n > 1 then
+ for i = n-1,1,-1 do
+ local g = copy_node(current)
+ setchar(g,t[i])
+ head, p = insert_before(head, p, g)
+ end
+ end
+ end
+ end
+ end
+ end
+ return head
+end
+
+interfaces.implement {
+ name = "settransliteration",
+ arguments = "string",
+ actions = transliteration.set,
+}
+
+interfaces.implement {
+ name = "definedtransliteration",
+ arguments = "2 strings",
+ actions = transliteration.define,
+}
+
+nodes.tasks.prependaction("processors", "normalizers", "languages.transliteration.handler", nil, "nut", "disabled" )
+
diff --git a/tex/context/base/mkiv/lang-tra.mkiv b/tex/context/base/mkiv/lang-tra.mkiv
new file mode 100644
index 000000000..b8e640661
--- /dev/null
+++ b/tex/context/base/mkiv/lang-tra.mkiv
@@ -0,0 +1,98 @@
+%D \module
+%D [ file=lang-tra,
+%D version=2020.10.31,
+%D title=\CONTEXT\ Language Macros,
+%D subtitle=Transliteration,
+%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 Language Macros / Transliteration}
+
+\registerctxluafile{lang-tra}{}
+
+\unprotect
+
+\definesystemattribute[transliteration][public,global]
+
+\installcorenamespace {transliteration}
+
+\unexpanded\def\definetransliteration
+ {\dodoubleempty\lang_transliteration_define}
+
+\unexpanded\def\lang_transliteration_define[#1][#2]%
+ {\clf_definedtransliteration{#1}{#2}}
+
+\unexpanded\def\settransliteration[#1]%
+ {\clf_settransliteration{#1}}
+
+\unexpanded\def\starttransliteration[#1]%
+ {\begingroup
+ \clf_settransliteration{#1}}
+
+\unexpanded\def\stoptransliteration
+ {\endgroup}
+
+\unexpanded\def\resettransliteration
+ {\c_attr_transliteration\attributeunsetvalue}
+
+\appendtoks
+ \resettransliteration
+\to \everyinitializeverbatim
+
+\protect \endinput
+
+% \setupbodyfont[dejavu]
+%
+% \input lang-tra.mkiv
+%
+% \definetransliteration[serbian][serbian to latin]
+%
+% \starttext
+%
+% \settransliteration[serbian to latin]
+%
+% \startchapter[title={АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ}]
+% АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ
+% \start
+% \settransliteration[serbian to latin]
+% АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ
+% \stop
+% АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ
+% \stopchapter
+%
+% \resettransliteration
+%
+% \startchapter[title={АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ}]
+% АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ
+% \start
+% \settransliteration[serbian to latin]
+% АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ
+% \stop
+% АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ
+% \stopchapter
+%
+% \definehead[ChapterA][chapter]
+% \definehead[ChapterB][chapter]
+%
+% \startsetups s-to-l
+% \settransliteration[serbian to latin]
+% \red
+% \stopsetups
+%
+% % maybe we need a setups key for this
+% % hm, \definesetups [xxx] [aa,bb,cc]
+%
+% \setuphead[ChapterB][commandbefore=\setups{s-to-l}]
+%
+% \startChapterA[title={АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ}]
+% \stopChapterA
+%
+% \startChapterB[title={АБВ ГДЕ ЖЗИЙ КЛМНОП РСТУ ФХЦЧ ШЩЪЬ ЮЯ}]
+% \stopChapterB
+%
+% \stoptext
diff --git a/tex/context/base/mkiv/lxml-ini.mkxl b/tex/context/base/mkiv/lxml-ini.mkxl
index 01e2024bf..e8d017bf3 100644
--- a/tex/context/base/mkiv/lxml-ini.mkxl
+++ b/tex/context/base/mkiv/lxml-ini.mkxl
@@ -323,7 +323,7 @@
\permanent\tolerant\protected\def\startxmldisplayverbatim[#1]%
{\startpacked
\edef\currenttyping{#1}%
- \ifx\currenttyping\empty
+ \ifempty\currenttyping
\let\currenttyping\v!typing
\else % maybe test for existence
\edef\currenttyping{xml:\currenttyping}%
@@ -339,7 +339,7 @@
\permanent\tolerant\protected\def\startxmlinlineverbatim[#1]%
{\begingroup
\edef\currenttype{#1}%
- \ifx\currenttype\empty
+ \ifempty\currenttype
\let\currenttype\v!type
\else % maybe test for existence
\edef\currenttype{xml:\currenttype}%
diff --git a/tex/context/base/mkiv/math-ali.mkxl b/tex/context/base/mkiv/math-ali.mkxl
index 997ecd3d7..b4336f857 100644
--- a/tex/context/base/mkiv/math-ali.mkxl
+++ b/tex/context/base/mkiv/math-ali.mkxl
@@ -373,7 +373,7 @@
\dostarttagged\t!mathtable\currentmathalignment
\numberedeqalign}
-\def\math_alignment_stop
+\def\math_alignment_stop % can be protected
{\math_finish_eqalign_no
\dostoptagged
\dostoptagged
@@ -728,7 +728,11 @@
\span\math_text_in_eqalign{\alignmark\alignmark}%
\crcr} % todo: number
-\def\math_cases_stop
+% When we have just protected we get an extra row but we can no flag
+% this as a proper alignment related command which means that uit gets
+% expanded.
+
+\noaligned\permanent\protected\def\math_cases_stop
{\crcr
\egroup
\popmacro\math_cases_NC
@@ -1161,7 +1165,7 @@
\appendtoks
\edef\p_simplecommand{\mathmatrixparameter\c!simplecommand}%
- \ifx\p_simplecommand\empty\else
+ \ifempty\p_simplecommand\else
\setuevalue{\p_simplecommand}{\math_matrix_simple[\currentmathmatrix]}%
\fi
\to \everydefinemathmatrix
@@ -1266,7 +1270,7 @@
\enforced\let\NR\crcr
\halign\bgroup\hfil\normalstartimath\scriptstyle\alignmark\alignmark\normalstopimath\hfil\crcr}
-\permanent\def\stopsubstack % todo: \protected and delayed
+\noaligned\permanent\protected\def\stopsubstack
{\crcr
\egroup
\egroup
@@ -1434,7 +1438,7 @@
\fi
\fi
\edef\p_interlinespace{\formulaparameter\c!interlinespace}%
- \ifx\p_interlinespace\empty\else\baselineskip\p_interlinespace\fi
+ \ifempty\p_interlinespace\else\baselineskip\p_interlinespace\fi
\global\d_strc_math_indent\zeropoint
\ifcase\mathraggedstatus\or\raggedleft\or\raggedcenter\or\raggedright\fi
\unhbox\b_strc_math_display
diff --git a/tex/context/base/mkiv/math-frc.mkxl b/tex/context/base/mkiv/math-frc.mkxl
index b6c77f4bb..983704f74 100644
--- a/tex/context/base/mkiv/math-frc.mkxl
+++ b/tex/context/base/mkiv/math-frc.mkxl
@@ -146,17 +146,17 @@
\relax}
\appendtoks
- \ifx\currentmathfraction\empty
+ \ifempty\currentmathfraction
\edef\m_math_fraction_distance_top{\mathfractionparameter\c!topdistance}%
\edef\m_math_fraction_distance_bot{\mathfractionparameter\c!bottomdistance}%
- \ifx\m_math_fraction_distance_top\empty
- \ifx\m_math_fraction_distance_bot\empty
+ \ifempty\m_math_fraction_distance_top
+ \ifempty\m_math_fraction_distance_bot
\let\math_fraction_set_distance\relax
\else
\let\math_fraction_set_distance\math_fraction_set_distance_bot
\fi
\else
- \ifx\m_math_fraction_distance_bot\empty
+ \ifempty\m_math_fraction_distance_bot
\let\math_fraction_set_distance\math_fraction_set_distance_top
\else
\let\math_fraction_set_distance\math_fraction_set_distance_all
@@ -196,7 +196,7 @@
\edef\currentmathfraction{#1}%
%
\edef\p_math_fraction_fences{\mathfractionparameter\c!fences}%
- \ifx\p_math_fraction_fences\empty \else
+ \ifempty\p_math_fraction_fences \else
\math_fenced_fenced_start\p_math_fraction_fences
\fi
%
@@ -211,14 +211,14 @@
\math_frac_no_strut
\fi
%
- \ifx\p_math_fractions_color\empty
+ \ifempty\p_math_fractions_color
\expandafter\math_frac_normal
\else
\expandafter\math_frac_colored
\fi}
\unexpanded\def\math_frac_wrapup
- {\ifx\p_math_fraction_fences\empty \else
+ {\ifempty\p_math_fraction_fences \else
\math_fenced_fenced_stop\p_math_fraction_fences
\fi
\endgroup}
@@ -238,7 +238,7 @@
\def\math_frac_command
{\clf_mathfraction
{\mathfractionparameter\c!rule}%
- \ifx\p_math_fraction_fences\empty
+ \ifempty\p_math_fraction_fences
\mathfractionparameter\c!left \space
\mathfractionparameter\c!right\space
\else
@@ -405,7 +405,7 @@
\appendtoks
\edef\p_distance{\rootmathfractionparameter\c!distance}%
- \ifx\p_distance\empty\else
+ \ifempty\p_distance\else
\ifcsname\??mathfractiondistance\p_distance\endcsname
\lastnamedcs
\fi
@@ -423,23 +423,23 @@
\to \everymathematics
\appendtoks
- \ifx\currentmathfraction\empty
+ \ifempty\currentmathfraction
\edef\p_threshold{\mathfractionparameter\c!inlinethreshold}%
- \ifx\p_threshold\empty
+ \ifempty\p_threshold
\let\math_fraction_set_threshold_inline\relax
- \else\ifx\p_threshold\v!auto
+ \orelse\ifx\p_threshold\v!auto
\let\math_fraction_set_threshold_inline\relax
\else
\let\math_fraction_set_threshold_inline\math_fraction_set_theshold_inline
- \fi\fi
+ \fi
\edef\p_threshold{\mathfractionparameter\c!displaythreshold}%
- \ifx\p_threshold\empty
+ \ifempty\p_threshold
\let\math_fraction_set_threshold_display\relax
- \else\ifx\p_threshold\v!auto
+ \orelse\ifx\p_threshold\v!auto
\let\math_fraction_set_threshold_display\relax
\else
\let\math_fraction_set_threshold_display\math_fraction_set_theshold_display
- \fi\fi
+ \fi
\fi
\to \everysetupmathfraction
@@ -641,7 +641,7 @@
\unexpanded\def\vfrac#1#2%
{\bgroup
\edef\p_math_fractions_color{\namedmathfractionparameter\s!vfrac\c!color}%
- \ifx\p_math_fractions_color\empty
+ \ifempty\p_math_fractions_color
\expandafter\math_frac_normal_vulgar
\else
\expandafter\math_frac_colored_vulgar
diff --git a/tex/context/base/mkiv/pack-box.mkxl b/tex/context/base/mkiv/pack-box.mkxl
index 2f52939ce..8ed2f65c0 100644
--- a/tex/context/base/mkiv/pack-box.mkxl
+++ b/tex/context/base/mkiv/pack-box.mkxl
@@ -252,7 +252,7 @@
\def\pack_boxes_collector_finish
{\edef\p_collector_rotation{\collectorparameter\c!rotation}%
\edef\p_collector_corner {\collectorparameter\c!corner}%
- \ifx\p_collector_rotation\empty \else
+ \ifempty\p_collector_rotation \else
\setbox\nextbox\hpack
{\rotate
[\c!location=\v!high,
@@ -575,11 +575,11 @@
\ifdone
\ifconditional\c_pack_boxes_l
\scratchwidth+\MPx\currentbgposition-\MPx\currentpageposition
- \else\ifconditional\c_pack_boxes_r
+ \orelse\ifconditional\c_pack_boxes_r
\paperwidth -\MPx\currentbgposition+\MPx\currentpageposition % not checked
\else
\scratchwidth
- \fi\fi
+ \fi
\else
\scratchwidth
\fi+\scratchhoffset
@@ -588,11 +588,11 @@
\ifdone
\ifconditional\c_pack_boxes_t
\paperheight -\MPy\currentbgposition+\MPy\currentpageposition % not checked
- \else\ifconditional\c_pack_boxes_b
+ \orelse\ifconditional\c_pack_boxes_b
\scratchheight+\MPy\currentbgposition-\MPy\currentpageposition + \MPh\currentbgposition % not checked (\MPh added)
\else
\scratchheight
- \fi\fi
+ \fi
\else
\scratchheight
\fi+\scratchvoffset
@@ -917,7 +917,7 @@
\setbox\nextbox\hpack
{\kern\scratchxposition
\lower\scratchyposition\hpack
- {\ifx\p_location\empty
+ {\ifempty\p_location
\box\nextbox
\else
\alignedbox[\p_location]\hpack{\box\nextbox}%
diff --git a/tex/context/base/mkiv/pack-com.mkxl b/tex/context/base/mkiv/pack-com.mkxl
index 5b7a16359..9392a68a6 100644
--- a/tex/context/base/mkiv/pack-com.mkxl
+++ b/tex/context/base/mkiv/pack-com.mkxl
@@ -169,7 +169,7 @@
\normalexpanded
{\definelabel
[\v!combination:\currentcombination]%
- [\v!combination\ifx\currentcombinationparent\empty\else:\currentcombinationparent\fi]}%
+ [\v!combination\ifempty\currentcombinationparent\else:\currentcombinationparent\fi]}%
[\s!counter=\currentcombination,\c!levels=1]%
\settrue\c_strc_constructions_define_commands
\to \everydefinecombination
@@ -235,7 +235,7 @@
\pack_combinations_push
\edef\currentcombination{#1}%
\edef\currentcombinationspec{#2}%
- \ifx\currentcombinationspec\empty
+ \ifempty\currentcombinationspec
\ifcondition\validassignment{#1}%
\let\currentcombination\empty
\setupcurrentcombination[#1]%
@@ -343,7 +343,7 @@
\usealignparameter\combinationparameter
\usecombinationstyleandcolor\c!style\c!color
\begstrut
- \normalexpanded{\strc_labels_command[\v!combination\ifx\currentcombination\empty\else:\currentcombination\fi]}%
+ \normalexpanded{\strc_labels_command[\v!combination\ifempty\currentcombination\else:\currentcombination\fi]}%
\endstrut
\egroup}
@@ -352,7 +352,7 @@
\ifx\p_pack_combinations_alternative\v!label
\edef\p_continue{\combinationparameter\c!continue}%
\ifx\p_continue\v!yes \else
- \normalexpanded{\strc_labels_reset{\v!combination\ifx\currentcombination\empty\else:\currentcombination\fi}{1}}%
+ \normalexpanded{\strc_labels_reset{\v!combination\ifempty\currentcombination\else:\currentcombination\fi}{1}}%
\fi
\fi
\to \everycombination
@@ -816,7 +816,7 @@
\def\pack_pairedbox_halign#1{\setbox#1\hpack to \s_pack_pairedboxes_size{\pack_pairedboxes_align_l\box#1\pack_pairedboxes_align_r}}
\def\pack_pairedboxes_before
- {\ifx\p_location\empty
+ {\ifempty\p_location
\csname\??pairedboxnature\v!left \endcsname
\csname\??pairedboxalign \v!middle\endcsname
\else
diff --git a/tex/context/base/mkiv/pack-mrl.mkxl b/tex/context/base/mkiv/pack-mrl.mkxl
index fd4153a6b..edc581953 100644
--- a/tex/context/base/mkiv/pack-mrl.mkxl
+++ b/tex/context/base/mkiv/pack-mrl.mkxl
@@ -61,9 +61,9 @@
\else
\vrule
\fi
- \ifx\p_width \v!max\s!width \emwidth\orelse\ifx\p_width \empty\else\s!width \p_width \fi
- \ifx\p_height\v!max\s!height\strutht\orelse\ifx\p_height\empty\else\s!height\p_height\fi
- \ifx\p_depth \v!max\s!depth \strutdp\orelse\ifx\p_depth \empty\else\s!depth \p_depth \fi
+ \ifx\p_width \v!max\s!width \emwidth\orelse\ifempty\p_width \else\s!width \p_width \fi
+ \ifx\p_height\v!max\s!height\strutht\orelse\ifempty\p_height\else\s!height\p_height\fi
+ \ifx\p_depth \v!max\s!depth \strutdp\orelse\ifempty\p_depth \else\s!depth \p_depth \fi
\egroup}
\setupblackrules
@@ -380,7 +380,7 @@
\thinrule
\ifnum\recurselevel<\scratchcounter\relax
% test needed, else messed up whitespace
- \ifx\p_inbetween\empty
+ \ifempty\p_inbetween
\softbreak % \ifhmode \hskip \parfillskip \break \fi
\else
\endgraf
@@ -390,7 +390,7 @@
\fi}%
\fi
\fi
- \ifx\p_after\empty
+ \ifempty\p_after
\carryoverpar\egroup
\else
\p_after\egroup
diff --git a/tex/context/base/mkiv/page-bck.mkxl b/tex/context/base/mkiv/page-bck.mkxl
index 9f9c5ee03..db1f8d864 100644
--- a/tex/context/base/mkiv/page-bck.mkxl
+++ b/tex/context/base/mkiv/page-bck.mkxl
@@ -59,7 +59,7 @@
{\ifcsname\??framed\currentotrbackground:\c!background\endcsname
%\edef\page_background_temp{\csname\??framed\currentotrbackground:\c!background\endcsname}%
\edef\page_background_temp{\lastnamedcs}%
- \ifx\page_background_temp\empty
+ \ifempty\page_background_temp
\expandafter\expandafter\expandafter\page_backgrounds_check_frame
\else
\page_backgrounds_set_yes
@@ -178,7 +178,7 @@
\def\page_backgrounds_add_to_box_indeed#1#2#3#4% area box width height / always non zero
{\edef\p_page_backgrounds_setups{\namedframedparameter{\??layoutbackgrounds#1}\c!setups}%
- \ifx\p_page_backgrounds_setups\empty \else
+ \ifempty\p_page_backgrounds_setups \else
\doprocesslocalsetups\p_page_backgrounds_setups % should not produce funny spaces !
\fi
% #2 has the right dimensions already
@@ -437,11 +437,11 @@
\def\page_backgrounds_set_box_cell#1#2#3#4% pos pos width height
{\begingroup
\edef\p_page_backgrounds_setups{\namedframedparameter{\??layoutbackgrounds#1#2}\c!setups}%
- \ifx\p_page_backgrounds_setups\empty \else
+ \ifempty\p_page_backgrounds_setups \else
\doprocesslocalsetups\p_page_backgrounds_setups % should not produce funny spaces !
\fi
\edef\p_page_backgrounds_command{\namedframedparameter{\??layoutbackgrounds#1#2}\c!command}%
- \ifx\p_page_backgrounds_command\empty
+ \ifempty\p_page_backgrounds_command
\expandafter\page_backgrounds_set_box_cell_nop
\else
\expandafter\page_backgrounds_set_box_cell_yes
@@ -505,8 +505,8 @@
\edef\p_page_backgrounds_offset{\namedframedparameter{\??layoutbackgrounds\v!page}\c!offset}%
\edef\p_page_backgrounds_depth {\namedframedparameter{\??layoutbackgrounds\v!page}\c!depth }%
\edef\p_page_backgrounds_state {\namedframedparameter{\??layoutbackgrounds }\c!state }%
- \global\d_page_backgrounds_offset\ifx\p_offset\empty\zeropoint\else\p_page_backgrounds_offset\fi
- \global\d_page_backgrounds_depth \ifx\p_depth \empty\zeropoint\else\p_page_backgrounds_depth \fi
+ \global\d_page_backgrounds_offset\ifempty\p_offset\zeropoint\else\p_page_backgrounds_offset\fi
+ \global\d_page_backgrounds_depth \ifempty\p_depth \zeropoint\else\p_page_backgrounds_depth \fi
\global\pagebackgroundoffset\d_page_backgrounds_offset\relax
\global\pagebackgrounddepth \d_page_backgrounds_depth \relax
\ifx\p_page_backgrounds_state\v!stop
diff --git a/tex/context/base/mkiv/page-ini.mkxl b/tex/context/base/mkiv/page-ini.mkxl
index 6a9b75d22..481e5abd5 100644
--- a/tex/context/base/mkiv/page-ini.mkxl
+++ b/tex/context/base/mkiv/page-ini.mkxl
@@ -225,15 +225,15 @@
\newconditional\c_page_marks_building_successive_pages \settrue\c_page_marks_building_successive_pages
\def\page_marks_synchronize_page#1% box
- {\strc_markings_synchronize[\v!page][#1][\ifconditional\c_page_marks_building_successive_pages\v!keep\fi]}
+ {\strc_markings_synchronize\v!page{#1}{\ifconditional\c_page_marks_building_successive_pages\v!keep\fi}}
\def\page_marks_synchronize_column#1#2#3#4% first last column box
{\ifnum#3=#1\relax
- \strc_markings_synchronize[\number#3,\v!column:\number#3,\v!first,\v!column:\v!first][#4][]%
+ \strc_markings_synchronize{\number#3,\v!column:\number#3,\v!first,\v!column:\v!first}{#4}{}%
\orelse\ifnum#3=#2\relax
- \strc_markings_synchronize[\number#3,\v!column:\number#3,\v!last, \v!column:\v!last ][#4][]%
+ \strc_markings_synchronize{\number#3,\v!column:\number#3,\v!last, \v!column:\v!last }{#4}{}%
\else
- \strc_markings_synchronize[\number#3,\v!column:\number#3 ][#4][]%
+ \strc_markings_synchronize{\number#3,\v!column:\number#3 }{#4}{}%
\fi}
% Page body building
diff --git a/tex/context/base/mkiv/page-lay.mkxl b/tex/context/base/mkiv/page-lay.mkxl
index d24621e60..5eefc8b9a 100644
--- a/tex/context/base/mkiv/page-lay.mkxl
+++ b/tex/context/base/mkiv/page-lay.mkxl
@@ -350,7 +350,7 @@
\permanent\tolerant\protected\def\definepapersize[#1]#*[#2]#*[#3]%
{\edef\currentlayouttarget{#1}%
- \ifx\currentlayouttarget\empty
+ \ifempty\currentlayouttarget
% invalid target
\orelse\ifhastok={#2}%
\definelayouttarget[#1][#2]%
@@ -383,14 +383,12 @@
\permanent\tolerant\protected\def\setuppapersize[#1]#*[#2]%
{\ifarguments
\page_paper_restore
- \or
- \ifhastok={#1}%
- \page_paper_setup_size_settings[#1]%
- \orelse\ifhastok={#2}%
- \page_paper_setup_size_settings_by_name[#1][#2]%
- \else
- \page_paper_setup_size_change_size[#1][#2]%
- \fi
+ \orelse\ifhastok={#1}%
+ \page_paper_setup_size_settings[#1]%
+ \orelse\ifhastok={#2}%
+ \page_paper_setup_size_settings_by_name[#1][#2]%
+ \else
+ \page_paper_setup_size_change_size[#1][#2]%
\fi}
\protected\def\page_paper_setup_size_settings[#1]% sometimes used to set paper/print size
@@ -411,10 +409,10 @@
\fi}
\def\page_paper_setup_size_settings_recalibrate
- {\ifx\m_layouttarget_paper\empty
+ {\ifempty\m_layouttarget_paper
% forget about it
\else
- \ifx\m_layouttarget_print\empty
+ \ifempty\m_layouttarget_print
\let\m_layouttarget_print\m_layouttarget_paper
\fi
\page_paper_set_current[\m_layouttarget_paper][\m_layouttarget_print]%
@@ -514,7 +512,7 @@
\let\currentlayouttarget\empty
\page_paper_reset_paper
\processcommacommand[\m_page_asked_paper]\page_paper_identify_target
- \ifx\currentlayouttarget\empty
+ \ifempty\currentlayouttarget
\let\currentlayouttarget\currentpage
\fi
\glet\papersize\currentlayouttarget
@@ -1146,11 +1144,11 @@
{\textwidth\makeupwidth % which is a tricky but valid value
\edef\m_currentlayout_text_width {\layoutparameter\c!textwidth }%
\edef\m_currentlayout_text_margin{\layoutparameter\c!textmargin}%
- \ifx\m_currentlayout_text_width\empty \else
+ \ifempty\m_currentlayout_text_width \else
\textwidth\m_currentlayout_text_width % local
\fi
\global\innermakeupwidth\textwidth
- \ifx\m_currentlayout_text_margin\empty
+ \ifempty\m_currentlayout_text_margin
\global\innermakeupmargin\zeropoint
\else
\global\innermakeupmargin\m_currentlayout_text_margin\relax
diff --git a/tex/context/base/mkiv/page-spr.mkxl b/tex/context/base/mkiv/page-spr.mkxl
index 877509e41..3a835a61c 100644
--- a/tex/context/base/mkiv/page-spr.mkxl
+++ b/tex/context/base/mkiv/page-spr.mkxl
@@ -58,13 +58,13 @@
\hss % right page
\ifarrangingpages
% writes don't matter anyway
- \else\ifconditional\c_page_spread_once
+ \orelse\ifconditional\c_page_spread_once
\global\setbox\b_page_spread_content\emptyhbox
\wd\b_page_spread_content\makeupwidth
\ht\b_page_spread_content\textheight
\else
% writes can interfere (todo: write stripper, but how about hyperlinks)
- \fi \fi
+ \fi
\box\b_page_spread_content
\fi}}
diff --git a/tex/context/base/mkiv/regi-ini.mkxl b/tex/context/base/mkiv/regi-ini.mkxl
new file mode 100644
index 000000000..31e8b4717
--- /dev/null
+++ b/tex/context/base/mkiv/regi-ini.mkxl
@@ -0,0 +1,37 @@
+%D \module
+%D [ file=regi-ini,
+%D version=2005.04.25,
+%D title=\CONTEXT\ Regime Macros,
+%D subtitle=Regime 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.
+
+\registerctxluafile{regi-ini}{}
+
+\unprotect
+
+%D \macros
+%D {enableregime,disableregime,
+%D startregime,stopregime,
+%D currentregime}
+%D
+%D Beware, the enable and disable commands are global switches, so best use the
+%D start|/|stop commands.
+
+\let\currentregime\empty
+
+\permanent\protected\def\enableregime[#1]{\clf_enableregime{#1}}
+\permanent\protected\def\disableregime {\clf_disableregime}
+\permanent\protected\def\startregime [#1]{\clf_startregime{#1}}
+\permanent\protected\def\stopregime {\clf_stopregime}
+
+% only for diagnostics:
+
+% \def\codepagename#1{\cldcontext{os.tocodepage("#1")}}
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/spac-hor.mkxl b/tex/context/base/mkiv/spac-hor.mkxl
index c394308f3..9576549d1 100644
--- a/tex/context/base/mkiv/spac-hor.mkxl
+++ b/tex/context/base/mkiv/spac-hor.mkxl
@@ -48,7 +48,7 @@
\def\spac_indentation_setup_options[#1]%
{\edef\m_spac_indentation_options{#1}% comma separated list
- \ifx\m_spac_indentation_options\empty \else
+ \ifempty\m_spac_indentation_options \else
\spac_indentation_setup_indeed
\fi}
@@ -73,7 +73,7 @@
\permanent\protected\def\useindentingparameter#1% faster local variant
{\edef\m_spac_indentation_options{#1\c!indenting}%
- \ifx\m_spac_indentation_options\empty \else
+ \ifempty\m_spac_indentation_options \else
\spac_indentation_setup_indeed
\fi}
@@ -156,7 +156,7 @@
\installindentingmethod \v!odd {\c_spac_indentation_toggle_state\plusone}
\installindentingmethod \v!even {\c_spac_indentation_toggle_state\plustwo}
-\installindentingmethod \v!normal{\ifx\normalindentation\empty\else
+\installindentingmethod \v!normal{\ifempty\normalindentation\else
\let\v_spac_indentation_current\normalindentation
\spac_indentation_setup_size
\fi}
@@ -286,7 +286,7 @@
\permanent\protected\def\useindentnextparameter#1% new, the more efficient variant
{\edef\p_indentnext{#1\c!indentnext}%
- \ifx\p_indentnext\empty\else
+ \ifempty\p_indentnext\else
\begincsname\??indentnext\p_indentnext\endcsname
\fi}
diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf
index 4970622c9..c8b80ef36 100644
--- a/tex/context/base/mkiv/status-files.pdf
+++ b/tex/context/base/mkiv/status-files.pdf
Binary files differ
diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf
index ceb04ac24..9ec23f869 100644
--- a/tex/context/base/mkiv/status-lua.pdf
+++ b/tex/context/base/mkiv/status-lua.pdf
Binary files differ
diff --git a/tex/context/base/mkiv/strc-con.mklx b/tex/context/base/mkiv/strc-con.mklx
index ce7f60176..5d5eba056 100644
--- a/tex/context/base/mkiv/strc-con.mklx
+++ b/tex/context/base/mkiv/strc-con.mklx
@@ -110,7 +110,7 @@
\settrue\c_strc_constructions_define_commands % use with care, might become a proper key
\appendtoks
- \ifx\currentconstructionparent\empty
+ \ifempty\currentconstructionparent
\letvalue{\??constructionmain\currentconstruction}\currentconstruction
\definelist[\currentconstruction]% goodie
\else
@@ -316,7 +316,7 @@
\edef\currentconstructionalternative{\constructionparameter\c!alternative}%
\edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}%
% catch fuzzyness
- \ifx\p_strc_constructions_renderingsetup\empty
+ \ifempty\p_strc_constructions_renderingsetup
\letconstructionparameter\c!alternative\v!left
\let\currentconstructionalternative\v!left
\edef\p_strc_constructions_renderingsetup{\constructionalternativeparameter\c!renderingsetup}%
@@ -351,7 +351,7 @@
% maybe we should have an option as i cannot oversee the consequences now
%
% \edef\p_strc_constructions_sample{\constructionparameter\c!sample}%
- % \ifx\p_strc_constructions_sample\empty
+ % \ifempty\p_strc_constructions_sample
% \strc_constructions_preroll_head\currentconstructiontext
% \else
% \strc_constructions_preroll_head\currentconstructiontextsample
@@ -363,7 +363,7 @@
\strc_constructions_ignore_head
\else
\edef\p_strc_constructions_sample{\constructionparameter\c!sample}%
- \ifx\p_strc_constructions_sample\empty
+ \ifempty\p_strc_constructions_sample
\strc_constructions_set_width_and_distance
\else
\strc_constructions_preroll_head\currentconstructionsample
@@ -395,7 +395,7 @@
\fi
\fi
\edef\p_strc_constructions_align{\constructionparameter\c!align}%
- \ifx\p_strc_constructions_align\empty \else
+ \ifempty\p_strc_constructions_align \else
\setupalign[\p_strc_constructions_align]% \use...
\fi
\ifcase\c_strc_constructions_nested_state
@@ -410,7 +410,7 @@
\directsetup\p_strc_constructions_renderingsetup\relax
% moved to here 2014-07-03
\edef\p_strc_constructions_indenting{\constructionparameter\c!indenting}%
- \ifx\p_strc_constructions_indenting\empty \else
+ \ifempty\p_strc_constructions_indenting \else
\indenting[\p_strc_constructions_indenting]% \use...
\fi
%
@@ -436,7 +436,7 @@
{\doifelse{\constructionalternativeparameter\c!alignbottom}{\v!yes}\vbox\vtop
{\hsize\constructionsheadwidth
\edef\p_strc_constructions_headalign{\constructionparameter\c!headalign}%
- \ifx\p_strc_constructions_headalign\empty \else
+ \ifempty\p_strc_constructions_headalign \else
\setupalign[\p_strc_constructions_headalign]% \use...
\fi
#1}}
@@ -540,7 +540,7 @@
{\forgetall
\dontcomplain
\hsize\constructionsheadwidth\relax
- \ifx\p_strc_constructions_headalign\empty
+ \ifempty\p_strc_constructions_headalign
\setupalign[#1]% use fast one
\else
\setupalign[\p_strc_constructions_headalign]% use fast one
@@ -558,7 +558,7 @@
{\forgetall
\dontcomplain
\hsize\constructionsheadwidth\relax
- \ifx\p_strc_constructions_headalign\empty
+ \ifempty\p_strc_constructions_headalign
\setupalign[#1]% use fast one
\else
\setupalign[\p_strc_constructions_headalign]% use fast one
@@ -569,7 +569,7 @@
\dp\constructionheadbox\strutdp}
\def\strc_constructions_set_hang#1%
- {\ifx\p_strc_constructions_hang\empty
+ {\ifempty\p_strc_constructions_hang
% nothing
\orelse\ifx\p_strc_constructions_hang\v!fit
\scratchdimen\htdp\constructionheadbox
@@ -741,7 +741,7 @@
\par
\nobreak
\edef\p_strc_constructions_inbetween{\constructionparameter\c!inbetween}%
- \ifx\p_strc_constructions_inbetween\empty \else
+ \ifempty\p_strc_constructions_inbetween \else
\p_strc_constructions_inbetween
% shouldn't this move to after the fi?
\directcheckedvspacing\v!samepage
@@ -970,7 +970,7 @@
{\ifconditional\csname\??constructionclosesymbol\currentconstruction\endcsname
\global\expandafter\setfalse\csname\??constructionclosesymbol\currentconstruction\endcsname
\edef\p_strc_constructions_closesymbol{\constructionparameter\c!closesymbol}%
- \ifx\p_strc_constructions_closesymbol\empty \else
+ \ifempty\p_strc_constructions_closesymbol \else
\constructionparameter\c!closecommand{\p_strc_constructions_closesymbol}% hm why {} maybe because box expected
\fi
\fi}
@@ -1014,11 +1014,11 @@
%xdef\currentconstructionshownumber {\constructionparameter\c!number}%
\xdef\currentconstructionincrementnumber{\constructionparameter\c!incrementnumber}%
%
- \ifx\currentconstructionexpansion\empty
+ \ifempty\currentconstructionexpansion
\glet\currentconstructionexpansion\v!no
\fi
%
- \ifx\currentconstructionreferenceprefix\empty
+ \ifempty\currentconstructionreferenceprefix
\glet\currentconstructionreferenceprefix\referenceprefix
\fi
\ifx\currentconstructionexpansion\s!xml
@@ -1028,7 +1028,7 @@
\xdef\currentconstructionmarking {\constructionparameter\c!marking}%
\xdef\currentconstructionlist {\constructionparameter\c!list}%
\xmlstopraw
- \ifx\currentconstructionlist\empty
+ \ifempty\currentconstructionlist
\glet\currentconstructionlist\currentconstructiontitle
\fi
\glet\currentconstructioncoding\s!xml
@@ -1043,14 +1043,14 @@
\xdef\currentconstructionbookmark{\detokenizedconstructionparameter\c!bookmark}%
\xdef\currentconstructionmarking {\detokenizedconstructionparameter\c!marking}%
\xdef\currentconstructionlist {\detokenizedconstructionparameter\c!list}%
- \iflocation \ifx\currentconstructionbookmark\empty
+ \iflocation \ifempty\currentconstructionbookmark
\begingroup
\simplifycommands
\xdef\currentconstructionbookmark{\detokenize\expandafter{\normalexpanded{\constructionparameter\c!title}}}%
\endgroup
\fi \fi
\fi
- \ifx\currentconstructionlist\empty
+ \ifempty\currentconstructionlist
\glet\currentconstructionlist\currentconstructiontitle
\fi
\glet\currentconstructioncoding\s!tex
diff --git a/tex/context/base/mkiv/strc-des.mklx b/tex/context/base/mkiv/strc-des.mklx
index 9bdb0e6ea..e6525448c 100644
--- a/tex/context/base/mkiv/strc-des.mklx
+++ b/tex/context/base/mkiv/strc-des.mklx
@@ -61,7 +61,7 @@
]
\appendtoks
- \ifx\currentdescriptionparent\empty
+ \ifempty\currentdescriptionparent
\defineconstruction[\currentdescription][\currentdescriptionparent][\s!handler=\v!description,\c!level=1]%
\else
\defineconstruction[\currentdescription][\s!handler=\v!description,\c!level=1]%
diff --git a/tex/context/base/mkiv/strc-enu.mklx b/tex/context/base/mkiv/strc-enu.mklx
index 6bc2f39d4..66d8390f9 100644
--- a/tex/context/base/mkiv/strc-enu.mklx
+++ b/tex/context/base/mkiv/strc-enu.mklx
@@ -142,7 +142,7 @@
\instance\setuevalue{\e!stop #tag}{\strc_enumerations_stop }}
\appendtoks
- \ifx\currentenumerationparent\empty
+ \ifempty\currentenumerationparent
% clone => parent | subclone => clone | subsubclone => subclone
\let\currentenumerationsub\empty
\strc_define_commands_enumeration
@@ -168,7 +168,7 @@
\edef\currentenumerationsub{\v!sub\currentenumerationsub}}%
\fi
\edef\p_counter{\enumerationparameter\s!counter}% can inherit from parent
- \ifx\p_counter\empty %
+ \ifempty\p_counter %
\let\p_counter\currentenumeration
\fi
\doifelsecounter\p_counter\donothing{\strc_enumerations_define_counter\p_counter}%
@@ -264,18 +264,18 @@
\ifconditional\c_strc_constructions_number_state
\ifx\currentconstructionreference\!!plustoken
\strc_enumerations_full_number_symbol
- \else\ifx\currentconstructionreference\!!minustoken
+ \orelse\ifx\currentconstructionreference\!!minustoken
\strc_enumerations_full_number_nop
\else
\strc_enumerations_full_number_coupling
- \fi\fi
+ \fi
\else
\strc_enumerations_full_number_nop
\fi}
\protected\def\strc_enumerations_inject_text_with_space
{\edef\p_text{\constructionparameter\c!text}%
- \ifx\p_text\empty \else
+ \ifempty\p_text \else
\p_text
\removeunwantedspaces
\nobreakspace
@@ -364,7 +364,7 @@
\fi
\strc_enumerations_full_number_yes
\edef\p_coupling{\constructionparameter\c!coupling}%
- \ifx\p_coupling\empty \else
+ \ifempty\p_coupling \else
\symbolreference[order(construction:\p_coupling:\the\locationorder)]%
\fi
\fi}
diff --git a/tex/context/base/mkiv/strc-ini.mklx b/tex/context/base/mkiv/strc-ini.mklx
new file mode 100644
index 000000000..3897c1d2a
--- /dev/null
+++ b/tex/context/base/mkiv/strc-ini.mklx
@@ -0,0 +1,81 @@
+%D \module
+%D [ file=strc-flt,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Structure Macros,
+%D subtitle=Initialization \& Helpers,
+%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 / Initialization & Helpers}
+
+\registerctxluafile{strc-ini}{}
+
+\unprotect
+
+% segments: 0:100 2:3 chapter:subsection 3 (=self+2) (alternative: sectionset)
+
+% section : [sectionnumber(s)]
+% sectionseparatorset (default) sectionconversionset (default) sectionstopper () sectionset sectionsegments
+
+% lists : [sectionnumber(s)] [text] [prefix(es)[separator][pagenumber(s)]
+% sectionseparatorset (default) sectionconversionset (default) sectionstopper sectionset sectionsegments
+% prefixseparatorset (default) prefixconversionset (default) prefixstopper (.) prefixset prefixsegments
+% pageseparatorset (default) pageconversionset (default) pagestopper () pagesegments
+% prefix (no)
+
+% counter : [prefix(es)[separator]][number(s)]
+% prefixseparatorset (default) prefixconversionset (default) prefixstopper (.) prefixset prefixsegments
+% numberseparatorset (default) numberconversionset (default) numberstopper () numbersegments
+% prefix (no)
+
+% pagenumber: [prefix(es)[separator]][pagenumber(s)]
+% prefixseparatorset (default) prefixconversionset (default) prefixstopper (.) prefixset prefixsegments
+% pageseparatorset (default) pageconversionset (default) pagestopper ()
+% prefix (no)
+
+% text mark reference list
+% section P P P P
+% float P.N P.N P.N
+% itemize P.N P.N
+% enumerate P.N P.N P.N
+% formula P.N P.N
+% footnote P.N P.N P.N
+% number P.N P.N
+
+% number prefix section page
+
+% [text|marking|reference|list]:[number|prefix|pagenumber|pageprefix]:[separatorset|conversionset|conversion|stopper|set|segments|resetset|order]
+
+% figure caption : text:number:* text:prefix:* -> \setupcaption[figure][...]; stores defaults
+% figure list : list:number:* list:prefix:* list:pagenumber:* list:pageprefix:* -> \setuplist[figure][...]; takes stored defaults for number and pagenumber]
+% figure reference: reference:number:* reference:prefix:* reference:pagenumber:* reference:pageprefix:* -> \setupreference[figure]]...]; takes stored defaults
+
+% This module deals with structure: section headers, list and numbering and
+% eventually cross referencing. These components are rather interwoven and
+% therefore an inbetween layer is used. Eventually this will replace the
+% corresponding code in core-sec, core-lst, core-num and core-ref.
+
+% We collect operations that deal with things like formatting on each level of a
+% number in sets. This is all handles at the \LUA\ end. References to such sets
+% travel with the multipass information.
+
+\permanent\tolerant\protected\def\defineresetset [#name]#spacer[#set]#spacer[#default]{\clf_definestructureset{structure:resets} {#name}{\detokenize{#set}}{\detokenize{#default}}true\relax}
+\permanent\tolerant\protected\def\defineseparatorset [#name]#spacer[#set]#spacer[#default]{\clf_definestructureset{structure:separators} {#name}{\detokenize{#set}}{\detokenize{#default}}false\relax}
+\permanent\tolerant\protected\def\defineconversionset[#name]#spacer[#set]#spacer[#default]{\clf_definestructureset{structure:conversions}{#name}{\detokenize{#set}}{\detokenize{#default}}false\relax}
+\permanent\tolerant\protected\def\defineprefixset [#name]#spacer[#set]#spacer[#default]{\clf_definestructureset{structure:prefixes} {#name}{\detokenize{#set}}{\detokenize{#default}}false\relax}
+
+\aliased\let\definestructureresetset \defineresetset
+\aliased\let\definestructureseparatorset \defineseparatorset
+\aliased\let\definestructureconversionset\defineconversionset
+\aliased\let\definestructureprefixset \defineprefixset
+
+% \defineseparatorset [weird][!,?,*][:] % tex content
+% \defineconversionset[weird][numbers,characters,romannumerals][numbers] % symbolic names
+% \defineresetset [weird][0,0,1][0] % numbers
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/strc-itm.mklx b/tex/context/base/mkiv/strc-itm.mklx
index aa105af33..ab558e8a8 100644
--- a/tex/context/base/mkiv/strc-itm.mklx
+++ b/tex/context/base/mkiv/strc-itm.mklx
@@ -336,8 +336,6 @@
\setuevalue{\e!setup\currentitemgroup\e!endsetup}{\setupitemgroup[\currentitemgroup]}% obsolete
\let\currentparentitemgroup\currentitemgroup
\definecounter[\v_strc_itemgroups_counter]%
- % beware ... we cannot use _ as the conversion set is not expanded
- % \defineconversionset[\v_strc_itemgroups_counter][\currentitemgroupconversionset][\currentitemgroupsymbol]%
\to \everydefineitemgroup
%D Global states
@@ -702,8 +700,8 @@
\c!numberconversionset=\v_strc_itemgroups_counter,
\c!numbersegments=\currentitemgroupsegments]%
% there will be a fixedconversion key
- %\normalexpanded{\defineconversionset[\v_strc_itemgroups_counter][\currentitemgroupconversionset][\currentitemgroupsymbol]}%
- \normalexpanded{\strc_sets_define_conversion_set[\v_strc_itemgroups_counter][\currentitemgroupconversionset][\currentitemgroupsymbol]}%
+ \normalexpanded{\defineconversionset[\v_strc_itemgroups_counter][\currentitemgroupconversionset][\currentitemgroupsymbol]}%
+ %\normalexpanded{\strc_sets_define_conversion_set[\v_strc_itemgroups_counter][\currentitemgroupconversionset][\currentitemgroupsymbol]}%
%
\convertedcounter[\v_strc_itemgroups_counter]% [\number\currentitemlevel]%
\strc_itemgroups_insert_reference
diff --git a/tex/context/base/mkiv/strc-lab.mkxl b/tex/context/base/mkiv/strc-lab.mkxl
index 2de2b1007..f93114870 100644
--- a/tex/context/base/mkiv/strc-lab.mkxl
+++ b/tex/context/base/mkiv/strc-lab.mkxl
@@ -72,7 +72,7 @@
% todo: \strc_labels_command for user
\appendtoks
- \ifx\currentlabelparent\empty
+ \ifempty\currentlabelparent
% clone => parent | subclone => clone | subsubclone => subclone
\let\currentlabelsub\empty
\strc_define_commands_label
@@ -98,7 +98,7 @@
\edef\currentlabelsub{\v!sub\currentlabelsub}}%
\fi
\edef\p_counter{\labelparameter\s!counter}% can inherit from parent
- \ifx\p_counter\empty %
+ \ifempty\p_counter %
\let\p_counter\currentlabel
\fi
\doifelsecounter\p_counter\donothing{\strc_labels_define_counter\p_counter}%
diff --git a/tex/context/base/mkiv/strc-mar.mkxl b/tex/context/base/mkiv/strc-mar.mkxl
new file mode 100644
index 000000000..a15db8265
--- /dev/null
+++ b/tex/context/base/mkiv/strc-mar.mkxl
@@ -0,0 +1,135 @@
+%D \module
+%D [ file=strc-mar,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Structure Macros,
+%D subtitle=Markings,
+%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 / Markings}
+
+\registerctxluafile{strc-mar}{}
+
+\unprotect
+
+%D Synchronizing marks is a rather tricky and messy business. When setting a mark, a
+%D node is added to the list in order for to \TEX\ be able to figure out the 3
+%D current marks when a page is made (last mark on previous page, first on current
+%D page, last on current page; in \LUATEX\ we might at one point have the first on
+%D the next page as well).
+%D
+%D Resetting a mark is not easy. An empty one will not erase the last one on the
+%D previous page for instance. In \LUATEX\ we can clear a marks state register with
+%D \type {\clearmarks} but since this is an immediate operation it might have
+%D unwanted side effects when \TEX\ has collected several pages of text and
+%D finishing off these pages uses marks.
+%D
+%D In \MKIV\ we provide an alternative model that permits some more control over the
+%D way marks are used. It is not entirely compatible with \MKII\ or previous \MKIV\
+%D implementations but in practice this is not a real problem. It's also easier now
+%D to extend this mechanism.
+
+\definesystemattribute [marks] [global]
+
+\installcorenamespace{marking}
+
+\installcommandhandler \??marking {marking} \??marking
+
+\newconditional\inhibitgetmarking % will become private
+\newconditional\inhibitsetmarking % will become private
+
+\newtoks \everymarking
+
+\appendtoks
+ \clf_definemarking{\currentmarking}{\currentmarkingparent}%
+\to \everydefinemarking
+
+\permanent\protected\tolerant\def\relatemarking [#1]#*[#2]{\clf_relatemarking{#1}{#2}}
+\permanent\protected\tolerant\def\resetmarking [#1]{\clf_resetmarking{#1}}
+\permanent\protected\tolerant\def\synchronizemarking[#1]#*[#2]#*[#3]{\ifvoid#2\else\clf_synchronizemarking{#1}#2{#3}\fi}
+\permanent \def\doifelsemarking #1{\clf_doifelsemarking{#1}} % no \noexpanded
+
+\def\strc_markings_synchronize#1#2#3{\ifvoid#2\else\clf_synchronizemarking{#1}#2{#3}\fi} % called in page-ini
+
+\permanent\protected\tolerant\def\setmarking[#1]#:#2%
+ {\ifconditional\inhibitsetmarking\else
+ \doifelse{\namedmarkingparameter{#1}\c!expansion}\v!yes
+ {\clf_setmarking{#1}{#2}}%
+ {\clf_setmarking{#1}{\detokenize{#2}}}%
+ \fi}
+
+\aliased\let\marking \setmarking
+\aliased\let\doifmarkingelse\doifelsemarking
+
+% defaults
+
+\setupmarking
+ [\c!expansion=\v!no,
+ \c!separator=\space\emdash\space,
+ \c!filtercommand=\firstofoneargument,
+ \c!state=\v!start]
+
+% fetching, regular interface
+
+\permanent\protected\def\getmarking
+ {\ifconditional\inhibitgetmarking
+ \expandafter\strc_markings_get_nop
+ \else
+ \expandafter\strc_markings_get_yes
+ \fi}
+
+\tolerant\def\strc_markings_get_nop[#-]#*[#-]#*[#-]%
+ {}
+
+\tolerant\def\strc_markings_get_yes[#1]#*[#2]#*[#3]%
+ {\doif{\namedmarkingparameter{#1}\c!state}\v!start
+ {\begingroup
+ \setsystemmode\v!marking
+ \the\everymarking
+ \ifparameter#3\or
+ \clf_getmarking{#1}{#2}{#3}%
+ \else
+ \clf_getmarking{#1}{\v!page}{#2}%
+ \fi
+ \endgroup}}
+
+% the fetchers are fully expandable: [name][method]
+
+\permanent\tolerant\def\fetchonemark[#1]#*[#2]{\ifconditional\inhibitgetmarking\else\clf_fetchonemark {#1}{\v!page}{#2}\fi}
+\permanent\tolerant\def\fetchtwomarks [#1]{\ifconditional\inhibitgetmarking\else\clf_fetchtwomarks{#1}{\v!page}\fi}
+\permanent\tolerant\def\fetchallmarks [#1]{\ifconditional\inhibitgetmarking\else\clf_fetchallmarks{#1}{\v!page}\fi}
+
+\aliased\let\fetchmark\fetchonemark
+
+% also fully expandable but here we have: [name][range][method]
+
+\permanent\tolerant\def\fetchonemarking[#1]#*[#2]#*[#3]{\ifconditional\inhibitgetmarking\else\clf_fetchonemark {#1}{#2}{#3}\fi}
+\permanent\tolerant\def\fetchtwomarkings [#1]#*[#2]{\ifconditional\inhibitgetmarking\else\clf_fetchtwomarks{#1}{#2}\fi}
+\permanent\tolerant\def\fetchallmarkings [#1]#*[#2]{\ifconditional\inhibitgetmarking\else\clf_fetchallmarks{#1}{#2}\fi}
+
+\aliased\let\fetchmarking\fetchonemarking
+
+\permanent\def\markingseparator#1{\namedmarkingparameter{#1}\c!separator}
+\permanent\def\markingcommand #1{\namedmarkingparameter{#1}\c!filtercommand}
+
+%D Experimental:
+%D
+%D \starttyping
+%D \definemarking[boxmark]
+%D
+%D \setbox0\ruledvbox{
+%D \marking[boxmark]{tufte} \input tufte \par
+%D \marking[boxmark]{ward} \input ward \par
+%D }
+%D
+%D \synchronizemarking[zerobox][0] \box0
+%D
+%D marks: (\getmarking[boxmark][zerobox][first],\getmarking[boxmark][zerobox][last])
+%D \stoptyping
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/strc-not.mklx b/tex/context/base/mkiv/strc-not.mklx
index 6e82c9c4e..e49bf6269 100644
--- a/tex/context/base/mkiv/strc-not.mklx
+++ b/tex/context/base/mkiv/strc-not.mklx
@@ -150,7 +150,7 @@
\instance\setuevalue{\e!stop #tag}{\strc_notations_stop }}
\appendtoks
- \ifx\currentnotationparent\empty
+ \ifempty\currentnotationparent
% clone => parent | subclone => clone | subsubclone => subclone
\let\currentnotationsub\empty
\strc_define_commands_notation
@@ -178,7 +178,7 @@
\definelist[\currentnotation][\currentnotationparent]% goodie
\fi
\edef\p_counter{\notationparameter\s!counter}% can inherit from parent
- \ifx\p_counter\empty %
+ \ifempty\p_counter
\let\p_counter\currentnotation
\fi
\doifelsecounter\p_counter\donothing{\strc_notes_define_counter\p_counter}%
@@ -402,7 +402,7 @@
\permanent\def\currentnoteinsertionnumber{\namedinsertionnumber{\noteparameter\s!insert}}
\appendtoks
- \ifx\currentnoteparent\empty
+ \ifempty\currentnoteparent
\doifelseinsertion\currentnote
\donothing
{\defineinsertion[\currentnote]% could be an option
@@ -641,7 +641,7 @@
\def\strc_notes_set_style_color_special
{\iftrialtypesetting
% keep
- \orelse\ifx\currentcolorparameter\empty
+ \orelse\ifempty\currentcolorparameter
\scratchcounter\clf_notedeltapage{\currentnote}\currentnotenumber\relax % todo calculate once
\setlocationcolorspecified\scratchcounter
\fi}
@@ -725,7 +725,7 @@
\protected\def\strc_notes_inject_separator % patch by WS due to request on list
{\edef\p_textseparator{\noteparameter\c!textseparator}%
- \ifx\p_textseparator\empty
+ \ifempty\p_textseparator
\kern\noteparameter\c!distance
\else
% skip or kern
@@ -832,7 +832,7 @@
\newtoks\everysynchronizenote % after a general setup has happened
\appendtoks
- \ifx\currentnote\empty \else
+ \ifempty\currentnote \else
\setupnotations[\currentnote][]% also a synchronize
\fi
\to \everysynchronizenote
@@ -923,7 +923,7 @@
\def\strc_notes_set_factor
{\edef\p_factor{\noteparameter\c!factor}%
- \ifx\p_factor\empty \else
+ \ifempty\p_factor \else
\ifnum\p_factor<\zerocount \else
% \global
\count\currentnoteinsertionnumber\p_factor % new: global
@@ -1012,13 +1012,13 @@
\appendtoks
\edef\p_spacebefore{\rootnoteparameter\c!spacebefore}%
- \ifx\p_spacebefore\empty
+ \ifempty\p_spacebefore
\global\s_strc_notes_before\zeropoint
\else
\setbox\scratchbox\vbox{\blank[\p_spacebefore]\global\s_strc_notes_before\lastskip}%
\fi
\edef\p_spaceinbetween{\rootnoteparameter\c!spaceinbetween}%
- \ifx\p_spaceinbetween\empty
+ \ifempty\p_spaceinbetween
\global\s_strc_notes_inbetween\zeropoint
\else
\setbox\scratchbox\vbox{\blank[\p_spaceinbetween]\global\s_strc_notes_inbetween\lastskip}%
@@ -1349,7 +1349,7 @@
% \else
% \setnoteparameter\c!width{\makeupwidth}%
% \fi
- \orelse\ifx\p_width\empty
+ \orelse\ifempty\p_width
\setnoteparameter\c!width{\hsize}%
\fi
\fi
@@ -1392,12 +1392,12 @@
\whitespace
\ifconditional\c_strc_notes_first_placed
\edef\p_spaceinbetween{\noteparameter\c!spaceinbetween}%
- \ifx\p_spaceinbetween\empty\else
+ \ifempty\p_spaceinbetween\else
\blank[\p_spaceinbetween]%
\fi
\else
\edef\p_spacebefore{\noteparameter\c!spacebefore}%
- \ifx\p_spacebefore\empty\else
+ \ifempty\p_spacebefore\else
\blank[\p_spacebefore]%
\fi
\fi
diff --git a/tex/context/base/mkiv/strc-num.mkxl b/tex/context/base/mkiv/strc-num.mkxl
new file mode 100644
index 000000000..12306781b
--- /dev/null
+++ b/tex/context/base/mkiv/strc-num.mkxl
@@ -0,0 +1,675 @@
+%D \module
+%D [ file=strc-num,
+%D version=2008.10.20,
+%D title=\CONTEXT\ Structure Macros,
+%D subtitle=Basic Numbering,
+%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 / Basic Numbering}
+
+\registerctxluafile{strc-num}{}
+
+\unprotect
+
+\startcontextdefinitioncode
+
+% work in progress
+% to be checked: can we use the command handler code here?
+% all settings will move to lua
+
+\installcorenamespace{counter}
+
+\installcommandhandler \??counter {counter} \??counter
+
+\aliased\let\setupcounters \setupcounter
+\aliased\let\setupstructurecounting\setupcounter % will disappear
+
+\setupcounter
+ [\c!way=\v!by\v!chapter,
+% \c!blockway=,
+% \c!prefixstarter=,
+% \c!prefixstopper=,
+ \c!prefixconnector=.,
+ \c!prefixsegments=\autostructureprefixsegments\rootcounterparameter,
+ \c!start=\zerocount,
+ \c!prefix=\v!yes,
+ \c!state=\v!start]
+
+\permanent\def\autostructureprefixsegments#1% todo: \c!prefixsegments=\v!auto
+ {2:\thenamedheadlevel{\clf_way{#1\c!way}}}
+
+\appendtoks
+ \resetcounterparameter\s!counter
+\to \everypresetcounter
+
+\appendtoks
+ \ifempty\currentcounterparent
+ \edef\p_start{\counterparameter\c!start}%
+ \clf_definecounter
+ name {\currentcounter}%
+ start \ifempty\p_start\zerocount\else\numexpr\p_start\relax\fi
+ counter {\counterparameter\s!counter}%
+ method {\counterparameter\c!method}%
+ \relax
+ \letcounterparameter\s!name\currentcounter
+ \else
+ % \letcounterparameter\s!name\currentcounterparent % we need a chained clone
+ \setexpandedcounterparameter\s!name{\namedcounterparameter\currentcounterparent\s!name}%
+ \fi
+ \strc_counters_check_setup
+\to \everydefinecounter
+
+\appendtoks
+ \ifempty\currentcounter \else
+ \edef\p_number{\counterparameter\c!number}%
+ \ifempty\p_number \else
+ \clf_setcounter{\counterparameter\s!name}\numexpr\p_number\relax
+ \letcounterparameter\c!number\empty
+ \fi
+ \edef\p_start{\counterparameter\c!start}%
+ \setexpandedcounterparameter\c!start{\ifempty\p_start0\else\number\p_start\fi}%
+ \strc_counters_check_setup
+ \fi
+\to \everysetupcounter
+
+% % % %
+
+\permanent\def\strc_counters_way #1{\clf_way{\namedcounterparameter{#1}\c!way}}
+\permanent\def\thenamedcounterlevel#1{\xthenamedheadlevel{\clf_way{\namedcounterparameter{#1}\c!way}}}
+
+\protected\def\strc_counters_check_setup
+ {\edef\p_name{\directcounterparameter\s!name}%
+ \ifx\currentcounter\p_name
+ \edef\currentcounterlevel{\thenamedcounterlevel\currentcounter}%
+ \edef\p_start{\counterparameter\c!start}%
+ \clf_checkcountersetup
+ {\currentcounter}%
+ \numexpr\currentcounterlevel\relax
+ \numexpr\ifempty\p_start\zerocount\else\p_start\fi\relax % bug in scanner
+ {\counterparameter\c!state}%
+ \fi}
+
+\permanent\protected\def\doifelsecounter #1{\clf_doifelsecounter{\namedcounterparameter{#1}\s!name}}
+\permanent\protected\def\doifcounter #1{\clf_doifcounter {\namedcounterparameter{#1}\s!name}}
+\permanent\protected\def\doifnotcounter #1{\clf_doifnotcounter {\namedcounterparameter{#1}\s!name}}
+
+\aliased\let\doifcounterelse\doifelsecounter
+
+\permanent\tolerant\protected\def\setcounter[#1]#*[#2]#*[#3]%
+ {\ifarguments\or\or
+ \clf_setcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \clf_setsubcounter{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\numexpr#3\relax
+ \fi}
+
+\permanent\tolerant\protected\def\setcounterown[#1]#*[#2]#*[#3]%
+ {\ifarguments\or\or
+ \clf_setowncounter {\namedcounterparameter{#1}\s!name}{#2}\or
+ \clf_setownsubcounter{\namedcounterparameter{#1}\s!name}\numexpr#2\relax{#3}%
+ \fi}
+
+\permanent\tolerant\protected\def\restartcounter[#1]#*[#2]#*[#3]%
+ {\ifarguments\or\or
+ \clf_restartcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \clf_restartsubcounter{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\numexpr#3\relax
+ \fi}
+
+\permanent\tolerant\protected\def\resetcounter[#1]#*[#2]%
+ {\ifarguments\or
+ \clf_resetcounter {\namedcounterparameter{#1}\s!name}\or
+ \clf_resetsubcounter{\namedcounterparameter{#1}\s!name}\numexpr#2\relax
+ \fi}
+
+\permanent\tolerant\protected\def\incrementcounter[#1]#*[#2]%
+ {\ifarguments\or
+ \strc_counters_increment_sub{#1}\plusone\or
+ \strc_counters_increment_sub{#1}{#2}%
+ \fi}
+
+\permanent\tolerant\protected\def\decrementcounter[#1]#*[#2]%
+ {\ifarguments\or
+ \clf_decrementcounter {\namedcounterparameter{#1}\s!name}\or
+ \clf_decrementsubcounter{\namedcounterparameter{#1}\s!name}\numexpr#2\relax
+ \fi}
+
+\permanent\tolerant\protected\def\rawcounter[#1]#*[#2]%
+ {\ifarguments\or\or
+ \clf_countervalue {\namedcounterparameter{#1}\s!name}%
+ \clf_subcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \fi}
+
+\permanent\tolerant\protected\def\lastcounter[#1]#*[#2]%
+ {\ifarguments\or\or
+ \clf_lastcountervalue {\namedcounterparameter{#1}\s!name}%
+ \clf_lastsubcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \fi}
+
+\permanent\tolerant\protected\def\firstcounter[#1]#*[#2]%
+ {\ifarguments\or\or
+ \clf_firstcountervalue {\namedcounterparameter{#1}\s!name}%
+ \clf_firstsubcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \fi}
+
+\permanent\tolerant\protected\def\prevcounter[#1]#*[#2]%
+ {\ifarguments\or\or
+ \clf_previouscountervalue {\namedcounterparameter{#1}\s!name}%}
+ \clf_previoussubcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \fi}
+
+\permanent\tolerant\protected\def\nextcounter[#1]#*[#2]%
+ {\ifarguments\or\or
+ \clf_nextcountervalue {\namedcounterparameter{#1}\s!name}%
+ \clf_nextsubcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \fi}
+
+\permanent\tolerant\protected\def\countersubs[#1]#*[#2]%
+ {\ifarguments\or\or
+ \clf_subcountervalues {\namedcounterparameter{#1}\s!name}%
+ \clf_subsubcountervalues{\namedcounterparameter{#1}\s!name}\numexpr#2\relax\or
+ \fi}
+
+\permanent\tolerant\protected\def\savecounter[#1]%
+ {\ifarguments\or
+ \clf_savecounter{\namedcounterparameter{#1}\s!name}%
+ \fi}
+
+\permanent\tolerant\protected\def\restorecounter[#1]%
+ {\ifarguments\or
+ \clf_restorecounter{\namedcounterparameter{#1}\s!name}%
+ \fi}
+
+\protected\def\strc_counters_set #1#2{\clf_setcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\protected\def\strc_counters_setown #1#2{\clf_setowncounter {\namedcounterparameter{#1}\s!name}{#2}}
+\protected\def\strc_counters_restart #1#2{\clf_restartcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\protected\def\strc_counters_reset #1{\clf_resetcounter {\namedcounterparameter{#1}\s!name}}
+\protected\def\strc_counters_decrement #1{\clf_decrementcounter {\namedcounterparameter{#1}\s!name}}
+
+ \def\strc_counters_raw #1{\clf_countervalue {\namedcounterparameter{#1}\s!name}}
+ \def\strc_counters_last #1{\clf_lastcountervalue {\namedcounterparameter{#1}\s!name}}
+ \def\strc_counters_first #1{\clf_firstcountervalue {\namedcounterparameter{#1}\s!name}}
+ \def\strc_counters_next #1{\clf_nextcountervalue {\namedcounterparameter{#1}\s!name}}
+ \def\strc_counters_prev #1{\clf_previouscountervalue {\namedcounterparameter{#1}\s!name}}
+ \def\strc_counters_subs #1{\clf_subcountervalues {\namedcounterparameter{#1}\s!name}}
+
+\protected\def\strc_counters_set_sub #1#2#3{\clf_setsubcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax\numexpr#3\relax}
+\protected\def\strc_counters_setown_sub #1#2#3{\clf_setownsubcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax{#3}}
+\protected\def\strc_counters_restart_sub #1#2#3{\clf_restartsubcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax\numexpr#3\relax}
+\protected\def\strc_counters_reset_sub #1#2{\clf_resetsubcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\protected\def\strc_counters_decrement_sub #1#2{\clf_decrementsubcounter {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+
+ \def\strc_counters_raw_sub #1#2{\clf_subcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax} % maybe raw
+ \def\strc_counters_last_sub #1#2{\clf_lastsubcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+ \def\strc_counters_first_sub #1#2{\clf_firstsubcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+ \def\strc_counters_next_sub #1#2{\clf_nextsubcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+ \def\strc_counters_prev_sub #1#2{\clf_previoussubcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+ \def\strc_counters_subs_sub #1#2{\clf_subsubcountervalues {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+
+\protected\def\strc_counters_save #1{\clf_savecounter {\namedcounterparameter{#1}\s!name}}
+\protected\def\strc_counters_restore #1{\clf_restorecounter {\namedcounterparameter{#1}\s!name}}
+
+\protected\def\strc_counters_incremented #1{\clf_incrementedcounter {\namedcounterparameter{#1}\s!name}}
+\protected\def\strc_counters_decremented #1{\clf_decrementedcounter {\namedcounterparameter{#1}\s!name}}
+
+\protected\def\showcounter [#1]{\clf_showcounter {\namedcounterparameter{#1}\s!name}}
+\protected\def\incrementedcounter[#1]{\clf_incrementedcounter{\namedcounterparameter{#1}\s!name}} % no \dosingleargument
+\protected\def\decrementedcounter[#1]{\clf_decrementedcounter{\namedcounterparameter{#1}\s!name}} % no \dosingleargument
+
+% public variants ... beware, for old cases, from now on the value variants are the
+% ones that are expandable
+
+\permanent\def\rawcountervalue [#1]{\clf_countervalue {\namedcounterparameter{#1}\s!name}}
+\permanent\def\lastcountervalue [#1]{\clf_lastcountervalue {\namedcounterparameter{#1}\s!name}}
+\permanent\def\firstcountervalue[#1]{\clf_firstcountervalue {\namedcounterparameter{#1}\s!name}}
+\permanent\def\nextcountervalue [#1]{\clf_nextcountervalue {\namedcounterparameter{#1}\s!name}}
+\permanent\def\prevcountervalue [#1]{\clf_previouscountervalue{\namedcounterparameter{#1}\s!name}}
+
+\permanent\def\rawsubcountervalue [#1]#*[#2]{\clf_subcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\permanent\def\lastsubcountervalue [#1]#*[#2]{\clf_lastsubcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\permanent\def\firstsubcountervalue[#1]#*[#2]{\clf_firstsubcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\permanent\def\nextsubcountervalue [#1]#*[#2]{\clf_nextsubcountervalue {\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+\permanent\def\prevsubcountervalue [#1]#*[#2]{\clf_previoussubcountervalue{\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+
+% The bypage check needs a multipass reference and therefore we only check for it when we increment
+% and know that some content will be placed. We could also check for spreads.
+
+\protected\def\strc_counters_increment_sub#1#2%
+ {% this will be combined into one lua call
+ \edef\m_strc_counters_way{\strc_counters_way{#1}}%
+ \ifx\m_strc_counters_way\v!page
+ \checkpagechange{#1}%
+ \ifpagechanged
+ \strc_counters_reset{#1}%
+ \fi
+ \fi
+ \clf_incrementsubcounter{\namedcounterparameter{#1}\s!name}\numexpr#2\relax}
+
+\protected\def\strc_counters_increment#1%
+ {\strc_counters_increment_sub{#1}\plusone}
+
+% so far for the hack
+
+\permanent\tolerant\protected\def\convertedcounter[#1]#*[#2]%
+ {\begingroup
+ \edef\currentcounter{#1}%
+ \ifparameter#2\or\setupcurrentcounter[#2]\fi
+ \clf_prefixedconverted
+ {\counterparameter\s!name}
+ {
+ prefix {\counterparameter\c!prefix}
+ separatorset {\counterparameter\c!prefixseparatorset}
+ conversion {\counterparameter\c!prefixconversion}
+ conversionset {\counterparameter\c!prefixconversionset}
+ starter {\counterparameter\c!prefixstarter}
+ stopper {\counterparameter\c!prefixstopper}
+ set {\counterparameter\c!prefixset}
+ segments {\counterparameter\c!prefixsegments}
+ connector {\counterparameter\c!prefixconnector}
+ }
+ {
+ order {\counterparameter\c!numberorder}
+ separatorset {\counterparameter\c!numberseparatorset}
+ conversion {\counterparameter\c!numberconversion}
+ conversionset {\counterparameter\c!numberconversionset}
+ starter {\counterparameter\c!numberstarter}
+ stopper {\counterparameter\c!numberstopper}
+ segments {\counterparameter\c!numbersegments}
+ type {\counterparameter\c!type}
+ criterium {\counterparameter\c!criterium}
+ }
+ \relax
+ \endgroup}
+
+\permanent\def\directconvertedcounter#1#2% name, type
+ {\clf_prefixedconverted
+ {\namedcounterparameter{#1}\s!name}
+ {
+ prefix {\namedcounterparameter{#1}\c!prefix}
+ separatorset {\namedcounterparameter{#1}\c!prefixseparatorset}
+ conversion {\namedcounterparameter{#1}\c!prefixconversion}
+ conversionset {\namedcounterparameter{#1}\c!prefixconversionset}
+ % starter {\namedcounterparameter{#1}\c!prefixstarter}
+ % stopper {\namedcounterparameter{#1}\c!prefixstopper}
+ set {\namedcounterparameter{#1}\c!prefixset}
+ segments {\namedcounterparameter{#1}\c!prefixsegments}
+ connector {\namedcounterparameter{#1}\c!prefixconnector}
+ }
+ {
+ order {\namedcounterparameter{#1}\c!numberorder}
+ separatorset {\namedcounterparameter{#1}\c!numberseparatorset}
+ conversion {\namedcounterparameter{#1}\c!numberconversion}
+ conversionset {\namedcounterparameter{#1}\c!numberconversionset}
+ starter {\namedcounterparameter{#1}\c!numberstarter}
+ stopper {\namedcounterparameter{#1}\c!numberstopper}
+ segments {\namedcounterparameter{#1}\c!numbersegments}
+ type {#2}
+ }
+ \relax}
+
+\permanent\tolerant\protected\def\convertedsubcounter[#1]#*[#2]#*[#3]% #2 can be n or n:m
+ {\ifarguments\or
+ \strc_counters_converted[#1][]%
+ \else
+ \strc_counters_converted[#1][\c!numbersegments=#2,#3]%
+ \fi}
+
+\permanent\protected\def\doifdefinedcounter {\doifcommandhandler \??counter}
+\permanent\protected\def\doifundefinedcounter {\doifnotcommandhandler \??counter}
+\permanent\protected\def\doifelsedefinedcounter{\doifelsecommandhandler\??counter}
+
+\aliased\let\doifdefinedcounterelse\doifelsedefinedcounter
+
+%D What follows is a compatibility layer. Do we need this?
+
+\aliased\let \numberparameter \namedcounterparameter % {name}\c!key
+
+\aliased\let \definenumber \definecounter % [name]
+\aliased\let \setupnumber \setupcounter % [name][setups]
+
+\aliased\let \setnumber \setcounter % [name]{value}
+\aliased\let \resetnumber \resetcounter % [name]
+\aliased\let \savenumber \savecounter % [name]
+\aliased\let \restorenumber \restorecounter % [name]
+\aliased\let \incrementnumber \incrementcounter % [name]
+\aliased\let \decrementnumber \decrementcounter % [name]
+\aliased\let \rawnumber \rawcounter % [name]
+\aliased\let \getnumber \convertedcounter % [name]
+\aliased\let \convertednumber \convertedcounter % [name]
+
+\aliased\let \doifdefinednumber \doifdefinedcounter % {number}{true}
+\aliased\let \doifundefinednumber \doifnotdefinedcounter % {number}{true}
+\aliased\let \doifelsedefinednumber \doifelsedefinedcounter % {number}{true}{false}
+\aliased\let \doifdefinednumberelse \doifelsedefinedcounter % {number}{true}{false}
+
+\aliased\let \setupnumbering \setupcounter
+
+%D Helpers:
+
+% call:
+%
+% \strc_counters_register_component
+% \currentfloat
+% \getfloatparameters \floatparameter \detokenizedfloatparameter
+% \hascaption \hastitle \hasnumber
+% [settings][userdata]
+%
+% sets:
+%
+% \m_strc_counters_last_registered_index
+% \m_strc_counters_last_registered_attribute
+% \m_strc_counters_last_registered_synchronize
+
+% currentstructurecomponent => \strc_current_ or just \m_strc_
+
+\protected\def\strc_counters_register_component#1#2#3#4#5#6#7[#8][#9]% maybe also nolist
+ {\begingroup
+ %
+ #2[\s!haslevel=1,#8]%
+ \edef\p_haslevel {#3\s!haslevel}%
+ \edef\p_hascaption{#3\s!hascaption}%
+ \edef\p_hastitle {#3\s!hastitle}%
+ \edef\p_hasnumber {#3\s!hasnumber}%
+ %
+ \edef\p_prefixsegments{#3\c!prefixsegments}%
+ \ifx\p_prefixsegments\v!auto
+ \edef\p_prefixsegments{\autostructureprefixsegments#3}%
+ \fi
+ %
+ \edef\currentname{#3\s!name}%
+ \ifempty\currentname
+ \edef\currentname{#1}%
+ \fi
+ \edef\currentcounter{#3\s!counter}%
+ \ifempty\currentcounter
+ \let\currentcounter\currentname
+ \fi
+ %
+ \ifx\p_hascaption\v!yes
+ \strc_counters_register_component_list{#1}{#3}{#4}{#9}%
+ \orelse\ifempty\currentstructurecomponentreference
+ \strc_counters_register_component_none
+ \else
+ \strc_counters_register_component_page{#3}%
+ \fi
+ \endgroup}
+
+\def\strc_counters_register_component_none
+ {\glet\m_strc_counters_last_registered_index \relax
+ \glet\m_strc_counters_last_registered_attribute \attributeunsetvalue
+ \glet\m_strc_counters_last_registered_synchronize\relax}
+
+\def\strc_counters_register_component_check_prefix
+ {\ifempty\currentstructurecomponentreferenceprefix
+ \let\currentstructurecomponentreferenceprefix\currentstructurereferenceprefix
+ \fi
+ \ifempty\currentstructurecomponentreferenceprefix
+ \let\currentstructurecomponentreferenceprefix\referenceprefix
+ \fi
+ \ifdefined\currentstructurecomponentreferenceprefix\else
+ \let\currentstructurecomponentreferenceprefix\empty
+ \fi}
+
+\def\strc_counters_register_component_page#1%
+ {\xdef\currentstructurecomponentreference {#1\c!reference}%
+ \xdef\currentstructurecomponentreferenceprefix{#1\c!referenceprefix}%
+ \strc_counters_register_component_check_prefix
+ \setnextinternalreference
+ \clf_setdestinationattribute
+ {%
+ references {%
+ internal \locationcount
+ % block {\currentsectionblock}% move to lua
+ view {\interactionparameter\c!focus}%
+ prefix {\currentstructurecomponentreferenceprefix}%
+ reference {\currentstructurecomponentreference}%
+ }%
+ metadata {%
+ kind {\s!page}%
+ }%
+ }%
+ \relax
+ \xdef\m_strc_counters_last_registered_attribute {\the\lastdestinationattribute}%
+ \glet\m_strc_counters_last_registered_index \relax
+ \glet\m_strc_counters_last_registered_synchronize\relax}
+
+\def\strc_counters_register_component_list#1#2#3#4%
+ {\xdef\currentstructurecomponentname {#2\s!name}%
+ \xdef\currentstructurecomponentlevel {#2\c!level}%
+ \edef\currentstructurecomponentexpansion {#2\c!expansion}%
+ \xdef\currentstructurecomponentxmlsetup {#2\c!xmlsetup}%
+ \xdef\currentstructurecomponentcatcodes {#2\s!catcodes}%
+ \xdef\currentstructurecomponentlabel {#2\c!label}%
+ \xdef\currentstructurecomponentreference {#2\c!reference}%
+ \xdef\currentstructurecomponentreferenceprefix{#2\c!referenceprefix}%
+ \strc_counters_register_component_check_prefix
+ \ifx\currentstructurecomponentexpansion\s!xml
+ \xmlstartraw
+ \xdef\currentstructurecomponenttitle {#2\c!title}%
+ \xdef\currentstructurecomponentbookmark{#2\c!bookmark}%
+ \xdef\currentstructurecomponentmarking {#2\c!marking}%
+ \xdef\currentstructurecomponentlist {#2\c!list}%
+ \xmlstopraw
+ \ifempty\currentstructurecomponentlist
+ \glet\currentstructurecomponentlist\currentstructurecomponenttitle
+ \fi
+ \glet\currentstructurecomponentcoding\s!xml
+ \else
+ \ifx\currentstructurecomponentexpansion\v!yes
+ \xdef\currentstructurecomponenttitle {#2\c!title}%
+ \xdef\currentstructurecomponentbookmark{#2\c!bookmark}%
+ \xdef\currentstructurecomponentmarking {#2\c!marking}%
+ \xdef\currentstructurecomponentlist {#2\c!list}%
+ \else
+ \xdef\currentstructurecomponenttitle {#3\c!title}%
+ \xdef\currentstructurecomponentbookmark{#3\c!bookmark}%
+ \xdef\currentstructurecomponentmarking {#3\c!marking}%
+ \xdef\currentstructurecomponentlist {#3\c!list}%
+ \iflocation \ifempty\currentstructurecomponentbookmark
+ \begingroup
+ \simplifycommands
+ \xdef\currentstructurecomponentbookmark{\detokenize\expandafter{\normalexpanded{#2\c!title}}}%
+ \endgroup
+ \fi \fi
+ \fi
+ \ifempty\currentstructurecomponentlist
+ \glet\currentstructurecomponentlist\currentstructurecomponenttitle
+ \fi
+ \glet\currentstructurecomponentcoding\s!tex
+ \fi
+ %
+ \setnextinternalreference
+ \scratchcounter\clf_addtolist %{
+ metadata {
+ kind {#1}
+ name {\currentname}
+ % level structures.sections.currentlevel()
+ catcodes \ifempty\currentstructurecomponentcatcodes\catcodetable\else\csname\currentstructurecomponentcatcodes\endcsname\fi
+ coding {\currentstructurecomponentcoding}
+ \ifx\currentstructurecomponentcoding\s!xml
+ xmlroot {\xmldocument}
+ \fi
+ \ifempty\currentstructurecomponentxmlsetup \else
+ xmlsetup {\currentstructurexmlsetup}
+ \fi
+ }
+ references {
+ internal \locationcount
+ % block {\currentsectionblock}
+ reference {\currentstructurecomponentreference}
+ prefix {\currentstructurecomponentreferenceprefix}
+ % section structures.sections.currentid()
+ view {\interactionparameter\c!focus}%
+ }
+ titledata {
+ label {\detokenize\expandafter{\currentstructurecomponentlabel}}
+ title {\detokenize\expandafter{\currentstructurecomponenttitle}}
+ \ifx\currentstructurecomponentbookmark\currentstructurecomponenttitle \else
+ bookmark {\detokenize\expandafter{\currentstructurecomponentbookmark}}
+ \fi
+ \ifx\currentstructurecomponentmarking\currentstructurecomponenttitle \else
+ marking {\detokenize\expandafter{\currentstructurecomponentmarking}}
+ \fi
+ \ifx\currentstructurecomponentlist\currentstructurecomponenttitle \else
+ list {\detokenize\expandafter{\currentstructurecomponentlist}}
+ \fi
+ }
+ \ifx\p_hasnumber\v!yes
+ prefixdata {
+ prefix {#2\c!prefix}
+ separatorset {#2\c!prefixseparatorset}
+ conversion {#2\c!prefixconversion}
+ conversionset {#2\c!prefixconversionset}
+ set {#2\c!prefixset}
+ % segments {#2\c!prefixsegments}
+ segments {\p_prefixsegments}
+ connector {#2\c!prefixconnector}
+ }
+ numberdata { % more helpers here, like compact elsewhere
+ numbers {\currentcounter}
+ group {#2\c!group}
+ groupsuffix {#2\c!groupsuffix}
+ counter {\currentcounter}
+ separatorset {#2\c!numberseparatorset}
+ conversion {#2\c!numberconversion}
+ conversionset {#2\c!numberconversionset}
+ starter {#2\c!numberstarter}
+ stopper {#2\c!numberstopper}
+ segments {#2\c!numbersegments}
+ }
+ \fi
+ userdata {\detokenize{#4}}
+ %}
+ \relax
+ \xdef\m_strc_counters_last_registered_index{\the\scratchcounter}%
+ \setstructurecomponentsynchronization\m_strc_counters_last_registered_index
+ \glet\m_strc_counters_last_registered_attribute \currentstructurecomponentattribute
+ \glet\m_strc_counters_last_registered_synchronize\currentstructurecomponentsynchronize}
+
+\let\m_strc_counters_last_registered_index \relax
+\let\m_strc_counters_last_registered_attribute \relax
+\let\m_strc_counters_last_registered_synchronize\relax
+
+% This can be improved as we don't need to pas all these variables
+% each time (we can set them up once).
+
+\protected\def\strc_counter_preset_using_parameter#1#2% \setupcommand \someparameter
+ {#1%
+ [\c!way =#2\c!way,
+ \c!prefix =#2\c!prefix,
+ \c!prefixseparatorset =#2\c!prefixseparatorset,
+ \c!prefixconversion =#2\c!prefixconversion,
+ \c!prefixconversionset=#2\c!prefixconversionset,
+ \c!prefixstarter =#2\c!prefixstarter,
+ \c!prefixstopper =#2\c!prefixstopper,
+ \c!prefixsegments =#2\c!prefixsegments,
+ \c!prefixset =#2\c!prefixset,
+ \c!prefixconnector =#2\c!prefixconnector,
+ \c!numberseparatorset =#2\c!numberseparatorset,
+ \c!numberconversion =#2\c!numberconversion,
+ \c!numberconversionset=#2\c!numberconversionset,
+ \c!numberstarter =#2\c!numberstarter,
+ \c!numberstopper =#2\c!numberstopper,
+ \c!numbersegments =#2\c!numbersegments]}
+
+\protected\def\strc_counter_setup_using_parameter#1#2% name \someparameter
+ {\edef\currentcounter{#1}%
+ %
+ \setcounterparameter \c!start{#2\c!start}%
+ \setcounterparameter \c!state{#2\c!state}% % beware, "" == start
+ \setcounterparameter \c!way{#2\c!way}%
+ %
+ \setcounterparameter \c!prefix{#2\c!prefix}%
+ \setcounterparameter \c!prefixseparatorset{#2\c!prefixseparatorset}%
+ \setcounterparameter \c!prefixconversion{#2\c!prefixconversion}%
+ \setcounterparameter\c!prefixconversionset{#2\c!prefixconversionset}%
+ \setcounterparameter \c!prefixstarter{#2\c!prefixstarter}%
+ \setcounterparameter \c!prefixstopper{#2\c!prefixstopper}%
+ \setcounterparameter \c!prefixset{#2\c!prefixset}%
+ \setcounterparameter \c!prefixsegments{#2\c!prefixsegments}%
+ \setcounterparameter \c!prefixset{#2\c!prefixset}%
+ \setcounterparameter \c!prefixconnector{#2\c!prefixconnector}%
+ %
+ \setcounterparameter \c!numberseparatorset{#2\c!numberseparatorset}%
+ \setcounterparameter \c!numberconversion{#2\c!numberconversion}%
+ \setcounterparameter\c!numberconversionset{#2\c!numberconversionset}%
+ \setcounterparameter \c!numberstarter{#2\c!numberstarter}%
+ \setcounterparameter \c!numberstopper{#2\c!numberstopper}%
+ \setcounterparameter \c!numbersegments{#2\c!numbersegments}%
+ %
+ \the\everysetupcounter}
+
+\protected\def\mult_interfaces_counter_association#1#2#3#4#5#6#7% tag current setup parameter list sync register
+ {\strc_counter_preset_using_parameter#3\rootcounterparameter
+ \newtoks#5%
+ \permanent\protected\def #6{\ifx#2\empty\the#5\else\strc_counter_setup_using_parameter#2#4\fi}% sync
+ \permanent\protected\def#7##1{\normalexpanded{#5{\the#5\strc_counter_setup_using_parameter{##1}\noexpand#4}}}} % register
+
+\permanent\protected\def\installcounterassociation#1% => synchronize#1counters register#1counter
+ {\normalexpanded
+ {\mult_interfaces_counter_association
+ {#1}% not \??xx but xx
+ \expandafter\noexpand\csname current#1\endcsname
+ \expandafter\noexpand\csname setup#1\endcsname
+ \expandafter\noexpand\csname #1parameter\endcsname
+ \expandafter\noexpand\csname counter_association_list_#1\endcsname
+ \expandafter\noexpand\csname synchronize#1counters\endcsname
+ \expandafter\noexpand\csname register#1counter\endcsname}}
+
+% needs testing:
+%
+% \protected\def\strc_counter_setup_push#1#2#3% \someparameter \directsomeparameter \setexpandedsomeparameter
+% {\let\savedcounterparameter \counterparameter
+% \let\saveddirectcounterparameter \directcounterparameter
+% \let\savedsetexpandedcounterparameter\setexpandedcounterparameter
+% % remap
+% \let\counterparameter #1%
+% \let\directcounterparameter #2%
+% \let\setexpandedcounterparameter #3}
+%
+% \protected\def\strc_counter_setup_pop
+% {\let\counterparameter \savedcounterparameter
+% \let\directcounterparameter \saveddirectcounterparameter
+% \let\setexpandedcounterparameter \savedsetexpandedcounterparameter}
+%
+% \protected\def\mult_interfaces_counter_association#1#2#3#4#5#6#7% tag current setup parameter list sync register
+% {\strc_counter_preset_using_parameter#3\rootcounterparameter
+% \newtoks#5%
+% \protected\def#6% sync
+% {\strc_counter_setup_push
+% \ifx#2\empty
+% \the#5%
+% \else
+% \let\currentcounter\empty
+% \the\everysetupcounter
+% \fi
+% \strc_counter_setup_pop}%
+% \protected\def#7##1% register
+% {\normalexpanded{#5{\the#5\edef\noexpand\currentcounter{##1}\noexpand\the\everysetupcounter}}}}
+
+%D For good old times (easier to explain in manuals):
+%D
+%D \starttyping
+%D \setcounter[userpage][9]
+%D \setupcounter[userpage][number=9]
+%D \setupuserpagenumber[number=9]
+%D \stoptyping
+
+% needs testing: we might have conflicts with mixins
+%
+% \appendtoks
+% \ifempty\currentcounter \else
+% \edef\p_number{\counterparameter\c!number}%
+% \ifempty\p_number \else
+% \strc_counters_set\currentcounter\p_number
+% \letcounterparameter\c!number\empty
+% \fi
+% \fi
+% \to \everysetupcounter
+
+\stopcontextdefinitioncode
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/strc-sbe.mkxl b/tex/context/base/mkiv/strc-sbe.mkxl
index 1b903cec7..e7878f205 100644
--- a/tex/context/base/mkiv/strc-sbe.mkxl
+++ b/tex/context/base/mkiv/strc-sbe.mkxl
@@ -53,7 +53,7 @@
\def\strc_sectionblock_handle_page
{\edef\p_strc_sectionblock_page{\sectionblockparameter\c!page}%
- \ifx\p_strc_sectionblock_page\empty \else
+ \ifempty\p_strc_sectionblock_page \else
\page[\p_strc_sectionblock_page]%
\fi}
diff --git a/tex/context/base/mkiv/strc-sec.mkxl b/tex/context/base/mkiv/strc-sec.mkxl
index 51d1f6019..a6e9b553c 100644
--- a/tex/context/base/mkiv/strc-sec.mkxl
+++ b/tex/context/base/mkiv/strc-sec.mkxl
@@ -59,7 +59,7 @@
\installglobalmacrostack\currentstructurereferenceprefix
\def\strc_sectioning_set_reference_prefix
- {\ifx\currentstructurereferenceprefix\empty
+ {\ifempty\currentstructurereferenceprefix
% nothing
\orelse\ifx\currentstructurereferenceprefix\m_strc_references_prefix_yes
\global\advance\prefixcounter \plusone % temp here
@@ -153,10 +153,10 @@
\xdef\currentstructuremarking {\structureparameter\c!marking}%
\xdef\currentstructurelist {\structureparameter\c!list}%
\xmlstopraw
- \iflocation \ifx\currentstructurebookmark\empty \ifconditional\c_strc_bookmarks_preroll
+ \iflocation \ifempty\currentstructurebookmark \ifconditional\c_strc_bookmarks_preroll
\strc_sectioning_autobookmark\currentstructuretitle
\fi \fi \fi
- \ifx\currentstructurelist\empty
+ \ifempty\currentstructurelist
\glet\currentstructurelist\currentstructuretitle
\fi
\glet\currentstructurecoding\s!xml
@@ -166,7 +166,7 @@
\xdef\currentstructurebookmark{\structureparameter\c!bookmark}%
\xdef\currentstructuremarking {\structureparameter\c!marking}%
\xdef\currentstructurelist {\structureparameter\c!list}%
- \iflocation \ifx\currentstructurebookmark\empty \ifconditional\c_strc_bookmarks_preroll
+ \iflocation \ifempty\currentstructurebookmark \ifconditional\c_strc_bookmarks_preroll
\strc_sectioning_autobookmark\currentstructuretitle
\fi \fi \fi
\else
@@ -174,7 +174,7 @@
\xdef\currentstructurebookmark{\detokenizedstructureparameter\c!bookmark}%
\xdef\currentstructuremarking {\detokenizedstructureparameter\c!marking}%
\xdef\currentstructurelist {\detokenizedstructureparameter\c!list}%
- \iflocation \ifx\currentstructurebookmark\empty
+ \iflocation \ifempty\currentstructurebookmark
\ifconditional\c_strc_bookmarks_preroll
\strc_sectioning_autobookmark{\structureparameter\c!title}%
\else
@@ -185,7 +185,7 @@
\fi
\fi \fi
\fi
- \ifx\currentstructurelist\empty
+ \ifempty\currentstructurelist
\glet\currentstructurelist\currentstructuretitle
\fi
\glet\currentstructurecoding\s!tex
@@ -207,12 +207,12 @@
metadata {
kind {section}
name {\currentstructurename}
- catcodes \ifx\currentstructurecatcodes\empty\catcodetable\else\csname\currentstructurecatcodes\endcsname\fi\space
+ catcodes \ifempty\currentstructurecatcodes\catcodetable\else\csname\currentstructurecatcodes\endcsname\fi\space
coding {\currentstructurecoding}
\ifx\currentstructurecoding\s!xml
xmlroot {\xmldocument}
\fi
- \ifx\currentstructurexmlsetup\empty \else
+ \ifempty\currentstructurexmlsetup \else
xmlsetup {\currentstructurexmlsetup}
\fi
\ifx\currentstructuresaveinlist\v!no
@@ -407,15 +407,15 @@
%\c!aftersection=\directsetup{document:\currenthead:stop}, % these might become defaults i.e. acpect document: namespace
]
-\let\setupheads\setuphead % will go
+\aliased\let\setupheads\setuphead % will go
\appendtoks
- \ifx\currentheadparent\empty
+ \ifempty\currentheadparent
\edef\currentheaddefault{\headparameter\c!default}%
\edef\currentheadsection{\headparameter\c!section}%
\ifx\currenthead\currentheaddefault
\let\currentheadparent\currentheadsection
- \orelse\ifx\currentheaddefault\empty
+ \orelse\ifempty\currentheaddefault
\let\currentheadparent\currentheadsection
\else
\let\currentheadparent\currentheaddefault
@@ -483,7 +483,7 @@
% compatible but better
\appendtoks
- \ifx\currenthead\empty \else
+ \ifempty\currenthead \else
\doifelse{\headparameter\c!ownnumber}\v!yes
{\instance\setuevalue\currenthead{\strc_sectioning_handle_own[\currenthead]}}
{\instance\setuevalue\currenthead{\strc_sectioning_handle_nop[\currenthead]}}%
@@ -503,15 +503,6 @@
\installmacrostack\currentnamedsection
-% todo: add grouping but where: before/after trickery .. probably inside because one can always add
-% grouping to the before/after settings
-
-\permanent\protected\def\startnamedsection
- {\dotripleempty\strc_sectioning_start_named_section}
-
-\permanent\protected\def\stopnamedsection
- {\normalexpanded{\strc_sectioning_stop[\currentnamedsection]}}
-
% structure sections (the parents of chapter etc)
\let\firstsectionname\empty
@@ -560,7 +551,7 @@
\newtoks\everydefinesection
-\protected\def\definesection[#1]%
+\permanent\protected\def\definesection[#1]%
{\ifcsname\??headlevel#1\endcsname \else
\edef\currentsection{#1}% not used, will go
\edef\currenthead{#1}%
@@ -575,31 +566,24 @@
\normalexpanded{\relatemarking[#1][\lastsectionname]}% so, the parent will reset the child
\fi
\xdef\lastsectionname{#1}%
- \ifx\firstsectionname\empty
+ \ifempty\firstsectionname
\glet\firstsectionname\lastsectionname
\fi
\fi}
\permanent\tolerant\protected\def\setupsection[#1]#*[#2]#*[#3]%
{\ifparameter#1\else
- \ifcsname\??headlevel#1\endcsname
- \strc_sectioning_setup_indeed[#1][#2][#3]%
+ \push_macro_currenthead
+ \edef\currenthead{\ifcsname\??headlevel#1\endcsname#1\else\sectionheadsection{#1}\fi}%
+ \ifparameter#3\or
+ \edef\currenthead{\currenthead#2}% not used at any more in mkiv (sets now)
+ \setupcurrenthead[#3]%
\else
- \strc_sectioning_setup_indeed[\sectionheadsection{#1}][#2][#3]%
+ \setupcurrenthead[#2]%
\fi
+ \pop_macro_currenthead
\fi}
-\def\strc_sectioning_setup_indeed[#1][#2][#3]%
- {\push_macro_currenthead
- \ifthirdargument
- \edef\currenthead{#1#2}% % not used at any more in mkiv (sets now)
- \setupcurrenthead[#3]%
- \else
- \edef\currenthead{#1}%
- \setupcurrenthead[#2]%
- \fi
- \pop_macro_currenthead}
-
% we share the parameters as sections are roots of heads so eventually we can
% consider \definesection -> \definehead with one argument
@@ -617,45 +601,41 @@
% head -> head
-\permanent\def\sectionheadmarkingtitle #1#2{\clf_markingtitle {#1}{#2}}
-\permanent\def\sectionheadmarkingnumber#1#2{\clf_markingnumber{#1}{#2}}
+\permanent\def\sectionheadmarkingtitle #1#2{\clf_markingtitle {#1}{#2}} % can be done at lua end
+\permanent\def\sectionheadmarkingnumber#1#2{\clf_markingnumber{#1}{#2}} % can be done at lua end
\permanent\def\sectionheadcoupling#1{\namedheadparameter{#1}\c!coupling}
\permanent\def\sectionheadsection #1{\namedheadparameter{#1}\c!section}
% head construction
-\protected\def\strc_sectioning_handle_own{\dodoubleempty\strc_sectioning_handle_own_indeed} % [ref] {nr} {title}
-\protected\def\strc_sectioning_handle_nop{\dodoubleempty\strc_sectioning_handle_nop_indeed} % [ref] {title}
-\protected\def\strc_sectioning_start {\dotripleempty\strc_sectioning_start_named_section} % [settings] [userdata] !!! also used at lua end
-
\newconditional\currentstructureown
\newtoks\everybeforehead % hook, todo: before/after keys
\newtoks\everyafterhead % hook, todo: before/after keys
-\protected\def\strc_sectioning_handle_own_indeed[#1][#2]#3#4%
+\permanent\tolerant\protected\def\strc_sectioning_handle_own[#1]#*[#2]#:#*#=#*#=% [ref] {nr} {title}
{\settrue\currentstructureown
\triggerautostructurelevel
\strc_sectioning_handle{#1}{\c!reference={#2},\c!ownnumber={#3},\c!title={#4}}{}} % name ref nr title --
-\protected\def\strc_sectioning_handle_nop_indeed[#1][#2]% for taco: [key=value] variant
+\permanent\tolerant\protected\def\strc_sectioning_handle_nop[#1]#*[#2]% [ref] {title} / for taco: [key=value] variant
{\setfalse\currentstructureown
\triggerautostructurelevel
- \ifcondition\validassignment{#2}%
+ \ifhastok={#2}%
\expandafter\strc_sectioning_handle_nop_indeed_yes
\else
\expandafter\strc_sectioning_handle_nop_indeed_nop
\fi
{#1}{#2}}
-\protected\def\strc_sectioning_handle_nop_indeed_yes#1#2%
+\def\strc_sectioning_handle_nop_indeed_yes#1#2%
{\strc_sectioning_handle{#1}{#2}{}}
-\protected\def\strc_sectioning_handle_nop_indeed_nop#1#2#3%
+\def\strc_sectioning_handle_nop_indeed_nop#1#2#3%
{\strc_sectioning_handle{#1}{\c!reference={#2},\c!title={#3}}{}} % name ref nr title --
-\protected\def\strc_sectioning_start_named_section[#1][#2][#3]% for the moment no grouping, too annoying with page breaks
+\permanent\tolerant\protected\def\strc_sectioning_start[#1]#*[#2]#*[#3]% for the moment no grouping, too annoying with page breaks
{\push_macro_currentnamedsection
\push_macro_currentstructurereferenceprefix
\edef\currentnamedsection{#1}%
@@ -669,7 +649,7 @@
% potential: \bgroup (can be optional: grouped = yes)
\headparameter\c!insidesection}
-\protected\def\strc_sectioning_stop[#1]% !!! also used at lua end
+\permanent\protected\def\strc_sectioning_stop[#1]% !!! also used at lua end
{\dostoptagged
\dostoptagged
% potential: \egroup
@@ -681,8 +661,16 @@
\pop_macro_currentstructurereferenceprefix
\pop_macro_currentnamedsection} % new, also here now
-\permanent\let\dostarthead\strc_sectioning_start % used at lua end
-\permanent\let\dostophead \strc_sectioning_stop % used at lua end
+\aliased\let\dostarthead\strc_sectioning_start % used at lua end
+\aliased\let\dostophead \strc_sectioning_stop % used at lua end
+
+% todo: add grouping but where: before/after trickery .. probably inside because one can always add
+% grouping to the before/after settings
+
+\aliased\let\startnamedsection\strc_sectioning_start
+
+\permanent\protected\def\stopnamedsection
+ {\normalexpanded{\strc_sectioning_stop[\currentnamedsection]}}
% \newconditional\structurereversesectionnumbers % todo: key/val
@@ -714,7 +702,7 @@
\permanent\protected\def\filterheadnumber
{\settrue\c_strc_sectioning_increment
\settrue\c_strc_sectioning_to_list
- \ifx\currentproduct\empty
+ \ifempty\currentproduct
% todo : filter from other toc (number, file, title)
% use : \currentheadincrement as spec
\fi}
@@ -784,11 +772,11 @@
% \currentstructuresynchronize
% \to \everyheadsynchronization
-\let\currentstructuresynchronize\donothing
+\aliased\let\currentstructuresynchronize\donothing
\appendtoks
\currentstructuresynchronize
- \glet\currentstructuresynchronize\donothing
+ \enforced\glet\currentstructuresynchronize\donothing
\to \everyheadsynchronization
\protected\def\theheadsynchonization
@@ -843,9 +831,6 @@
\strc_show_used
\to \everystoptext
-\permanent\protected\def\placeheadtext {\dosingleempty\strc_sectioning_place_head_text } % use with care
-\permanent\protected\def\placeheadnumber{\dosingleempty\strc_sectioning_place_head_number} % use with care
-
\protected\def\strc_sectioning_report{\clf_reportstructure}
\ifdefined\strc_rendering_initialize_style_and_color \else
@@ -858,23 +843,23 @@
\fi
-\def\strc_sectioning_place_head_text[#1]%
+\permanent\tolerant\protected\def\placeheadtext[#1]%
{\dontleavehmode
\begingroup
\protected\def\\{\space}% messy here, but the default (and needs to be grouped)
\global\settrue\headisdisplay % triggers interlinespace checking
- \edef\currenthead{#1}%
+ \edef\currenthead{#1}% maybe only when #1 is given
\strc_rendering_initialize_style_and_color\c!textstyle\c!textcolor
\relax
\getspecificstructuretitle{\thenamedheadlevel{#1}}%
\endgraf
\endgroup}
-\def\strc_sectioning_place_head_number[#1]%
+\permanent\tolerant\protected\def\placeheadnumber[#1]%
{\dontleavehmode
\begingroup
\global\settrue\headisdisplay % triggers interlinespace checking
- \edef\currenthead{#1}%
+ \edef\currenthead{#1}% maybe only when #1 is given
\strc_rendering_initialize_style_and_color\c!numberstyle\c!numbercolor
\relax
\getfullstructurenumber{\thenamedheadlevel{#1}}%
@@ -991,7 +976,7 @@
\setfalse\c_strc_sectioning_ignore_page
% ignorespaces prevents spaces creeping in when after=\dontleavehmode
\dostarttagged\t!sectioncontent\empty
- \ifx\currentstructureplaceholder\empty
+ \ifempty\currentstructureplaceholder
\ifconditional\headisdisplay
\doubleexpandafter\ignorespaces
\else
@@ -1106,7 +1091,7 @@
\def\strc_sectioning_check_layout
{\edef\p_page{\headparameter\c!page}%
- \ifx\p_page\empty
+ \ifempty\p_page
\strc_sectioning_check_layout_nop
\else
\strc_sectioning_check_layout_yes
@@ -1119,15 +1104,15 @@
{\page[\p_page]%
\expandnamespaceparameter\??headmarkyes\headparameter\c!marking\s!unknown
\edef\p_header{\headparameter\c!header}%
- \ifx\p_header\empty \else
+ \ifempty\p_header \else
\doifelselayouttextline\v!header{\normalexpanded{\setuplayouttext[\v!header][\c!state=\p_header]}}\donothing
\fi
\edef\p_text{\headparameter\c!text}%
- \ifx\p_text\empty \else
+ \ifempty\p_text \else
\doifelselayouttextline\v!text {\normalexpanded{\setuplayouttext[\v!text ][\c!state=\p_text ]}}\donothing
\fi
\edef\p_footer{\headparameter\c!footer}%
- \ifx\p_footer\empty \else
+ \ifempty\p_footer \else
\doifelselayouttextline\v!footer{\normalexpanded{\setuplayouttext[\v!footer][\c!state=\p_footer]}}\donothing
\fi}
@@ -1159,7 +1144,7 @@
{\ifconditional\c_strc_sectioning_empty
% this needs checking
\penalty\plustenthousand
- \vskip-\lineheight
+ \vskivskip-\lineheight
\kern\zeropoint
\prevdepth\strutdepth
\fi}
@@ -1268,13 +1253,10 @@
% \chapter{some} \setupheadnumber[chapter][3] \chapter{more}
% \setupheadnumber[section][8] \section{b} \section{c} \setupheadnumber[section][-1] \section{d}
-\def\thenamedheadlevel#1%
+\permanent\def\thenamedheadlevel#1%
{\sectionlevel{\sectionheadsection{\sectionheadcoupling{#1}}}}
-\permanent\protected\def\setupheadnumber
- {\dodoubleargument\strc_sectioning_setup_number}
-
-\def\strc_sectioning_setup_number[#1][#2]% todo: reset if at other level
+\permanent\tolerant\protected\def\setupheadnumber[#1]#*[#2]% todo: reset if at other level
{\setstructurenumber{\thenamedheadlevel{#1}}{\number#2}}
\def\currentheadnumber{0} % ==> \currentheadnumber
@@ -1287,16 +1269,10 @@
\permanent\def\namedheadnumber #1{\getstructurenumber {\thenamedheadlevel{#1}}}
\permanent\def\somenamedheadnumber#1#2{\getsomestructurenumber{\thenamedheadlevel{#1}}{#2}}
-\permanent\protected\def\headnumber
- {\dodoubleempty\strc_sectioning_number}
-
-\def\strc_sectioning_number[#1][#2]% simple case is just a number
- {\getsomefullstructurenumber{\iffirstargument\thenamedheadlevel{#1}\fi}{#2}}
-
-\permanent\protected\def\someheadnumber
- {\dodoubleempty\strc_sectioning_number_some}
+\permanent\tolerant\protected\def\headnumber[#1]#*[#2]% simple case is just a number
+ {\getsomefullstructurenumber{\ifparameter#1\or\thenamedheadlevel{#1}\fi}{#2}}
-\def\strc_sectioning_number_some[#1][#2]%
+\permanent\tolerant\protected\def\someheadnumber[#1]#*[#2]%
{\dontleavehmode
\begingroup
\edef\currenthead{#1}%
diff --git a/tex/context/base/mkiv/strc-syn.mkxl b/tex/context/base/mkiv/strc-syn.mkxl
index 130d1737a..337f1d71a 100644
--- a/tex/context/base/mkiv/strc-syn.mkxl
+++ b/tex/context/base/mkiv/strc-syn.mkxl
@@ -176,7 +176,7 @@
\appendtoks
\setfalse\c_strc_constructions_define_commands
- \ifx\currentsimplelistparent\empty
+ \ifempty\currentsimplelistparent
\defineconstruction[\currentsimplelist][\s!handler=\v!simplelist,\c!level=1]%
\else
\defineconstruction[\currentsimplelist][\currentsimplelistparent][\s!handler=\v!simplelist,\c!level=1]%
@@ -592,7 +592,7 @@
\strc_constructions_initialize{#1}%
\setupcurrentsimplelist[#2]%
\edef\p_simplelist_command{\simplelistparameter\c!command}%
- \ifx\p_simplelist_command\empty
+ \ifempty\p_simplelist_command
\let\synonymentry\strc_sorting_normal
\else
\let\synonymentry\strc_sorting_command
diff --git a/tex/context/base/mkiv/supp-ran.mkiv b/tex/context/base/mkiv/supp-ran.mkiv
index a616dd54f..d3cc00a6e 100644
--- a/tex/context/base/mkiv/supp-ran.mkiv
+++ b/tex/context/base/mkiv/supp-ran.mkiv
@@ -29,6 +29,7 @@
\registerctxluafile{supp-ran}{}
\unprotect
+
\protected\def\getrandomcount #1#2#3{#1=\clf_getrandomnumber\numexpr#2\relax\numexpr#3\relax\relax}
\protected\def\getrandomdimen #1#2#3{#1=\clf_getrandomdimen\dimexpr#2\relax\dimexpr#3\relax\scaledpoint\relax}
\protected\def\getrandomnumber#1#2#3{\edef#1{\clf_getrandomnumber\numexpr#2\relax\numexpr#3\relax}}
diff --git a/tex/context/base/mkiv/symb-ini.mkxl b/tex/context/base/mkiv/symb-ini.mkxl
new file mode 100644
index 000000000..5d10ae1ba
--- /dev/null
+++ b/tex/context/base/mkiv/symb-ini.mkxl
@@ -0,0 +1,345 @@
+%D \module
+%D [ file=symb-ini,
+%D version=1998.07.20,
+%D title=\CONTEXT\ Symbol Libraries,
+%D subtitle=Basic Symbols Commands,
+%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.
+
+%D The macros described here used to be part of the \type {core-con} module. I
+%D decided to move them here when symbolsets saw the light. Let their light shine.
+
+\writestatus{loading}{ConTeXt Symbol Libraries / Initialization}
+
+\registerctxluafile{symb-ini}{}
+
+\unprotect
+
+%D \macros
+%D {definesymbol, symbol}
+%D
+%D Converting numbers or levels into a character, romannumeral, symbol or something
+%D else, is supported by many \CONTEXT\ commands. Therefore we need a mechanism for
+%D linking such numbers to their counterparts.
+%D
+%D First we take care of symbols. These are for instance used in enumerations and
+%D itemizations. We have:
+%D
+%D \showsetup{definesymbol}
+%D \showsetup{symbol}
+%D
+%D Symbols are simply linked to a tag. Such tags can be numbers or strings.
+%D
+%D \starttyping
+%D \definesymbol [1] [$\bullet$]
+%D \definesymbol [level 5] [$\star$]
+%D \stoptyping
+
+\installcorenamespace{symbol}
+\installcorenamespace{symbols}
+\installcorenamespace{symbolset}
+\installcorenamespace{symboldefault}
+
+%D For now we only have one option.
+
+\installparameterhandler\??symbols {symbols}
+\installsetuphandler \??symbols {symbols}
+
+\appendtoks
+ \doifelse{\symbolsparameter\c!stylealternative}\v!math
+ \settrue\setfalse\prefermathovertextchar
+\to \everysetupsymbols
+
+\setupsymbols
+ [\c!stylealternative=\v!text]
+
+\let\currentsymbol \empty
+\let\currentsymbolset\empty
+
+\newtoks\t_symb_setups
+
+\let\m_symb_current_set\empty
+
+\newconditional\c_symb_found
+
+\newtoks\everysymbol
+
+%D We don't use the commandhandler as symbols have their own subsystem for resolving
+%D values.
+
+\permanent\tolerant\protected\def\definesymbol[#1]#*[#2]#*[#3]%
+ {\ifparameter#3\or
+ \setvalue{\??symbol#1:#2}{#3}%
+ \doifsomething{#1}{\addvalue{\??symbolset#1}{#2}}%
+ \else
+ \setvalue{\??symbol\m_symb_current_set:#1}{#2}%
+ \addvalue{\??symbolset\m_symb_current_set}{#1}%
+ \fi}
+
+\permanent\protected\def\doifelseinsymbolset#1#2{\ifcsname\??symbol#1:#2\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
+\permanent\protected\def\doifinsymbolset #1#2{\ifcsname\??symbol#1:#2\endcsname\expandafter\firstofoneargument \else\expandafter\gobbleoneargument \fi}
+\permanent\protected\def\doifelsesymbolset #1{\ifcsname\??symbolset#1\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
+
+\aliased\let\doifinsymbolsetelse\doifelseinsymbolset
+\aliased\let\doifsymbolsetelse \doifelsesymbolset
+
+\letvalue{\??symbolset}\empty
+
+%def\symbolset#1{\csname\??symbolset\ifcsname\??symbolset#1\endcsname#1\fi\endcsname} % no [#1], to be used in commalists etc
+
+\permanent\def\symbolset#1{\begincsname\??symbolset#1\endcsname} % no [#1], to be used in commalists etc
+
+%D Since symbols are used frequently in interactive documents, we speed up this one.
+%D Well, that was history, since now we simplified things a bit, because the low
+%D level macros have been sped up every now and then.
+
+% We support both:
+%
+% Test test \symbol[whatever]\ test \symbol[whatever].
+% Test test \symbol{whatever} test \symbol{whatever}.
+
+\permanent\tolerant\protected\def\symbol[#1]#*[#2]%
+ {\ifarguments
+ \expandafter\symb_place_argument
+ \or
+ \symb_place_argument{#1}%
+ \or
+ \dontleavehmode
+ \edef\currentsymbol{#2}%
+ \ifcsname\??symbol#1:#2\endcsname
+ \symb_place_indeed{#1:#2}% maybe use \lastnamescs
+ \orelse\ifcsname\??symboldefault#1\endcsname
+ \symb_place_named{#1}% maybe use \lastnamescs
+ \else
+ \symb_place_normal
+ \fi
+ \fi}
+
+\def\symb_place_argument#1%
+ {\dontleavehmode
+ \edef\currentsymbol{#1}%
+ \ifcsname\??symbol\currentsymbolset:#1\endcsname
+ \symb_place_indeed{\currentsymbolset:#1}%
+ \else
+ \symb_place_normal
+ \fi}
+
+\def\symb_place_normal
+ {\setfalse\c_symb_found
+ \the\t_symb_setups
+ \ifconditional\c_symb_found \else
+ \symb_place_retry\currentsymbol % hm, isn't this redundant?
+ \fi}
+
+\def\symb_place_indeed#1% \relax's prevent lookahead problems
+ {\settrue\c_symb_found
+ \begingroup
+ \the\everysymbol
+ \csname\??symbol#1\endcsname\relax
+ \endgroup}
+
+\letvalue{\??symbol}\firstofoneargument
+
+\permanent\def\directsymbol#1#2% no \relax, there can be an argument, see lists
+ {\begincsname\??symbol#1:#2\endcsname}
+
+\protected\def\symb_fetch
+ {\ifconditional\c_symb_found
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\symb_fetch_indeed
+ \fi}
+
+\def\symb_fetch_indeed#1%
+ {\ifcsname\??symbol#1:\currentsymbol\endcsname
+ \symb_place_indeed{#1:\currentsymbol}%
+ \orelse\ifcsname\??symboldefault#1\endcsname
+ \symb_place_named{#1}%
+ \fi}
+
+\def\symb_place_named#1% \relax's prevent lookahead problems
+ {\begingroup
+ \setbox\scratchbox\hbox\bgroup
+ \the\everysymbol
+ \getglyphstyled
+ {\csname\??symboldefault#1\endcsname}%
+ {\tochar{n:\currentsymbol}}%
+ \relax
+ \egroup
+ \ifdim\wd\scratchbox>\zeropoint
+ \unhbox\scratchbox
+ \endgroup
+ \setxvalue{\??symbol#1:\currentsymbol}%
+ {\symb_place_named_indeed{#1}{\currentsymbol}}%
+ \settrue\c_symb_found
+ \else
+ \endgroup
+ \fi}
+
+\protected\def\symb_place_named_indeed#1#2% \relax's prevent lookahead problems
+ {\settrue\c_symb_found
+ \begingroup
+ \the\everysymbol
+ \getglyphstyled
+ {\csname\??symboldefault#1\endcsname}%
+ {\tochar{n:#2}}%
+ \relax
+ \endgroup}
+
+\def\symb_place_retry#1%
+ {\ifcsname\??symbol:#1\endcsname
+ \symb_place_indeed{:#1}%
+ \else
+ #1%
+ \fi}
+
+%D \macros
+%D {definefiguresymbol}
+%D
+%D To simplify defining figure symbols, we offer:
+%D
+%D \showsetup{definefiguresymbol}
+%D
+%D By default, such symbols scale along the current bodyfont size or running font
+%D size (which is better).
+
+\ifdefined\externalfigure \else \def\externalfigure[#1][#2]{#1} \fi
+\ifdefined\resetexternalfigures \else \let\resetexternalfigures\relax \fi
+
+\def\defaultsymbolfactor{10}
+\def\defaultsymbolheight{1.25ex}
+
+\permanent\tolerant\protected\def\figuresymbol[#1]#*[#2]%
+ {\externalfigure[#1][\c!reset=\v!yes,\c!symbol=\v!yes,\c!height=\defaultsymbolheight,#2]}
+
+\appendtoks
+ \resetexternalfigures
+\to \everysymbol
+
+\permanent\tolerant\protected\def\definefiguresymbol[#1]#*[#2]#*[#3]%
+ {\ifarguments\or\else
+ \definesymbol[#1][{\symb_figure[#2][#3]}]%
+ \fi}
+
+%D \macros
+%D {doifsymboldefinedelse}
+%D
+%D A handy private one:
+
+\def\symb_fetch_first
+ {\ifconditional\c_symb_found
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\symb_fetch_first_indeed
+ \fi}
+
+\def\symb_fetch_first_indeed#1%
+ {\doifinsymbolset{#1}\currentsymbol{\settrue\c_symb_found}}
+
+\def\symb_fetch_second#1%
+ {\doifinsymbolset\empty\currentsymbol{\settrue\c_symb_found}}
+
+\permanent\protected\def\doifelsesymboldefined#1%
+ {\begingroup
+ \edef\currentsymbol{#1}%
+ \let\symb_fetch\symb_fetch_first
+ \setfalse\c_symb_found
+ \the\t_symb_setups
+ \ifconditional\c_symb_found
+ \endgroup\expandafter\firstoftwoarguments
+ \orelse\ifconditional\c_symb_found
+ \symb_fetch_second\currentsymbol
+ \endgroup\expandafter\firstoftwoarguments
+ \else
+ \symb_fetch_second\currentsymbol
+ \endgroup\expandafter\secondoftwoarguments
+ \fi}
+
+\aliased\let\doifsymboldefinedelse\doifelsesymboldefined
+
+%D \macros
+%D {setupsymbolset,startsymbolset}
+%D
+%D From these macro definitions one can deduce that symbols can be grouped in
+%D symbol sets:
+%D
+%D \starttyping
+%D \startsymbolset [navigation 1]
+%D \definefiguresymbol [Next] [mp-symb.1]
+%D \definefiguresymbol [Prev] [mp-symb.2]
+%D \stopsymbolset
+%D \stoptyping
+%D
+%D Such a symbol can be typeset with:
+%D
+%D \starttyping
+%D \setupsymbolset[navigation 1]\symbol[Next]
+%D \stoptyping
+%D
+%D or simply:
+%D
+%D \starttyping
+%D \symbol[navigation 1][Next]
+%D \stoptyping
+%D
+%D Formally:
+%D
+%D \showsetup{setupsymbolset}
+%D \showsetup{startsymbolset}
+
+\installcorenamespace{symbolsets}
+
+\permanent\tolerant\protected\def\startsymbolset[#1]#*[#2]%
+ {\pushmacro\m_symb_current_set
+ \def\m_symb_current_set{#1}%
+ \ifarguments\or\or
+ \getdummyparameters[\s!font=,#2]%
+ \edef\p_font{\dummyparameter\s!font}%
+ \ifempty\p_font\else
+ \letvalue{\??symboldefault#1}\p_font
+ \fi
+ \fi}
+
+\permanent\protected\def\stopsymbolset
+ {\popmacro\m_symb_current_set}
+
+\permanent\protected\def\setupsymbolset[#1]%
+ {\edef\currentsymbolset{#1}%
+ \ifcsname\??symbolsets\currentsymbolset\endcsname \else
+ \symb_setup_symbol_set
+ \fi}
+
+\def\symb_setup_symbol_set
+ {\normalexpanded{\t_symb_setups{\symb_fetch{\currentsymbolset}\the\t_symb_setups}}%
+ \letvalue{\??symbolsets\currentsymbolset}\empty} % speedup
+
+\permanent\protected\def\resetsymbolset
+ {\t_symb_setups\emptytoks}
+
+\permanent\protected\def\forcesymbolset[#1]%
+ {\t_symb_setups{\symb_fetch{#1}}}
+
+%D \macros
+%D {showsymbolset}
+%D
+%D \showsetup{showsymbolset}
+
+\fetchruntimecommand \showsymbolset \f!symb_run
+
+%D \macros
+%D {usesymbols}
+%D
+%D \showsetup{usesymbols}
+
+\permanent\protected\def\usesymbols[#1]{\clf_usesymbols{#1}}
+
+%D As longs as symbols are linked to levels or numbers, we can also use the
+%D conversion mechanism, but in for instance the itemization macros, we prefer
+%D symbols because they can more easier be (partially) redefined.
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/syst-aux.mkxl b/tex/context/base/mkiv/syst-aux.mkxl
index 4f3b65ad8..b94bc285c 100644
--- a/tex/context/base/mkiv/syst-aux.mkxl
+++ b/tex/context/base/mkiv/syst-aux.mkxl
@@ -1366,7 +1366,7 @@
\protected\def\rawdoifelseinset#1%
{\edef\m_syst_sub_string{#1}% expand #1 here
- \ifx\m_syst_sub_string\empty
+ \ifempty\m_syst_sub_string
\expandafter\thirdofthreearguments
\else
\expandafter\syst_helpers_do_if_else_in_set
diff --git a/tex/context/base/mkiv/syst-fnt.mkxl b/tex/context/base/mkiv/syst-fnt.mkxl
new file mode 100644
index 000000000..f0f023f6e
--- /dev/null
+++ b/tex/context/base/mkiv/syst-fnt.mkxl
@@ -0,0 +1,47 @@
+%D \module
+%D [ file=syst-fnt,
+%D version=2006.08.11,
+%D title=\CONTEXT\ System Macros,
+%D subtitle=Font Things,
+%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.
+
+% formal names cf the tb \& tbt
+
+\unprotect
+
+\immutable\protected\def\fontslantperpoint {\fontdimen\plusone }
+\immutable\protected\def\fontinterwordspace {\fontdimen\plustwo }
+\immutable\protected\def\fontinterwordstretch{\fontdimen\plusthree}
+\immutable\protected\def\fontinterwordshrink {\fontdimen\plusfour }
+\immutable\protected\def\fontexheight {\fontdimen\plusfive }
+\immutable\protected\def\fontemwidth {\fontdimen\plussix }
+\immutable\protected\def\fontextraspace {\fontdimen\plusseven}
+
+\immutable\protected\def\slantperpoint {\fontdimen\plusone \font}
+\immutable\protected\def\interwordspace {\fontdimen\plustwo \font}
+\immutable\protected\def\interwordstretch {\fontdimen\plusthree\font}
+\immutable\protected\def\interwordshrink {\fontdimen\plusfour \font}
+\immutable\protected\def\exheight {\fontdimen\plusfive \font}
+\immutable\protected\def\emwidth {\fontdimen\plussix \font}
+\immutable\protected\def\extraspace {\fontdimen\plusseven\font}
+
+\aliased\let\mathaxisheight\Umathaxis % takes style
+
+\permanent\def\currentspaceskip{\interwordspace\s!plus\interwordstretch\s!minus\interwordshrink\relax}
+
+\permanent\def\currentspacevalue{\the\interwordspace
+ \ifzeropt\interwordstretch\else{ plus }\the\interwordstretch\fi
+ \ifzeropt\interwordshrink \else{ minus }\the\interwordshrink \fi}
+
+\permanent\def\usedspacevalue{\ifzeropt\spaceskip\the\spaceskip\else\currentspacevalue\fi}
+
+\permanent\def\mathstacktotal{\dimexpr\Umathstacknumup\scriptstyle+\Umathstackdenomdown\scriptstyle\relax}
+\permanent\def\mathstackvgap {\Umathstackvgap\scriptstyle}
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/tabl-frm.mkxl b/tex/context/base/mkiv/tabl-frm.mkxl
index 5cafec76a..9bbc510c5 100644
--- a/tex/context/base/mkiv/tabl-frm.mkxl
+++ b/tex/context/base/mkiv/tabl-frm.mkxl
@@ -141,9 +141,9 @@
% {\??framedtablerow\currentframedtable
% \ifcsname\??framedtablerow\currentframedtable:\currentframed\endcsname
% :\currentframed
-% \else\ifcsname\??framedtablerow\currentframedtable:\v!each\endcsname
+% \orelse\ifcsname\??framedtablerow\currentframedtable:\v!each\endcsname
% :\v!each
-% \fi\fi}%
+% \fi}%
% \pack_framed_start_framed_whatever}
%
% \permanent\protected\def\stopframedrow
@@ -185,9 +185,9 @@
{\??framedtablerow\currentframedtable
\ifcsname\??framedtablerow\currentframedtable:\currentframed\endcsname
:\currentframed
- \else\ifcsname\??framedtablerow\currentframedtable:\v!each\endcsname
+ \orelse\ifcsname\??framedtablerow\currentframedtable:\v!each\endcsname
:\v!each
- \fi\fi}%
+ \fi}%
\pack_framed_start_framed_whatever}
\protected\def\stopframedrow_two
@@ -210,9 +210,9 @@
{\??framedtablecolumn\currentframedtable
\ifcsname\??framedtablecolumn\currentframedtable:\currentframed\endcsname
:\currentframed
- \else\ifcsname\??framedtablecolumn\currentframedtable:\v!each\endcsname
+ \orelse\ifcsname\??framedtablecolumn\currentframedtable:\v!each\endcsname
:\v!each
- \fi\fi}%
+ \fi}%
\ifcase\c_tabl_framed_pass
\or
\letframedparameter\c!background\empty
diff --git a/tex/context/base/mkiv/tabl-ltb.mkxl b/tex/context/base/mkiv/tabl-ltb.mkxl
index b72c5c7d6..527bb0860 100644
--- a/tex/context/base/mkiv/tabl-ltb.mkxl
+++ b/tex/context/base/mkiv/tabl-ltb.mkxl
@@ -112,11 +112,11 @@
\permanent\protected\def\doifelselinetablecparameter#1%
{\ifcsname\??linetable c:\number\c_tabl_lines_column#1\endcsname
\expandafter\firstoftwoarguments
- \else\ifcsname\??linetable c:#1\endcsname
- \doubleexpandafter\firstoftwoarguments
+ \orelse\ifcsname\??linetable c:#1\endcsname
+ \expandafter\firstoftwoarguments
\else
- \doubleexpandafter\secondoftwoarguments
- \fi\fi}
+ \expandafter\secondoftwoarguments
+ \fi}
\aliased\let\doiflinetablecparameterelse\doifelselinetablecparameter
@@ -125,9 +125,9 @@
\??linetable
\ifcsname\??linetable c:\number\c_tabl_lines_column#1\endcsname
c:\number\c_tabl_lines_column
- \else\ifcsname\??linetable c:#1\endcsname
+ \orelse\ifcsname\??linetable c:#1\endcsname
c:%
- \fi\fi
+ \fi
#1%
\endcsname}
@@ -137,15 +137,15 @@
\ifnum\c_tabl_lines_row=\zerocount % geen ifcase
\ifcsname\??linetable r:\v!header#1\endcsname
r:\v!header
- \else\ifcsname\??linetable r:0#1\endcsname
+ \orelse\ifcsname\??linetable r:0#1\endcsname
r:0%
- \fi\fi
+ \fi
\else
\ifcsname\??linetable r:\number\c_tabl_lines_row#1\endcsname
r:\number\c_tabl_lines_row
- \else\ifcsname\??linetable r:\v!oddeven\c_tabl_lines_row#1\endcsname
+ \orelse\ifcsname\??linetable r:\v!oddeven\c_tabl_lines_row#1\endcsname
r:\v!oddeven\c_tabl_lines_row
- \fi\fi
+ \fi
\fi
#1%
\endcsname}
@@ -292,8 +292,8 @@
\c!type=\linetablecparameter\c!type,
\c!mp=\linetablecparameter\c!mp,
\c!rulethickness=\linetablecparameter\c!rulethickness,
- \c!height=\ifx\p_height\empty\ht\scratchbox\else\p_height\fi,
- \c!depth=\ifx\p_depth \empty\dp\scratchbox\else\p_depth \fi,
+ \c!height=\ifempty\p_height\ht\scratchbox\else\p_height\fi,
+ \c!depth=\ifempty\p_depth \dp\scratchbox\else\p_depth \fi,
\c!width=\wd\scratchbox]%
\hskip-\wd\scratchbox\box\scratchbox}}
@@ -324,7 +324,7 @@
\backgroundline[\linetablerparameter\c!backgroundcolor]{\box\scratchbox}%
\else
\edef\p_type{\linetablerparameter\c!type}%
- \ifx\p_type\empty
+ \ifempty\p_type
\box\scratchbox
\else
\tabl_lines_wrap_up_auto_r
@@ -584,7 +584,7 @@
\global\c_tabl_lines_subcol\plusone
\d_tabl_lines_height\zeropoint
\edef\p_height{\linetablerparameter\c!height}%
- \ifx\p_height\empty
+ \ifempty\p_height
\c_tabl_lines_hmode \zerocount
\orelse\ifx\p_height\v!fit
\c_tabl_lines_hmode \plusone
diff --git a/tex/context/base/mkiv/tabl-tab.mkxl b/tex/context/base/mkiv/tabl-tab.mkxl
index 5fb7f928c..7b26aca05 100644
--- a/tex/context/base/mkiv/tabl-tab.mkxl
+++ b/tex/context/base/mkiv/tabl-tab.mkxl
@@ -1338,7 +1338,8 @@
\fi[#1]}
% We cannot define the stopper as \type {\protected} because lookahead in
-% alignments fail then, so we relax it and define it locally.
+% alignments fail then, so we relax it and define it locally. Actually we
+% now can.
\permanent\let\stoptable\relax
diff --git a/tex/context/base/mkiv/tabl-xtb.mklx b/tex/context/base/mkiv/tabl-xtb.mklx
index b54685863..9265ff782 100644
--- a/tex/context/base/mkiv/tabl-xtb.mklx
+++ b/tex/context/base/mkiv/tabl-xtb.mklx
@@ -490,13 +490,13 @@
\def\tabl_x_setup_character_align
{\edef\p_left {\directxtableparameter\c!alignmentleftsample}%
\edef\p_right{\directxtableparameter\c!alignmentrightsample}%
- \ifx\p_left\empty
+ \ifempty\p_left
\scratchdimenone\dimexpr\directxtableparameter\c!alignmentleftwidth\relax
\else
\setbox\scratchbox\hbox{\p_left}%
\scratchdimenone\wd\scratchbox
\fi
- \ifx\p_right\empty
+ \ifempty\p_right
\scratchdimentwo\dimexpr\directxtableparameter\c!alignmentrightwidth\relax
\else
\setbox\scratchbox\hbox{\p_right}%
@@ -557,7 +557,7 @@
% \def\tabl_x_set_hsize
% {\edef\p_width{\xtableparameter\c!width}%
-% \ifx\p_width\empty
+% \ifempty\p_width
% \hsize.25\maxdimen % is this really needed
% \fi}
@@ -783,7 +783,7 @@
\fi[#tag]}
\protected\def\tabl_x_start_group_delayed_two[#tag]%
- {\ifx\currentxtable\empty \else
+ {\ifempty\currentxtable \else
\chaintocurrentxtable{#tag}%
\fi
\edef\currentxtable{#tag}%
@@ -808,7 +808,7 @@
\fi[#tag]}
\protected\def\tabl_x_start_cell_delayed_two[#tag]%
- {\ifx\currentxtable\empty \else
+ {\ifempty\currentxtable \else
\chaintocurrentxtable{#tag}%
\fi
\edef\currentxtable{#tag}%
@@ -832,7 +832,7 @@
\fi[#tag]}
\permanent\protected\def\tabl_x_start_row_delayed_two[#tag]%
- {\ifx\currentxtable\empty \else
+ {\ifempty\currentxtable \else
\chaintocurrentxtable{#tag}%
\fi
\edef\currentxtable{#tag}%
@@ -909,7 +909,7 @@
\def\tabl_x_collect_cell_start_nop#content\stopxcell
{\tabl_x_collect_advance
- \ifx\m_tabl_x_swapped_settings\empty
+ \ifempty\m_tabl_x_swapped_settings
\gtoksapp\t_tabl_x_swapped{\tabl_x_c_cell_start{}#content\tabl_x_c_cell_stop}%
\else
\gtoksapp\t_tabl_x_swapped\expandafter{\expandafter\tabl_x_c_cell_start\expandafter{\m_tabl_x_swapped_settings}#content\tabl_x_c_cell_stop}%
@@ -917,7 +917,7 @@
\def\tabl_x_collect_cell_start_yes[#settings]#content\stopxcell
{\tabl_x_collect_advance
- \ifx\m_tabl_x_swapped_settings\empty
+ \ifempty\m_tabl_x_swapped_settings
\gtoksapp\t_tabl_x_swapped{\tabl_x_c_cell_start{}[#settings]#content\tabl_x_c_cell_stop}%
\else
\gtoksapp\t_tabl_x_swapped\expandafter{\expandafter\tabl_x_c_cell_start\expandafter{\m_tabl_x_swapped_settings}[#settings]#content\tabl_x_c_cell_stop}%
diff --git a/tex/context/base/mkiv/toks-ini.lmt b/tex/context/base/mkiv/toks-ini.lmt
index 23896883c..4b2d1facc 100644
--- a/tex/context/base/mkiv/toks-ini.lmt
+++ b/tex/context/base/mkiv/toks-ini.lmt
@@ -54,6 +54,9 @@ local scan_luanumber = token.scan_luanumber or scan_float -- only lmtx
local scan_luainteger = token.scan_luainteger or scan_integer -- only lmtx
local scan_luacardinal = token.scan_luacardinal or scan_cardinal -- only lmtx
+local scan_integer_argument = token.scan_integer_argument
+local scan_dimen_argument = token.scan_dimen_argument
+
-- todo: gobble_integer -- might go away
-- todo: gobble_dimension -- might go away
@@ -154,58 +157,61 @@ if not scan_box then
end
tokens.scanners = { -- these expand
- token = scan_token,
- toks = scan_toks,
- tokens = scan_toks,
- box = scan_box,
- hbox = function() return scan_box("hbox") end,
- vbox = function() return scan_box("vbox") end,
- vtop = function() return scan_box("vtop") end,
- dimen = scan_dimen,
- dimension = scan_dimen,
- glue = scan_glue,
- gluevalues = function() return scan_glue(false,false,true) end,
- gluespec = scan_skip,
- integer = scan_integer,
- cardinal = scan_cardinal,
- real = scan_real,
- float = scan_float,
- luanumber = scan_luanumber,
- luainteger = scan_luainteger,
- luacardinal = scan_luacardinal,
- count = scan_integer,
- string = scan_string,
- argument = scan_argument,
- delimited = scan_delimited,
- tokenlist = scan_tokenlist,
- verbatim = scan_verbatim, -- detokenize
- code = scan_code,
- tokencode = scan_token_code,
- word = scan_word,
- letters = scan_letters,
- key = scan_key,
- value = scan_value,
- char = scan_char,
- number = scan_number,
- boolean = scan_boolean,
- keyword = scan_keyword,
- keywordcs = scan_keyword_cs,
- csname = scan_csname,
-
- next = token.scan_next,
- nextexpanded = token.scan_next_expanded,
-
- peek = token.peek_next,
- peekexpanded = token.peek_next_expanded,
- peekchar = token.peek_next_char,
-
- skip = token.skip_next,
- skipexpanded = token.skip_next_expanded,
-
- cmdchr = token.scan_cmdchr,
- cmdchrexpanded = token.scan_cmdchr_expanded,
-
- ischar = token.is_next_char,
+ token = scan_token,
+ toks = scan_toks,
+ tokens = scan_toks,
+ box = scan_box,
+ hbox = function() return scan_box("hbox") end,
+ vbox = function() return scan_box("vbox") end,
+ vtop = function() return scan_box("vtop") end,
+ dimen = scan_dimen,
+ dimension = scan_dimen,
+ glue = scan_glue,
+ gluevalues = function() return scan_glue(false,false,true) end,
+ gluespec = scan_skip,
+ integer = scan_integer,
+ cardinal = scan_cardinal,
+ real = scan_real,
+ float = scan_float,
+ luanumber = scan_luanumber,
+ luainteger = scan_luainteger,
+ luacardinal = scan_luacardinal,
+ count = scan_integer,
+ string = scan_string,
+ argument = scan_argument,
+ delimited = scan_delimited,
+ tokenlist = scan_tokenlist,
+ verbatim = scan_verbatim, -- detokenize
+ code = scan_code,
+ tokencode = scan_token_code,
+ word = scan_word,
+ letters = scan_letters,
+ key = scan_key,
+ value = scan_value,
+ char = scan_char,
+ number = scan_number,
+ boolean = scan_boolean,
+ keyword = scan_keyword,
+ keywordcs = scan_keyword_cs,
+ csname = scan_csname,
+
+ next = token.scan_next,
+ nextexpanded = token.scan_next_expanded,
+
+ peek = token.peek_next,
+ peekexpanded = token.peek_next_expanded,
+ peekchar = token.peek_next_char,
+
+ skip = token.skip_next,
+ skipexpanded = token.skip_next_expanded,
+
+ cmdchr = token.scan_cmdchr,
+ cmdchrexpanded = token.scan_cmdchr_expanded,
+
+ ischar = token.is_next_char,
+
+ integerargument = scan_integer_argument,
+ dimenargument = scan_dimen_argument,
}
tokens.getters = { -- these don't expand
diff --git a/tex/context/base/mkiv/toks-ini.mkxl b/tex/context/base/mkiv/toks-ini.mkxl
new file mode 100644
index 000000000..c7d7bceb3
--- /dev/null
+++ b/tex/context/base/mkiv/toks-ini.mkxl
@@ -0,0 +1,20 @@
+%D \module
+%D [ file=toks-ini,
+%D version=2007.03.03,
+%D title=\CONTEXT\ Token Support,
+%D subtitle=Initialization,
+%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 Token Support / Initialization}
+
+\unprotect
+
+\registerctxluafile{toks-ini}{autosuffix}
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/toks-scn.mkxl b/tex/context/base/mkiv/toks-scn.mkxl
new file mode 100644
index 000000000..12abf0cb8
--- /dev/null
+++ b/tex/context/base/mkiv/toks-scn.mkxl
@@ -0,0 +1,26 @@
+%D \module
+%D [ file=toks-ini,
+%D version=2007.03.03,
+%D title=\CONTEXT\ Token Support,
+%D subtitle=Initialization,
+%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 Token Support / Scanners}
+
+\unprotect
+
+\registerctxluafile{toks-scn}{}
+\registerctxluafile{cldf-scn}{}
+\registerctxluafile{cldf-stp}{}
+
+\ifcase \contextlmtxmode \else
+ \registerctxluafile{cldf-lmt}{}
+\fi
+
+\protect \endinput
diff --git a/tex/context/base/mkiv/unic-ini.mkiv b/tex/context/base/mkiv/unic-ini.mkiv
index 684e3aa04..a48bd6ad7 100644
--- a/tex/context/base/mkiv/unic-ini.mkiv
+++ b/tex/context/base/mkiv/unic-ini.mkiv
@@ -17,7 +17,7 @@
\unprotect
-\def\unicodenumber #1{\the \numexpr#1\relax} % no lookahead
+\def\unicodenumber #1{\the\numexpr#1\relax} % no lookahead
\def\unicodehexnumber#1{\cldcontext{number.toevenhex(\number#1))}}
%D \startbuffer