From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: lua and brackets
Date: Thu, 03 Nov 2011 14:17:27 +0100 [thread overview]
Message-ID: <4EB29467.3050407@wxs.nl> (raw)
In-Reply-To: <4EB27E27.3090902@bbaw.de>
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
___________________________________________________________________________________
next prev parent reply other threads:[~2011-11-03 13:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-03 9:15 Martin Fechner
2011-11-03 11:01 ` Hans Hagen
2011-11-03 11:42 ` Martin Fechner
2011-11-03 13:17 ` Hans Hagen [this message]
2011-11-03 14:10 ` Martin Fechner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EB29467.3050407@wxs.nl \
--to=pragma@wxs.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).