From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87524 Path: news.gmane.org!not-for-mail From: luigi scarso Newsgroups: gmane.comp.tex.context Subject: Re: Simple command with variable number of arguments Date: Fri, 23 May 2014 13:44:30 +0200 Message-ID: References: <6EAF5FDE-7BE4-4766-B683-FA9994227A04@indiana.edu> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1832491592==" X-Trace: ger.gmane.org 1400845489 28393 80.91.229.3 (23 May 2014 11:44:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 May 2014 11:44:49 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri May 23 13:44:45 2014 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wnnu0-0004hQ-5K for gctc-ntg-context-518@m.gmane.org; Fri, 23 May 2014 13:44:44 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C955B1023E for ; Fri, 23 May 2014 13:44:43 +0200 (CEST) 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 Hsf2p+86XRuN for ; Fri, 23 May 2014 13:44:43 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id A2F8B10220 for ; Fri, 23 May 2014 13:44:39 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 84333101EC for ; Fri, 23 May 2014 13:44:35 +0200 (CEST) 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 Ot66UCqsIMKV for ; Fri, 23 May 2014 13:44:33 +0200 (CEST) Original-Received: from filter4-ams.mf.surf.net (filter4-ams.mf.surf.net [192.87.102.72]) by balder.ntg.nl (Postfix) with ESMTP id 4FEDD101E8 for ; Fri, 23 May 2014 13:44:33 +0200 (CEST) Original-Received: from mail-qc0-x235.google.com (mail-qc0-x235.google.com [IPv6:2607:f8b0:400d:c01::235]) by filter4-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s4NC7DA9004533 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 23 May 2014 14:07:14 +0200 Original-Received: by mail-qc0-f181.google.com with SMTP id m20so7842995qcx.40 for ; Fri, 23 May 2014 04:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ra+sgma48C/hiIY5lgrjkhdbgV/YJwlrOPu2gXB6v6c=; b=sI1y9YFPtf0EIz32DG2FBxx13MO44Eca+VA31Q4VxctAYYJlFRizanSaiRQFzUP8in ai78dNmVSr4mADdPD/oLM7ZVBTA0ucrL6xlBoVX34n6ilFRAUW2cPob5t7G5vf7cPAF2 kTERz+PIYyTpcc+sP5tzmAfEujwOh/+15iGzCOKh4qrV3Jt21xZ10DUMYYnITDi12Xhp lD06p4xwyRR1FTwDcONbRujT6y6r+cjmik101IFsFFGUQei0h7UWt7CHEbVDAX1Bk9eO aWigMpw5tnkYDLBznJZfQD1qFmmOL/ZfAaZR3wCDrhtfNmti34V0FRhwayswL1Eis54n E9Rw== X-Received: by 10.140.44.72 with SMTP id f66mr5328036qga.78.1400845471060; Fri, 23 May 2014 04:44:31 -0700 (PDT) Original-Received: by 10.140.30.98 with HTTP; Fri, 23 May 2014 04:44:30 -0700 (PDT) In-Reply-To: <6EAF5FDE-7BE4-4766-B683-FA9994227A04@indiana.edu> X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2607:f8b0:400d:c01::235; country=US X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 01M5o7eO6 - 1d495ed25e14 - 20140523 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:87524 Archived-At: --===============1832491592== Content-Type: multipart/alternative; boundary=001a1139a7e4b0196404fa0fc069 --001a1139a7e4b0196404fa0fc069 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, May 23, 2014 at 11:54 AM, Matthias Weber wrot= e: > Dear All, > > I would like to define a command that expands > > \vector{2,4} % or vector[2,4] if that=E2=80=99s easier > > to > > \startpmatrix > \NC 2 \NR > \NC 4 \NR > \stoppmatrix > > and more generally > > \vector{2,4,1,7} > > to > > \startpmatrix > \NC 2 \NR > \NC 4 \NR > \NC 1 \NR > \NC 7 \NR > \stoppmatrix > > Any hints how to achieve this? > > Thanks, > \definemathmatrix [pmatrix] [left=3D{\left(\,},right=3D{\,\right)}] \startluacode document =3D document or {} document.matthias =3D document.matthias or {} local function lua_columnvector(a) context.startpmatrix() for i,v in ipairs(a) do context.NC() context(tostring(v)) context.NR() end context.stoppmatrix() end document.matthias.lua_columnvector =3D document.matthias.lua_columnvector = or lua_columnvector \stopluacode \def\columnvector#1{\ctxlua{document.matthias.lua_columnvector(#1)}} \starttext \startformula \columnvector{{1,2,3}} %% watch the double { ! \stopformula \stoptext --=20 luigi --001a1139a7e4b0196404fa0fc069 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Fri, May 23, 2014 at 11:54 AM, Matthias Weber = <matweber@indi= ana.edu> wrote:
Dear All,

I would like to define a command that expands

\vector{2,4} % or vector[2,4] if that=E2=80=99s easier

to

\startpmatrix
=C2=A0\NC 2 \NR
=C2=A0\NC 4 \NR
\stoppmatrix

and more generally

\vector{2,4,1,7}

to

\startpmatrix
=C2=A0\NC 2 \NR
=C2=A0\NC 4 \NR
\NC 1 \NR
\NC 7 \NR
\stoppmatrix

Any hints how to achieve this?

Thanks,



\definemathmatrix<= /div>
=C2=A0 [pmatrix]
=C2=A0 [left=3D{\left(\,},right=3D{\,\= right)}]

\startluacode
document =3D document or {}
document.matthias =3D =C2=A0document.matthias or {}=C2=A0
local= function lua_columnvector(a)
=C2=A0context.startpmatrix()
<= div>=C2=A0 for i,v in ipairs(a) do
=C2=A0 =C2=A0 =C2=A0context.NC() context(tostring(v)) =C2=A0context.NR= ()
=C2=A0end
=C2=A0context.stoppmatrix()
end<= /div>
document.matthias.lua_columnvector =3D document.matthias.lua_colu= mnvector =C2=A0or lua_columnvector
\stopluacode

\def\columnvector#1{\ctxlua{docu= ment.matthias.lua_columnvector(#1)}}

\starttext
\startformula
\columnvector{{1,2,3}} %% watch the double = { !
\stopformula


\stoptext

--
luigi
--001a1139a7e4b0196404fa0fc069-- --===============1832491592== 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 ___________________________________________________________________________________ --===============1832491592==--