ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Philipp Gesang <Philipp.Gesang@alumni.uni-heidelberg.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: ctxluacode inside bTABLE
Date: Wed, 27 Nov 2013 18:09:22 +0100	[thread overview]
Message-ID: <20131127170922.GA1854@phlegethon> (raw)
In-Reply-To: <CAPBmU9Fe=akFTBxtCgkaViycCGYHVt2bF7r_5=QE7N9A-qCaUg@mail.gmail.com>


[-- 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
___________________________________________________________________________________

  reply	other threads:[~2013-11-27 17:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 16:54 DesdeChaves
2013-11-27 17:09 ` Philipp Gesang [this message]
2013-11-27 17:24   ` DesdeChaves
2013-11-27 17:45     ` DesdeChaves
2013-11-27 17:49       ` Philipp Gesang

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=20131127170922.GA1854@phlegethon \
    --to=philipp.gesang@alumni.uni-heidelberg.de \
    --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).