From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/66341 Path: news.gmane.org!not-for-mail From: Philipp Gesang Newsgroups: gmane.comp.tex.context Subject: Re: TaBlE from Lua Date: Thu, 24 Feb 2011 02:16:13 +0100 Message-ID: <20110224011613.GA5149@orcus> References: <20110223230738.GD9491@clanspum.net> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1707510036==" X-Trace: dough.gmane.org 1298510222 23193 80.91.229.12 (24 Feb 2011 01:17:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 24 Feb 2011 01:17:02 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Feb 24 02:16:56 2011 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PsPp8-0004Tp-DV for gctc-ntg-context-518@m.gmane.org; Thu, 24 Feb 2011 02:16:54 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 771F4CAA34; Thu, 24 Feb 2011 02:16:53 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id zyVbSQaeO8Xq; Thu, 24 Feb 2011 02:16:41 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4626ECAA4F; Thu, 24 Feb 2011 02:16:41 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 65207CAA4F for ; Thu, 24 Feb 2011 02:16:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id iWZgDNh15Pio for ; Thu, 24 Feb 2011 02:16:18 +0100 (CET) Original-Received: from filter5-til.mf.surf.net (filter5-til.mf.surf.net [194.171.167.221]) by balder.ntg.nl (Postfix) with ESMTP id C3728CAA34 for ; Thu, 24 Feb 2011 02:16:18 +0100 (CET) Original-Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by filter5-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p1O1GHOY013333 for ; Thu, 24 Feb 2011 02:16:18 +0100 Original-Received: from ix.urz.uni-heidelberg.de (cyrus-portal.urz.uni-heidelberg.de [129.206.100.176]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id p1O1GG2P029320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 24 Feb 2011 02:16:16 +0100 Original-Received: from extmail.urz.uni-heidelberg.de (extmail.urz.uni-heidelberg.de [129.206.100.140]) by ix.urz.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id p1O1GFu4031739 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 24 Feb 2011 02:16:15 +0100 Original-Received: from localhost (mnhm-5f75e0ba.pool.mediaWays.net [95.117.224.186]) (authenticated bits=0) by extmail.urz.uni-heidelberg.de (8.13.4/8.13.1) with ESMTP id p1O1GDVt027901 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Thu, 24 Feb 2011 02:16:15 +0100 In-Reply-To: <20110223230738.GD9491@clanspum.net> X-Operating-System: Linux orcus 2.6.37-ARCH User-Agent: Mutt/1.5.21 (2010-09-15) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=129.206.210.211; country=DE; region=01; city=Heidelberg; latitude=49.4167; longitude=8.7000; http://maps.google.com/maps?q=49.4167,8.7000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0xEbBghBf - d674b5f1d7e3 - 20110224 X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.221 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:66341 Archived-At: --===============1707510036== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="JP+T4n/bALQSJXh8" Content-Disposition: inline --JP+T4n/bALQSJXh8 Content-Type: multipart/mixed; boundary="0OAP2g/MAC+5xKAE" Content-Disposition: inline --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2011-02-23 <17:07:38>, Daniel Lyons wrote: > Is there a convenient way to create TaBlE tables from Lua? If so, > where can I read about it? Good evening, Daniel! [-1] Isn=E2=80=99t TaBlE deprecated? [0] If you aim for convenience, wouldn=E2=80=99t you rather want to switch to \[start|stop]tabulate? Its syntax is very similar and there are a few examples to learn from in the context source code. [1] I don=E2=80=99t know how your table structure looks like, but the example 1 can be a starting point, assuming a 2dimensional table where all rows have the same element count: [2] Item example 2, but using the cld interface . Put both files in the same directory and run =E2=80=9Ccontext=E2=80=9D on table.tex to build the examples. Regards, Philipp >=20 > Thanks, >=20 > --=20 > Daniel --0OAP2g/MAC+5xKAE Content-Type: text/x-tex; charset=us-ascii Content-Disposition: attachment; filename="table.tex" \registerctxluafile{table}{} %%% Example 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\typesetatable{% \ctxlua{userdata.do_typesetatable(userdata.t)}% } %%% Example 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\typesetcldtable{% \ctxlua{userdata.do_typesetcldtable(userdata.t)}% } \starttext %%% Demo 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \placetable[here]{Concatenation based}{\typesetatable} %%% Demo 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \placetable[here]{CLD-based}{\typesetcldtable} \stoptext \endinput --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="table.lua" userdata = userdata or { } userdata.t = { { 0, 0, 0, }, { 0, 0, 1, }, { 0, 1, 0, }, { 0, 1, 1, }, { 1, 0, 0, }, { 1, 0, 1, }, { 1, 1, 0, }, { 1, 1, 1, }, } --- Lua stuff 1 ------------------------------------------------- userdata.env = [[ \starttable[%s] \HL %s \HL \stoptable ]] local fmt, rep, unpack = string.format, string.rep, table.unpack userdata.do_typesetatable = function (t) local maxx, maxy, lines = #t[1], #t, { } local template = rep("\\NC %s", maxx) for n=1, maxy do local row = t[n] lines[n] = " " .. fmt(template, unpack(row)) .. "\\AR" end context( fmt(userdata.env, "|" .. rep("c|", maxx), table.concat(lines, "\n")) ) end --- Lua stuff 2 ------------------------------------------------- local AR, HL, NC = context.AR, context.HL, context.NC userdata.do_typesetcldtable = function (t) local maxx, maxy = #t[1], #t context.starttable({ "|" .. rep("c|", maxx) }) HL() for n=1, maxy do local row = t[n] for m=1, maxx do NC() context(row[m]) end AR() end HL() context.stoptable() end --0OAP2g/MAC+5xKAE-- --JP+T4n/bALQSJXh8 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk1lsV0ACgkQ02lYlJYWs9KB4ACgg0Vp3kJfbzfMeKVzqypW+wpy RfgAniQ4pwFj+qQsfUvBDW59dCcROiXK =ZJXT -----END PGP SIGNATURE----- --JP+T4n/bALQSJXh8-- --===============1707510036== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 ___________________________________________________________________________________ --===============1707510036==--