为什么 mlist_to_hlist 转换后数学节点属性丢失?

为什么 mlist_to_hlist 转换后数学节点属性丢失?

如果我向数学节点添加属性,它们不会出现在 HLIST 转换节点中。但如果我添加属性,它们将一直保留在此节点中。如果我创建自定义节点(例如user_definedWHATSIT),则当 MLIST 转换为 HLIST 时,属性不会消失。

\documentclass{article}
\usepackage[color=no,verbosity=0,channel=log]{nodetree}
 \nodetreeregister{preout}
 \nodetreeregister{mhlist}

\directlua{
    %% node.set_properties_mode(true,true)

    function set_mathchar_property(n)

      if node.type(n.id) == "math_char" then
        % set any attribute
        node.set_attribute(n, 999, 999)
        % set any property
        node.setproperty(n, {math_char = true})
                
      elseif node.type(n.id) == "noad" then
        if n.nucleus then
          set_mathchar_property(n.nucleus)
        end
        
      elseif node.type(n.id) == 'sub_mlist' then
        set_mathchar_property(n.head)      
        
        local USER_MARK   = node.new(node.id("whatsit"), 8)
        USER_MARK.type    = 115   
        USER_MARK.value   = "math added whatsit"    
        
        node.set_attribute(USER_MARK, 888, 888)
        node.setproperty(USER_MARK, {math_whatsit = true})

        n.head = node.insert_before(n.head, n.head, USER_MARK)
        
      end
    end
    function parse_math_char(h)
      set_mathchar_property(h)
      return h
    end
    luatexbase.add_to_callback('pre_mlist_to_hlist_filter', parse_math_char, 'set_mathchar_property')
}

\begin{document}
${aa}$
\end{document}

以下是输出。您可以看到换行后只有 WHATSIT 具有属性,并且属性 888=888, 999=999 保持粘性:

Callback: mlist_to_hlist
- need_penalties: true
- display_type: text
------------------------------------------
└─NOAD 
  ╚═nucleus:
    └─SUB_MLIST 
      ╚═head:
        ├─WHATSIT subtype: user_defined, type: 115, value: math added whatsit, attr: 888=888 
        │   properties: {['math_whatsit'] = true}
        ├─NOAD 
        │ ╚═nucleus:
        │   └─MATH_CHAR fam: 1, char: a, attr: 999=999 
        │       properties: {['math_char'] = true}
        └─NOAD 
          ╚═nucleus:
            └─MATH_CHAR fam: 1, char: a
-----------------------



Callback: post_linebreak_filter
------------------------------------------
├─GLUE subtype: baselineskip, width: 7.69pt
└─HLIST subtype: line, width: 345pt, height: 4.31pt
  ╚═head:
    ├─LOCAL_PAR 
    ├─HLIST subtype: indent, width: 15pt
    ├─MATH 
    ├─HLIST width: 10.57pt, height: 4.31pt
    │ ╚═head:
    │   ├─WHATSIT subtype: user_defined, type: 115, value: math added whatsit, attr: 888=888 
    │   │ ╚═  properties: {['math_whatsit'] = true}
    │   ├─GLYPH subtype: 256, char: a, width: 5.29pt, height: 4.31pt, attr: 999=999 
    │   └─GLYPH subtype: 256, char: a, width: 5.29pt, height: 4.31pt
    ├─MATH subtype: endmath
    ├─PENALTY subtype: linepenalty, penalty: 10000
    ├─GLUE subtype: parfillskip, stretch: +1fil
    └─GLUE subtype: rightskip
-----------------------

有一个设置node.set_properties_mode(true,true)应该可以对属性复制进行一些操作,但在这里它什么也不做。如何向数学节点添加属性?我想标记一些节点并在发货时对其进行后期处理。

相关内容