* Re: Simple command with variable number of arguments
[not found] <mailman.56.1400848757.2240.ntg-context@ntg.nl>
@ 2014-05-23 13:48 ` Jeong Dal
2014-05-23 18:00 ` Hans Hagen
[not found] ` <537FA66D.3000608@wxs.nl>
0 siblings, 2 replies; 13+ messages in thread
From: Jeong Dal @ 2014-05-23 13:48 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1: Type: text/plain, Size: 777 bytes --]
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
[-- Attachment #2: MatrixLuacode.tex --]
[-- Type: application/octet-stream, Size: 3510 bytes --]
\startenvironment MatrixLuacode
\startbuffer[luaMatrix]
\startluacode
matrixOP = matrixOP or {} -- recommended: use namespace
matrixOP.symMatrix = function(sym, x, y) -- symMatrix("a", "m", "n")
local entry
local mrow={}
local mm={}
for i=1, 2 do -- first two rows
mrow={}
for j=1, 2 do
entry=sym.."_{"..i..j.."}"
table.insert(mrow, entry)
end
entry="\\cdots"
table.insert(mrow, entry)
entry=sym.."_{"..i..y.."}"
table.insert(mrow, entry)
table.insert(mm,mrow)
end
entry = {"\\vdots","\\vdots","\\ddots","\\vdots"} --3rd row
table.insert(mm,entry)
mrow={}
for j=1, 2 do -- last row
entry=sym.."_{"..x..j.."}"
table.insert(mrow, entry)
end
entry="\\cdots"
table.insert(mrow, entry)
entry=sym.."_{"..x..y.."}"
table.insert(mrow, entry)
table.insert(mm,mrow)
return mm
end
matrixOP.write = function (t)
context.startmatrix{left = "\\left(\\,", right = "\\,\\right)"}
for _, r in ipairs(t) do
for _, c in ipairs(r) do
context.NC(c)
end
context.NR()
end
context.stopmatrix()
end
matrixOP.writeDet = function (t)
context.startmatrix{left = "\\left|\\ ", right = "\\ \\right|"}
for _, r in ipairs(t) do
for _, c in ipairs(r) do
context.NC(c)
end
context.NR()
end
context.stopmatrix()
end
matrixOP.rowChange = function(t, i, j) -- interchange two rows(i-th, j-th)
t[i] , t[j]= t[j], t[i]
end
matrixOP.rowMult = function(t, i, m) -- replace i-th row with m*(i-th row)
local len
len = #(t[i])
for k = 1, len do t[i][k] = m*t[i][k] end
end
matrixOP.rowMultSum = function(t, i, j, m) -- replace i-th row with i-th row + m*(j-th row)
local len
len = #(t[1])
for k = 1, len do t[i][k] = t[i][k] + m*t[j][k] end
end
matrixOP.transpose = function(m) -- transpose of a matrix
local temp
local mT={}
local mTrow
for j = 1, #m[1] do
mTrow={}
for i=1, #m do
temp = m[i][j]
table.insert(mTrow, temp)
end
table.insert(mT, mTrow)
end
return mT
end
matrixOP.inner = function (u, v) -- inner product of two vectors
temp=0
if #u == #v then
for i=1, #u do
temp = temp + u[i]*v[i]
end
end
return temp
end
matrixOP.product = function(m1, m2) -- product of two matrices
local temp
local m3={}
local mrow
if #m1[1] == #m2 then
for i = 1, #m1 do
mrow={}
for j=1, #m2[1] do
temp = 0
for k=1, #m1[1] do
u = m1[i][k]*m2[k][j]
temp = temp + u
end
table.insert(mrow, temp)
end
table.insert(m3, mrow)
end
end
return m3
end
matrixOP.searchRow = function(m, i)
local pv, pr
pr = #m + 1
for k=i+1, #m do
pv=m[k][i]
if pv == 0 then
k = k+1
else
pr = k
break
end
end
if pr <= #m then
return pr
else
return 0
end
end
matrixOP.upperTri = function(m)
local pivot, pRow, multiple
local temp
temp = m
for i=1, #temp-1 do
pivot = temp[i][i]
if pivot == 0 then
pRow = matrixOP.searchRow(temp, i)
if pRow==0 then
-- context("Singular Matrix")
break
end
matrixOP.rowChange(temp, i, pRow)
sgn=(-1)*sgn
end
for k=i+1, #temp do
multiple = -temp[k][i]/temp[i][i]
matrixOP.rowMultSum(temp, k, i,multiple)
end
end
return temp
end
matrixOP.determinant = function(m)
local det, sgn
if #m ==#m[1] then
det=1
sgn=1
matrixOP.upperTri(m)
for i = 1, #m do
det = det*m[i][i]
end
det = sgn*det
else
det = 0
end
-- context(det)
return det
end
\stopluacode
\stopbuffer
\stopenvironment
[-- Attachment #3: Type: text/plain, Size: 1748 bytes --]
>
> Message: 1
> Date: Fri, 23 May 2014 13:44:30 +0200
> From: luigi scarso <luigi.scarso@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+vnQBJEtA@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Fri, May 23, 2014 at 11:54 AM, Matthias Weber <matweber@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>
>
> ------------------------------
[-- Attachment #4: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 13:48 ` Simple command with variable number of arguments Jeong Dal
@ 2014-05-23 18:00 ` Hans Hagen
[not found] ` <537FA66D.3000608@wxs.nl>
1 sibling, 0 replies; 13+ messages in thread
From: Hans Hagen @ 2014-05-23 18:00 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 7691 bytes --]
On 5/23/2014 3:48 PM, Jeong Dal wrote:
> 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.
A bit more readable:
matrixOP.symMatrix = function(sym, x, y, nx ,ny) -- symMatrix("a", "m", "n")
local nx = nx or 2
local ny = ny or nx
local function filled(i,y)
local mrow = { }
for j=1,nx do
table.insert(mrow, string.formatters["%s_{%s%s}"](sym,i,j))
end
table.insert(mrow,"\\cdots")
table.insert(mrow,string.formatters["%s_{%s%s}"](sym,i,y))
return mrow
end
local function dummy()
local mrow = { }
for j=1,nx do
table.insert(mrow,"\\vdots")
end
table.insert(mrow,"\\ddots")
table.insert(mrow,"\\vdots")
return mrow
end
--
local mm = { }
for i=1,ny do
table.insert(mm,filled(i,y))
end
table.insert(mm,dummy())
table.insert(mm,filled(x,y))
return mm
end
Also, variable nx, ny:
\ctxlua{matrixOP.write(matrixOP.symMatrix("a","m","n",4,8))}
Maybe this too:
local default = {
left = [[\left(\,]],
right = [[\,\right)]],
}
matrixOP.write = function (t)
context.startmatrix(default)
for _, r in ipairs(t) do
for _, c in ipairs(r) do
context.NC(c)
end
context.NR()
end
context.stopmatrix()
end
matrixOP.writeDet = function(t)
context.startmatrix(default)
for _, r in ipairs(t) do
for _, c in ipairs(r) do
context.NC(c)
end
context.NR()
end
context.stopmatrix()
end
And:
matrixOP.rowMult = function(t, i, m) -- replace i-th row with m*(i-th row)
for k = 1, #t[i] do t[i][k] = m*t[i][k] end
end
matrixOP.rowMultSum = function(t, i, j, m) -- replace i-th row with i-th
row + m*(j-th row)
for k = 1, #t[1] do t[i][k] = t[i][k] + m*t[j][k] end
end
(no need for further speedup as it't non-critical code with neglectable
runtime)
More Luaish (local usage):
matrixOP.transpose = function(m) -- transpose of a matrix
local mT={}
for j = 1, #m[1] do
local mTrow={}
for i=1, #m do
local temp = m[i][j]
table.insert(mTrow, temp)
end
table.insert(mT, mTrow)
end
return mT
end
Don't forget the local here:
matrixOP.inner = function (u, v) -- inner product of two vectors
local temp=0
if #u == #v then
for i=1, #u do
temp = temp + u[i]*v[i]
end
end
return temp
end
and here:
matrixOP.product = function(m1, m2) -- product of two matrices
local m3={}
if #m1[1] == #m2 then
for i = 1, #m1 do
local mrow={}
for j=1, #m2[1] do
local temp = 0
for k=1, #m1[1] do
u = m1[i][k]*m2[k][j]
temp = temp + u
end
table.insert(mrow, temp)
end
table.insert(m3, mrow)
end
end
return m3
end
less code:
matrixOP.searchRow = function(m, i)
local pr = #m + 1
for k=i+1, #m do
if m[k][i] == 0 then
k = k+1
else
pr = k
break
end
end
if pr <= #m then
return pr
else
return 0
end
end
Are you sure this is ok? I've added a copy as you might want to keep the
original table:
matrixOP.upperTri = function(m)
local temp = table.copy(m)
for i=1, #temp-1 do
local pivot = temp[i][i]
if pivot == 0 then
local pRow = matrixOP.searchRow(temp, i)
if pRow==0 then
break
end
matrixOP.rowChange(temp, i, pRow)
sgn=(-1)*sgn
end
for k=i+1, #temp do
matrixOP.rowMultSum(temp, k, i,-temp[k][i]/temp[i][i])
end
end
return temp
end
So then, watch how we use the return value of this one:
matrixOP.determinant = function(m)
if #m ==#m[1]then
local det = 1
local t = matrixOP.upperTri(m)
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.scarso@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+vnQBJEtA@mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> On Fri, May 23, 2014 at 11:54 AM, Matthias Weber <matweber@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
> ___________________________________________________________________________________
>
--
-----------------------------------------------------------------
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
-----------------------------------------------------------------
[-- Attachment #2: xtest.tex --]
[-- Type: application/x-tex, Size: 3986 bytes --]
[-- Attachment #3: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
[not found] ` <537FA66D.3000608@wxs.nl>
@ 2014-05-24 0:36 ` Jeong Dal
2014-05-24 6:55 ` Jeong Dal
1 sibling, 0 replies; 13+ messages in thread
From: Jeong Dal @ 2014-05-24 0:36 UTC (permalink / raw)
To: Hans Hagen, ntg-context
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
[not found] ` <537FA66D.3000608@wxs.nl>
2014-05-24 0:36 ` Jeong Dal
@ 2014-05-24 6:55 ` Jeong Dal
1 sibling, 0 replies; 13+ messages in thread
From: Jeong Dal @ 2014-05-24 6:55 UTC (permalink / raw)
To: Hans Hagen, ntg-context
[-- Attachment #1: Type: text/plain, Size: 1132 bytes --]
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
[-- Attachment #2: MatrixLuacode.tex --]
[-- Type: application/octet-stream, Size: 3519 bytes --]
\startenvironment MatrixLuacode
\startbuffer[luaMatrix]
\startluacode
matrixOP = matrixOP or {} -- recommended: use namespace
matrixOP.symMatrix = function(sym, x, y) -- symMatrix("a", "m", "n")
local entry
local mrow={}
local mm={}
for i=1, 2 do -- first two rows
mrow={}
for j=1, 2 do
entry=sym.."_{"..i..j.."}"
table.insert(mrow, entry)
end
entry="\\cdots"
table.insert(mrow, entry)
entry=sym.."_{"..i..y.."}"
table.insert(mrow, entry)
table.insert(mm,mrow)
end
entry = {"\\vdots","\\vdots","\\ddots","\\vdots"} --3rd row
table.insert(mm,entry)
mrow={}
for j=1, 2 do -- last row
entry=sym.."_{"..x..j.."}"
table.insert(mrow, entry)
end
entry="\\cdots"
table.insert(mrow, entry)
entry=sym.."_{"..x..y.."}"
table.insert(mrow, entry)
table.insert(mm,mrow)
return mm
end
matrixOP.write = function (t)
context.startmatrix{left = "\\left(\\,", right = "\\,\\right)"}
for _, r in ipairs(t) do
for _, c in ipairs(r) do
context.NC(c)
end
context.NR()
end
context.stopmatrix()
end
matrixOP.writeDet = function (t)
context.startmatrix{left = "\\left|\\ ", right = "\\ \\right|"}
for _, r in ipairs(t) do
for _, c in ipairs(r) do
context.NC(c)
end
context.NR()
end
context.stopmatrix()
end
matrixOP.rowChange = function(t, i, j) -- interchange two rows(i-th, j-th)
t[i] , t[j]= t[j], t[i]
end
matrixOP.rowMult = function(t, i, m) -- replace i-th row with m*(i-th row)
local len
len = #(t[i])
for k = 1, len do t[i][k] = m*t[i][k] end
end
matrixOP.rowMultSum = function(t, i, j, m) -- replace i-th row with i-th row + m*(j-th row)
local len
len = #(t[1])
for k = 1, len do t[i][k] = t[i][k] + m*t[j][k] end
end
matrixOP.transpose = function(m) -- transpose of a matrix
local temp
local mT={}
local mTrow
for j = 1, #m[1] do
mTrow={}
for i=1, #m do
temp = m[i][j]
table.insert(mTrow, temp)
end
table.insert(mT, mTrow)
end
return mT
end
matrixOP.inner = function (u, v) -- inner product of two vectors
temp=0
if #u == #v then
for i=1, #u do
temp = temp + u[i]*v[i]
end
end
return temp
end
matrixOP.product = function(m1, m2) -- product of two matrices
local temp
local m3={}
local mrow
if #m1[1] == #m2 then
for i = 1, #m1 do
mrow={}
for j=1, #m2[1] do
temp = 0
for k=1, #m1[1] do
u = m1[i][k]*m2[k][j]
temp = temp + u
end
table.insert(mrow, temp)
end
table.insert(m3, mrow)
end
end
return m3
end
matrixOP.searchRow = function(m, i)
local pv, pr
pr = #m + 1
for k=i+1, #m do
pv=m[k][i]
if pv == 0 then
k = k+1
else
pr = k
break
end
end
if pr <= #m then
return pr
else
return 0
end
end
matrixOP.upperTri = function(m)
local pivot, pRow, multiple
local temp
temp = m
sgn= 1
for i=1, #temp-1 do
pivot = temp[i][i]
if pivot == 0 then
pRow = matrixOP.searchRow(temp, i)
if pRow==0 then
-- context("Singular Matrix")
break
end
matrixOP.rowChange(temp, i, pRow)
sgn=(-1)*sgn
end
for k=i+1, #temp do
multiple = -temp[k][i]/temp[i][i]
matrixOP.rowMultSum(temp, k, i,multiple)
end
end
return temp
end
matrixOP.determinant = function(m)
local det, sgn
if #m ==#m[1] then
det=1
sgn=1
matrixOP.upperTri(m)
for i = 1, #m do
det = det*m[i][i]
end
det = sgn*det
else
det = 0
end
-- context(det)
return det
end
\stopluacode
\stopbuffer
\stopenvironment
[-- Attachment #3: Type: text/plain, Size: 2 bytes --]
[-- Attachment #4: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 11:44 ` luigi scarso
@ 2014-05-23 12:12 ` Matthias Weber
0 siblings, 0 replies; 13+ messages in thread
From: Matthias Weber @ 2014-05-23 12:12 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1.1: Type: text/plain, Size: 1853 bytes --]
Thanks Luigi! Now I have a lot to play with…
Matthias
On May 23, 2014, at 7:44 AM, luigi scarso <luigi.scarso@gmail.com> wrote:
>
>
>
> On Fri, May 23, 2014 at 11:54 AM, Matthias Weber <matweber@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
> ___________________________________________________________________________________
[-- Attachment #1.1.2: Type: text/html, Size: 3357 bytes --]
[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 11:37 ` Aditya Mahajan
@ 2014-05-23 12:08 ` Matthias Weber
0 siblings, 0 replies; 13+ messages in thread
From: Matthias Weber @ 2014-05-23 12:08 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1.1: Type: text/plain, Size: 283 bytes --]
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 <adityam@umich.edu> wrote:
>>
>
> Strange. What version of context are you using?
>
> Aditya
>
>
[-- Attachment #1.1.2: Type: text/html, Size: 1071 bytes --]
[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 9:54 Matthias Weber
2014-05-23 10:08 ` Otared Kavian
2014-05-23 10:56 ` Aditya Mahajan
@ 2014-05-23 11:44 ` luigi scarso
2014-05-23 12:12 ` Matthias Weber
2 siblings, 1 reply; 13+ messages in thread
From: luigi scarso @ 2014-05-23 11:44 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1120 bytes --]
On Fri, May 23, 2014 at 11:54 AM, Matthias Weber <matweber@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
[-- Attachment #1.2: Type: text/html, Size: 1935 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 11:14 ` Matthias Weber
@ 2014-05-23 11:37 ` Aditya Mahajan
2014-05-23 12:08 ` Matthias Weber
0 siblings, 1 reply; 13+ messages in thread
From: Aditya Mahajan @ 2014-05-23 11:37 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2637 bytes --]
On May 23, 2014, at 7:14 AM, Matthias Weber <matweber@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 <adityam@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.
>>
>> Aditya<t-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
> ___________________________________________________________________________________
[-- Attachment #1.2: Type: text/html, Size: 5019 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 10:56 ` Aditya Mahajan
@ 2014-05-23 11:14 ` Matthias Weber
2014-05-23 11:37 ` Aditya Mahajan
0 siblings, 1 reply; 13+ messages in thread
From: Matthias Weber @ 2014-05-23 11:14 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1.1: Type: text/plain, Size: 1857 bytes --]
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
Matthias
On May 23, 2014, at 6:56 AM, Aditya Mahajan <adityam@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.
>
> Aditya<t-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
> ___________________________________________________________________________________
[-- Attachment #1.1.2.1: Type: text/html, Size: 649 bytes --]
[-- Attachment #1.1.2.2: texshop_image.pdf --]
[-- Type: application/pdf, Size: 5089 bytes --]
[-- Attachment #1.1.2.3: Type: text/html, Size: 3052 bytes --]
[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 9:54 Matthias Weber
2014-05-23 10:08 ` Otared Kavian
@ 2014-05-23 10:56 ` Aditya Mahajan
2014-05-23 11:14 ` Matthias Weber
2014-05-23 11:44 ` luigi scarso
2 siblings, 1 reply; 13+ messages in thread
From: Aditya Mahajan @ 2014-05-23 10:56 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: TEXT/PLAIN, Size: 946 bytes --]
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
[-- Attachment #2: Type: TEXT/PLAIN, Size: 2365 bytes --]
%D \module
%D [ file=t-simplematrix,
%D version=2014.02.18,
%D title=\CONTEXT\ User Module,
%D subtitle=Simple matrix,
%D author=Aditya Mahajan,
%D date=\currentdate,
%D copyright=Aditya Mahajan,
%D email=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
[-- Attachment #3: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 10:08 ` Otared Kavian
@ 2014-05-23 10:55 ` Matthias Weber
0 siblings, 0 replies; 13+ messages in thread
From: Matthias Weber @ 2014-05-23 10:55 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2765 bytes --]
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 <otared@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 <matweber@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
> ___________________________________________________________________________________
[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Simple command with variable number of arguments
2014-05-23 9:54 Matthias Weber
@ 2014-05-23 10:08 ` Otared Kavian
2014-05-23 10:55 ` Matthias Weber
2014-05-23 10:56 ` Aditya Mahajan
2014-05-23 11:44 ` luigi scarso
2 siblings, 1 reply; 13+ messages in thread
From: Otared Kavian @ 2014-05-23 10:08 UTC (permalink / raw)
To: mailing list for ConTeXt users
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 <matweber@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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
* Simple command with variable number of arguments
@ 2014-05-23 9:54 Matthias Weber
2014-05-23 10:08 ` Otared Kavian
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Matthias Weber @ 2014-05-23 9:54 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 354 bytes --]
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
[-- Attachment #1.2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-05-24 6:55 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <mailman.56.1400848757.2240.ntg-context@ntg.nl>
2014-05-23 13:48 ` Simple command with variable number of arguments Jeong Dal
2014-05-23 18:00 ` Hans Hagen
[not found] ` <537FA66D.3000608@wxs.nl>
2014-05-24 0:36 ` Jeong Dal
2014-05-24 6:55 ` Jeong Dal
2014-05-23 9:54 Matthias Weber
2014-05-23 10:08 ` Otared Kavian
2014-05-23 10:55 ` Matthias Weber
2014-05-23 10:56 ` Aditya Mahajan
2014-05-23 11:14 ` Matthias Weber
2014-05-23 11:37 ` Aditya Mahajan
2014-05-23 12:08 ` Matthias Weber
2014-05-23 11:44 ` luigi scarso
2014-05-23 12:12 ` Matthias Weber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).