OSDN Git Service

Fix ticket #33832
[luatex-ja/luatexja.git] / src / ltj-math.lua
index 59d5ec0..df28db0 100644 (file)
@@ -13,7 +13,7 @@ local Dnode = node.direct or node
 local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end
 local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end
 local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end
-local getlist = (Dnode ~= node) and Dnode.getlist or function(n) return n.head end
+-- getlist cannot be used for sub_box nodes. Use instead λp. getfield(p, 'head')
 local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end
 
 local nullfunc = function(n) return n end
@@ -22,7 +22,7 @@ local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc
 
 local node_traverse = Dnode.traverse
 local node_new = Dnode.new
-local node_next = Dnode.getnext
+local node_next = (Dnode ~= node) and Dnode.getnext or node.next
 local node_free = Dnode.free
 local has_attr = Dnode.has_attribute
 local set_attr = Dnode.set_attribute
@@ -90,9 +90,9 @@ local function conv_jchar_to_hbox(head, sty)
         else sty = 2
         end
        end
-   end 
+   end
    return head
-end 
+end
 
 local MJT  = luatexja.stack_table_index.MJT
 local MJS  = luatexja.stack_table_index.MJS
@@ -100,25 +100,25 @@ local MJSS = luatexja.stack_table_index.MJSS
 local capsule_glyph_math = ltjw.capsule_glyph_math
 local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct
 
-conv_jchar_to_hbox_A = 
+conv_jchar_to_hbox_A =
 function (p, sty)
    if not p then return nil
    else
       local pid = getid(p)
       if pid == id_sub_mlist then
-         if getlist(p) then
-            setfield(p, 'head', conv_jchar_to_hbox(getlist(p), sty))
+         if getfield(p, 'head') then
+            setfield(p, 'head', conv_jchar_to_hbox(getfield(p, 'head'), sty))
          end
       elseif pid == id_mchar then
          local fam = has_attr(p, attr_jfam) or -1
         local pc = getchar(p)
          if (not is_math_letters[pc]) and is_ucs_in_japanese_char(p) and fam>=0 then
-            local f = ltjs.get_penalty_table(MJT + 0x100 * sty + fam, -1, tex_getcount('ltj@@stack'))
+            local f = ltjs.get_stack_table(MJT + 0x100 * sty + fam, -1, tex_getcount('ltj@@stack'))
             if f ~= -1 then
                local q = node_new(id_sub_box)
                local r = node_new(id_glyph); setfield(r, 'next', nil)
                setfield(r, 'char', pc); setfield(r, 'font', f); setfield(r, 'subtype', 256)
-               local k = has_attr(r,attr_ykblshift) or 0 
+               local k = has_attr(r,attr_ykblshift) or 0
                set_attr(r, attr_ykblshift, 0)
                -- ltj-setwidth 内で実際の位置補正はおこなうので,補正量を退避
                local met = ltjf_font_metric_table[f]
@@ -127,15 +127,15 @@ function (p, sty)
                set_attr(r, attr_yablshift, k)
             end
          end
-      elseif pid == id_sub_box and getlist(p) then
+      elseif pid == id_sub_box and getfield(p, 'head') then
          -- \hbox で直に与えられた内容は上下位置を補正する必要はない
-         set_attr(getlist(p), attr_icflag, PROCESSED)
+         set_attr(getfield(p, 'head'), attr_icflag, PROCESSED)
       end
    end
    return p
 end
 
-luatexbase.add_to_callback('mlist_to_hlist', 
+luatexbase.add_to_callback('mlist_to_hlist',
    function (n, display_type, penalties)
       local head = to_node(conv_jchar_to_hbox(to_direct(n), 0))
       head = node.mlist_to_hlist(head, display_type, penalties)