2 -- luatexja/ltj-math.lua
5 luatexja.load_module('base'); local ltjb = luatexja.base
6 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
7 luatexja.load_module('jfont'); local ltjf = luatexja.jfont
8 luatexja.load_module('stack'); local ltjs = luatexja.stack
9 luatexja.load_module('setwidth'); local ltjw = luatexja.setwidth
11 local node_new = node.new
12 local node_next = node.next
13 local node_free = node.free
14 local has_attr = node.has_attribute
15 local set_attr = node.set_attribute
16 local tex_getcount = tex.getcount
18 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
19 local attr_icflag = luatexbase.attributes['ltj@icflag']
20 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
21 local attr_jfam = luatexbase.attributes['jfam']
22 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
24 local id_glyph = node.id('glyph')
25 local id_hlist = node.id('hlist')
26 local id_vlist = node.id('vlist')
27 local id_mchar = node.id('math_char')
28 local id_sub_box = node.id('sub_box')
29 local id_radical = node.id('radical')
30 local id_choice = node.id('choice')
31 local id_accent = node.id('accent')
32 local id_style = node.id('style')
33 local id_frac = node.id('fraction')
34 local id_simple = node.id('noad')
35 local id_sub_mlist = node.id('sub_mlist')
37 local PROCESSED = luatexja.icflag_table.PROCESSED
39 local ltjf_font_metric_table = ltjf.font_metric_table
40 local ltjf_find_char_class = ltjf.find_char_class
42 -- table of mathematical characters
43 local is_math_letters = {}
45 local conv_jchar_to_hbox_A
47 -- sty : 0 (display or text), 1 (script), >=2 (scriptscript)
48 local function conv_jchar_to_hbox(head, sty)
52 if p.id == id_simple or p.id == id_accent then
53 p.nucleus = conv_jchar_to_hbox_A(p.nucleus, sty)
54 p.sub = conv_jchar_to_hbox_A(p.sub, sty + 1)
55 p.sup = conv_jchar_to_hbox_A(p.sup, sty + 1)
56 elseif p.id == id_choice then
57 p.display = conv_jchar_to_hbox(p.display, 0)
58 p.text = conv_jchar_to_hbox(p.text, 0)
59 p.script = conv_jchar_to_hbox(p.script, 1)
60 p.scriptscript = conv_jchar_to_hbox(p.scriptscript, 2)
61 elseif p.id == id_frac then
62 p.num = conv_jchar_to_hbox_A(p.num, sty + 1)
63 p.denom = conv_jchar_to_hbox_A(p.denom, sty + 1)
64 elseif p.id == id_radical then
65 p.nucleus = conv_jchar_to_hbox_A(p.nucleus, sty)
66 p.sub = conv_jchar_to_hbox_A(p.sub, sty + 1)
67 p.sup = conv_jchar_to_hbox_A(p.sup, sty + 1)
69 p.degree = conv_jchar_to_hbox_A(p.degree, sty + 1)
71 elseif p.id == id_style then
72 if p.style == "display'" or p.style == 'display'
73 or p.style == "text'" or p.style == 'text' then
75 elseif p.style == "script'" or p.style == 'script' then
85 local MJT = luatexja.stack_table_index.MJT
86 local MJS = luatexja.stack_table_index.MJS
87 local MJSS = luatexja.stack_table_index.MJSS
89 conv_jchar_to_hbox_A =
91 if not p then return nil
92 elseif p.id == id_sub_mlist then
94 p.head = conv_jchar_to_hbox(p.head, sty)
96 elseif p.id == id_mchar then
97 local fam = has_attr(p, attr_jfam) or -1
98 if (not is_math_letters[p.char]) and ltjc.is_ucs_in_japanese_char(p) and fam>=0 then
99 local f = ltjs.get_penalty_table(MJT + 0x100 * sty + fam, -1, tex_getcount('ltj@@stack'))
101 local q = node_new(id_sub_box)
102 local r = node_new(id_glyph); r.next = nil
103 r.char = p.char; r.font = f; r.subtype = 256
104 local k = has_attr(r,attr_ykblshift) or 0
105 set_attr(r, attr_ykblshift, 0)
106 set_attr(r, attr_icflag, PROCESSED)
107 local met = ltjf_font_metric_table[f]
108 ltjw.head = r; ltjw.capsule_glyph(r, tex.mathdir , true, met, ltjf_find_char_class(p.char, met));
109 q.head = ltjw.head; node_free(p); p=q;
110 set_attr(q.head, attr_yablshift, k)
117 luatexbase.add_to_callback('mlist_to_hlist',
118 function (n, display_type, penalties)
119 local head = conv_jchar_to_hbox(n, 0);
120 head = node.mlist_to_hlist(head, display_type, penalties)
122 end,'ltj.mlist_to_hlist', 1)
124 luatexja.math = { is_math_letters = is_math_letters }