Re: [NTG-context] Simple command with variable number of arguments

2014-05-24 Thread Jeong Dal
Dear Hans,

Here is the file in my desktop.
The reason I didn’t define “sgn” in the function “uppertri” is that it is 
inherited from the call of “determinant’.
However, I put “sgn=1” so that the function “uppertri” works independently.

I checked the function “uppertri” and found that it worked fine. Here is a 
sample file.

\environment MatrixLuacode


\starttext
\getbuffer[luaMatrix]

\startformula\startalign
\startluacode
local mat = {{0, 2, 4, -4, 1},{0, 0, 2, 3 , 4}, {2, 2, -6, 2, 4 }, {2,0 , -6, 
9, 7},{2, 2, -6, 2, 4 },{2, 2, -6, 2, 4 }}
-- local mat = {{1,2,3},{3,4,5},{3,4,5},{3,4,5},{3,4,5}}
context.NC(\\text{Given Matrix}\\quad\\Rightarrow\\quad)
context.NC()
matrixOP.write(mat)
context.NR()
context.NC()
context(\\text{Upper Triangular}\\quad\\Rightarrow\\quad)
mat = matrixOP.upperTri(mat)
context.NC()
matrixOP.write(mat)
context.NR()
\stopluacode
\stopalign\stopformula

\stoptext


Sometimes, I got “-0” as an entry of matrix after calculation but I couldn’t 
resolve it(I asked about it to this list before). 

Thank you.

Best regards,

Dalyoung



MatrixLuacode.tex
Description: Binary data


___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Otared Kavian
Hi,

Some time ago Wolfgang S. gave a solution to a similar problem: maybe this can 
help you.

 begin
\def\somemacro#1%
  {\def\dosomemacro##1{Execute ##1, }%
   \processcommalist[#1]\dosomemacro}

\starttext
\somemacro{A,B,C}

\somemacro{E,F}
\stoptext
 end

Best regards: OK

On 23 May 2014, at 11:54, 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,
 
 Matthias
 ___
 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
 ___

___
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
___


Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Matthias Weber
Thanks Otared,

that looks very promising. My attempt to wrap the arguments with \NC \NR fails, 
though.
It looks like only the first argument is used, and I am clearly missing 
something.
Also, I’d like to use the example you posted but without the last comma so that 
in the example below
I get (4,5) instead of (4,5,).

Matthias


\definemathmatrix
  [pmatrix]
  [left={\left(\,},right={\,\right)}]
  

\def\docolumnvector#1{\NC#1\NR}
  
\def\columnvector#1
{\startpmatrix
\processcommalist[#1]\docolumnvector
\stoppmatrix}


\def\dorowvector#1{#1,}
  
\def\rowvector#1
{\startpmatrix
\processcommalist[#1]\dorowvector
\stoppmatrix}

\starttext

\startformula
\columnvector{1,2,3}
\stopformula

\startformula
\rowvector{4,5}
\stopformula

\stoptext





On May 23, 2014, at 6:08 AM, Otared Kavian ota...@gmail.com wrote:

 Hi,
 
 Some time ago Wolfgang S. gave a solution to a similar problem: maybe this 
 can help you.
 
  begin
 \def\somemacro#1%
  {\def\dosomemacro##1{Execute ##1, }%
   \processcommalist[#1]\dosomemacro}
 
 \starttext
 \somemacro{A,B,C}
 
 \somemacro{E,F}
 \stoptext
  end
 
 Best regards: OK
 
 On 23 May 2014, at 11:54, 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,
 
 Matthias
 ___
 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
 ___
 
 ___
 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
 ___



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Aditya Mahajan

On Fri, 23 May 2014, Matthias Weber 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?


Surprisingly, this is not as simple as it may seem at first glance. Some 
time ago, I had written a module to achieve this. See attached. The usage 
is:


\usemodule[simplematrix]

\definesimplematrix[MATRIX][fence=bracket]

(any predefined math-fence will work) and then:

\MATRIX{1,2,3} for row vectors and \MATRIX{1;2;3} for column vectors, and 
\MATRIX{1,2,3; 4,5,6} for matrices.


You can use \definesimplematrix[...][distance=..., align=...] to influence 
the distance and align keys of mathmatrix.


Aditya%D \module
%D   [ file=t-simplematrix,
%D  version=2014.02.18,
%Dtitle=\CONTEXT\ User Module,
%D subtitle=Simple matrix,
%D   author=Aditya Mahajan,
%D date=\currentdate,
%Dcopyright=Aditya Mahajan,
%Demail=adityam at ieee dot org,
%D  license=Simplified BSD License]

\writestatus{loading}{Simple matrix (ver: 2014.02.18)}

\startmodule[simplematrix]

\unprotect

\definenamespace
  [simplematrix]
  [   \c!type=module,
  \c!name=simplematrix,
   \c!command=\v!yes,
setup=\v!list,
\s!parent=simplematrix,
  ]

\setupsimplematrix
  [
\c!distance=\emwidth,
\c!mathstyle=,
fence=bracket,
\c!align=
  ]

\appendtoks
  \setevalue{\currentsimplematrix}{\usesimplematrix[\currentsimplematrix]}
\to \everydefinesimplematrix

\newtoks\simplematrixtoks

\define[1]\simplematrix_row
{\processcommalist[#1]\simplematrix_col
 \appendtoks \NR \to \simplematrixtoks}

\define[1]\simplematrix_col
{\appendtoks \NC #1 \to \simplematrixtoks}

\unexpanded\def\usesimplematrix
{\dodoubleargument\usesimplematrix_indeed}

\def\simplematrix_left

{\edef\p_left{\namedmathfenceparameter{\simplematrixparameter{fence}}\c!left}%
 \normalleft\ifx\p_left\empty.\else\Udelimiter\plusfour\fam\p_left\relax\fi
 \,}

\def\simplematrix_right

{\edef\p_right{\namedmathfenceparameter{\simplematrixparameter{fence}}\c!right}%
 \,
 
\normalright\ifx\p_right\empty.\else\Udelimiter\plusfive\fam\p_right\relax\fi}
 

\def\usesimplematrix_indeed[#name][#options]#matrix%
{\begingroup
 \edef\currentsimplematrix{#name}%
 \setupsimplematrix[#name][#options]%
 \simplematrixtoks\emptytoks
 \startusemathstyleparameter\simplematrixparameter
 \appendtoks 
   \bgroup
   \startmathmatrix
[
  \c!distance=\simplematrixparameter\c!distance,
  \c!left=\simplematrix_left,
  \c!right=\simplematrix_right,
  \c!align=\simplematrixparameter\c!align,
]
\to \simplematrixtoks
 \processlist[];\simplematrix_row[#matrix]%
 \appendtoks \stopmathmatrix \egroup \to \simplematrixtoks
 \the\simplematrixtoks
 \stopusemathstyleparameter
 \endgroup}

\protect

\stopmodule
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Matthias Weber
Thanks Aditya,but out of the box the following\usemodule[simplematrix]\definesimplematrix[MATRIX][fence=bracket]\starttext\startformula\MATRIX{1,2,3}\MATRIX{1;2;3}\stopformula\stoptextgives me

texshop_image.pdf
Description: Adobe PDF document
MatthiasOn May 23, 2014, at 6:56 AM, Aditya Mahajan adit...@umich.edu wrote:On Fri, 23 May 2014, Matthias Weber wrote:Dear All,I would like to define a command that expands\vector{2,4} % or vector[2,4] if that’s easierto\startpmatrix\NC 2 \NR\NC 4 \NR\stoppmatrixand more generally\vector{2,4,1,7}to\startpmatrix\NC 2 \NR\NC 4 \NR\NC 1 \NR\NC 7 \NR\stoppmatrixAny hints how to achieve this?Surprisingly, this is not as simple as it may seem at first glance. Some time ago, I had written a module to achieve this. See attached. The usage is:\usemodule[simplematrix]\definesimplematrix[MATRIX][fence=bracket](any predefined math-fence will work) and then:\MATRIX{1,2,3} for row vectors and \MATRIX{1;2;3} for column vectors, and \MATRIX{1,2,3; 4,5,6} for matrices.You can use \definesimplematrix[...][distance=..., align=...] to influence the distance and align keys of mathmatrix.Adityat-simplematrix.mkvi___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-contextwebpage :http://www.pragma-ade.nl/http://tex.aanhet.netarchive :http://foundry.supelec.fr/projects/contextrev/wiki :http://contextgarden.net___

signature.asc
Description: Message signed with OpenPGP using GPGMail
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Aditya Mahajan
On May 23, 2014, at 7:14 AM, Matthias Weber matwe...@indiana.edu wrote:
 
 Thanks Aditya,
 
 but out of the box the following
 
 \usemodule[simplematrix]
 
 \definesimplematrix[MATRIX][fence=bracket]
 
 \starttext
 
 \startformula
 \MATRIX{1,2,3}
 \MATRIX{1;2;3} 
 \stopformula
 
 \stoptext
 
 gives me 
 texshop_image.pdf
 Matthias
 

Strange. What version of context are you using? 

Aditya


 
 On May 23, 2014, at 6:56 AM, Aditya Mahajan adit...@umich.edu wrote:
 
 On Fri, 23 May 2014, Matthias Weber 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?
 
 Surprisingly, this is not as simple as it may seem at first glance. Some 
 time ago, I had written a module to achieve this. See attached. The usage is:
 
 \usemodule[simplematrix]
 
 \definesimplematrix[MATRIX][fence=bracket]
 
 (any predefined math-fence will work) and then:
 
 \MATRIX{1,2,3} for row vectors and \MATRIX{1;2;3} for column vectors, and 
 \MATRIX{1,2,3; 4,5,6} for matrices.
 
 You can use \definesimplematrix[...][distance=..., align=...] to influence 
 the distance and align keys of mathmatrix.
 
 Adityat-simplematrix.mkvi___
 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
 ___
 
 ___
 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
 ___
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread luigi scarso
On Fri, May 23, 2014 at 11:54 AM, Matthias Weber matwe...@indiana.eduwrote:

 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
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Matthias Weber
Indeed - I should have checked, I tried this with the TeXLive version. With the 
current beta it works.
Thank!

Matthias

On May 23, 2014, at 7:37 AM, Aditya Mahajan adit...@umich.edu wrote:
 
 
 Strange. What version of context are you using? 
 
 Aditya
 
 



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Matthias Weber
Thanks Luigi! Now I have a lot to play with…

Matthias


On May 23, 2014, at 7:44 AM, luigi scarso luigi.sca...@gmail.com wrote:

 
 
 
 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
 ___
 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
 ___



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Jeong Dal
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.eduwrote:
 
 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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Hans Hagen
)
for i=1,#t do
det = det * t[i][i]
end
return det
else
return 0
end
end


I always thank to this list and to developers of ConTeXt.


Based on the attached I can make a more efficient version that we can 
then add to the distribution (maybe you need more than this?)


Hans


Best regards,

Dalyoung










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.eduwrote:


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
___




--

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-


xtest.tex
Description: TeX document
___
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
___

Re: [NTG-context] Simple command with variable number of arguments

2014-05-23 Thread Jeong Dal
Dear Hans,

Thank you for checking and enhancing.
I also got an error at “uppertri” as you point out. 
The version that I have sent is one in my notebook which may be different from 
that in the desktop at school. When I made a class material, it worked fine. I 
have to check it and send it to you again.
I appreciate you for making it more usable for ConTeXt users.

I also found that there is a matrix module for lua programming. It is nice for 
the calculation of matrix, but I have a difficulty to typeset the result. 
That’s why I try to write a code even though I am not good in Lua programming. 
If it is easy to take over the result into TeX, using the lua module is much 
efficient and correct, I think. 

Anyway, I hope that it helps to typeset matrices.

Best regards,

Dalyoung

 Hi,
 
 Can you check the attached? The uppertri is wrong but it was already wrong 
 (e.g. sign is used but never assigned). I inlined some code so ... I think 
 there were some more errors (obscured by the fact that that piece of code is 
 not reached).
 
 We can turn this into m-matrix or so, maybe we need to add some more.
 
 Hans
 
 -
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
 -
 xtest.tex

___
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
___