Debian Codegraph @

texmf-dist/tex/lualatex/lua-unicode-math/lua-unicode-math--dots.lua

raw
1 local dots_node_id = luatexbase.new_whatsit'dots'
2
3 local func = luatexbase.new_luafunction'dots'
4 token.set_lua("mdots@", func, 'protected')
5
6 lua.get_functions_table()[func] = function(id)
7 check_math(id)
8 write_whatsit_wrapped(dots_node_id, 100, 0, 9)
9 end
10
11 local accent_t = node.id'accent'
12 local math_char_t = node.id'math_char'
13 local sub_mlist_t = node.id'sub_mlist'
14 local whatsit_t = node.id'whatsit'
15 local noad_t = node.id'noad'
16 local radical_t = node.id'radical'
17 local user_defined_sub = node.subtype'user_defined'
18
19 local cp = utf8.codepoint
20
21 local comma_cp = cp','
22 local ldots = cp'…'
23 local cdots = cp'⋯'
24 local binary_dots = cdots
25 local comma_dots = ldots
26 local int_dots = cdots
27 local other_dots = ldots
28 local lookup = {
29 -- [cp'']
30 }
31
32 local function select_dots_from_next(noad)
33 -- FIXME: Handle \boldsymbol. See \boldsymboldots@
34 if not noad or noad.id ~= noad_t then return other_dots end
35 local sub = noad.subtype
36 if sub == 4 or sub == 5 then -- bin or rel
37 return binary_dots
38 end
39 local nucleus = noad.nucleus
40 local id = nucleus.id
41 if id == math_char_t then
42 local cp = nucleus.char
43 if cp == comma_cp then
44 return comma_dots
45 end
46 if nucleus.char == comma_cp then return comma_dots end
47 elseif id == whatsit_t and nucleus.subtype == user_defined_sub then
48 if nucleus.user_id == not_whatsit then
49 return binary_dots
50 end
51 -- TODO: Consider: How to handle another \dots
52 end
53 return other_dots
54 end
55
56 math_whatsit_processors[dots_node_id] = function(_style, n, parent_head, parent)
57 assert(parent)
58 -- local char = n.value
59 local pre_sup, pre_sub
60 local after = parent.next
61
62 local dots_cp = select_dots_from_next(after)
63
64 node.free(n)
65 local char_node = node.new(math_char_t)
66 char_node.attr, char_node.fam, char_node.char = n.attr, main_fam, dots_cp
67 parent.nucleus = char_node
68 return parent_head, parent
69 end
70
71 local func = luatexbase.new_luafunction'__l_uni_math_set_previous_dots_type:w'
72 token.set_lua("__l_uni_math_set_previous_dots_type:w", func, 'protected')
73
74 lua.get_functions_table()[func] = function(id)
75 local cp = token.scan_int()
76 local top_nest = tex.nest.top
77 local tail = top_nest.tail
78 if tail.id ~= noad_t then return end
79 local nucleus = tail.nucleus
80 if (nucleus and nucleus.id) ~= whatsit_t then return end
81 if nucleus.subtype ~= user_defined_sub then return end
82 if nucleus.user_id ~= dots_node_id then return end
83 local char_node = node.new(math_char_t)
84 char_node.attr, char_node.fam, char_node.char = nucleus.attr, main_fam, cp
85 node.free(nucleus)
86 tail.nucleus = char_node
87 end