1if not modules then modules = { } end modules ['s-physics-units'] = {
2 version = 1.001,
3 comment = "companion to s-physics-units.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
9moduledata.physics = moduledata.physics or { }
10moduledata.physics.units = moduledata.physics.units or { }
11
12local tables = physics.units.tables
13local units = tables.units
14local shortcuts = tables.shortcuts
15
16local HL = context.HL
17local NC = context.NC
18local NR = context.NR
19
20local function typeset(list,followup,name,category)
21 if list then
22 if followup then
23 context.TB()
24 end
25 if category then
26 HL()
27 NC()
28 context.rlap(category .. ":" .. name)
29 NC()
30 NC()
31 NR()
32 HL()
33 end
34 for k, v in table.sortedhash(list) do
35 NC()
36 context(k)
37 NC()
38 if isunit then
39 context(v)
40 else
41 context.type(v)
42 end
43 NC()
44 if name == "units" or name == "symbols" or name == "packaged" then
45 context.unittext(v)
46 elseif name == "prefixes" then
47 context.prefixtext(v)
48 elseif name == "operators" then
49 context.operatortext(v)
50 elseif name == "suffixes" then
51 context.suffixtext(v)
52 end
53 NC()
54 NR()
55 end
56 if category and name then
57 HL()
58 end
59 end
60end
61
62function moduledata.physics.units.showlist(name)
63 specification = interfaces.checkedspecification(specification)
64 context.starttabulate { "|lT|l|c|" }
65 local name = specification.name
66 if name and name ~= "" then
67 local first, second = string.match(name,"(.-):(.-)")
68 if first then
69 typeset(tables[first] and tables[first][second],false)
70 else
71 typeset(units[name],false)
72 typeset(shortcuts[name],true)
73 end
74 else
75 local done = false
76 for what, list in table.sortedhash(units) do
77 typeset(list,done,what,"units")
78 done = true
79 end
80 for what, list in table.sortedhash(shortcuts) do
81 typeset(list,done,what,"shortcuts")
82 done = true
83 end
84 end
85 context.stoptabulate()
86end
87 |