Re: [NTG-context] Problem with \definemathmatrix

2018-01-17 Thread Aditya Mahajan

On Wed, 17 Jan 2018, Fabrice Couvreur wrote:


Hello,
This macro that is not mine worked very well. I just tested the following
file and there is a problem.


Otared has already answered your question but ...


\math{M^3=\startpmatrix
  \NC 2 \NC 3 \NC 6  \NC 4 \NC 2 \NC 7  \NC 3  \NC 1 \NR
  \NC 3 \NC 0 \NC 1  \NC 1 \NC 2 \NC 3  \NC 6  \NC 4 \NR
  \NC 6 \NC 1 \NC 4  \NC 4 \NC 4 \NC 9  \NC 10 \NC 6 \NR
  \NC 4 \NC 1 \NC 4  \NC 4 \NC 5 \NC 8  \NC 8  \NC 3 \NR
  \NC 2 \NC 2 \NC 4  \NC 5 \NC 2 \NC 7  \NC 3  \NC 1 \NR
  \NC 7 \NC 3 \NC 9  \NC 8 \NC 7 \NC 8  \NC 10 \NC 3 \NR
  \NC 3 \NC 6 \NC 10 \NC 8 \NC 3 \NC 10 \NC 4  \NC 1 \NR
  \NC 1 \NC 4 \NC 6  \NC 3 \NC 1 \NC 3  \NC 1  \NC 0 \NR

\stoppmatrix}


If you type a lot of such matrices, you might find the attached module 
interesting. Using it you can use matlab-like syntax for writing matrices:


\usemodule[simplematrix]
\definesimplematrix[MATRIX][fence=parenthesis, align=middle]

\starttext
$\MATRIX{1,2,3,4;5,6,7,8;9,10,11,12}$
\stoptext

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  ieee  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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] Problem with \definemathmatrix

2018-01-17 Thread Otared Kavian
Hi Fabrice,

I think the problem comes from a blank line in your matrix (after your last 
line of entries in your matrix). The following works fine for me:

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

\startformula
A = \startpmatrix
\NC 11 \NC 12 \NR
\NC 21 \NC 22 \NR
\stoppmatrix
\stopformula

\startformula
M^3 = \startpmatrix
   \NC 2 \NC 3 \NC 6  \NC 4 \NC 2 \NC 7  \NC 3  \NC 1 \NR 
   \NC 3 \NC 0 \NC 1  \NC 1 \NC 2 \NC 3  \NC 6  \NC 4 \NR  
   \NC 6 \NC 1 \NC 4  \NC 4 \NC 4 \NC 9  \NC 10 \NC 6 \NR  
   \NC 4 \NC 1 \NC 4  \NC 4 \NC 5 \NC 8  \NC 8  \NC 3 \NR  
   \NC 2 \NC 2 \NC 4  \NC 5 \NC 2 \NC 7  \NC 3  \NC 1 \NR  
   \NC 7 \NC 3 \NC 9  \NC 8 \NC 7 \NC 8  \NC 10 \NC 3 \NR  
   \NC 3 \NC 6 \NC 10 \NC 8 \NC 3 \NC 10 \NC 4  \NC 1 \NR  
   \NC 1 \NC 4 \NC 6  \NC 3 \NC 1 \NC 3  \NC 1  \NC 0 \NR  
\stoppmatrix
\stopformula

\stoptext

Best regards: OK


> On 17 Jan 2018, at 19:19, Fabrice Couvreur  
> wrote:
> 
> Hello,
> This macro that is not mine worked very well. I just tested the following 
> file and there is a problem.
> Thank you
> Fabrice
> 
> \definemathmatrix
>   [pmatrix]
>   [left={\left(\,},right={\,\right)}]
>   
> \starttext
> 
> \math{M^3=\startpmatrix
>\NC 2 \NC 3 \NC 6  \NC 4 \NC 2 \NC 7  \NC 3  \NC 1 \NR 
>\NC 3 \NC 0 \NC 1  \NC 1 \NC 2 \NC 3  \NC 6  \NC 4 \NR  
>\NC 6 \NC 1 \NC 4  \NC 4 \NC 4 \NC 9  \NC 10 \NC 6 \NR  
>\NC 4 \NC 1 \NC 4  \NC 4 \NC 5 \NC 8  \NC 8  \NC 3 \NR  
>\NC 2 \NC 2 \NC 4  \NC 5 \NC 2 \NC 7  \NC 3  \NC 1 \NR  
>\NC 7 \NC 3 \NC 9  \NC 8 \NC 7 \NC 8  \NC 10 \NC 3 \NR  
>\NC 3 \NC 6 \NC 10 \NC 8 \NC 3 \NC 10 \NC 4  \NC 1 \NR  
>\NC 1 \NC 4 \NC 6  \NC 3 \NC 1 \NC 3  \NC 1  \NC 0 \NR  
>
>  \stoppmatrix}  
>   
> \stoptext
> ___
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] Problem with \definemathmatrix

2018-01-17 Thread Fabrice Couvreur
Hello,
This macro that is not mine worked very well. I just tested the following
file and there is a problem.
Thank you
Fabrice

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

\starttext

\math{M^3=\startpmatrix
   \NC 2 \NC 3 \NC 6  \NC 4 \NC 2 \NC 7  \NC 3  \NC 1 \NR
   \NC 3 \NC 0 \NC 1  \NC 1 \NC 2 \NC 3  \NC 6  \NC 4 \NR
   \NC 6 \NC 1 \NC 4  \NC 4 \NC 4 \NC 9  \NC 10 \NC 6 \NR
   \NC 4 \NC 1 \NC 4  \NC 4 \NC 5 \NC 8  \NC 8  \NC 3 \NR
   \NC 2 \NC 2 \NC 4  \NC 5 \NC 2 \NC 7  \NC 3  \NC 1 \NR
   \NC 7 \NC 3 \NC 9  \NC 8 \NC 7 \NC 8  \NC 10 \NC 3 \NR
   \NC 3 \NC 6 \NC 10 \NC 8 \NC 3 \NC 10 \NC 4  \NC 1 \NR
   \NC 1 \NC 4 \NC 6  \NC 3 \NC 1 \NC 3  \NC 1  \NC 0 \NR

 \stoppmatrix}

\stoptext
___
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___