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
\tracingoutput=1
\tracingonline=1
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen

\directlua{dofile("m.lua")}

\mathdir TRT

$$
{123} \quad {456} \quad 789
$$
\bye
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
    )

Reply via email to