[luatex] node.isert_before() bug?

Khaled Hosny khaledhosny at eglug.org
Sun Jun 19 21:44:24 CEST 2011


Hi all,

While trying to do some right-to-left math experimentation (with very
good results so far[1]) I tried writing some lua code that takes care of
keeping numbers left-to-right by inserting TLT dir nodes around them.

I just found that when node.insert_before() is executed on the very
first node in an hlist no nodes get inserted, I'm not sure if this is a
bug, feature or some dumb thing in the code I wrote. Tested with luatex
0.70.1 and 0.67.0.

See the attached files.

[1] http://tex.stackexchange.com/questions/20666/typesetting-right-to-left-math/21082#21082

BTW, I noticed that \textdir and \mathdir has no effect inside math
formulas, is there any other way to override the global math direction
(apart from fiddling with lua.)

Regards,
 Khaled


-- 
 Khaled Hosny
 Egyptian
 Arab
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m.tex
Type: text/x-tex
Size: 167 bytes
Desc: not available
URL: <http://tug.org/pipermail/luatex/attachments/20110619/dd5f1421/attachment.bin>
-------------- next part --------------
rtlmath = {}

local glyph     = node.id("glyph")
local hlist     = node.id("hlist")
local vlist     = node.id("vlist")

local function isnumber(n)
    local c = n.char
    if c <= 0x39 and c >= 0x30 then
        return true
    else
        return false
    end
end

local function newdir(dir)
    local n = node.new("whatsit","dir")
    n.dir = dir
    return n
end

local function donumbers(head)
    local start = false
    for n in node.traverse(head) do
        if n.id == glyph then
            if isnumber(n) then
                if start then
                    if n.next and n.next.id == glyph and isnumber(n.next) then
                    else
                        node.insert_after(head, n, newdir("-TLT"))
                        start = false
                    end
                else
                    if n.next and n.next.id == glyph and isnumber(n.next) then
                        node.insert_before(head, n, newdir("+TLT"))
                        start = true
                    else
                    end
                end
            end
        else
            if start then
                node.insert_after(head, n, newdir("-TLT"))
                start = false
            end
            if n.id == hlist or n.id == vlist then
                donumbers(n.list)
            end
        end
    end
    return head
end

rtlmath.numbers = donumbers

--nodes.tasks.appendaction("math", "after", "rtlmath.numbers")
callback.register("mlist_to_hlist",
    function(h, s, b)
        h = node.mlist_to_hlist(h, s, b)
        h = donumbers(h)
        return h
    end
    )


More information about the luatex mailing list