Simple command with variable number of arguments
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
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
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 ___________________________________________________________________________________
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
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
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 ___________________________________________________________________________________
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
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
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
___________________________________________________________________________________ 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 ___________________________________________________________________________________
On May 23, 2014, at 7:14 AM, 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
\stoptext
gives me
Matthias
Strange. What version of context are you using? Aditya
On May 23, 2014, at 6:56 AM, Aditya Mahajan
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
___________________________________________________________________________________ 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 ___________________________________________________________________________________
On Fri, May 23, 2014 at 11:54 AM, Matthias Weber
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
Thanks Luigi! Now I have a lot to play with…
Matthias
On May 23, 2014, at 7:44 AM, luigi scarso
On Fri, May 23, 2014 at 11:54 AM, 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?
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 ___________________________________________________________________________________
participants (4)
-
Aditya Mahajan
-
luigi scarso
-
Matthias Weber
-
Otared Kavian