* lua and brackets
@ 2011-11-03 9:15 Martin Fechner
2011-11-03 11:01 ` Hans Hagen
0 siblings, 1 reply; 5+ messages in thread
From: Martin Fechner @ 2011-11-03 9:15 UTC (permalink / raw)
To: mailing list for ConTeXt users
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?
Best regards,
Martin
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: lua and brackets
2011-11-03 9:15 lua and brackets Martin Fechner
@ 2011-11-03 11:01 ` Hans Hagen
2011-11-03 11:42 ` Martin Fechner
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2011-11-03 11:01 UTC (permalink / raw)
To: mailing list for ConTeXt users
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]"
-----------------------------------------------------------------
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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: lua and brackets
2011-11-03 11:01 ` Hans Hagen
@ 2011-11-03 11:42 ` Martin Fechner
2011-11-03 13:17 ` Hans Hagen
0 siblings, 1 reply; 5+ messages in thread
From: Martin Fechner @ 2011-11-03 11:42 UTC (permalink / raw)
To: mailing list for ConTeXt users
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])}
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: lua and brackets
2011-11-03 11:42 ` Martin Fechner
@ 2011-11-03 13:17 ` Hans Hagen
2011-11-03 14:10 ` Martin Fechner
0 siblings, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2011-11-03 13:17 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: lua and brackets
2011-11-03 13:17 ` Hans Hagen
@ 2011-11-03 14:10 ` Martin Fechner
0 siblings, 0 replies; 5+ messages in thread
From: Martin Fechner @ 2011-11-03 14:10 UTC (permalink / raw)
To: Hans Hagen; +Cc: mailing list for ConTeXt users
> 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
>
Thanks, the lua solution works fine. One question: is the same possible
with linereferences as with pagereferences? It's very important for the
critical edition project I'm working at.
Greetings, Martin
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-11-03 14:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-03 9:15 lua and brackets Martin Fechner
2011-11-03 11:01 ` Hans Hagen
2011-11-03 11:42 ` Martin Fechner
2011-11-03 13:17 ` Hans Hagen
2011-11-03 14:10 ` Martin Fechner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).