1

Math nodes mark boundaries of math expressions in TeX/LuaTeX typesetting engine. LuaTeX document states,

"Math nodes represent the boundaries of a math formula, normally wrapped into $ signs."

The document seems to suggest that math expressions are always surrounded by math nodes of subtype=0 (beginmath), and subtype=1 (endmath). In the following code, there is no node marking the beginning of math expression, though there is one marking its end.

Output:

Screenshot of output

Code:

% >>> 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}

Console (look for string "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

2 Answers 2

7

LuaTeX does always add them, but in your example they get discarded before you can see them:

In TeX, some node types (glue, kern, penalty and math nodes) are known as "discardable". Whenever a line break occurs, TeX removes all discardable nodes until the first non-discardable node is seen. (There is an exception when another linebreak is being done on one of these nodes, see the TeXbook for details.)

In your example, the first node in the second line is a math node, so it gets discarded after linebreaking.

6
  • 1
    +1 and a question: Is "node " a lua term? As far as I can see the TeX book uses the word "node" only once (referring to a "whatsit node"), otherwise it's always about "items".
    – campa
    Nov 20, 2020 at 13:40
  • @campa I never really noticed that the TeXbook calls them items. But the original TeX source code in "TeX: The program" also calls them nodes, so it's not really LuaTeX specific. (TeX: The program actually talks about one-word nodes and variable/more than one-word/"normal" nodes. Only the last kind are nodes as used in LuaTeX, one-word nodes refer to elements of token lists.) Nov 20, 2020 at 14:06
  • Oh, so that's programmer's language... then I'm out :-). Thx.
    – campa
    Nov 20, 2020 at 14:09
  • @MarcelKrüger Thanks! Given TeX removes the beginmath math node, what would be the best alternative to mark math boundary? Two things come to mind: 1) declare and use a "math" attribute that is set for math, 2) add user-defined whatsit nodes before and after math. Which one do you think is better? Would user-defined whatsit nodes affect the result of linebreaking algorithm like in: tex.stackexchange.com/questions/147785/…. Will I have to put all the equations in some new macro for this? Do you want me to post another question?
    – codepoet
    Nov 21, 2020 at 6:22
  • 1
    @reportaman Probably better as a new question, basically it depends on what you want the mark to be used for. Nov 21, 2020 at 7:12
2

Your question isn't luatex specific. TeXbook refers about discardable items at page 95 and math items are mentioned as discardable too.

And your example should be shown without luatex, only in TeX:

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

and .log says:

\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
1
  • Thanks for the explanation!
    – codepoet
    Nov 21, 2020 at 7:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .