Re: [NTG-context] making tables with lua
![](https://secure.gravatar.com/avatar/ecffc5c1eb6692198d091ee98e921822.jpg?s=120&d=mm&r=g)
Dear Proch?zka Luk?? Ing and Hans, Thank you for the reply. It works fine. I modify your code to write a matrix and it also works too. \startformula \startluacode local NC, NR = context.NC, context.NR local t = {{1,0,3,4},{0,2,-2,5},{0,0,1,2}} context.startmatrix() --"{left={\left (\,},right={\,\right)}}") for _, r in ipairs(t) do for _, c in ipairs(r) do NC() context(c) end NR() end context.stopmatrix() \stopluacode \stopformula But I couldn't put "( )" before and after matrix. If I use context.startmatrix("{left={\left (\,},right={\,\right)}}") then it wrote "left…" as text before the matrix. How to enclose matrix with ( )? Thank you again. Best regards, Dalyoung
4. Re: making tables with lua (Proch?zka Luk?? Ing. - Pontex s. r. o.)
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
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
![](https://secure.gravatar.com/avatar/27c34cb91f1e92bd850fe60b3d9ef336.jpg?s=120&d=mm&r=g)
Am 17.10.2012 um 10:34 schrieb Jeong Dal
Dear Proch?zka Luk?? Ing and Hans,
Thank you for the reply.
It works fine.
I modify your code to write a matrix and it also works too.
\startformula \startluacode local NC, NR = context.NC, context.NR local t = {{1,0,3,4},{0,2,-2,5},{0,0,1,2}} context.startmatrix() --"{left={\left (\,},right={\,\right)}}") for _, r in ipairs(t) do for _, c in ipairs(r) do NC() context(c) end NR() end context.stopmatrix() \stopluacode \stopformula
But I couldn't put "( )" before and after matrix. If I use context.startmatrix("{left={\left (\,},right={\,\right)}}") then it wrote "left…" as text before the matrix.
How to enclose matrix with ( )?
context.startmatrix{left="\\left(\\,",right="\\,\\right)"} Wolfgang
![](https://secure.gravatar.com/avatar/d6e7462bd4209f9c4cd08271985a50df.jpg?s=120&d=mm&r=g)
On Wed, 17 Oct 2012 10:34:22 +0200, Jeong Dal
Dear Proch?zka Luk?? Ing and Hans,
Thank you for the reply.
It works fine.
I modify your code to write a matrix and it also works too.
\startformula \startluacode local NC, NR = context.NC, context.NR local t = {{1,0,3,4},{0,2,-2,5},{0,0,1,2}} context.startmatrix() --"{left={\left (\,},right={\,\right)}}") for _, r in ipairs(t) do for _, c in ipairs(r) do NC() context(c) end NR() end context.stopmatrix() \stopluacode \stopformula
But I couldn't put "( )" before and after matrix. If I use context.startmatrix("{left={\left (\,},right={\,\right)}}") then it wrote "left…" as text before the matrix.
How to enclose matrix with ( )?
... See the new sample attached. ---- printMatrix = function(tab) context.startmatrix{left = "\\left(\\,", right = "\\,\\right)"} for _, r in ipairs(tab) do for _, c in ipairs(r) do context.NC(c) end context.NR() end context.stopmatrix() end ---- Best regards, Lukas
Thank you again.
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
participants (3)
-
Jeong Dal
-
Procházka Lukáš Ing. - Pontex s. r. o.
-
Wolfgang Schuster