ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Procházka Lukáš Ing. - Pontex s. r. o." <LPr@pontex.cz>
To: "mailing list for ConTeXt users" <ntg-context@ntg.nl>
Subject: Re: making tables with lua
Date: Wed, 17 Oct 2012 08:49:18 +0200	[thread overview]
Message-ID: <op.wma88gn0tpjj8f@lpr> (raw)
In-Reply-To: <068711A7-7280-46F2-BAF8-65B913644727@me.com>

[-- Attachment #1: Type: text/plain, Size: 3053 bytes --]

Hello,

my experience is that the best way is to create the table first, then to call Lua function to typeset the table.

You may choose whether the table will be typeset with 'tabulate' family functions or 'TABLE' family; I may recommend you the latter as it gives you much more control of the final look than the former; 'TABLE' is much better anyway.

Once you have such functions prepared, you just select to type:

printTabulate(mytab) -- via 'tabulate'

or

printTABLE(mytab) -- via 'TABLE'

If you insist on 'tabulate' family, you could use the following snippet for your start:

----
\starttext
   \startluacode
     local tab = {{1,2},{3,4}}

     printTabulate = function(tab)
       context.starttabulate{"|" .. string.rep("c|", #tab[1])}
         context.HL()
         for _, r in ipairs(tab) do
           for _, c in ipairs(r) do
             context.VL()
             context(c)
           end
           context.VL()
           context.NR()
           context.HL()
         end
       context.stoptabulate()
     end

     printTabulate(tab)
   \stopluacode
\stoptext
----

You can write a similar function(s) to typeset via 'TABLE'.

Best regards,

Lukas


On Wed, 17 Oct 2012 03:13:39 +0200, Jeong Dal <haksan@me.com> wrote:

> Dear all,
>
> I used code which generates the table as following:
>
> \startluacode
> local NC, NR, HL, VL = context.NC, context.NR, context.HL, context.VL
> context.starttabulate { "|c|c|c|c|c|c|c|c|c|c|" }
> HL()
> for i=1, 6, 1 do
> 	for j=1,10 ,1 do
> 		k= i % 3
> 		if k==1 then
> 			VL() context(10*(i - k)/3+j)
> 		else
> 			VL()
> 		end
> 	end
> 	VL()
> 	NR()
> 	if k==0 then
> 		HL()
> 	end
> end
> context.stoptabulate()
> \stopluacode
>
> But it has a fixed column definition as "|c|c|c|c|c|c|c|c|c|c|" and the number of columns.
> I wonder it is possible to use the variable for "j" to control the number of columns and the column setting.
> Of course, I may put similar codes  which are different only in the number of columns and column settings when I need a table.
> But I have many similar tables whose number of columns are different only.
> If such a method is possible, I'd like to put such a code in \startbuffer…\stopbudffer and call it to generate tables of various number of columns given at each time.
> I also don't know whether it is possible to convey a number from ConTeXt to the variable in Lua code.
>
> I write this email because I saw a hope in recent discussion "Re: Fwd: Need help with \definetabulate" which has a method to vary the column setting.
>
> \definetabulate
> [whatever]
> [|l|r|]
>
> \definetabulate
> [whatever][else]
> [|l|c|r|]
>
>
> It may be a lazy man's question with no need for others.
>
> Thank you for reading.
>
> Best regards,
>
> Dalyoung


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

[-- Attachment #2: t-Tabulate.mkiv --]
[-- Type: application/octet-stream, Size: 496 bytes --]

\starttext
  \startluacode
    local tab = {{1,2},{3,4}}

    printTabulate = function(tab)
      context.starttabulate{"|" .. string.rep("c|", #tab[1])}
        context.HL()
        for _, r in ipairs(tab) do
          for _, c in ipairs(r) do
            context.VL()
            context(c)
          end
          context.VL()
          context.NR()
          context.HL()
        end
      context.stoptabulate()
    end

    printTabulate(tab)
  \stopluacode
\stoptext

[-- Attachment #3: t-Tabulate.pdf --]
[-- Type: application/pdf, Size: 5121 bytes --]

[-- Attachment #4: 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:[~2012-10-17  6:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-17  1:13 Jeong Dal
2012-10-17  6:49 ` Procházka Lukáš Ing. - Pontex s. r. o. [this message]
2012-10-17  7:19 ` Hans Hagen
     [not found] <mailman.522.1350456904.2084.ntg-context@ntg.nl>
2012-10-17  8:34 ` Jeong Dal
2012-10-17  9:18   ` Wolfgang Schuster
2012-10-17  9:24   ` Procházka Lukáš Ing. - Pontex s. r. o.
2012-10-18  4:43 Jeong Dal

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=op.wma88gn0tpjj8f@lpr \
    --to=lpr@pontex.cz \
    --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).