summaryrefslogtreecommitdiff
path: root/tex/context/base/s-phy-01.mkiv
blob: dde3f9bbb322f1391c29beea086b534b09677fe7 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
%D \module
%D   [       file=s-phy-01,
%D        version=2011-11-24,
%D          title=\CONTEXT\ Modules,
%D       subtitle=Units Tables,
%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.

\unprotect

% todo: better breaks of head line

\startluacode
moduledata.units = moduledata.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.units.show_table(name)
    context.starttabulate { "|lT|l|c|" }
    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

\stopluacode

\unexpanded\def\ShowUnitsTable
  {\dosingleempty\Show_Units_Table}

\def\Show_Units_Table[#1]%
  {\ctxlua{moduledata.units.show_table("#1")}}

\protect

\continueifinputfile{s-phy-01.mkiv}

\usemodule[art-01]

\starttext
    \ShowUnitsTable
\stoptext