LuaTeX 并不总是像文档中承诺的那样在数学公式的开头添加数学节点

LuaTeX 并不总是像文档中承诺的那样在数学公式的开头添加数学节点

数学节点标记 TeX/LuaTeX 排版引擎中数学表达式的边界。LuaTeX 文档指出,

“数学节点表示数学公式的边界,通常用 $ 符号表示。”

文档似乎表明数学表达式总是被 subtype=0 (beginmath) 和 subtype=1 (endmath) 的数学节点包围。在下面的代码中,没有标记数学表达式开始的节点,但有一个标记其结束的节点。

输出:

输出截图

代码:

% >>> lualatex mathmode.tex
\documentclass{article}
\usepackage[callback={}]{nodetree}

\begin{document}

\setbox0=\vbox{{\noindent Hello\\ $x=a+b^2$}}

\directlua{
    local nodetree = require('nodetree')
    nodetree.print(tex.box[0])
}

\box0

\end{document}

控制台(查找字符串“MATH”):

└─VLIST width: 345pt, depth: 0.83pt, height: 18.94pt
  ╚═head:
    ├─HLIST subtype: line, width: 345pt, depth: 0.11pt, height: 6.94pt
    │ ╚═head:
    │   ├─LOCAL_PAR 
    │   ├─GLYPH subtype: 256, char: H, width: 7.5pt, height: 6.83pt
    │   ├─GLYPH subtype: 256, char: e, width: 4.44pt, height: 4.48pt, depth: 0.11pt
    │   ├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
    │   ├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
    │   ├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
    │   ├─PENALTY penalty: 10000
    │   ├─GLUE stretch: +1fil
    │   ├─PENALTY penalty: -10000
    │   └─GLUE subtype: rightskip
    ├─PENALTY subtype: linebreakpenalty, penalty: 300
    ├─GLUE subtype: baselineskip, width: 3.75pt
    └─HLIST subtype: line, width: 345pt, depth: 0.83pt, height: 8.14pt
      ╚═head:
        ├─GLYPH subtype: 256, char: x, width: 5.72pt, height: 4.31pt
        ├─GLUE subtype: thickmuskip, width: 2.78pt, stretch: 2.78pt
        ├─GLYPH subtype: 256, char: =, width: 7.78pt, height: 3.67pt, depth: -1.33pt
        ├─PENALTY subtype: noadpenalty, penalty: 500
        ├─GLUE subtype: thickmuskip, width: 2.78pt, stretch: 2.78pt
        ├─GLYPH subtype: 256, char: a, width: 5.29pt, height: 4.31pt
        ├─GLUE subtype: medmuskip, width: 2.22pt, stretch: 1.11pt, shrink: 2.22pt
        ├─GLYPH subtype: 256, char: +, width: 7.78pt, height: 5.83pt, depth: 0.83pt
        ├─PENALTY subtype: noadpenalty, penalty: 700
        ├─GLUE subtype: medmuskip, width: 2.22pt, stretch: 1.11pt, shrink: 2.22pt
        ├─GLYPH subtype: 256, char: b, width: 4.29pt, height: 6.94pt
        ├─HLIST subtype: sup, width: 4.49pt, height: 4.51pt, shift: -3.63pt
        │ ╚═head:
        │   └─GLYPH char: 2, width: 3.99pt, height: 4.51pt
        ├─MATH subtype: endmath
        ├─PENALTY subtype: linepenalty, penalty: 10000
        ├─GLUE subtype: parfillskip, stretch: +1fil
        └─GLUE subtype: rightskip

答案1

LuaTeX总是添加它们,但是在您的示例中,它们在您看到它们之前就被丢弃了:

在 TeX 中,某些节点类型(glue、kern、penalty 和 math 节点)被称为“可丢弃的”。每当出现换行符时,TeX 都会删除所有可丢弃节点,直到出现第一个不可丢弃节点。(当其中一个节点上发生另一个换行符时会出现例外情况,有关详细信息,请参阅 TeXbook。)

在您的示例中,第二行中的第一个节点是一个数学节点,因此它在换行后会被丢弃。

答案2

您的问题与 luatex 无关。TeXbook 在第 95 页提到了可丢弃物品,并且数学物品也被提及为可丢弃的。

并且您的示例应该不带 luatex 显示,只在 TeX 中显示:

\setbox0=\vbox{{\noindent Hello\hfil\break $x=a+b^2$}}
\showbox0

并且 .log 说:

\box0=
\vbox(18.88875+0.83333)x455.24408, direction TLT
.\hbox(6.88875+0.0)x455.24408, glue set 432.74408fil, direction TLT
..\localpar
...\localinterlinepenalty=0
...\localbrokenpenalty=0
...\localleftbox=null
...\localrightbox=null
..\_tenrm H
..\_tenrm e
..\_tenrm l
..\_tenrm l
..\_tenrm o
..\glue 0.0 plus 1.0fil
..\penalty -10000
..\glue(\rightskip) 0.0
.\penalty 20000
.\glue(\baselineskip) 3.85997
.\hbox(8.14003+0.83333)x455.24408, glue set 409.90973fil, direction TLT
..\_mF x
..\glue(\thickmuskip) 2.77771 plus 2.77771
..\_mF =
..\penalty 500
..\glue(\thickmuskip) 2.77771 plus 2.77771
..\_mF a
..\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
..\_mF +
..\penalty 700
..\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
..\_mF b
..\hbox(4.51111+0.0)x4.48616, shifted -3.62892, direction TLT
...\_mF 2
..\mathoff
..\penalty 10000
..\glue(\parfillskip) 0.0 plus 1.0fil
..\glue(\rightskip) 0.0

相关内容