summaryrefslogtreecommitdiff
path: root/tex/context/modules/mkiv/s-physics-units.lua
blob: 0083208587008186330f98e602786b86868c899a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
if not modules then modules = { } end modules ['s-physics-units'] = {
    version   = 1.001,
    comment   = "companion to s-physics-units.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

moduledata.physics       = moduledata.physics       or { }
moduledata.physics.units = moduledata.physics.units or { }

local tables    = physics.units.tables
local units     = tables.units
local shortcuts = tables.shortcuts

local HL = context.HL
local NC = context.NC
local NR = context.NR

local function typeset(list,followup,name,category)
    if list then
        if followup then
            context.TB()
        end
        if category then
            HL()
            NC()
            context.rlap(category .. ":" .. name)
            NC()
            NC()
            NR()
            HL()
        end
        for k, v in table.sortedhash(list) do
            NC()
            context(k)
            NC()
            if isunit then
                context(v)
            else
                context.type(v)
            end
            NC()
            if name == "units" or name == "symbols" or name == "packaged" then
                context.unittext(v)
            elseif name == "prefixes" then
                context.prefixtext(v)
            elseif name == "operators" then
                context.operatortext(v)
            elseif name == "suffixes" then
                context.suffixtext(v)
            end
            NC()
            NR()
        end
        if category and name then
            HL()
        end
    end
end

function moduledata.physics.units.showlist(name)
    specification = interfaces.checkedspecification(specification)
    context.starttabulate { "|lT|l|c|" }
    local name = specification.name
    if name and name ~= "" then
        local first, second = string.match(name,"(.-):(.-)") -- [units|shortcuts]:[units|...]
        if first then
            typeset(tables[first] and tables[first][second],false)
        else
            typeset(units[name],false)
            typeset(shortcuts[name],true)
        end
    else
        local done = false
        for what, list in table.sortedhash(units) do
            typeset(list,done,what,"units")
            done = true
        end
        for what, list in table.sortedhash(shortcuts) do
            typeset(list,done,what,"shortcuts")
            done = true
        end
    end
    context.stoptabulate()
end