Dear Luigi and listers, Last year, I need to write a text for a linear algebra class. Since there are many \startmatrix … \stopmatrix and matrix calculations, I wrote a lua code which did matrix calculations and writing with a lot of help from this list. Using the code, I can write class materials easily. It is good enough for my purpose. I am not good in Lua coding, so there may be many things to be checked for efficiency and for stability.
However, I attached the code because there may be someone who need it. It is also good thing to return what I get from the list back. I hope that you enhance the code for better performance since you are an expert in Lua. I always thank to this list and to developers of ConTeXt. Best regards, Dalyoung
MatrixLuacode.tex
Description: Binary data
> > Message: 1 > Date: Fri, 23 May 2014 13:44:30 +0200 > From: luigi scarso <luigi.sca...@gmail.com> > To: mailing list for ConTeXt users <ntg-context@ntg.nl> > Subject: Re: [NTG-context] Simple command with variable number of > arguments > Message-ID: > <CAG5iGsCadu33Hw=hphmde+wp1b_fcpjn0caxwjaso+vnqbj...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > On Fri, May 23, 2014 at 11:54 AM, Matthias Weber <matwe...@indiana.edu>wrote: > >> Dear All, >> >> I would like to define a command that expands >> >> \vector{2,4} % or vector[2,4] if that?s 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={\left(\,},right={\,\right)}] > > \startluacode > document = document or {} > document.matthias = 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 = 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 > > -- > luigi > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://www.ntg.nl/pipermail/ntg-context/attachments/20140523/569165d6/attachment-0001.html> > > ------------------------------
___________________________________________________________________________________ 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 ___________________________________________________________________________________