[luatex] Processing every letter in math
Esger Renkema
post at elrenkema.nl
Tue Mar 15 19:39:55 CET 2022
>How can I process every single letter in math? Processing
>glyph nodes in text is more or less trivial, and to some
>extent even in-line math (surrounded by 'math' type nodes),
>but processing math, including displays, sub/superscripts,
>fractions, radicals. etc.? From the manual I think the
>solution must be the node.mlist_to_hlist and the
>corresponding callback [...]
That is the correct callback. But at this point, you are still working
on noads, not nodes, so ids 0 and 1 will not be the only ones containing
nested node lists.
See the following code, taken from minim-math.lua:
-----------------------------------------------------------------
local listmathfields = { 'head', 'nucleus', 'sub', 'sup', 'accent',
'bot_accent', 'display', 'text', 'script', 'scriptscript', 'num',
'denom', 'degree', 'next' } -- note that ‘next’ should be last!
local function noad_iterator(head)
local nodelist = { up=nil, current=head }
return function()
if nodelist == nil then return nil end
local n = nodelist.current
nodelist = nodelist.up
for _,f in pairs(listmathfields) do
if node.has_field(n, f) and n[f] ~= nil then
nodelist = { up=nodelist, current=n[f] }
end
end
return n
end
end
local function inspect_noads(h,d,n)
for nd in noad_iterator(h) do
if nd.id == node.id('math_char') then
-- TODO: whatever you wish
end
end
node.mlist_to_hlist(h,d,n)
end
callback.register('mlist_to_hlist', inspect_noads)
-----------------------------------------------------------------
More information about the luatex
mailing list.