[luatex] Processing every letter in math

Hans Hagen j.hagen at xs4all.nl
Tue Mar 15 18:53:20 CET 2022


On 3/15/2022 6:16 PM, Javier Bezos wrote:
> 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, and this is what I’ve achieved
> so far:
> 
> -----------------------
> \directlua{
> 
> function math_tweak(head, d, p)
>    head = node.mlist_to_hlist(head, d, p)
>    for item in node.traverse(head) do
>      if item.id == node.id'glyph' then
>        item.char = 88
>      end
>    end
>    return head, d, p
> end
> 
> callback.register('mlist_to_hlist', math_tweak)
> 
> }
> 
> $a$ ${b\over c}$ $\sqrt{d}$ $e$
> 
> $$f$$
> 
> \bye
> ------------------------
> 
> Here, only ‘a’, ‘e’ and ‘f’ are converted to ‘X’ (= 88).
> 
> With a branch for item.id == 0 calling recursively the
> function sub/superscripts are processed, but that’s not
> quite correct.
just print(item.id) and you'll probably see vlists as well so you need 
to also process item.id == 1; you might also run into composed shapes 
(extensibles) .. it also depends onm what a macro package does (\frac, 
\sqrt which is not standardized and therefore less predictable)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the luatex mailing list.