1if not modules then modules = { } end modules ['strc-itm'] = {
2 version = 1.001,
3 comment = "companion to strc-itm.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9local structures = structures
10local itemgroups = structures.itemgroups
11local jobpasses = job.passes
12
13local implement = interfaces.implement
14
15local setvariable = jobpasses.save
16local getvariable = jobpasses.getfield
17
18local texsetcount = tex.setcount
19local texsetdimen = tex.setdimen
20
21local f_stamp = string.formatters["itemgroup:%s:%s"]
22local counts = table.setmetatableindex("number")
23
24
25
26
27
28local trialtypesetting = context.trialtypesetting
29
30local function analyzeitemgroup(name,level)
31 local n = counts[name]
32 if level == 1 then
33 n = n + 1
34 counts[name] = n
35 end
36 local stamp = f_stamp(name,n)
37 local n = getvariable(stamp,level,1,0)
38 local w = getvariable(stamp,level,2,0)
39 texsetcount("c_strc_itemgroups_max_items",n)
40 texsetdimen("d_strc_itemgroups_max_width",w)
41end
42
43local function registeritemgroup(name,level,nofitems,maxwidth)
44 local n = counts[name]
45 if not trialtypesetting() then
46
47 setvariable(f_stamp(name,n), { nofitems, maxwidth }, level)
48 elseif level == 1 then
49 counts[name] = n - 1
50 end
51end
52
53implement {
54 name = "analyzeitemgroup",
55 actions = analyzeitemgroup,
56 arguments = { "string", "integer" }
57}
58
59implement {
60 name = "registeritemgroup",
61 actions = registeritemgroup,
62 arguments = { "string", "integer", "integer", "dimen" }
63}
64 |