![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 3-11-2011 12:42, Martin Fechner wrote:
Am 03.11.2011 12:01, schrieb Hans Hagen:
On 3-11-2011 10:15, Martin Fechner wrote:
Hi all,
I try to call a lua-function, but it seems that it doesn't work if the parameter contains squared brackets. Here is a short example:
\starttext sometext \reference[myref]{} is \ctxlua{tex.print(\atpage[myref])} \stoptext
Is there a way to mask the brackets?
"\atpage[myref]"
My lua function doesn't just print the parameter. I have a function like this:
\startluacode function pagesetup(page1,page2) if page1==page2 then tex.print(page1) elseif page1+1==page2 then tex.print(page1..'f.') else tex.print(page1..'-'..page2) end function \stopluacode
\starttext \reference[myref1]{} \page \reference[myref2]{} \ctxlua{\at[myref1],\at[myref2]} \stoptext
But I find no way that it works with the two references with brackets. Somewhere else I have an similar problem when I work with counters. The lua-function there doesn't accept this
\ctxlua{dosomething(\getnumber[mynumber])}
wrong thinking .. \atpage and such print back to tex but in most cases it involves typesetting so there can be anything there, not per se a bare number At the tex end you can do: \starttext \doifreferencefoundelse{one} {\edef\PageOne {\currentreferencerealpage}}{\def\PageOne {0}} \doifreferencefoundelse{two} {\edef\PageTwo {\currentreferencerealpage}}{\def\PageTwo {0}} \doifreferencefoundelse{two-a}{\edef\PageTwoA{\currentreferencerealpage}}{\def\PageTwoA{0}} \doifreferencefoundelse{two-b}{\edef\PageTwoB{\currentreferencerealpage}}{\def\PageTwoB{0}} (\PageOne) (\PageTwo ) (\PageTwoA) (\PageTwoB) one \pagereference[one] \page two \pagereference[two-a] two \pagereference[two-b] \page \stoptext And if you want pure lua, you can do: \startluacode function document.pagesetup(ref_one,ref_two) local one, bug = structures.references.identify("",ref_one) if bug then context("[unknown reference: %s]",ref_one) return end local two, bug = structures.references.identify("",ref_two) if bug then context("[unknown reference: %s]",ref_two) return end structures.references.analyze(one) structures.references.analyze(two) local r_one = one.realpage local r_two = two.realpage if not r_one or not r_two then context("[unknown pagenumbers]") elseif r_one == r_two then context("[same pagenumbers]") else context("[different pagenumbers]") end end \stopluacode \ctxlua{document.pagesetup("one","two")} \ctxlua{document.pagesetup("one","two-a")} \ctxlua{document.pagesetup("two-a","two-b")} but the reference interface is not yet documented 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 -----------------------------------------------------------------