summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-itm.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2014-11-17 01:15:05 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2014-11-17 01:15:05 +0100
commit4270545e13cb1bdf4cc0b3305a62ac9d680e296a (patch)
tree9eaaa8d7564bb2fd517a72387ff7c9e4cfb3dde3 /tex/context/base/strc-itm.lua
parent1de6c31af257171be8ba0d5c7e28896612214dca (diff)
downloadcontext-4270545e13cb1bdf4cc0b3305a62ac9d680e296a.tar.gz
2014-11-17 00:34:00
Diffstat (limited to 'tex/context/base/strc-itm.lua')
-rw-r--r--tex/context/base/strc-itm.lua64
1 files changed, 37 insertions, 27 deletions
diff --git a/tex/context/base/strc-itm.lua b/tex/context/base/strc-itm.lua
index 4945c282f..675917d59 100644
--- a/tex/context/base/strc-itm.lua
+++ b/tex/context/base/strc-itm.lua
@@ -6,33 +6,43 @@ if not modules then modules = { } end modules ['strc-itm'] = {
license = "see context related readme files"
}
-local structures = structures
-local itemgroups = structures.itemgroups
-local jobpasses = job.passes
-
-local setvariable = jobpasses.save
-local getvariable = jobpasses.getfield
-
-function itemgroups.register(name,nofitems,maxwidth)
- setvariable("itemgroup", { nofitems, maxwidth })
-end
-
-function itemgroups.nofitems(name,index)
- return getvariable("itemgroup", index, 1, 0)
-end
-
-function itemgroups.maxwidth(name,index)
- return getvariable("itemgroup", index, 2, 0)
-end
-
--- interface (might become counter/dimension)
-
-commands.registeritemgroup = itemgroups.register
-
-function commands.nofitems(name,index)
- context(getvariable("itemgroup", index, 1, 0))
+local structures = structures
+local itemgroups = structures.itemgroups
+local jobpasses = job.passes
+
+local setvariable = jobpasses.save
+local getvariable = jobpasses.getfield
+
+local texsetcount = tex.setcount
+local texsetdimen = tex.setdimen
+local texgetcount = tex.getcount
+
+local f_stamp = string.formatters["itemgroup:%s:%s"]
+local counts = table.setmetatableindex("number")
+
+-- We keep the counter at the Lua end so we can group the items within
+-- an itemgroup which in turn makes for less passes when one itemgroup
+-- entry is added or removed.
+
+function commands.analyzeitemgroup(name,level)
+ local n = counts[name]
+ if level == 1 then
+ n = n + 1
+ counts[name] = n
+ end
+ local stamp = f_stamp(name,n)
+ local n = getvariable(stamp,level,1,0)
+ local w = getvariable(stamp,level,2,0)
+ texsetcount("local","c_strc_itemgroups_max_items",n)
+ texsetdimen("local","d_strc_itemgroups_max_width",w)
end
-function commands.maxitemwidth(name,index)
- context(getvariable("itemgroup", index, 2, 0))
+function commands.registeritemgroup(name,level,nofitems,maxwidth)
+ local n = counts[name]
+ if texgetcount("@@trialtypesetting") == 0 then
+ -- no trialtypsetting
+ setvariable(f_stamp(name,n), { nofitems, maxwidth }, level)
+ elseif level == 1 then
+ counts[name] = n - 1
+ end
end