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
-----------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>

<a>
  <b> <c>1</c> <d>Text</d>           </b>
  <b> <c>2</c> <d>More text</d>      </b>
  <b> <c>2</c> <d>Even more text</d> </b>
  <b> <c>2</c> <d>And more</d>       </b>
  <b> <c>3</c> <d>And even more</d>  </b>
</a>
-- 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

Attachment: test-style.tex
Description: TeX document

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to