* ctxluacode inside bTABLE
@ 2013-11-27 16:54 DesdeChaves
2013-11-27 17:09 ` Philipp Gesang
0 siblings, 1 reply; 5+ messages in thread
From: DesdeChaves @ 2013-11-27 16:54 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 512 bytes --]
I try make a table with some random numbers but I found a problem with this
code:
\starttext
\ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
\bTABLE
\bTR\bTD Distance (cm) \eTD\bTD $\Delta t$ (s) \eTD\eTR
\bTR\bTD[nr=3] \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
\eTD\bTD t1 \eTD\eTR
\bTR\bTD t2 \eTD\eTR
\bTR\bTD t3 \eTD\eTR
\eTABLE
\stoptext
\ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;} don't work
inside the bTABLE environment.
Thanks in advance.
Jorge
[-- Attachment #1.2: Type: text/html, Size: 932 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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: ctxluacode inside bTABLE
2013-11-27 16:54 ctxluacode inside bTABLE DesdeChaves
@ 2013-11-27 17:09 ` Philipp Gesang
2013-11-27 17:24 ` DesdeChaves
0 siblings, 1 reply; 5+ messages in thread
From: Philipp Gesang @ 2013-11-27 17:09 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1475 bytes --]
Hi Jorge,
···<date: 2013-11-27, Wednesday>···<from: DesdeChaves>···
> I try make a table with some random numbers but I found a problem with this
> code:
>
>
> \starttext
> \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
>
> \bTABLE
> \bTR\bTD Distance (cm) \eTD\bTD $\Delta t$ (s) \eTD\eTR
> \bTR\bTD[nr=3] \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
> \eTD\bTD t1 \eTD\eTR
> \bTR\bTD t2 \eTD\eTR
> \bTR\bTD t3 \eTD\eTR
> \eTABLE
>
>
> \stoptext
>
> \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;} don't work
> inside the bTABLE environment.
just wrap the code in a macro. Lua code needs a different catcode
regime and expansion rules that don’t cooperate well with the
table scanner. E.g.
\startluacode
local mathrandom = math.random
local context = context
document.get_random_number = function ()
context ("%0.1f", mathrandom (400, 600) / 10)
end
\stopluacode
\def \getrandomnumber {\ctxluacode {document.get_random_number ()}}
\starttext
\bTABLE
\bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD \eTR
\bTR \bTD[nr=3] \getrandomnumber \eTD \bTD t1 \eTD \eTR
\bTR \bTD t2 \eTD \eTR
\bTR \bTD t3 \eTD \eTR
\eTABLE
\stoptext
Hth,
Philipp
[-- Attachment #1.2: Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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: ctxluacode inside bTABLE
2013-11-27 17:09 ` Philipp Gesang
@ 2013-11-27 17:24 ` DesdeChaves
2013-11-27 17:45 ` DesdeChaves
0 siblings, 1 reply; 5+ messages in thread
From: DesdeChaves @ 2013-11-27 17:24 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2964 bytes --]
Is there a way to pass arguments to getrandomnumber() function?
\startluacode
local mathrandom = math.random
local context = context
document.get_random_number = function (min,max,delta)
context ("%0.1f", mathrandom (min, max) / decimal)
end
\stopluacode
\def \getrandomnumber#1#2#3 {\ctxluacode {document.get_random_number
(#1,#2,#3)}}
\starttext
\bTABLE
\bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD \eTR
\bTR \bTD[nr=3] \getrandomnumber{34,56,10} \eTD \bTD t1
\eTD \eTR
\bTR \bTD t2 \eTD \eTR
\bTR \bTD t3 \eTD \eTR
\eTABLE
\stoptext
2013/11/27 Philipp Gesang <Philipp.Gesang@alumni.uni-heidelberg.de>
> Hi Jorge,
>
> ···<date: 2013-11-27, Wednesday>···<from: DesdeChaves>···
>
> > I try make a table with some random numbers but I found a problem with
> this
> > code:
> >
> >
> > \starttext
> > \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
> >
> > \bTABLE
> > \bTR\bTD Distance (cm) \eTD\bTD $\Delta t$ (s) \eTD\eTR
> > \bTR\bTD[nr=3] \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v)
> ;}
> > \eTD\bTD t1 \eTD\eTR
> > \bTR\bTD t2 \eTD\eTR
> > \bTR\bTD t3 \eTD\eTR
> > \eTABLE
> >
> >
> > \stoptext
> >
> > \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;} don't work
> > inside the bTABLE environment.
>
> just wrap the code in a macro. Lua code needs a different catcode
> regime and expansion rules that don’t cooperate well with the
> table scanner. E.g.
>
> \startluacode
> local mathrandom = math.random
> local context = context
> document.get_random_number = function ()
> context ("%0.1f", mathrandom (400, 600) / 10)
> end
> \stopluacode
>
> \def \getrandomnumber {\ctxluacode {document.get_random_number ()}}
>
> \starttext
> \bTABLE
> \bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD \eTR
> \bTR \bTD[nr=3] \getrandomnumber \eTD \bTD t1 \eTD \eTR
> \bTR \bTD t2 \eTD \eTR
> \bTR \bTD t3 \eTD \eTR
> \eTABLE
> \stoptext
>
>
> Hth,
> Philipp
>
>
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>
--
Atentamente
DesdeChaves
[-- Attachment #1.2: Type: text/html, Size: 4200 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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: ctxluacode inside bTABLE
2013-11-27 17:24 ` DesdeChaves
@ 2013-11-27 17:45 ` DesdeChaves
2013-11-27 17:49 ` Philipp Gesang
0 siblings, 1 reply; 5+ messages in thread
From: DesdeChaves @ 2013-11-27 17:45 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 3241 bytes --]
Solved
\getrandomnumber{36}{56}{10}
2013/11/27 DesdeChaves <desdechaves@gmail.com>
> Is there a way to pass arguments to getrandomnumber() function?
>
> \startluacode
> local mathrandom = math.random
> local context = context
> document.get_random_number = function (min,max,delta)
> context ("%0.1f", mathrandom (min, max) / decimal)
> end
> \stopluacode
>
> \def \getrandomnumber#1#2#3 {\ctxluacode {document.get_random_number
> (#1,#2,#3)}}
>
> \starttext
> \bTABLE
> \bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD \eTR
> \bTR \bTD[nr=3] \getrandomnumber{34,56,10} \eTD \bTD t1
> \eTD \eTR
> \bTR \bTD t2 \eTD \eTR
> \bTR \bTD t3 \eTD \eTR
> \eTABLE
> \stoptext
>
>
> 2013/11/27 Philipp Gesang <Philipp.Gesang@alumni.uni-heidelberg.de>
>
>> Hi Jorge,
>>
>> ···<date: 2013-11-27, Wednesday>···<from: DesdeChaves>···
>>
>> > I try make a table with some random numbers but I found a problem with
>> this
>> > code:
>> >
>> >
>> > \starttext
>> > \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
>> >
>> > \bTABLE
>> > \bTR\bTD Distance (cm) \eTD\bTD $\Delta t$ (s) \eTD\eTR
>> > \bTR\bTD[nr=3]
>> \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
>> > \eTD\bTD t1 \eTD\eTR
>> > \bTR\bTD t2 \eTD\eTR
>> > \bTR\bTD t3 \eTD\eTR
>> > \eTABLE
>> >
>> >
>> > \stoptext
>> >
>> > \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;} don't work
>> > inside the bTABLE environment.
>>
>> just wrap the code in a macro. Lua code needs a different catcode
>> regime and expansion rules that don’t cooperate well with the
>> table scanner. E.g.
>>
>> \startluacode
>> local mathrandom = math.random
>> local context = context
>> document.get_random_number = function ()
>> context ("%0.1f", mathrandom (400, 600) / 10)
>> end
>> \stopluacode
>>
>> \def \getrandomnumber {\ctxluacode {document.get_random_number ()}}
>>
>> \starttext
>> \bTABLE
>> \bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD
>> \eTR
>> \bTR \bTD[nr=3] \getrandomnumber \eTD \bTD t1 \eTD
>> \eTR
>> \bTR \bTD t2 \eTD
>> \eTR
>> \bTR \bTD t3 \eTD
>> \eTR
>> \eTABLE
>> \stoptext
>>
>>
>> Hth,
>> Philipp
>>
>>
>>
>> ___________________________________________________________________________________
>> 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
>>
>> ___________________________________________________________________________________
>>
>
>
>
> --
> Atentamente
>
> DesdeChaves
>
--
Atentamente
DesdeChaves
[-- Attachment #1.2: Type: text/html, Size: 4882 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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: ctxluacode inside bTABLE
2013-11-27 17:45 ` DesdeChaves
@ 2013-11-27 17:49 ` Philipp Gesang
0 siblings, 0 replies; 5+ messages in thread
From: Philipp Gesang @ 2013-11-27 17:49 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 4334 bytes --]
···<date: 2013-11-27, Wednesday>···<from: DesdeChaves>···
> Solved
>
> \getrandomnumber{36}{56}{10}
Or define it monadic:
\def \getrandomnumber #1{\ctxluacode {document.get_random_number (#1)}}
Now you can use your original syntax:
\getrandomnumber {23, 42, 10}
Though it blurs the line between TeX and Lua code.
Best,
Philipp
>
>
> 2013/11/27 DesdeChaves <desdechaves@gmail.com>
>
> > Is there a way to pass arguments to getrandomnumber() function?
> >
> > \startluacode
> > local mathrandom = math.random
> > local context = context
> > document.get_random_number = function (min,max,delta)
> > context ("%0.1f", mathrandom (min, max) / decimal)
> > end
> > \stopluacode
> >
> > \def \getrandomnumber#1#2#3 {\ctxluacode {document.get_random_number
> > (#1,#2,#3)}}
> >
> > \starttext
> > \bTABLE
> > \bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD \eTR
> > \bTR \bTD[nr=3] \getrandomnumber{34,56,10} \eTD \bTD t1
> > \eTD \eTR
> > \bTR \bTD t2 \eTD \eTR
> > \bTR \bTD t3 \eTD \eTR
> > \eTABLE
> > \stoptext
> >
> >
> > 2013/11/27 Philipp Gesang <Philipp.Gesang@alumni.uni-heidelberg.de>
> >
> >> Hi Jorge,
> >>
> >> ···<date: 2013-11-27, Wednesday>···<from: DesdeChaves>···
> >>
> >> > I try make a table with some random numbers but I found a problem with
> >> this
> >> > code:
> >> >
> >> >
> >> > \starttext
> >> > \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
> >> >
> >> > \bTABLE
> >> > \bTR\bTD Distance (cm) \eTD\bTD $\Delta t$ (s) \eTD\eTR
> >> > \bTR\bTD[nr=3]
> >> \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;}
> >> > \eTD\bTD t1 \eTD\eTR
> >> > \bTR\bTD t2 \eTD\eTR
> >> > \bTR\bTD t3 \eTD\eTR
> >> > \eTABLE
> >> >
> >> >
> >> > \stoptext
> >> >
> >> > \ctxluacode{v=math.random(400,600)/10;context("%0.1f",v) ;} don't work
> >> > inside the bTABLE environment.
> >>
> >> just wrap the code in a macro. Lua code needs a different catcode
> >> regime and expansion rules that don’t cooperate well with the
> >> table scanner. E.g.
> >>
> >> \startluacode
> >> local mathrandom = math.random
> >> local context = context
> >> document.get_random_number = function ()
> >> context ("%0.1f", mathrandom (400, 600) / 10)
> >> end
> >> \stopluacode
> >>
> >> \def \getrandomnumber {\ctxluacode {document.get_random_number ()}}
> >>
> >> \starttext
> >> \bTABLE
> >> \bTR \bTD Distance (cm) \eTD \bTD $\Delta t$ (s) \eTD
> >> \eTR
> >> \bTR \bTD[nr=3] \getrandomnumber \eTD \bTD t1 \eTD
> >> \eTR
> >> \bTR \bTD t2 \eTD
> >> \eTR
> >> \bTR \bTD t3 \eTD
> >> \eTR
> >> \eTABLE
> >> \stoptext
> >>
> >>
> >> Hth,
> >> Philipp
> >>
> >>
> >>
> >> ___________________________________________________________________________________
> >> 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
> >>
> >> ___________________________________________________________________________________
> >>
> >
> >
> >
> > --
> > Atentamente
> >
> > DesdeChaves
> >
>
>
>
> --
> Atentamente
>
> DesdeChaves
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
[-- Attachment #1.2: Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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:[~2013-11-27 17:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-27 16:54 ctxluacode inside bTABLE DesdeChaves
2013-11-27 17:09 ` Philipp Gesang
2013-11-27 17:24 ` DesdeChaves
2013-11-27 17:45 ` DesdeChaves
2013-11-27 17:49 ` Philipp Gesang
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).