summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/char-brl.lmt
blob: 046436b5977d9f5e06c70bd5457106d6986bbd1a (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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
if not modules then modules = { } end modules ['char-bri'] = {
    version   = 1.001,
    comment   = "companion to char-ini.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- We use a somewhat indirect approach because we generated the database and
-- have to do that again probably. At some point we can move some to char-def
-- so the interfaces here are kind of private and can change.
--
-- This is just an experiment. The data is taken from Wikipedia and the nemeth
-- sequences come from a 2021 blog by Murray Sargent (from Microsoft):
--
-- https://devblogs.microsoft.com/math-in-office/unicode-math-braille-sequences/

local next = next
local gsub = string.gsub
local utfbyte, utfsplit = utf.byte, string.utfvaluetable
local sortedkeys = table.sortedkeys

local braille      = { }
characters.braille = braille

local codepoints = {
    digits = {
        [48] = "⠚",
        [49] = "⠁",
        [50] = "⠃",
        [51] = "⠉",
        [52] = "⠙",
        [53] = "⠑",
        [54] = "⠋",
        [55] = "⠛",
        [56] = "⠓",
        [57] = "⠊",
    },
    letters = {
        [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] = "⠵",
    },
    punctuation = {
        [33] = "⠖",
        [34] = "⠸⠡",
        [40] = "⠐⠣",
        [41] = "⠐⠜",
        [44] = "⠂",
        [45] = "⠤",
        [46] = "⠲",
        [47] = "⠸⠌",
        [58] = "⠒",
        [59] = "⠆",
        [63] = "⠦",
      [8211] = "⠠⠤",
      [8212] = "⠐⠠⠤",
      [8216] = "⠄⠦",
      [8217] = "⠄⠴",
      [8220] = "⠘⠦",
      [8221] = "⠘⠴",
    },
    ueb = {
        [33] = "⠖",
        [34] = "⠠⠶",
        [35] = "⠸⠹",
        [36] = "⠈⠎",
        [37] = "⠨⠴",
        [38] = "⠈⠯",
        [39] = "⠄",
        [40] = "⠐⠣",
        [41] = "⠐⠜",
        [42] = "⠐⠔",
        [43] = "⠐⠖",
        [44] = "⠂",
        [45] = "⠤",
        [46] = "⠼⠲",
        [47] = "⠸⠌",
        [58] = "⠒",
        [59] = "⠆",
        [60] = "⠈⠣",
        [61] = "⠐⠶",
        [62] = "⠈⠜",
        [63] = "⠦",
        [64] = "⠈⠁",
        [91] = "⠨⠣",
        [92] = "⠸⠡",
        [93] = "⠨⠜",
        [94] = "⠈⠢",
        [95] = "⠨⠤",
       [123] = "⠸⠣",
       [124] = "⠸⠳",
       [125] = "⠸⠜",
       [126] = "⠈⠔",
       [162] = "⠈⠉",
       [163] = "⠈⠇",
       [167] = "⠘⠎",
       [169] = "⠘⠉",
       [172] = "⠈⠹",
       [174] = "⠘⠗",
       [176] = "⠘⠚",
       [177] = "⠸⠖",
       [182] = "⠘⠏",
       [215] = "⠐⠦",
       [247] = "⠐⠌",
       [913] = "⠠⠨⠁",
       [914] = "⠠⠨⠃",
       [915] = "⠠⠨⠛",
       [916] = "⠠⠨⠙",
       [917] = "⠠⠨⠑",
       [918] = "⠠⠨⠵",
       [919] = "⠠⠨⠱",
       [920] = "⠠⠨⠹",
       [921] = "⠠⠨⠊",
       [922] = "⠠⠨⠅",
       [923] = "⠠⠨⠇",
       [924] = "⠠⠨⠍",
       [925] = "⠠⠨⠝",
       [926] = "⠠⠨⠭",
       [927] = "⠠⠨⠕",
       [928] = "⠠⠨⠏",
       [929] = "⠠⠨⠗",
       [931] = "⠠⠨⠎",
       [932] = "⠠⠨⠞",
       [933] = "⠠⠨⠥",
       [934] = "⠠⠨⠋",
       [935] = "⠠⠨⠯",
       [936] = "⠠⠨⠽",
       [937] = "⠠⠨⠺",
       [945] = "⠨⠁",
       [946] = "⠨⠃",
       [947] = "⠨⠛",
       [948] = "⠨⠙",
       [949] = "⠨⠑",
       [950] = "⠨⠵",
       [951] = "⠨⠱",
       [952] = "⠨⠹",
       [953] = "⠨⠊",
       [954] = "⠨⠅",
       [955] = "⠨⠇",
       [956] = "⠨⠍",
       [957] = "⠨⠝",
       [958] = "⠨⠭",
       [959] = "⠨⠕",
       [960] = "⠨⠏",
       [961] = "⠨⠗",
       [962] = "⠨⠎",
       [963] = "⠨⠎",
       [964] = "⠨⠞",
       [965] = "⠨⠥",
       [966] = "⠨⠋",
       [967] = "⠨⠯",
       [968] = "⠨⠽",
       [969] = "⠨⠺",
      [8212] = "⠠⠤",
      [8213] = "⠐⠠⠤",
      [8216] = "⠠⠦",
      [8217] = "⠠⠴",
      [8220] = "⠘⠦",
      [8221] = "⠘⠴",
      [8224] = "⠈⠠⠹",
      [8225] = "⠈⠠⠻",
      [8226] = "⠸⠲",
      [8242] = "⠶",
      [8243] = "⠶⠶",
      [8592] = "⠳⠪",
      [8593] = "⠳⠬",
      [8594] = "⠳⠕",
      [8595] = "⠳⠩",
      [8596] = "⠰⠳⠺⠗⠕",
      [8598] = "⠳⠱",
      [8599] = "⠳⠎",
      [8600] = "⠳⠣",
      [8601] = "⠳⠜",
      [8656] = "⠰⠳⠶⠶⠪",
      [8657] = "⠰⠳⠶⠶⠬",
      [8658] = "⠰⠳⠶⠶⠕",
      [8659] = "⠰⠳⠶⠶⠩",
      [8704] = "⠘⠁",
      [8706] = "⠈⠙",
      [8707] = "⠘⠢",
      [8709] = "⠈⠚",
      [8711] = "⠘⠙",
      [8712] = "⠘⠑",
      [8715] = "⠈⠘⠑",
      [8722] = "⠐⠤",
      [8723] = "⠸⠤",
      [8728] = "⠐⠴",
      [8730] = "⠐⠩",
      [8733] = "⠸⠐⠶",
      [8734] = "⠼⠿",
      [8736] = "⠸⠪",
      [8737] = "⠨⠸⠪",
      [8741] = "⠼⠇",
      [8743] = "⠈⠦",
      [8744] = "⠈⠖",
      [8745] = "⠨⠦",
      [8746] = "⠨⠖",
      [8747] = "⠮",
      [8748] = "⠮⠮",
      [8749] = "⠮⠮⠮",
      [8750] = "⠈⠮",
      [8756] = "⠠⠡",
      [8757] = "⠈⠌",
      [8758] = "⠒",
      [8759] = "⠒⠒",
      [8771] = "⠸⠔",
      [8773] = "⠐⠸⠔",
      [8776] = "⠘⠔",
      [8783] = "⠘⠐⠶",
      [8785] = "⠨⠐⠶",
      [8800] = "⠐⠶⠈⠱",
      [8801] = "⠸⠿",
      [8804] = "⠸⠈⠣",
      [8805] = "⠸⠈⠜",
      [8810] = "⠨⠈⠣",
      [8811] = "⠨⠈⠜",
      [8834] = "⠘⠣",
      [8835] = "⠘⠜",
      [8838] = "⠸⠘⠣",
      [8839] = "⠸⠘⠜",
      [8842] = "⠨⠘⠣",
      [8843] = "⠨⠘⠜",
      [8853] = "⠰⠫⠿⠪⠐⠖⠱",
      [8867] = "⠈⠸⠒",
      [8869] = "⠼⠤",
      [8870] = "⠸⠒",
      [8872] = "⠘⠸⠒",
      [8882] = "⠈⠸⠣",
      [8883] = "⠈⠸⠜",
      [8884] = "⠸⠸⠣",
      [8885] = "⠸⠸⠜",
      [8894] = "⠼⠸⠪",
      [8901] = "⠐⠲",
      [9675] = "⠿",
     [10764] = "⠮⠮⠮⠮",
    },
    specials = {
        uppercase = "⠠",
        space     = "⠀",
        number    = "⠼",
        rule      = "⠒",
    },
    alphabets = {
        ["lowercasenormal"]                    = "⠰",
        ["lowercasegreeknormal"]               = "⠨",
        ["lowercasegreekitalic"]               = "⠨⠨",
        ["lowercaseitalic"]                    = "⠨",
        ["lowercasebold"]                      = "⠸",
        ["lowercasebolditalic"]                = "⠸⠨",
        ["lowercasefraktur"]                   = "⠸",
        ["lowercaseboldfraktur"]               = "⠸⠸",
        ["lowercasescript"]                    = "⠈",
        ["lowercaseboldscript"]                = "⠸⠈",
        ["lowercasesansserifnormal"]           = "⠠⠨",
        ["lowercasesansserifitalic"]           = "⠠⠨⠨",
        ["lowercasesansserifbold"]             = "⠠⠨⠸",
        ["lowercasesansserifbolditalic"]       = "⠠⠨⠸⠨",

        ["uppercase"]                          = "⠠",

     -- ["russian"]                            = "⠈⠈",
     -- ["hebrew"]                             = "⠠⠠",
     -- ["altgreek"]                           = "⠨⠈",

     -- ["lowercasedoublestruck"]              = ""
     -- ["lowercasegreekbold"]                 = ""
     -- ["lowercasegreekbolditalic"]           = ""
     -- ["lowercasegreeksansserifbold"]        = ""
     -- ["lowercasegreeksansserifbolditalic"]  = ""
     -- ["lowercasemonospace"]                 = ""
    },
}

braille.codepoints = codepoints

local textunicodes, mathunicodes, textstrings, mathstrings, textlist, mathlist, specials

local function prepare()

    local charblocks  = characters.blocks
    local uccodes     = characters.uccodes

    local letters     = codepoints.letters
    local cspecials   = codepoints.specials
    local uppercase   = cspecials.uppercase
    local number      = cspecials.number
    local space       = cspecials.space
    local rule        = cspecials.rule

    -- filtered from the mentioned blog webpage:

    local nemeth      = table.load(resolvers.find_file("math-brl.lmt")).nemeth
    codepoints.nemeth = nemeth

    -- we let the tex math engine do the spacing but it can become an option:

    for k, v in next, nemeth do
        nemeth[k] = gsub(v,space,"")
    end

    textstrings  = { }
    mathstrings  = { }
    textunicodes = { }
    mathunicodes = { }

    for k, v in next, codepoints.letters do
        textstrings[k] = v
        mathstrings[k] = v
        local K = uccodes[k]
        if K then
            local V = uppercase .. v
            textstrings[K] = V
            mathstrings[K] = V
        end
    end

    for k, v in next, codepoints.digits do
        local d = number .. v
        textstrings[k] = v
        mathstrings[k] = v
    end

    for k, v in next, codepoints.punctuation do
        textstrings[k] = v
        mathstrings[k] = v
    end
    -- overlaps with the above

    for k, v in next, codepoints.ueb do
        textstrings[k] = v
        mathstrings[k] = v
    end

    for k, v in next, codepoints.nemeth do
        mathstrings[k] = v
        if not textstrings[k] then
            textstrings[k] = v
        end
    end

    for k, v in next, codepoints.alphabets do
        local block = charblocks[k]
        if block then
            local c = utfbyte('a')
            for i=block.first,block.last do
                mathstrings[i] = v..letters[c]
                if not textstrings[i] then
                    textstrings[i] = v .. letters[c]
                end
                c = c + 1
            end
        end
    end

    for k, v in next, textstrings do
        textunicodes[k] = utfsplit(v)
    end
    for k, v in next, mathstrings do
        mathunicodes[k] = utfsplit(v)
    end

    textlist = sortedkeys(textstrings)
    mathlist = sortedkeys(mathstrings)

    specials = {
        uppercase = utfbyte(uppercase),
        number    = utfbyte(number),
        space     = utfbyte(space),
        rule      = utfbyte(rule)
    }
end

-- maybe an iterator

function braille.textlist   ()  if not textlist     then prepare() end return textlist        end
function braille.mathlist   ()  if not mathlist     then prepare() end return mathlist        end
function braille.textunicode(n) if not textunicodes then prepare() end return textunicodes[n] end
function braille.mathunicode(n) if not mathunicodes then prepare() end return mathunicodes[n] end
function braille.textstring (n) if not textstrings  then prepare() end return textstrings [n] end
function braille.mathstring (n) if not mathstrings  then prepare() end return mathstrings [n] end
function braille.special    (n) if not specials     then prepare() end return specials    [n] end