[NTG-context] xtables and xml and lua

Hans Hagen pragma at wxs.nl
Wed Jun 18 16:32:12 CEST 2014


On 6/18/2014 1:03 PM, Thomas A. Schmitz wrote:
> Hi all,
>
> I'm terribly sorry I have to send three files for this test case, but
> I'm trying to process xml with lua, so it's difficult to do otherwise. I
> have two problems:
>
> 1. (probably unrelated to xml/lua): when I try to set the options (l.
> 22-3 in test-style.tex)
>
> \setupxtable [split=yes,
>                spaceinbetween=medium]
>
> for the xtable environment, I get an error:
>
> tex error       > error on line 22 in file
> /mnt/shared/context/tex/texmf-context/tex/context/base/cont-yes.mkiv: !
> You can't use `\prevdepth' in horizontal mode
>
>
> \nointerlineskip ^^@-\prevdepth
>                                -\thousandpoint
> l.22 \nointerlineskip
>
> \ctxcommand #1o-\directlua {commands.#1}
>
> \tabl_x_process ...lse \tabl_x_flush_text_checked
>                                                    \fi \fi \ctxcommand
> {x_tab...
> l.8 }
>
> \ctxlxml #1h-\ctxlua {lxml.#1}
>
> ....
> l.91 \stopluacode
>
> This looks like a buglet in xtables to me.
>
> 2. I would like to test whether a certain element has already been seen
> (l. 8-13 in test-style.lua). However, since tables are two-pass, the
> test will always return "true." How could I test properly?

many ways ... (ok, i might provide some hook into tables) ... three 
attached

i bet you'll choose the third solution

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.xml
Type: text/xml
Size: 259 bytes
Desc: not available
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20140618/7a901c64/attachment.xml>
-------------- next part --------------
-- solution 1

-- local lasttitle = nil
--
-- function xml.functions.test_b(t)
--     local title = xml.text(t, "c")
--     local content = xml.text(t, "d")
--     context.startxrow()
--     context.startxcell( { background="color", backgroundcolor="yellow" } )
--     if lasttitle == title then
--         context.color( { "red" }, title)
--     else
--         lasttitle = title
--         context.color( { "blue" }, title)
--     end
--     context.stopxcell()
--     context.startxcell()
--     context(content)
--     context.stopxcell()
--     context.stopxrow()
-- end

-- solution 2

-- local titles = { }
--
-- function xml.functions.reset_b(t)
--     titles = { }
-- end
--
-- function xml.functions.test_b(t)
--     local title = xml.text(t, "c")
--     local content = xml.text(t, "d")
--     context.startxrow()
--     context.startxcell( { background="color", backgroundcolor="yellow" } )
--     if titles[title] then
--         context.color( { "red" }, title)
--     else
--         titles[title] = true
--         context.color( { "blue" }, title)
--     end
--     context.stopxcell()
--     context.startxcell()
--     context(content)
--     context.stopxcell()
--     context.stopxrow()
-- end

-- solution 3

function xml.functions.test_b(t)
    local title = xml.text(t, "c")
    local content = xml.text(t, "d")
    context.startxrow()
    context.startxcell( { background="color", backgroundcolor="yellow" } )
    if xml.text(t,"./preceding-sibling::/[-1]") == title then
        context.color( { "red" }, title)
    else
        context.color( { "blue" }, title)
    end
    context.stopxcell()
    context.startxcell()
    context(content)
    context.stopxcell()
    context.stopxrow()
end

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-style.tex
Type: application/x-tex
Size: 758 bytes
Desc: not available
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20140618/7a901c64/attachment.tex>


More information about the ntg-context mailing list