summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/catc-ini.lua
blob: b2c793a6a985253d580b9d7b9dba13e03e2db6f5 (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
if not modules then modules = { } end modules ['catc-ini'] = {
    version   = 1.001,
    comment   = "companion to catc-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- todo: everywhere replace tex.ctxcatcodes -> catcodes.numbers.ctxcatcodes

catcodes         = catcodes         or { }
catcodes.numbers = catcodes.numbers or { }
catcodes.names   = catcodes.names   or { }

storage.register("catcodes/numbers", catcodes.numbers, "catcodes.numbers")
storage.register("catcodes/names",   catcodes.names,   "catcodes.names")

-- this only happens at initime

function catcodes.register(name,number)
    catcodes.numbers[name] = number
    local cnn = catcodes.names[number]
    if cnn then
        cnn[#cnn+1] = name
    else
        catcodes.names[number] = { name }
    end
    tex[name] = number
end

-- this only happens at runtime

for k, v in next, catcodes.numbers do
    tex[k] = v
end

-- nasty

table.setmetatableindex(catcodes.numbers,function(t,k) if type(k) == "number" then t[k] = k return k end end)
table.setmetatableindex(catcodes.names,  function(t,k) if type(k) == "string" then t[k] = k return k end end)