在 LuaTeX 中生成不同类型的节点

在 LuaTeX 中生成不同类型的节点

我正在编写一个工具来显示 LuaTeX 节点的详细信息。例如,此文档

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{luacode}
\usepackage{luatexbase}

\begin{luacode*}
-- my developing source code
require "luatex-node-to-table"
inspect = require"inspect"

function test_ntt(n,s)
  for n1 in node.traverse(n) do
    -- my function
    local t = luatex_node_to_table(n1)
    texio.write_nl(inspect(t))
  end
  return n
end

luatexbase.add_to_callback("pre_linebreak_filter", test_ntt, "test_ntt")

\end{luacode*}

\begin{document}

A-B

\end{document}

输出结果如下

{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  box_left = {},
  box_left_width = 0,
  box_right = {},
  box_right_width = 0,
  dir = "TLT",
  id = "local_par(9)",
  next = { "<node    462 <    417 >    398 : hlist 3>" },
  pen_broken = 0,
  pen_inter = 0,
  prev = {},
  subtype = {}
}
{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  depth = "0.000000pt",
  dir = "TLT",
  glue_order = 0,
  glue_set = 0.0,
  glue_sign = "normal(0)",
  head = {},
  height = "0.000000pt",
  id = "hlist(0)",
  list = {},
  next = { "<node    417 <    398 >    500 : glyph 256>" },
  prev = { "<node    nil <    462 >    417 : local_par 0>" },
  shift = 0,
  subtype = "indent(3)",
  width = "15.000000pt"
}
{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  char = "'A'(65)",
  components = {},
  data = 0,
  depth = "0.000000pt",
  expansion_factor = 0,
  font = 26,
  height = "6.888748pt",
  id = "glyph(29)",
  lang = 0,
  left = 2,
  next = { "<node    398 <    500 >    475 : disc 2>" },
  prev = { "<node    462 <    417 >    398 : hlist 3>" },
  right = 3,
  subtype = "*unknown*(256)",
  uchyph = 1,
  width = "7.500000pt",
  xoffset = 0,
  yoffset = 0
}
{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  id = "disc(7)",
  next = { "<node    500 <    475 >    329 : glyph 256>" },
  penalty = 50,
  post = {},
  pre = {
    attr = {
      [0] = 0,
      id = "attribute_list(40)"
    },
    char = "'-'(45)",
    components = {},
    data = 0,
    depth = "0.000000pt",
    expansion_factor = 0,
    font = 26,
    height = "2.416656pt",
    id = "glyph(29)",
    lang = 0,
    left = 1,
    next = {},
    prev = {},
    right = 1,
    subtype = "*unknown*(256)",
    uchyph = 0,
    width = "3.333328pt",
    xoffset = 0,
    yoffset = 0
  },
  prev = { "<node    417 <    398 >    500 : glyph 256>" },
  replace = {
    attr = {
      [0] = 0,
      id = "attribute_list(40)"
    },
    char = "'-'(45)",
    components = {},
    data = 0,
    depth = "0.000000pt",
    expansion_factor = 0,
    font = 26,
    height = "2.416656pt",
    id = "glyph(29)",
    lang = 0,
    left = 2,
    next = {},
    prev = {},
    right = 3,
    subtype = "*unknown*(256)",
    uchyph = 1,
    width = "3.333328pt",
    xoffset = 0,
    yoffset = 0
  },
  subtype = "automatic(2)"
}
{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  char = "'B'(66)",
  components = {},
  data = 0,
  depth = "0.000000pt",
  expansion_factor = 0,
  font = 26,
  height = "6.888748pt",
  id = "glyph(29)",
  lang = 0,
  left = 2,
  next = { "<node    475 <    329 >    482 : penalty 2>" },
  prev = { "<node    398 <    500 >    475 : disc 2>" },
  right = 3,
  subtype = "*unknown*(256)",
  uchyph = 1,
  width = "7.082993pt",
  xoffset = 0,
  yoffset = 0
}
{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  id = "penalty(14)",
  next = { "<node    329 <    482 >    nil : glue 15>" },
  penalty = 10000,
  prev = { "<node    500 <    475 >    329 : glyph 256>" },
  subtype = "linepenalty(2)"
}
{
  attr = {
    [0] = 0,
    id = "attribute_list(40)"
  },
  id = "glue(12)",
  leader = {},
  next = {},
  prev = { "<node    475 <    329 >    482 : penalty 2>" },
  shrink = 0,
  shrink_over = {},
  stretch = 65536,
  stretch_over = {},
  subtype = "parfillskip(15)",
  width = "0.000000pt"
}

我想测试我的代码是否适用于所有 LuaTeX 节点,尤其是whatsit节点。有没有办法创建一个包含所有类型节点的文档?

还有一个问题,除了使用之外pre_linebreak_filter,还有其他方法可以遍历文档中的所有节点吗?

相关内容