-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaketable-luatex.lua
executable file
·154 lines (138 loc) · 4.26 KB
/
maketable-luatex.lua
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env lua
require("unicode")
require("unimath-data")
local function write_styles(kind, data, default)
for key, value in pairs(data) do
local name, safe
if type(value) == "string" then
name = value
safe = false
else
name = value.name
safe = value.safe or false
end
local safe_str = safe and "safe" or "unsafe"
local factory = "\\um_new_" .. safe_str .. "_" .. kind .. ":nN"
local name_arg = " { " .. name .. " }"
local isdefault = name == default
local isdefault_arg = " { " .. tostring(isdefault) .. " }"
local command_arg = " \\" .. key
io.write(factory .. name_arg .. isdefault_arg .. command_arg .. "\n")
end
local setdefault = "\\um_set_default_" .. kind .. ":n"
local name_arg = " { " .. default .. " }"
io.write(setdefault .. name_arg .. "\n")
end
local function write_families()
write_styles("family", unimath.data.families, unimath.data.default_family)
end
local function write_mappings()
write_styles("mapping", unimath.data.mappings, unimath.data.default_mapping)
end
local class_codes = {
ordinary = 0,
operator = 1,
binary = 2,
relation = 3,
open = 4,
close = 5,
punctuation = 6,
variable = 7
}
local function is_entity_code(entity)
return type(entity) == "number" or (type(entity) == "string" and unicode.utf8.len(entity) == 1)
end
local function get_entity_code(entity)
if type(entity) == "number" then
return entity
else
return unicode.utf8.byte(entity)
end
end
local function get_entity_ctlseq(entity)
if string.byte(entity) == 0x5C then
return entity
else
return "\\" .. entity
end
end
local function get_delim_code(entity, delim)
if type(delim) == "nil" then
return -1
elseif type(delim) == "bool" then
if delim then
return get_entity_code(entity)
else
return -1
end
else
return get_entity_code(delim)
end
end
-- rules 1 to 5
local function write_simple_def(entity, definition)
-- mathematical code or character definition
local is_code = is_entity_code(entity)
local factory, entity_arg
if is_code then
factory = "\\um_assign_mathcode:nNNn"
local entity_code = get_entity_code(entity)
entity_arg = " { " .. entity_code .. " }"
else
local safe = definition.safe or false
local safe_str = safe and "safe" or "unsafe"
factory = "\\um_new_" .. safe_str .. "_chdef:NNNn"
local entity_ctlseq = get_entity_ctlseq(entity)
entity_arg = " " .. entity_ctlseq
end
local class = definition.class or "ordinary"
local class_arg = " \\c_um_class_" .. class .. "_int"
local family = definition.family or unimath.data.default_family
local family_arg = " \\g_um_" .. family .. "_fam"
local char = definition.char or entity
local mathcode = get_entity_code(char)
local mathcode_arg = " { " .. mathcode .. " }"
io.write(factory .. entity_arg .. class_arg .. family_arg .. mathcode_arg .. "\n")
-- delimiter code
if is_code then
local delim = definition.delim or false
if delim then
local delcode = get_delim_code(entity, delim)
local delcode_arg = " { " .. delcode .. " }"
local factory = "\\um_assign_delcode:nNn"
io.write(factory .. entity_arg .. family_arg .. delcode_arg .. "\n")
end
end
end
local simple_classes = {
ordinary = true,
binary = true,
relation = true,
punctuation = true
}
local function write_immediate_defs()
for key, value in pairs(unimath.data.characters) do
if type(value) == "table" and simple_classes[value.class] then
-- rules 1 and 3
write_simple_def(key, value)
elseif is_entity_code(value) then
-- rule 2
write_simple_def(key, {class = "ordinary", char = key})
elseif type(value) == "string" and simple_classes[value] then
-- rule 4
write_simple_def(key, {class = value, char = key})
end
end
end
local function write_deferred_defs()
for key, value in pairs(unimath.data.characters) do
end
end
io.output("unicode-math-table-luatex-immediate.tex")
write_families()
write_mappings()
write_immediate_defs()
io.close()
io.output("unicode-math-table-luatex-deferred.tex")
write_deferred_defs()
io.close()