summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-07-06 21:31:37 +0000
committerKarl Berry <karl@freefriends.org>2018-07-06 21:31:37 +0000
commita721f45f8576209fefa4722a159acef42fb5e34d (patch)
tree4ba8959c919edae393cd8615c29e1c564f6588d4
parent7a0530fc446c4a173b43abcb0302be9e8c08ebd2 (diff)
nicematrix (6jul18)
git-svn-id: svn://tug.org/texlive/trunk@48154 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/nicematrix/README.md4
-rw-r--r--Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdfbin252875 -> 313739 bytes
-rw-r--r--Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx1572
-rw-r--r--Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty1009
4 files changed, 1867 insertions, 718 deletions
diff --git a/Master/texmf-dist/doc/latex/nicematrix/README.md b/Master/texmf-dist/doc/latex/nicematrix/README.md
index 30055711b03..3b5de617204 100644
--- a/Master/texmf-dist/doc/latex/nicematrix/README.md
+++ b/Master/texmf-dist/doc/latex/nicematrix/README.md
@@ -6,5 +6,5 @@ This extension is entirely contained in a single file : nicematrix.sty
The LaTeX package nicematrix provides new environments similar to the classical environments
array and matrix but with some additional features. Among these features are the
-possibilities to fix the width of the columns and to draw continuous ellipsis dots between the cells
-of the array. \ No newline at end of file
+possibilities to fix the width of the columns, to draw continuous ellipsis dots between the cells
+of the array and to add an exterior line and an exterior column. \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf
index 4acb39a6d0c..379601d6730 100644
--- a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf
+++ b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx
index 5093c59642a..18b1e89ad3a 100644
--- a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx
+++ b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx
@@ -15,8 +15,8 @@
%
% \fi
% \iffalse
-\def\myfileversion{1.4}
-\def\myfiledate{2018/04/16}
+\def\myfileversion{2.0}
+\def\myfiledate{2018/07/06}
%
%
%<*batchfile>
@@ -44,7 +44,7 @@ version 2005/12/01 or later.
\endgroup
%</batchfile>
%
-%<@@=nm>
+%<@@=nicem>
%<*driver>
\documentclass[dvipsnames]{l3doc}% dvipsnames is for xcolor (loaded by Tikz, loaded by nicematrix)
\VerbatimFootnotes
@@ -52,10 +52,16 @@ version 2005/12/01 or later.
\usepackage{geometry}
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
\usepackage{nicematrix}
+\usetikzlibrary{fit}
\NewDocumentEnvironment {scope} {} {} {}
\def\interitem{\vskip 7mm plus 2 mm minus 3mm}
\def\emphase{\bgroup\color{RoyalPurple}\let\next=}
\fvset{commandchars=\~\#\@,formatcom={\color{gray}}}
+\usepackage{titlesec}
+\titlespacing*{\section}{0pt}{6.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
+\titlespacing*{\subsection}{0pt}{4.5ex plus 1ex minus .2ex}{2ex plus .2ex}
+\usepackage{multicol}
+\setlength{\columnseprule}{0.4pt}
\parindent 0pt
\DisableCrossrefs
\begin{document}
@@ -66,6 +72,7 @@ version 2005/12/01 or later.
% \title{The package \pkg{nicematrix}\thanks{This document corresponds to the version~\myfileversion\space of \pkg{nicematrix},
% at the date of~\myfiledate.}} \author{F. Pantigny \\ \texttt{fpantigny@wanadoo.fr}}
%
+%
% \maketitle
%
% \begin{abstract}
@@ -80,74 +87,148 @@ version 2005/12/01 or later.
%
% This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by the classical workflow
% |latex|-|dvips|-|ps2pdf| (or Adobe Distiller). Two or three compilations may be necessary. This package requires
-% the packages \pkg{expl3}, \pkg{l3keys2e}, \pkg{xparse}, \pkg{array}, \pkg{mathtools} and \pkg{tikz}.
+% and loads the packages \pkg{expl3}, \pkg{l3keys2e}, \pkg{xparse}, \pkg{array}, \pkg{mathtools} and \pkg{tikz}.
+%
+% \tikzset{highlight/.style={rectangle,
+% fill=red!15,
+% blend mode = multiply,
+% inner sep=1pt}}
+%
%
% \medskip
-% The package \pkg{nicematrix} aims to draw beautiful matrices in a way almost transparent for the user.
+% \begin{minipage}{0.6\linewidth}
+% This package provides some new tools to draw mathematical matrices. The main features are the following:
+%
+% \textbullet\ continuous dotted lines;
+%
+% \textbullet\ a first row and a last column for labels;
+%
+% \textbullet\ a control of the width of the columns.
+% \end{minipage}
+% \hspace{1.4cm}
+% $\vcenter{
+% \begin{bNiceArrayRC}{CCCC}%
+% [code-for-last-col=\color{blue}\scriptstyle,
+% code-for-first-row=\color{blue}\scriptstyle,
+% code-after = {\tikz \node [highlight,fit = (0-1) (0-4)] {};
+% \tikz \node [highlight,fit = (1-5) (4-5)] {};},
+% columns-width = auto]
+% C_1 & C_2 & \Cdots & C_n \\
+% a_{11} & a_{12} & \Cdots & a_{1n} & L_1 \\
+% a_{21} & a_{22} & \Cdots & a_{2n} & L_2 \\
+% \Vdots & \Vdots & \Ddots & \Vdots & \Vdots \\
+% a_{n1} & a_{n2} & \Cdots & a_{nn} & L_n \\
+% \end{bNiceArrayRC}
+% }$
%
% \medskip
-% Consider, for example, the matrix\enskip
-% $A = \begin{pmatrix}
-% 1 &\cdots &\cdots &1 \\
-% 0 &\ddots & &\vdots \\
-% \vdots &\ddots &\ddots &\vdots \\
-% 0 &\cdots &0 &1
-% \end{pmatrix}$
+% A command |\NiceMatrixOptions| is provided to fix the options (the scope of the options fixed by this command is
+% the current TeX group).
+%
+%
+% \bigskip
+% \textbf{An example for the continuous dotted lines}
%
% \medskip
-% Usually, when using LaTeX and \pkg{amsmath} (or \pkg{mathtools}), such a matrix is composed with an environment
-% |{pmatrix}| and the following code:
-% \begin{Verbatim}
+% \begin{minipage}{10cm}
+% For example, consider the following code which uses an environment |{pmatrix}| of \pkg{amsmath} (or
+% \pkg{mathtools}).
+%
+% \smallskip
+% \begin{BVerbatim}
% $A = \begin{pmatrix}
% 1 & \cdots & \cdots & 1 \\
% 0 & \ddots & & \vdots \\
% \vdots & \ddots & \ddots & \vdots \\
% 0 & \cdots & 0 & 1
% \end{pmatrix}$
-% \end{Verbatim}
-%
-% \medskip
-% If we load the package \pkg{nicematrix} with the option |transparent|, the same code will give the
-% following result:
+% \end{BVerbatim}
+%
+% \smallskip
+% This code composes the matrix $A$ on the right.
+% \end{minipage}\hspace{1cm}
+% $A = \begin{pmatrix}
+% 1 &\cdots &\cdots &1 \\
+% 0 &\ddots & &\vdots \\
+% \vdots &\ddots &\ddots &\vdots \\
+% 0 &\cdots &0 &1
+% \end{pmatrix}$
+%
%
+% \bigskip
% \begin{scope}
% \NiceMatrixOptions{transparent}
-% \[A = \begin{pmatrix}
+% \begin{minipage}{10cm}
+% Now, if we use the package \pkg{nicematrix} with the option |transparent|, the same code will give the
+% result on the right.
+% \end{minipage}\hspace{1cm}
+% $A = \begin{pmatrix}
% 1 & \cdots & \cdots & 1 \\
% 0 & \ddots & & \vdots \\
% \vdots & \ddots & \ddots & \vdots \\
% 0 & \cdots & 0 & 1
-% \end{pmatrix}\]
+% \end{pmatrix}$
% \end{scope}
+%
+%
+%
+% \section{The environments of this extension}
+%
+% The extension \pkg{nicematrix} defines the following new environments.
+%
+% \medskip
+% \begin{ttfamily}
+% \setlength{\tabcolsep}{3mm}
+% \begin{tabular}{llll}
+% \{NiceMatrix\} & \{NiceArray\} & \{pNiceArrayC\} & \{pNiceArrayRC\} \\
+% \{pNiceMatrix\} & & \{bNiceArrayC\} & \{bNiceArrayRC\} \\
+% \{bNiceMatrix\} & & \{BNiceArrayC\} & \{BNiceArrayRC\} \\
+% \{BNiceMatrix\} & & \{vNiceArrayC\} & \{vNiceArrayRC\} \\
+% \{vNiceMatrix\} & & \{VNiceArrayC\} & \{VNiceArrayRC\} \\
+% \{VNiceMatrix\} & & \{NiceArrayCwithDelims\} & \{NiceArrayRCwithDelims\} \\
+% \end{tabular}
+% \end{ttfamily}
+%
%
% \medskip
-% The dotted lines are drawn with Tikz. Two compilations may be necessary.
+% By default, the environments |{NiceMatrix}|, |{pNiceMatrix}|, |{bNiceMatrix}|, |{BNiceMatrix}|, |{vNiceMatrix}|
+% and |{VNiceMatrix}| behave almost exactly as the corresponding environments of \pkg{amsmath} (and
+% \pkg{mathtools}): |{matrix}|, |{pmatrix}|, |{bmatrix}|, |{Bmatrix}|, |{vmatrix}| and |{Vmatrix}|.
%
+%
% \medskip
-% A command |\NiceMatrixOptions| is provided to fix the options (the scope of the options fixed by this command is
-% the current TeX group).
+% The environment |{NiceArray}| is similar to the environment |{array}| of the package |{array}|. However, for
+% technical reasons, in the preamble of the environment |{NiceArray}|, the user must use the letters |L|, |C|
+% and~|R| instead of |l|, |c| and |r|. It's possible to use the constructions \verb|w{...}{...}|,
+% \verb|W{...}{...}|, \verb+|+, |>{...}|, |<{...}|, |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, |m| and
+% |b| should not be used. See p.~\pageref{NiceArray} the section relating to |{NiceArray}|.
%
+% \medskip
+% The environments with |C| at the end of their name, |{pNiceArrayC}|, |{bNiceArrayC}|, |{BNiceArrayC}|,
+% |{vNiceArrayC}| and |{VNiceArrayC}| are similar to the environment |{NiceArray}| (especially the special letters
+% |L|, |C| and |R|) but create an exterior column (on the right of the closing delimiter). See
+% p.~\pageref{pNiceArrayC} the section relating to |{pNiceArrayC}|.
%
-% \section{How to use \{NiceMatrix\} for new code}
+% \medskip
+% The environments with |RC|, |{pNiceArrayRC}|, |{bNiceArrayRC}|, |{BNiceArrayRC}|, |{vNiceArrayRC}|,
+% |{VNiceArrayRC}| are similar to the environment |{NiceArray}| but create an exterior row (above the main matrix)
+% and an exterior column. See p.~\pageref{pNiceArrayRC} the section relating to |{pNiceArrayRC}|.
%
-% \subsection{The environment \{NiceMatrix\} and its variants}
%
-% The package \pkg{nicematrix} provides new environments |{NiceMatrix}|, |{pNiceMatrix}|, |{bNiceMatrix}|,
-% |{BNiceMatrix}|, |{vNiceMatrix}| and |{VNiceMatrix}|. By default, these environments behave almost exactly as the
-% corresponding environments of \pkg{amsmath} (and \pkg{mathtools}): |{matrix}|, |{pmatrix}|, |{bmatrix}|,
-% |{Bmatrix}|, |{vmatrix}| and |{Vmatrix}|.
+%
+% \section{The continuous dotted lines}
%
-% \smallskip
-% Inside these environments, five new commands are defined: |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots| and |\Iddots|.
-% These commands are intended to be used in place of |\dots|, |\cdots|, |\vdots|, |\ddots| and
-% |\iddots|.\footnote{The command |\iddots|, defined in \pkg{nicematrix}, is a variant of
-% |\ddots| with dots going forward: \smash{$\iddots$}. If |mathdots| is loaded, the version of |mathdots| is used.}
+% Inside the environments of the extension \pkg{nicematrix}, new commands are defined: |\Ldots|, |\Cdots|,
+% |\Vdots|, |\Ddots|, and |\Iddots|. These commands are intended to be used in place of |\dots|, |\cdots|,
+% |\vdots|, |\ddots| and |\iddots|.\footnote{The command |\iddots|, defined in \pkg{nicematrix}, is a variant of
+% |\ddots| with dots going forward: \smash{$\iddots$}. If |mathdots| is loaded, the version of |mathdots| is used.
+% It corresponds to the command |\adots| of \pkg{unicode-math}.}
%
% \smallskip
% Each of them must be used alone in the cell of the array and it draws a dotted line between the first non-empty
% cells\footnote{The precise definition of a ``non-empty cell'' is given below.} on both sides of the current cell.
% Of course, for |\Ldots| and |\Cdots|, it's an horizontal line; for |\Vdots|, it's a vertical line and for
-% |\Ddots| and |\Iddots| diagonals ones.\par\nobreak
+% |\Ddots| and |\Iddots| diagonal ones.\par\nobreak
% \bigskip
% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
% \begin{bNiceMatrix}
@@ -268,7 +349,6 @@ version 2005/12/01 or later.
% 0 & \Cdots & & 0
% \end{bNiceMatrix}$
%
-% \vskip1cm
% \subsection{The option nullify-dots}
%
% Consider the following matrix composed classicaly with the environment |{pmatrix}|.\par\nobreak
@@ -366,9 +446,36 @@ version 2005/12/01 or later.
% The option |nullify-dots| smashes the instructions |\Ldots| (and the variants) vertically but also horizontally.
%
%
+% \subsection{The command Hdotsfor}
+%
+% Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to draw horizontal dotted lines in a
+% matrix. In the environments of \pkg{nicematrix}, they should use instead the command |\Hdotsfor| and they will
+% have the same style of dotted lines. We recommand not to use this command in new code since it's more coherent to
+% use exclusively |\Cdots|, |\Vdots|, |\Ddots|, etc. However, it can be useful in adapting existing code,
+% especially when using the option |transparent| (see below).
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=7cm]
+% $\begin{pNiceMatrix}
+% 1 & 2 & 3 & 4 & 5 \\
+% 1 & ~emphase#\Hdotsfor{3}@ & 5 \\
+% 1 & 2 & 3 & 4 & 5 \\
+% 1 & 2 & 3 & 4 & 5 \\
+% \end{pNiceMatrix}$
+% \end{BVerbatim}
+% $\begin{pNiceMatrix}
+% 1 & 2 & 3 & 4 & 5 \\
+% 1 & \Hdotsfor{3} & 5 \\
+% 1 & 2 & 3 & 4 & 5 \\
+% 1 & 2 & 3 & 4 & 5 \\
+% \end{pNiceMatrix}$
+%
+% \medskip
+% The command |\hdotsfor| of \pkg{amsmath} takes an optional argument (between square brackets) which is
+% used for fine tuning of the space beetween two consecutive dots. For homogeneity, the command |\Hdotsfor| has
+% also an optional argument but this argument is discarded silently.
%
-% \vskip1cm
-% \section{How to use nicematrix for existing code}
+% \subsection{How to generate the continuous dotted lines transparently}
%
% The package \pkg{nicematrix} provides an option called |transparent| for using existing code transparently in the
% environments |{matrix}|. This option can be set as option of |\usepackage| or with the command
@@ -381,10 +488,10 @@ version 2005/12/01 or later.
%
% \begin{itemize}
% \item The option |renew-dots|\par\nobreak
-% With this option, the commands |\ldots|, |\cdots|, |\vdots|, |\ddots| and |\iddots|\footnote{The command
+% With this option, the commands |\ldots|, |\cdots|, |\vdots|, |\ddots|, |\iddots|\footnote{The command
% |\iddots| is not a command of LaTeX but is defined by the package \pkg{nicematrix}. If |mathdots| is loaded, the
-% version of |mathdots| is used.} are redefined within the environments provided by \pkg{nicematrix}
-% and behave like |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots| and |\Iddots|; the command |\dots| (``automatic
+% version of |mathdots| is used.} and |\hdotsfor| are redefined within the environments provided by \pkg{nicematrix}
+% and behave like |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| and |\Hdotsfor|; the command |\dots| (``automatic
% dots'' of |amsmath| --- and |mathtools|) is also redefined to behave like |\Ldots|.
%
% \item The option |renew-matrix|\par\nobreak
@@ -395,7 +502,9 @@ version 2005/12/01 or later.
% \bigskip
% Therefore, with the option |transparent|, a classical code gives directly the ouput of \pkg{nicematrix}.\par\nobreak
% \bigskip
-% \begin{BVerbatim}[baseline=c]
+% \begin{scope}
+% \NiceMatrixOptions{transparent}
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
% ~emphase#\NiceMatrixOptions{transparent}@
% \begin{pmatrix}
% 1 & \cdots & \cdots & 1 \\
@@ -404,9 +513,6 @@ version 2005/12/01 or later.
% 0 & \cdots & 0 & 1
% \end{pmatrix}
% \end{BVerbatim}
-% \hspace{2cm}
-% \begin{scope}
-% \NiceMatrixOptions{transparent}
% $\begin{pmatrix}
% 1 & \cdots & \cdots & 1 \\
% 0 & \ddots & & \vdots \\
@@ -415,38 +521,197 @@ version 2005/12/01 or later.
% \end{pmatrix}$
% \end{scope}
%
+% \section{The width of the columns}
+% \label{width}
%
-% \section{The environment \{NiceArray\}}
+% In the environments with an explicit preamble (like |{NiceArray}|, |{pNiceArrayC}|, etc.), It's possible to fix the
+% width of a given column with the standard letters |w| and |W| of the package \pkg{array}.
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
+% $\left(\begin{NiceArray}{~emphase#wc{1cm}@CC}
+% 1 & 12 & -123 \\
+% 12 & 0 & 0 \\
+% 4 & 1 & 2
+% \end{NiceArray}\right)$
+% \end{BVerbatim}
+% $\left(\begin{NiceArray}{wc{1cm}CC}
+% 1 & 12 & -123 \\
+% 12 & 0 & 0 \\
+% 4 & 1 & 2
+% \end{NiceArray}\right)$
+%
+%
+% \bigskip
+% It's also possible to fix the width of all the columns of a matrix directly with the option |columns-width| (in
+% all the environments of \pkg{nicematrix}).
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
+% $\begin{pNiceMatrix}[~emphase#columns-width = 1cm@]
+% 1 & 12 & -123 \\
+% 12 & 0 & 0 \\
+% 4 & 1 & 2
+% \end{pNiceMatrix}$
+% \end{BVerbatim}
+% $\begin{pNiceMatrix}[columns-width = 1cm]
+% 1 & 12 & -123 \\
+% 12 & 0 & 0 \\
+% 4 & 1 & 2
+% \end{pNiceMatrix}$
%
-% In fact, the environment |{NiceMatrix}| relies upon an environment |{NiceArray}| defined in the package
-% \pkg{nicematrix}.
+% \medskip
+% Note that the space inserted between two columns (equal to 2 |\arraycolsep|) is not suppressed.
%
+% \bigskip
+% It's possible to give the value |auto| to the option |columns-width|: all the columns of the array will
+% have a width equal to the widest cell of the array. \textbf{Two or three compilations may be necessary.}\par\nobreak
% \medskip
-% This environment |{NiceArray}| itself relies upon the environment |{array}| of the package \pkg{array}.\footnote{The
-% environment |{array}| is defined in standard LaTeX but is redefined in the package \pkg{array} (loaded by
-% \pkg{nicematrix}).}
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
+% $\begin{pNiceMatrix}[~emphase#columns-width = auto@]
+% 1 & 12 & -123 \\
+% 12 & 0 & 0 \\
+% 4 & 1 & 2
+% \end{pNiceMatrix}$
+% \end{BVerbatim}
+% $\begin{pNiceMatrix}[columns-width = auto]
+% 1 & 12 & -123 \\
+% 12 & 0 & 0 \\
+% 4 & 1 & 2
+% \end{pNiceMatrix}$
%
+% \bigskip
+% It's possible to fix the width of the columns of all the matrices of a current scope with the command
+% |\NiceMatrixOptions|.\par\nobreak
% \medskip
-% The differences between |{NiceArray}| and |{array}| are as follow.
-% \begin{itemize}
-% \item The commands |\Cdots| and its variants are available in the environment |{NiceArray}|.
-% \item The environment |{NiceArray}| accepts (between brackets) the options |t|, |c| and |b| as the classical
-% |{array}| but also the following options defined by \pkg{nicematrix}: |renew-dots|, |nullify-dots|,
-% |columns-width| (explained below), |exterior-arraycolsep| and |parallelize-diags| (these last two options are
-% technical options described further).
-% \item For technical reasons, in the preamble of the environment |{NiceArray}|, the user
-% must use the letters |L|, |C| and~|R|\footnote{The column types |L|, |C| and |R| are defined locally inside
-% |{NiceArray}| with |\newcolumntype| of \pkg{array}. This definition overrides an eventual previous definition.}
-% instead of |l|, |c| and |r|. It's possible to use the constructions \verb|w{...}{...}|, \verb|W{...}{...}|,
-% \verb+|+, |>{...}|, |<{...}|, |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, |m| and |b| should not be used.
-% \end{itemize}
+% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm]
+% ~emphase#\NiceMatrixOptions{columns-width=10mm}@
+% $\begin{pNiceMatrix}
+% a & b \\ c & d \\
+% \end{pNiceMatrix}
+% =
+% \begin{pNiceMatrix}
+% 1 & 1245 \\ 345 & 2 \\
+% \end{pNiceMatrix}$
+% \end{BVerbatim}
+% \begin{scope}
+% \NiceMatrixOptions{columns-width=10mm}
+% $\begin{pNiceMatrix}
+% a & b \\
+% c & d \\
+% \end{pNiceMatrix}
+% =
+% \begin{pNiceMatrix}
+% 1 & 1245 \\
+% 345 & 2 \\
+% \end{pNiceMatrix}$
+% \end{scope}
+%
+%
+% \bigskip
+% But it's also possible to fix a zone where all the matrices will have their columns of the same width, equal to
+% the widest cell of all the matrices. This construction uses the environment |{NiceMatrixBlock}| with the option
+% |auto-columns-width|.\footnote{At this time, this is the only usage of the environment |{NiceMatrixBlock}| but
+% it may have other usages in the future.}
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm]
+% ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@
+% $\begin{pNiceMatrix}
+% a & b \\ c & d \\
+% \end{pNiceMatrix}
+% =
+% \begin{pNiceMatrix}
+% 1 & 1245 \\ 345 & 2 \\
+% \end{pNiceMatrix}$
+% ~emphase#\end{NiceMatrixBlock}@
+% \end{BVerbatim}
+% \begin{NiceMatrixBlock}[auto-columns-width]
+% $\begin{pNiceMatrix}
+% a & b \\ c & d \\
+% \end{pNiceMatrix}
+% =
+% \begin{pNiceMatrix}
+% 1 & 1245 \\ 345 & 2 \\
+% \end{pNiceMatrix}$
+% \end{NiceMatrixBlock}
+%
+%
+% \section{The Tikz nodes created by nicematrix}
+%
+% The package \pkg{nicematrix} creates a Tikz node for each cell of the considered array. These nodes are used to
+% draw the dotted lines between the cells of the matrix. However, the user may wish to use directly these nodes.
+% It's possible. First, the user have to give a name to the matrix (with a key called |name|). Then, the nodes are
+% accessible through the names ``\textsl{name}-$i$-$j$'' where \textsl{name} is the name given to the matrix and
+% $i$ and $j$ the number of the row and the column of the considered cell.
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=11cm]
+% $\begin{pNiceMatrix}[name=~emphase#mymatrix@]
+% 1 & 2 & 3 \\
+% 4 & 5 & 6 \\
+% 7 & 8 & 9 \\
+% \end{pNiceMatrix}$
+% \tikz[remember picture,overlay]
+% \draw ~emphase#(mymatrix-2-2)@ circle (2mm) ;
+% \end{BVerbatim}
+% $\begin{pNiceMatrix}[name=mymatrix]
+% 1 & 2 & 3 \\
+% 4 & 5 & 6 \\
+% 7 & 8 & 9 \\
+% \end{pNiceMatrix}$
+% \tikz[remember picture,overlay]
+% \draw (mymatrix-2-2) circle (2mm) ;
+%
+%
+% \medskip
+% Don't forget the options |remember picture| and |overlay|.
+%
+% \section{The code-after}
+%
+% The option |code-after| may be used to give some code that will be excuted after the construction of the matrix
+% (and, hence, after the construction of all the Tikz nodes).
+%
+% In the |code-after|, the Tikz nodes should be accessed by a name of the form $i$-$j$ (without the prefix of the
+% name of the environment).
+%
+% Morevover, a special command, called |\line| is available to draw directly dotted lines between nodes.
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=12cm]
+% $\begin{pNiceMatrix}[~emphase#code-after = {\line {1-1} {3-3}}@]
+% 0 & 0 & 0 \\
+% 0 & & 0 \\
+% 0 & 0 & 0 \\
+% \end{pNiceMatrix}$
+% \end{BVerbatim}
+% $\begin{pNiceMatrix}[code-after = {\line {1-1} {3-3}}]
+% 0 & 0 & 0 \\
+% 0 & & 0 \\
+% 0 & 0 & 0 \\
+% \end{pNiceMatrix}$
+%
+%
+% \section{The environment \{NiceArray\}}
+% \label{NiceArray}
+%
+% The environment |{NiceArray}| is similar to the environment |{array}|. As for |{array}|, the mandatory argument
+% is the preamble of the array. However, for technical reasons, in this preamble, the user must use the letters
+% |L|, |C| and~|R|\footnote{The column types |L|, |C| and |R| are defined locally inside |{NiceArray}| with
+% |\newcolumntype| of \pkg{array}. This definition overrides an eventual previous definition.} instead of |l|, |c|
+% and |r|. It's possible to use the constructions \verb|w{...}{...}|, \verb|W{...}{...}|, \verb+|+, |>{...}|,
+% |<{...}|, |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, |m| and |b| should not be used.
+%
+% \medskip
+% The environment |{NiceArray}| accepts the classical options |t|, |c| and |b| of |{array}| but also other options
+% defined by \pkg{nicematrix} (|renew-dots|, |columns-width|, etc.).
%
%
% \vspace{1cm}
% An example with a linear system (we need |{NiceArray}| for the vertical rule):
%
% \bigskip
-% \begin{BVerbatim}[baseline=c]
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
% $\left[\begin{NiceArray}{CCCC|C}
% a_1 & ? & \Cdots & ? & ? \\
% 0 & & \Ddots & \Vdots & \Vdots\\
@@ -454,7 +719,6 @@ version 2005/12/01 or later.
% 0 & \Cdots & 0 & a_n & ? \\
% \end{NiceArray}\right]$
% \end{BVerbatim}
-% \hspace{2.5cm}
% $\left[\begin{NiceArray}{CCCC|C}
% a_1 & ? & \Cdots & ? & ? \\
% 0 & & \Ddots & \Vdots & \Vdots\\
@@ -466,7 +730,7 @@ version 2005/12/01 or later.
% An example where we use |{NiceArray}| because we want to use the types |L| and |R| for the columns:
%
% \bigskip
-% \begin{BVerbatim}[baseline=c]
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
% $\left(\begin{NiceArray}{LCR}
% a_{11} & \Cdots & a_{1n} \\
% a_{21} & & a_{2n} \\
@@ -474,7 +738,6 @@ version 2005/12/01 or later.
% a_{n-1,1} & \Cdots & a_{n-1,n} \\
% \end{NiceArray}\right)$
% \end{BVerbatim}
-% \hspace{4cm}
% $\left(\begin{NiceArray}{LCR}
% a_{11} & \Cdots & a_{1n} \\
% a_{21} & & a_{2n} \\
@@ -482,107 +745,25 @@ version 2005/12/01 or later.
% a_{n-1,1} & \Cdots & a_{n-1,n} \\
% \end{NiceArray}\right)$
%
-% \vskip1cm
-% As in the environment |{array}| of the extension \pkg{array}, it's possible to fix the width of a column by using
-% the letter |w| or the letter |W| in the preamble. In the following example, the width of the third column is
-% fixed to 1~cm.\par\nobreak
-% \medskip
-% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
-% $\left(\begin{NiceArray}{CC~emphase#w{c}{1cm}@}
-% 1 & 2 & 3 \\
-% 4 & 5 & 6 \\
-% 7 & 8 & 9
-% \end{NiceArray}\right)$
-% \end{BVerbatim}
-% $\left(\begin{NiceArray}{CCw{c}{1cm}}
-% 1 & 2 & 3 \\
-% 4 & 5 & 6 \\
-% 7 & 8 & 9
-% \end{NiceArray}\right)$
%
-% \bigskip
-% However, the environment |{NiceArray}| and the other environments defined in this extension have an option called
-% |columns-width| which fixes the width of all columns of the matrix.\par\nobreak
-% \medskip
-% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
-% $\begin{pNiceMatrix}[~emphase#columns-width = 1cm@]
-% 1 & 12 & -123 \\
-% 12 & 0 & 0 \\
-% 4 & 1 & 2
-% \end{pNiceMatrix}$
-% \end{BVerbatim}
-% $\begin{pNiceMatrix}[columns-width = 1cm]
-% 1 & 12 & -123 \\
-% 12 & 0 & 0 \\
-% 4 & 1 & 2
-% \end{pNiceMatrix}$
-%
-% \medskip
-% Note that the space inserted between two columns (equal to 2 |\arraycolsep|) is not suppressed.
-%
-% \bigskip
-% It's also possible to give the value |auto| to the option |columns-width|: all the columns of the array will
-% have a width equal to the widest cell of the array. \emph{Two or three compilations may be necessary}.\par\nobreak
-% \medskip
-% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
-% $\begin{pNiceMatrix}[~emphase#columns-width = auto@]
-% 1 & 12 & -123 \\
-% 12 & 0 & 0 \\
-% 4 & 1 & 2
-% \end{pNiceMatrix}$
-% \end{BVerbatim}
-% $\left(\begin{NiceArray}[columns-width = auto]{CCC}
-% 1 & 12 & -123 \\
-% 12 & 0 & 0 \\
-% 4 & 1 & 2
-% \end{NiceArray}\right)$
%
%
% \section{The environment \{pNiceArrayC\} and its variants}
+% \label{pNiceArrayC}
%
-% The package \pkg{nicematrix} provides also environments to compose matrices with an exterior column, that is to
-% say on the right of the closing delimiter. These environments are |{pNiceArrayC}|, |{vNiceArrayC}|,
-% |{VNiceArrayC}|, |{bNiceArrayC}| and |{BNiceArrayC}| (there is no environment |{NiceArrayC}| since such an
-% environment would logically be equivalent to |{NiceArray}|).
-%
-% All these environments have the same characteristics even if, for sake of simplicity, we will speak only of
-% |{pNiceArrayC}|.
+% The environment |{pNiceArrayC}| composes a matrix with an exterior column.
%
-% \medskip
-% \begin{itemize}
-% \item The command |\Cdots| and its variants are available in |{pNiceArrayC}|.
-% \item The environment |{pNiceArrayC}| takes a mandatory argument which is the preamble of the array. The types
-% of columns available are the same as for the environment |{NiceArray}|. \emph{However, no specification must be
-% given for the last column:} it will automatically (and necessarily) be a column~|L|.
-% \item The options available are |columns-width| (doesn't apply to the exterior column), |renew-dots|,
-% |nullify-dots|, |parallelize-diags| (this technical option is described further) and an option specific to these
-% environments, called |code-for-last-col|. This last option specifies tokens that will be inserted before each
-% cell of the last column, \emph{before} the symbol |$| of the math mode.
-% \end{itemize}
+% The environment |{pNiceArrayC}| takes a mandatory argument which is the preamble of the array. The types
+% of columns available are the same as for the environment |{NiceArray}|. \textbf{However, no specification must be
+% given for the last column.} It will automatically (and necessarily) be a column~|L| column.
%
+% A special option, called |code-for-last-col|, specifies tokens that will be inserted before each cell of the last
+% column. The option |columns-width| doesn't apply to this external column.
%
% \bigskip
-% \begin{BVerbatim}[baseline=c]
-% \begin{pNiceArrayC}{RRRR|R}[~emphase#code-for-last-col={\small\color{blue}}@,
-% columns-width=auto]
-% 1& 2& 2& 3& -2 \\
-% 0& 0& -1& 5& -5 & L_2 \gets 2L_1-L_2 \\
-% 0& -1& -3& 3& -7 & L_3 \gets L_1-L_3
-% \end{pNiceArrayC}
-% \end{BVerbatim}
-%
-% \smallskip
-% \[\begin{pNiceArrayC}{RRRR|R}[code-for-last-col={\small\color{blue}},
-% columns-width=auto]
-% 1& 2& 2& 3& -2 \\
-% 0& 0& -1& 5& -5 & L_2 \gets 2L_1-L_2 \\
-% 0& -1& -3& 3& -7 & L_3 \gets L_1-L_3
-% \end{pNiceArrayC}\]
-%
-% \bigskip
%
% \begin{Verbatim}
-% $\begin{pNiceArrayC}{*6C|C}[nullify-dots,code-for-last-col={\small}]
+% $\begin{pNiceArrayC}{*6C|C}[nullify-dots,~emphase#code-for-last-col={\scriptstyle}@]
% 1 & 1 & 1 &\Cdots & & 1 & 0 & \\
% 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\
% 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\
@@ -592,7 +773,7 @@ version 2005/12/01 or later.
% \end{pNiceArrayC}$
% \end{Verbatim}
%
-% \[\begin{pNiceArrayC}{*6C|C}[nullify-dots,code-for-last-col={\small}]
+% \[\begin{pNiceArrayC}{*6C|C}[nullify-dots,code-for-last-col={\scriptstyle}]
% 1 & 1 & 1 &\Cdots & & 1 & 0 & \\
% 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\
% 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\
@@ -601,13 +782,110 @@ version 2005/12/01 or later.
% 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1
% \end{pNiceArrayC}\]
%
+%
+% \bigskip
+% In fact, the environment |{pNiceArrayC}| and its variants are based upon an more general environment, called
+% |{NiceArrayCwithDelims}|. The first two mandatory arguments of this environment are the left and right delimiter
+% used in the construction of the matrix. It's possible to use |{NiceArrayCwithDelims}| if we want to use atypical
+% delimiters.
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=11cm]
+% $\begin{NiceArrayCwithDelims}%
+% {\downarrow}{\downarrow}{CCC}
+% 1 & 2 & 3 & L_1 \\
+% 4 & 5 & 6 & L_2 \\
+% 7 & 8 & 9 & L_3
+% \end{NiceArrayCwithDelims}$
+% \end{BVerbatim}
+% $\begin{NiceArrayCwithDelims}%
+% {\downarrow}{\downarrow}{CCC}
+% 1 & 2 & 3 & L_1 \\
+% 4 & 5 & 6 & L_2 \\
+% 7 & 8 & 9 & L_3
+% \end{NiceArrayCwithDelims}$
+%
+%
+% \section{The environment \{pNiceArrayRC\} and its variants}
+% \label{pNiceArrayRC}
+%
+% The environment |{pNiceArrayRC}| composes a matrix with an exterior row and an exterior column.
+%
+% This environment |{pNiceArrayRC}| takes a mandatory argument which is the preamble of the array. As for the
+% environment |{pNiceArrayC}|, no specification must be given for the last column (it will automatically be a |L|
+% column).
+%
+% For technical reasons, the key |columns-width| is mandatory, with an numerical value (e.g. 1~cm) or with
+% the special value |auto|. This implies that all the columns of an environment |{pNiceArrayRC}| have necessarily
+% the same width.
+%
+% A special option, called |code-for-first-row|, specifies tokens that will be inserted before each cell of the
+% first row.
+%
+% \bigskip
+% \begin{BVerbatim}[baseline=c,boxwidth=11cm]
+% $\begin{pNiceArrayRC}{CCC}%
+% [columns-width = auto,
+% code-for-first-row = {\color{blue}},
+% code-for-last-col = {\color{blue}}]
+% C_1 & C_2 & C_3 \\
+% 1 & 2 & 3 & L_1\\
+% 4 & 5 & 6 & L_2\\
+% 7 & 8 & 9 & L_3\\
+% \end{pNiceArrayRC}$
+% \end{BVerbatim}
+% $\begin{pNiceArrayRC}{CCC}[columns-width=auto,
+% code-for-first-row = {\color{blue}},
+% code-for-last-col = {\color{blue}}]
+% C_1 & C_2 & C_3 \\
+% 1 & 2 & 3 & L_1 \\
+% 4 & 5 & 6 & L_2 \\
+% 7 & 8 & 9 & L_3 \\
+% \end{pNiceArrayRC}$
+%
+%
+% \bigskip
+% For technical reasons, the first line of the array (which will be composed ``above'' the main matrix)
+% must \emph{not} contain the command |\\| and no verbatim material.
+%
+% \bigskip
+% The first row of an environment |{pNiceArrayRC}| has the number $0$, and not $1$. This number is used for the
+% names of the Tikz nodes (the names of these nodes are used, for example, by the command |\line| in |code-after|).
+%
+%
+% \bigskip
+% In fact, the environment |{pNiceArrayRC}| and its variants are based upon an more general environment, called
+% |{NiceArrayRCwithDelims}|. The first two mandatory arguments of this environment are the left and right delimiter
+% used in the construction of the matrix. It's possible to use |{NiceArrayRCwithDelims}| if we want to use atypical
+% delimiters.
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=11cm]
+% $\begin{NiceArrayRCwithDelims}%
+% {\downarrow}{\downarrow}{CCC}[columns-width=auto]
+% C_1 & C_2 & C_3 \\
+% 1 & 2 & 3 \\
+% 4 & 5 & 6 \\
+% 7 & 8 & 9
+% \end{NiceArrayRCwithDelims}$
+% \end{BVerbatim}
+% $\begin{NiceArrayRCwithDelims}%
+% {\downarrow}{\downarrow}{CCC}[columns-width=auto]
+% C_1 & C_2 & C_3 \\
+% 1 & 2 & 3 \\
+% 4 & 5 & 6 \\
+% 7 & 8 & 9
+% \end{NiceArrayRCwithDelims}$
+%
+%
%
% \section{Technical remarks}
%
% \subsection{Diagonal lines}
%
-% By default, all the diagonal lines of a same array are ``parallelized''. That means that the first diagonal line
-% is drawn and, then, the other lines are drawn parallel to the first one (by rotation around the left-most
+% By default, all the diagonal lines\footnote{We speak of the lines created by |\Ddots| and not the lines created
+% by a command |\line| in |code-after|.} of a same array are ``parallelized''. That means that the first diagonal
+% line is drawn and, then, the other lines are drawn parallel to the first one (by rotation around the left-most
% extremity of the line). That's why the position of the instructions |\Ddots| in the array can have a marked
% effect on the final result.
%
@@ -671,11 +949,10 @@ version 2005/12/01 or later.
%
% \end{scope}
%
-% \vskip1cm
% \subsection{The ``empty'' cells}
%
% An instruction like |\Ldots|, |\Cdots|, etc. tries to determine the first non-empty cell on both
-% sides\footnote{If \pkg{nicematrix} can't find theses cells, an error |Imposible instruction| is raised. Nevertheless,
+% sides\footnote{If \pkg{nicematrix} can't find these cells, an error |Imposible instruction| is raised. Nevertheless,
% with the option |silent|, these instructions are discarded silently.}. However, a empty cell is not necessarily a
% cell with no TeX content (that is to say a cell with no token between the two ampersands~|&|). Indeed, a cell
% with contents |\hspace*{1cm}| may be considered as empty.
@@ -713,10 +990,9 @@ version 2005/12/01 or later.
% A dotted line must be delimited by two non-empty cells. If it's not possible to find one of these cells whitin
% the boundaries of the matrix, an error is issued and the instruction is ignored.
%
-% \vspace{1cm}
% \subsection{The option exterior-arraycolsep}
%
-% The environment |{array}| inserts un horizontal space equal to |\arraycolsep| before and after each column. In
+% The environment |{array}| inserts an horizontal space equal to |\arraycolsep| before and after each column. In
% particular, there is a space equal to |\arraycolsep| before and after the array. This feature of the environment
% |{array}| was probably not a good idea.\footnote{In the documentation of |{amsmath}|, we can read: {\itshape The
% extra space of |\arraycolsep| that \pkg{array} adds on each side is a waste so we remove it [in |{matrix}|]
@@ -728,8 +1004,7 @@ version 2005/12/01 or later.
%
% However, the user can change this behaviour with the boolean option |exterior-arraycolsep|. With this option,
% |{NiceArray}| will insert the same horizontal spaces as the environment |{array}|. This
-% option can be set as an option of an environment |{NiceArray}| (between square brackets) or with the command
-% |\NiceMatrixOptions|.
+% option can be set for a given environment or globally with the command |\NiceMatrixOptions|.
%
%
% \section{Examples}
@@ -804,11 +1079,168 @@ version 2005/12/01 or later.
% 1 & 0 & \Cdots & 0
% \end{pNiceMatrix}$
%
+% \vspace{2cm}
%
+% An example for the resultant of two polynoms :
%
+% \bigskip
+% \begin{BVerbatim}
+% \setlength{\extrarowheight}{1mm}
+% \[\begin{vNiceMatrix}[columns-width=6mm]
+% a_0 & && &b_0 & & \\
+% a_1 &\Ddots && &b_1 &\Ddots & \\
+% \Vdots &\Ddots && &\Vdots &\Ddots &b_0 \\
+% a_p & &&a_0 & & &b_1 \\
+% &\Ddots &&a_1 &b_q & &\Vdots\\
+% & &&\Vdots & &\Ddots & \\
+% & &&a_p & & &b_q \\
+% \end{vNiceMatrix}\]
+% \end{BVerbatim}
%
-% \vspace{1cm}
+% \bigskip
+%
+% \begin{scope}
+% \setlength{\extrarowheight}{1mm}
+% \[\begin{vNiceMatrix}[columns-width=6mm]
+% a_0 & && &b_0 & & \\
+% a_1 &\Ddots&& &b_1 &\Ddots& \\
+% \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\
+% a_p & &&a_0 & & &b_1 \\
+% &\Ddots&&a_1 &b_q & &\Vdots\\
+% & &&\Vdots & &\Ddots& \\
+% & &&a_p & & &b_q \\
+% \end{vNiceMatrix}\]
+% \end{scope}
+%
+%
+% \vspace{2cm}
+% In the following example, we use the environment |{NiceMatrixBlock}| with the option |auto-columns-width| because
+% we want the same automatic width for all the columns of the matrices.
+%
+% \bigskip
+% \begin{BVerbatim}
+% ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@
+% \NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle}
+% \setlength{\extrarowheight}{1mm}
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 2&4&8&16&9&\\
+% 3&9&27&81&36&\\
+% 4&16&64&256&100&\\
+% \end{pNiceArrayC}$
+% ...
+% ~emphase#\end{NiceMatrixBlock}@
+% \end{BVerbatim}
+%
+% \bigskip
+%
+% \begin{multicols}{2}
+% \begin{NiceMatrixBlock}[auto-columns-width]
+% \NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle}
+% \setlength{\extrarowheight}{1mm}
+%
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 2&4&8&16&9&\\
+% 3&9&27&81&36&\\
+% 4&16&64&256&100&\\
+% \end{pNiceArrayC}$
+%
+% \medskip
+%
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 0&2&6&14&7&L_2\gets-2L_1+L_2 \\
+% 0&6&24&78&33&L_3\gets-3L_1+L_3 \\
+% 0&12&60&252&96&L_4\gets-4L_1+L_4 \\
+% \end{pNiceArrayC}$
+%
+% \medskip
+%
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 0&1&3&7&\frac72&L_2\gets\frac12L_2\\
+% 0&3&12&39&\frac{33}2&L_3\gets\frac12L_3 \\
+% 0&1&5&21&8&L_4\gets\frac1{12}L_4 \\
+% \end{pNiceArrayC}$
+%
+% \medskip
+%
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 0&1&3&7&\frac72&\\
+% 0&0&3&18&6&L_3 \gets -3L_2+L_3 \\
+% 0&0&-2&-14&-\frac92&L_4 \gets L_2-L_4 \\
+% \end{pNiceArrayC}$
+%
+% \medskip
+%
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 0&1&3&7&\frac72&\\
+% 0&0&1&6&2&L_3 \gets \frac13L_3\\
+% 0&0&-2&-14&-\frac92&\\
+% \end{pNiceArrayC}$
+%
+% \medskip
+%
+% \quad $\begin{pNiceArrayC}{CCCC|C}
+% 1&1&1&1&1&\\
+% 0&1&3&7&\frac72&\\
+% 0&0&1&6&2& \\
+% 0&0&0&-2&-\frac12 & L_4 \gets 2L_3+L_4 \\
+% \end{pNiceArrayC}$
+% \end{NiceMatrixBlock}
+% \end{multicols}
+%
+% \vspace{2cm}
+%
+% In the following example, we want to highlight a row of the matrix. To do so, we create a rectangular Tikz node
+% which encompasses the nodes of the second row with the Tikz library |fit|. This Tikz node is filled
+% after the construction of the matrix. In order to see the text \emph{under} this node, we have to use
+% transparency with the |blend mode| equal to |multiply|.
+%
+% \medskip
+% \begin{Verbatim}
+% \tikzset{highlight/.style={rectangle,
+% fill=red!15,
+% ~emphase#blend mode = multiply@,
+% inner sep=1pt}}
+%
+% $\begin{pNiceMatrix}[~emphase#code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}@]
+% 0 & \Cdots & 0 \\
+% 1 & \Cdots & 1 \\
+% 0 & \Cdots & 0 \\
+% \end{pNiceMatrix}$
+% \end{Verbatim}
+%
+% \[\begin{pNiceMatrix}[code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}]
+% 0 & \Cdots & 0 \\
+% 1 & \Cdots & 1 \\
+% 0 & \Cdots & 0 \\
+% \end{pNiceMatrix}\]
+%
+%
+% \bigskip
+% This code fails with |latex|-|dvips|-|ps2pdf| because Tikz for |dvips|, as for now, doesn't support blend modes. However, the
+% following code, in the preamble, should activate blend modes in this way of compilation.
+%
+%
+%
+% |\ExplSyntaxOn|
+%
+% |\makeatletter|
+%
+% |\tl_set:Nn \l_tmpa_tl {pgfsys-dvips.def}|
+%
+% |\tl_if_eq:NNT \l_tmpa_tl \pgfsysdriver|
+%
+% | {\cs_set:Npn\pgfsys@blend@mode#1{\special{ps:~/\tl_upper_case:n #1~.setblendmode}}}|
+%
+% |\makeatother|
%
+% |\ExplSyntaxOff|
+%
% \section{Implementation}
%
% By default, the package \pkg{nicematrix} doesn't patch any existing code.
@@ -820,16 +1252,18 @@ version 2005/12/01 or later.
% redefined.
%
% \smallskip
-% On the other hand, the environnement |{array}| is never redefined.
+% On the other hand, the environment |{array}| is never redefined.
%
% \smallskip
% Of course, the package \pkg{nicematrix} uses the features of the package \pkg{array}. It tries to be independant of its
% implementation. Unfortunately, it was not possible to be strictly independant: the package \pkg{nicematrix} relies upon the
% fact that the package |{array}| uses |\ialign| to begin the |\halign|.
+%
+% \smallskip
+% The desire to do no modification to existing code leads to complications in the code of this extension.
%
% \subsection{Declaration of the package and extensions loaded}
%
-% \bigskip
% We give the traditionnal declaration of a package written with |expl3|:
% \begin{macrocode}
\RequirePackage{l3keys2e}
@@ -857,9 +1291,7 @@ version 2005/12/01 or later.
\RequirePackage{xparse}
% \end{macrocode}
%
-% \bigskip
% \subsection{Technical definitions}
-%
%
% First, we define a command |\iddots| similar to |\ddots| ($\ddots$) but with dots going forward ($\iddots$). We
% use |\ProvideDocumentCommand| of \pkg{xparse}, and so, if the command |\iddots| has already been defined (for
@@ -881,9 +1313,9 @@ version 2005/12/01 or later.
%
% \bigskip
% In the environment |{NiceMatrix}|, the command |\multicolumn| will be linked to the following command
-% |\@@_multicolumn:| but only if the option |renew-matrix| is not set. Indeed, if the option |renew-matrix| is used,
-% we want to let the possibility to the user to use |\multicolumn| (or |\hdotsfor| of \pkg{amsmath}) in some
-% matrices without dotted lines and to have the automatic dotted lines of \pkg{nicematrix} in other matrices.
+% |\@@_multicolumn:nn| but only if the option |renew-matrix| is not set. Indeed, if the option |renew-matrix| is used,
+% we want to let the possibility to the user to use |\multicolumn| in some matrices without dotted lines and to
+% have the automatic dotted lines of \pkg{nicematrix} in other matrices.
% \begin{macrocode}
\cs_new_protected:Nn \@@_multicolumn:nn
{\msg_error:nn {nicematrix} {Multicolumn~forbidden}}
@@ -904,10 +1336,41 @@ version 2005/12/01 or later.
% \begin{macrocode}
\dim_new:N \l_@@_columns_width_dim
% \end{macrocode}
+%
+% \bigskip
+% The sequence |\g_@@_names_seq| will be the list of all the names of environments used (via the option |name|) in
+% the document : two environments must not have the same name.
+% \begin{macrocode}
+\seq_new:N \g_@@_names_seq
+% \end{macrocode}
+%
+% \bigskip
+% The integer |\l_@@_number_of_first_row_int| is the number of the first row of the array. With a value of $0$ (the
+% default), the first row of the array will have the number~$1$. Within the environment |{NiceArrayRC}|, we will give
+% the value $-1$ to |\l_@@_number_of_first_row_int| and, therefore, the first row of the array will have the number~$0$.
+% \begin{macrocode}
+\int_new:N \l_@@_number_of_first_row_int
+% \end{macrocode}
+%
% \bigskip
+% The flag |\l_@@_direct_NiceArray_bool| will indicate if the current environment |{NiceArray}| is ``direct'' : that
+% means that it is not encompassed in another environment of the extension \pkg{nicematrix} like |{NiceMatrix}| or
+% |{pNiceArrayC}|.
+% \begin{macrocode}
+\bool_new:N \l_@@_direct_NiceArray_bool
+\bool_set_true:N \l_@@_direct_NiceArray_bool
+% \end{macrocode}
+%
+% \bigskip
+% The token list |\l_@@_code_for_cell_tl| is a code that will be inserted in the beginning of each cell of the
+% array (before the symbol |$| of the mathematical mode).
+% \begin{macrocode}
+\tl_new:N \l_@@_code_for_cell_tl
+% \end{macrocode}
+%
% \subsection{The options}
%
-% The token list |\l_@@_pos_env_tl| will contains one of the three values |t|, |c| or |b| and will indicate to
+% The token list |\l_@@_pos_env_tl| will contain one of the three values |t|, |c| or |b| and will indicate the
% position of the environment as in the option of the environment |{array}|. For the environment |{NiceMatrix}|
% (and its variants) and |{pNiceArrayC}| (and its variants), the value will programmatically be fixed to |c|. For the
% environment |{NiceArray}|, however, the three values |t|, |c| and |b| are possible.
@@ -918,7 +1381,7 @@ version 2005/12/01 or later.
%
% The boolean |\l_@@_exterior_arraycolsep_bool| corresponds to the option |exterior-arraycolsep|. If this option is
% set, a space equal to |\arraycolsep| will be put on both sides of an environment |{NiceArray}| (but neither for
-% |{NiceMatrix}| and its variants nor |{pNiceArrayC}| and its variants even if these environments relies upon |{NiceArray}|).
+% |{NiceMatrix}|, |{pNiceArrayC}|, |{pNiceArrayRC}| and their variants even if these environments rely upon |{NiceArray}|).
% \begin{macrocode}
\bool_new:N \l_@@_exterior_arraycolsep_bool
% \end{macrocode}
@@ -954,13 +1417,22 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
-% The token list |\l_@@_code_for_last_col_tl| will contains code inserted at the beginning of each cell\footnote{At
-% the beginning of each cell but before the character |$| of the mathematical mode.} of the last
+% The token list |\l_@@_code_for_last_col_tl| will contain code inserted at the beginning of each cell of the last
% column in the environment |{pNiceArrayC}| (and its variants). It corresponds to the option |code-for-last-col|.
% \begin{macrocode}
\tl_new:N \l_@@_code_for_last_col_tl
% \end{macrocode}
%
+
+% \bigskip
+% The token list |\g_@@_name_tl| will contain the optional name of the environment : this name can be used to
+% access to the Tikz nodes created in the array from outside the environment. This variable is global for technical
+% reasons (some commands will be executed in an |\aftergroup| because we don't want to patch the commands of the
+% package \pkg{array}).
+% \begin{macrocode}
+\tl_new:N \g_@@_name_tl
+% \end{macrocode}
+%
% \bigskip
% We define a set of options which will be used with the command |NiceMatrixOptions|.\footnote{Before the version
% 1.3, the names of the options were in ``caml style'' (like |ParallelizeDiagonals|) which was not a good idea. In
@@ -1018,7 +1490,7 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
-% The following option is only for the environment |{pNiceArrayC}| and its variants. It will contains code inserted
+% The following option is only for the environment |{pNiceArrayC}| and its variants. It will contain code inserted
% at the beginning of each cell of the last column.\footnote{In an environment |{pNiceArrayC}|, the last column is
% composed outside the parentheses of the array.}
% \begin{macrocode}
@@ -1032,6 +1504,20 @@ version 2005/12/01 or later.
% \begin{macrocode}
exterior-arraycolsep .bool_set:N = \l_@@_exterior_arraycolsep_bool ,
exterior-arraycolsep .default:n = true,
+% \end{macrocode}
+%
+% \bigskip
+% If the option |columns-width| is used, all the columns will have the same width. In |\NiceMatrixOptions|, the
+% special value |auto| is not available.
+% \begin{macrocode}
+ columns-width .code:n = \str_if_eq:nnTF {#1} {auto}
+ {\msg_error:nn {nicematrix}
+ {Option~auto~for~columns-width}}
+ {\dim_set:Nn \l_@@_columns_width_dim {#1}},
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
unknown .code:n = \msg_error:nn {nicematrix} {Unknown~key~for~NiceMatrixOptions}}
% \end{macrocode}
%
@@ -1051,6 +1537,13 @@ version 2005/12/01 or later.
renew-matrix~
and~transparent}
% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnn {nicematrix}
+ {Option~auto~for~columns-width}
+ {You~can't~give~the~value~"auto"~to~the~option~"columns-width"~here.~
+ If~you~go~on,~the~option~will~be~ignored.}
+% \end{macrocode}
%
% \bigskip
% |\NiceMatrixOptions| is the command of the \pkg{nicematrix} package to fix options at the document level. The
@@ -1078,6 +1571,20 @@ version 2005/12/01 or later.
{\bool_set_true:N
\l_@@_auto_columns_width_bool}
{\dim_set:Nn \l_@@_columns_width_dim {#1}},
+ name .code:n = {\seq_if_in:NnTF \g_@@_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g_@@_names_seq {#1}}
+ \tl_gset:Nn \g_@@_name_tl {#1}},
+ name .value_required:n = true,
+% \end{macrocode}
+% Since we don't want to modify or patch any existing code, the ``code after'' will be inserted with an
+% |\aftergroup|. Thus, we can't use a local variable for the ``code after'' and that's why we use a global variable.
+% \begin{macrocode}
+ code-after .tl_gset:N = \g_@@_code_after_tl,
+ code-after .initial:n = \c_empty_tl,
+ code-after .value_required:n = true,
unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceMatrix}}
% \end{macrocode}
%
@@ -1089,7 +1596,9 @@ version 2005/12/01 or later.
If~you~go~on,~it~will~be~ignored.\\
For~a~list~of~the~available~options,~type~H~<return>.}
{The~available~options~are~(in~alphabetic~order):~
+ code-after,~
columns-width,~
+ name,~
nullify-dots,~
parallelize-diags~
and~renew-dots.}
@@ -1110,15 +1619,25 @@ version 2005/12/01 or later.
{\bool_set_true:N \l_@@_auto_columns_width_bool}
{\dim_set:Nn \l_@@_columns_width_dim {#1}},
columns-width .value_required:n = true,
+ name .code:n = {\seq_if_in:NnTF \g_@@_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g_@@_names_seq {#1}}
+ \tl_gset:Nn \g_@@_name_tl {#1}},
+ name .value_required:n = true,
% \end{macrocode}
%
% \bigskip
% The options |c|, |t| and |b| of the environment |{NiceArray}| have the same meaning as the option of the classical
% environment |{array}|.
% \begin{macrocode}
- c .code:n = \tl_set:Nn \l_@@_pos_env_tl c,
- t .code:n = \tl_set:Nn \l_@@_pos_env_tl t,
- b .code:n = \tl_set:Nn \l_@@_pos_env_tl b,
+ c .code:n = \tl_set:Nn \l_@@_pos_env_tl c,
+ t .code:n = \tl_set:Nn \l_@@_pos_env_tl t,
+ b .code:n = \tl_set:Nn \l_@@_pos_env_tl b,
+ code-after .tl_gset:N = \g_@@_code_after_tl,
+ code-after .initial:n = \c_empty_tl,
+ code-after .value_required:n = true,
unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArray}}
% \end{macrocode}
%
@@ -1132,15 +1651,16 @@ version 2005/12/01 or later.
{The~available~options~are~(in~alphabetic~order):~
b,~
c,~
+ code-after,~
columns-width,~
exterior-arraycolsep,~
+ name,~
nullify-dots,~
parallelize-diags,~
renew-dots~
and~t.}
% \end{macrocode}
%
-% \bigskip
% \subsection{The environments \{NiceArray\} and \{NiceMatrix\}}
%
% The pseudo-environment |\@@_Cell:n|--|\@@_end_Cell:| will be used to format the cells of the array. In the code,
@@ -1157,7 +1677,8 @@ version 2005/12/01 or later.
% We increment |\g_@@_column_int|, which is the counter of the columns.
% \begin{macrocode}
\int_gincr:N \g_@@_column_int
- \hbox_set:Nw \l_tmpa_box $} % $
+ \hbox_set:Nw \l_tmpa_box $ % $
+ \l_@@_code_for_cell_tl }
% \end{macrocode}
%
% \begin{macrocode}
@@ -1165,15 +1686,26 @@ version 2005/12/01 or later.
{$ % $
\hbox_set_end:
% \end{macrocode}
+%
% We want to compute in |\l_@@_max_cell_width_dim| the width of the widest cell of the array (except the cells of
% the last column of an environment of the kind of |{pNiceArrayC}|).
% \begin{macrocode}
\dim_gset:Nn \g_@@_max_cell_width_dim
{\dim_max:nn \g_@@_max_cell_width_dim {\box_wd:N \l_tmpa_box}}
- \tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
- \node [anchor=base] (nm-\int_use:N \g_@@_env_int-
- \int_use:N \g_@@_row_int-
- \int_use:N \g_@@_column_int)
+ \tl_if_empty:NTF \g_@@_name_tl
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor = base,
+ name = nm-\int_use:N \g_@@_env_int-
+ \int_use:N \g_@@_row_int-
+ \int_use:N \g_@@_column_int] }
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor = base,
+ name = nm-\int_use:N \g_@@_env_int-
+ \int_use:N \g_@@_row_int-
+ \int_use:N \g_@@_column_int,
+ alias = \tl_use:N \g_@@_name_tl-
+ \int_use:N \g_@@_row_int-
+ \int_use:N \g_@@_column_int] }
\bgroup
\box_use:N \l_tmpa_box
\egroup ;}
@@ -1200,7 +1732,9 @@ version 2005/12/01 or later.
% Here's the definition of |{NiceMatrix}|:
% \begin{macrocode}
\NewDocumentEnvironment {NiceMatrix} {O{}}
- {\keys_set:nn {NiceMatrix/NiceMatrix} {#1}
+ {\bool_set_false:N \l_@@_direct_NiceArray_bool
+ \tl_gclear:N \g_@@_code_after_tl
+ \keys_set:nn {NiceMatrix/NiceMatrix} {#1}
\tl_set:Nn \l_@@_pos_env_tl c
\bool_set_false:N \l_@@_exterior_arraycolsep_bool
\NiceArray{*\c@MaxMatrixCols{C}}
@@ -1212,22 +1746,38 @@ version 2005/12/01 or later.
% \interitem
% For the definition of |{NiceArray}| (just below), we have the following constraints:
% \begin{itemize}
-% \item we must use |\array| in the first part of |{NiceArray}| and, therefore, |\endarray| in the second part ;
+% \item we must use |\array| in the first part of |{NiceArray}| and, therefore, |\endarray| in the second part;
% \item we have to put a |\aftergroup \@@_draw_lines:| in the first part of |{NiceArray}| so that |\@@_draw_lines|
% will be executed at the end of the current environment (either |{NiceArray}| or |{NiceMatrix}|).
% \end{itemize}
%
% \begin{macrocode}
\cs_generate_variant:Nn \dim_set:Nn {Nx}
+% \end{macrocode}
+%
+% \bigskip
+% First, we test if we are yet in an environment |{NiceArray}| (nested environment are forbidden). It's easy to
+% test whether we are in an environment |{NiceArray}| : a special command |\@@_in_NiceArray:| is defined.
+% \begin{macrocode}
\NewDocumentEnvironment {NiceArray} {O{} m O{}}
- {\aftergroup \@@_write_max_cell_width:
+ {\cs_if_exist:NT \@@_in_NiceArray:
+ {\msg_error:nn {nicematrix} {We~are~yet~in~an~environment~NiceArray}}
+ \cs_set:Npn \@@_in_NiceArray: {--Void--}
\aftergroup \@@_draw_lines:
% \end{macrocode}
%
% We increment the counter |\g_@@_env_int| which counts the environments |{NiceArray}|.
% \begin{macrocode}
\int_gincr:N \g_@@_env_int
- \dim_gzero_new:N \g_@@_max_cell_width_dim
+ \bool_if:NF \l_@@_block_auto_columns_width_bool
+ {\dim_gzero_new:N \g_@@_max_cell_width_dim}
+% \end{macrocode}
+% Maybe, an encompassing environment |{NiceMatrix}| or |{pNiceArrayC}| (for example) has already set the value for
+% |\g_@@_code_after_tl| (via the option |code-after|) and we don't want to erase this value. Thanks to the flag
+% |\l_@@_direct_NiceArray_bool|, it's possible.
+% \begin{macrocode}
+ \bool_if:NT \l_@@_direct_NiceArray_bool
+ {\tl_gclear:N \g_@@_code_after_tl}
\keys_set:nn {NiceMatrix/NiceArray} {#1,#3}
% \end{macrocode}
%
@@ -1236,10 +1786,21 @@ version 2005/12/01 or later.
% |\l_@@_columns_width_dim| will be set to zero --- and the columns will have their natural width).
% \begin{macrocode}
\bool_if:NT \l_@@_auto_columns_width_bool
- {\cs_if_free:cTF {_@@_max_cell_width_\int_use:N \g_@@_env_int}
- {\dim_set:Nn \l_@@_columns_width_dim \c_zero_dim}
- {\dim_set:Nx \l_@@_columns_width_dim
- {\use:c {_@@_max_cell_width_\int_use:N \g_@@_env_int}}}}
+ {\aftergroup \@@_write_max_cell_width:
+ \cs_if_free:cTF {_@@_max_cell_width_\int_use:N \g_@@_env_int}
+ {\dim_set:Nn \l_@@_columns_width_dim \c_zero_dim}
+ {\dim_set:Nx \l_@@_columns_width_dim
+ {\use:c {_@@_max_cell_width_\int_use:N \g_@@_env_int}}}
+% \end{macrocode}
+% If the environment has a name, we read the value of the maximal value of the columns from
+% |_@@_name_cell_width|{\ttfamily\slshape name} (the value will be the correct value even if the number of the
+% environment has changed (for example because the user has created or deleted an environment before the current one).
+% \begin{macrocode}
+ \tl_if_empty:NF \g_@@_name_tl
+ {\cs_if_free:cF {_@@_max_cell_width_\g_@@_name_tl}
+ {\dim_set:Nx \l_@@_columns_width_dim
+ {\use:c {_@@_max_cell_width_\g_@@_name_tl}}}}
+ }
% \end{macrocode}
% The environment |{array}| uses internally the command |\ialign| and, in particular, this command |\ialign| sets
% |\everycr| to |{}|. However, we want to use |\everycr| in our array (in particular to increment |\g_@@_row_int|).
@@ -1320,12 +1881,14 @@ version 2005/12/01 or later.
\cs_set_eq:NN \Iddots \@@_Iddots
\cs_set_eq:NN \Hspace \@@_Hspace:
\cs_set_eq:NN \NiceMatrixEndPoint \@@_NiceMatrixEndPoint:
+ \cs_set_eq:NN \Hdotsfor \@@_Hdotsfor
\bool_if:NT \l_@@_renew_dots_bool
{\cs_set_eq:NN \ldots \@@_Ldots
\cs_set_eq:NN \cdots \@@_Cdots
\cs_set_eq:NN \vdots \@@_Vdots
\cs_set_eq:NN \ddots \@@_Ddots
- \cs_set_eq:NN \iddots \@@_Iddots}
+ \cs_set_eq:NN \iddots \@@_Iddots
+ \cs_set_eq:NN \hdotsfor \@@_Hdotsfor}
\bool_if:NF \l_@@_renew_matrix_bool
{\cs_set_eq:NN \multicolumn \@@_multicolumn:nn}
% \end{macrocode}
@@ -1340,7 +1903,7 @@ version 2005/12/01 or later.
\tl_clear_new:N \g_@@_preamble_aux_tl
% \end{macrocode}
%
-% The sequence |\g_@@_empty_cells_seq| will contains a list of ``empty'' cells (not all the empty cells of the
+% The sequence |\g_@@_empty_cells_seq| will contain a list of ``empty'' cells (not all the empty cells of the
% matrix). If we want to indicate that the cell in row~$i$ and column~$j$ must be considered as empty, the token
% list ``|i-j|'' will be put in this sequence.
% \begin{macrocode}
@@ -1356,6 +1919,7 @@ version 2005/12/01 or later.
% |\everycr|). At the end of the environment |{array}|, this counter will give the total number of rows of the matrix.
% \begin{macrocode}
\int_gzero_new:N \g_@@_row_int
+ \int_gset_eq:NN \g_@@_row_int \l_@@_number_of_first_row_int
% \end{macrocode}
%
% The counter |\g_@@_column_int| will be used to count the columns of the array (it will be set to zero in
@@ -1422,26 +1986,34 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \interitem
-% For the option \verb|columns-width=auto|, we want to known the maximal width of the cells of the array (except
+% For the option \verb|columns-width=auto| (or the option |auto-columns-width| of the environment
+% |{NiceMatrixBlock}|), we want to know the maximal width of the cells of the array (except
% the cells of the ``exterior'' column of an environment of the kind of |{pNiceAccayC}|). This length can be known
-% only after the end of the construction of the array: that's why we store this value in the main |.aux| file and
-% it will be available in the next run.
+% only after the end of the construction of the array (or at the end of the environment |{NiceMatrixBlock}|).
+% That's why we store this value in the main |.aux| file and it will be available in the next run. We write a
+% dedicated command for this because it will be called in a~|\aftergroup|.
+% \begin{macrocode}
+\cs_new_protected:Nn \@@_write_max_cell_width:
+ {\bool_if:NF \l_@@_block_auto_columns_width_bool
+ {\iow_now:Nn \@mainaux {\ExplSyntaxOn}
+ \iow_now:Nx \@mainaux {\cs_gset:cpn {_@@_max_cell_width_\int_use:N \g_@@_env_int}
+ {\dim_use:N \g_@@_max_cell_width_dim} }
+% \end{macrocode}
+% If the environment has a name, we also create an alias named |\_@@_max_cell_width_|{\ttfamily\slshape name}.
% \begin{macrocode}
-\cs_new:Nn \@@_write_max_cell_width:
- {\iow_now:Nx \@mainaux
- {\ExplSyntaxOn
- \cs_gset:cpn {_@@_max_cell_width_\int_use:N \g_@@_env_int}
- {\dim_use:N \g_@@_max_cell_width_dim}
- \ExplSyntaxOff}}
+ \iow_now:Nx \@mainaux {\cs_gset:cpn {_@@_max_cell_width_\g_@@_name_tl}
+ {\dim_use:N \g_@@_max_cell_width_dim} }
+ \iow_now:Nn \@mainaux {\ExplSyntaxOff}}
+ \tl_gclear:N \g_@@_name_tl}
% \end{macrocode}
%
% \interitem
-% The conditionnal |\@@_if_not_empty_cell:nnT| test wether a cell is empty. The first two arguments must be LaTeX3
+% The conditionnal |\@@_if_not_empty_cell:nnT| tests wether a cell is empty. The first two arguments must be LaTeX3
% counters for the row and the column of the considered cell.
% \begin{macrocode}
\prg_set_conditional:Npnn \@@_if_not_empty_cell:nn #1#2 {T}
% \end{macrocode}
-% If the cell is a implicit cell (that is after the symbol |\\| of end of row), the cell must, of course, be
+% If the cell is an implicit cell (that is after the symbol |\\| of end of row), the cell must, of course, be
% considered as empty. It's easy to check wether we are in this situation considering the correspondant Tikz node.
% \begin{macrocode}
{\cs_if_exist:cTF {pgf@sh@ns@nm-\int_use:N \g_@@_env_int-
@@ -1515,9 +2087,8 @@ version 2005/12/01 or later.
% \end{macrocode}
%
%
-% \bigskip
% \subsection{We draw the lines in the matrix}
-
+%
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_lines:
{
@@ -1558,7 +2129,7 @@ version 2005/12/01 or later.
\int_zero_new:N \l_@@_iddots_int
% \end{macrocode}
%
-% The dimensions |\l_@@_delta_x_one_dim| and |\l_@@_delta_y_one_dim| will contains the $\Delta_x$ and $\Delta_y$ of the
+% The dimensions |\l_@@_delta_x_one_dim| and |\l_@@_delta_y_one_dim| will contain the $\Delta_x$ and $\Delta_y$ of the
% first |\Ddots| diagonal. We have to store these values in order to draw the others |\Ddots| diagonals parallel to
% the first one. Similarly |\l_@@_delta_x_two_dim| and |\l_@@_delta_y_two_dim| are the $\Delta_x$ and $\Delta_y$ of
% the first |\Iddots| diagonal.
@@ -1643,7 +2214,7 @@ version 2005/12/01 or later.
% \end{macrocode}
% We test if we are still in the matrix.
% \begin{macrocode}
- \bool_if:nTF { \int_compare_p:nNn \l_@@_final_i_int < 1
+ \bool_if:nTF { \int_compare_p:nNn \l_@@_final_i_int < \l_@@_number_of_first_row_int
|| \int_compare_p:nNn \l_@@_final_i_int > \g_@@_row_int
|| \int_compare_p:nNn \l_@@_final_j_int < 1
|| \int_compare_p:nNn \l_@@_final_j_int > \g_@@_column_int}
@@ -1678,7 +2249,7 @@ version 2005/12/01 or later.
{\int_sub:Nn \l_@@_initial_i_int \l_@@_di_int
\int_sub:Nn \l_@@_initial_j_int \l_@@_dj_int
\bool_if:nTF
- { \int_compare_p:nNn \l_@@_initial_i_int < 1
+ { \int_compare_p:nNn \l_@@_initial_i_int < \l_@@_number_of_first_row_int
|| \int_compare_p:nNn \l_@@_initial_i_int > \g_@@_row_int
|| \int_compare_p:nNn \l_@@_initial_j_int < 1
|| \int_compare_p:nNn \l_@@_initial_j_int > \g_@@_column_int}
@@ -1739,13 +2310,20 @@ version 2005/12/01 or later.
% \begin{macrocode}
\int_incr:N \l_@@_instruction_int
}
+ \group_begin:
+ \tikzset{every~picture/.style = {overlay,
+ remember~picture,
+ name~prefix = nm-\int_use:N \g_@@_env_int-}}
+ \cs_set_eq:NN \line \@@_line:nn
+ \g_@@_code_after_tl
+ \group_end:
}
% \end{macrocode}
%
%
% \interitem
% The command |\@@_retrieve_coords:nn| retrieves the Tikz coordinates of the two extremities of the dotted line we
-% will have to draw \footnote{In fact, with diagonals lines, or vertical lines in columns of type |L| or |R|, a
+% will have to draw \footnote{In fact, with diagonal lines, or vertical lines in columns of type |L| or |R|, an
% adjustment of one of the coordinates may be done.}. This command has four implicit arguments which are
% |\l_@@_initial_i_int|, |\l_@@_initial_j_int|, |\l_@@_final_i_int| and |\l_@@_final_j_int|.
%
@@ -1801,21 +2379,17 @@ version 2005/12/01 or later.
% \begin{macrocode}
\tl_set:Nx \l_tmpa_tl {\tl_item:Nn \g_@@_preamble_tl \l_@@_initial_j_int}
% \end{macrocode}
-% If the column is of type |l|, we will draw the dotted on the left-most abscissa.
+% If the column is of type |l|, we will draw the dotted line on the left-most abscissa.
% \begin{macrocode}
- \tl_set:Nn \l_tmpb_tl {l}
- \tl_if_eq:NNT \l_tmpa_tl \l_tmpb_tl
- {\dim_set:Nn \l_tmpa_dim {\dim_min:nn \g_@@_x_initial_dim \g_@@_x_final_dim}
- \dim_set_eq:NN \g_@@_x_initial_dim \l_tmpa_dim
- \dim_set_eq:NN \g_@@_x_final_dim \l_tmpa_dim}
+ \str_if_eq:VnT \l_tmpa_tl {l}
+ {\dim_set:Nn \g_@@_x_initial_dim {\dim_min:nn \g_@@_x_initial_dim \g_@@_x_final_dim}
+ \dim_set_eq:NN \g_@@_x_final_dim \g_@@_x_initial_dim}
% \end{macrocode}
-% If the column is of type |r|, we will draw the dotted on the right-most abscissa.
+% If the column is of type |r|, we will draw the dotted line on the right-most abscissa.
% \begin{macrocode}
- \tl_set:Nn \l_tmpb_tl {r}
- \tl_if_eq:NNT \l_tmpa_tl \l_tmpb_tl
- {\dim_set:Nn \l_tmpa_dim {\dim_max:nn \g_@@_x_initial_dim \g_@@_x_final_dim}
- \dim_set_eq:NN \g_@@_x_initial_dim \l_tmpa_dim
- \dim_set_eq:NN \g_@@_x_final_dim \l_tmpa_dim}
+ \str_if_eq:VnT \l_tmpa_tl {r}
+ {\dim_set:Nn \g_@@_x_initial_dim {\dim_max:nn \g_@@_x_initial_dim \g_@@_x_final_dim}
+ \dim_set_eq:NN \g_@@_x_final_dim \g_@@_x_initial_dim}
% \end{macrocode}
% Now, the coordinates of the line to draw are computed in |\g_@@_x_initial_dim|, |\g_@@_y_initial_dim|,
% |\g_@@_x_final_dim| and |\g_@@_y_final_dim|. We can draw the line with |\l_@@_draw_tikz_line:| as usual.
@@ -1887,57 +2461,61 @@ version 2005/12/01 or later.
%
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_tikz_line:
- {
+ {
% \end{macrocode}
% The dimension |\l_@@_l_dim| is the length $\ell$ of the line to draw. We use the floating point reals of
% \pkg{expl3} to compute this length.
% \begin{macrocode}
- \dim_zero_new:N \l_@@_l_dim
- \dim_set:Nn \l_@@_l_dim
- { \fp_to_dim:n
- { sqrt( ( \dim_use:N \g_@@_x_final_dim
- -\dim_use:N \g_@@_x_initial_dim) ^2
- +( \dim_use:N \g_@@_y_final_dim
- -\dim_use:N \g_@@_y_initial_dim) ^2 )}
- }
+ \dim_zero_new:N \l_@@_l_dim
+ \dim_set:Nn \l_@@_l_dim
+ { \fp_to_dim:n
+ { sqrt( ( \dim_use:N \g_@@_x_final_dim
+ -\dim_use:N \g_@@_x_initial_dim) ^2
+ +( \dim_use:N \g_@@_y_final_dim
+ -\dim_use:N \g_@@_y_initial_dim) ^2 )}
+ }
+% \end{macrocode}
+% We draw only if the length is not equel to zero (in fact, in the first compilation, the length may be equal to
+% zero).
+% \begin{macrocode}
+ \dim_compare:nNnF \l_@@_l_dim = \c_zero_dim
% \end{macrocode}
% The integer |\l_tmpa_int| is the number of dots of the dotted line.
% \begin{macrocode}
- \int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l_@@_l_dim - 0.54em}
- {0.45em}}
+ {\int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l_@@_l_dim - 0.54em}
+ {0.45em}}
% \end{macrocode}
% The dimensions |\l_tmpa_dim| and |\l_tmpb_dim| are the coordinates of the vector between two dots in the
% dotted line.
% \begin{macrocode}
- \dim_set:Nn \l_tmpa_dim { (\g_@@_x_final_dim - \g_@@_x_initial_dim)
- * \dim_ratio:nn {0.45em} \l_@@_l_dim}
- \dim_set:Nn \l_tmpb_dim { (\g_@@_y_final_dim - \g_@@_y_initial_dim)
- * \dim_ratio:nn {0.45em} \l_@@_l_dim}
+ \dim_set:Nn \l_tmpa_dim { (\g_@@_x_final_dim - \g_@@_x_initial_dim)
+ * \dim_ratio:nn {0.45em} \l_@@_l_dim}
+ \dim_set:Nn \l_tmpb_dim { (\g_@@_y_final_dim - \g_@@_y_initial_dim)
+ * \dim_ratio:nn {0.45em} \l_@@_l_dim}
% \end{macrocode}
% In the loop over the dots (|\int_step_inline:nnnn|), the dimensions |\g_@@_x_initial_dim| and
% |\g_@@_y_initial_dim| will be used for the coordinates of the dots.
% \begin{macrocode}
- \dim_gadd:Nn \g_@@_x_initial_dim
- { (\g_@@_x_final_dim - \g_@@_x_initial_dim)
- * \dim_ratio:nn {\l_@@_l_dim - 0.45 em * \l_tmpa_int}
- {\l_@@_l_dim * 2}}
- \dim_gadd:Nn \g_@@_y_initial_dim
- { (\g_@@_y_final_dim - \g_@@_y_initial_dim)
+ \dim_gadd:Nn \g_@@_x_initial_dim
+ { (\g_@@_x_final_dim - \g_@@_x_initial_dim)
* \dim_ratio:nn {\l_@@_l_dim - 0.45 em * \l_tmpa_int}
{\l_@@_l_dim * 2}}
- \begin{tikzpicture}[overlay]
- \int_step_inline:nnnn 0 1 \l_tmpa_int
- { \pgfpathcircle{\pgfpoint{\g_@@_x_initial_dim}
- {\g_@@_y_initial_dim}}
- {0.53pt}
- \pgfusepath{fill}
- \dim_gadd:Nn \g_@@_x_initial_dim \l_tmpa_dim
- \dim_gadd:Nn \g_@@_y_initial_dim \l_tmpb_dim }
- \end{tikzpicture}
+ \dim_gadd:Nn \g_@@_y_initial_dim
+ { (\g_@@_y_final_dim - \g_@@_y_initial_dim)
+ * \dim_ratio:nn {\l_@@_l_dim - 0.45 em * \l_tmpa_int}
+ {\l_@@_l_dim * 2}}
+ \begin{tikzpicture}[overlay]
+ \int_step_inline:nnn 0 \l_tmpa_int
+ { \pgfpathcircle{\pgfpoint{\g_@@_x_initial_dim}
+ {\g_@@_y_initial_dim}}
+ {0.53pt}
+ \pgfusepath{fill}
+ \dim_gadd:Nn \g_@@_x_initial_dim \l_tmpa_dim
+ \dim_gadd:Nn \g_@@_y_initial_dim \l_tmpb_dim }
+ \end{tikzpicture}}
}
% \end{macrocode}
%
-% \bigskip
% \subsection{User commands available in the new environments}
%
% We give new names for the commands |\ldots|, |\cdots|, |\vdots| and |\ddots| because these commands will be
@@ -2020,6 +2598,27 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
+% The command |\@@_Hdotsfor| will be linked to |\Hdotsfor| in |{NiceArray}|. This command uses an optionnal
+% argument like |\hdotsfor| but this argument is discarded (in |\hdotsfor|, this argument is used for fine tuning
+% of the space beetween two consecutive dots).
+% \begin{macrocode}
+\NewDocumentCommand \@@_Hdotsfor {O{} m}
+% \end{macrocode}
+% First, we store in the |code-after| (that is in |\g_@@_code_after_tl|) a command |\line| to draw the dotted line
+% after the construction of the matrix.
+% \begin{macrocode}
+ {\int_set:Nn \l_tmpa_int {\g_@@_column_int - 1}
+ \int_set:Nn \l_tmpb_int {\g_@@_column_int + #2}
+ \tl_gput_right:Nx \g_@@_code_after_tl
+ {\exp_not:N \line {\int_use:N\g_@@_row_int-\int_use:N\l_tmpa_int}
+ {\int_use:N\g_@@_row_int-\int_use:N\l_tmpb_int}}
+% \end{macrocode}
+% Then, we insert the correct number of ampersands (|&|).
+% \begin{macrocode}
+ \prg_replicate:nn {#2-1} {&}}
+% \end{macrocode}
+% Tikz nodes are created for all the cells of the array, even the implicit cells of the |\Hdotsfor|.
+%
% \subsection{We process the options}
%
% We process the options when the package is loaded (with |\usepackage|) but we recommend to use
@@ -2033,8 +2632,31 @@ version 2005/12/01 or later.
\ProcessKeysOptions {NiceMatrix}
% \end{macrocode}
%
+% \subsection{The command \textbackslash line accessible in code-after}
+%
+% In the |code-after|, the command |\@@_line:nn| will be linked to |\line|. This command takes two arguments which
+% are the specification of two cells in the array (in the format $i$-$j$) and draws a dotted line between these cells.
+% \begin{macrocode}
+\cs_new_protected:Nn \@@_line:nn
+ {\dim_zero_new:N \g_@@_x_initial_dim
+ \dim_zero_new:N \g_@@_y_initial_dim
+ \dim_zero_new:N \g_@@_x_final_dim
+ \dim_zero_new:N \g_@@_y_final_dim
+ \begin{tikzpicture}
+ \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ;
+ \tikz@parse@node\pgfutil@firstofone (i)
+ \dim_gset:Nn \g_@@_x_initial_dim \pgf@x
+ \dim_gset:Nn \g_@@_y_initial_dim \pgf@y
+ \tikz@parse@node\pgfutil@firstofone (f)
+ \dim_gset:Nn \g_@@_x_final_dim \pgf@x
+ \dim_gset:Nn \g_@@_y_final_dim \pgf@y
+ \end{tikzpicture}
+ \@@_draw_tikz_line:}
+% \end{macrocode}
+%
+% The commands |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| don't use this command because they have to do
+% other settings (for example, the diagonal lines must be parallelized).
%
-% \bigskip
% \subsection{The error messages}
% \begin{macrocode}
\msg_new:nnnn {nicematrix}
@@ -2057,14 +2679,72 @@ version 2005/12/01 or later.
\msg_new:nnn {nicematrix}
{Multicolumn~forbidden}
{The~command~\token_to_str:N \multicolumn\
- is~forbidden~in~the~environment~\{NiceMatrix\}~
+ is~forbidden~in~the~environment~\{\@currenvir\}~
and~its~variants.~The~command~\token_to_str:N \hdotsfor\
of~amsmath~is~also~forbidden~since~it~uses~
- \token_to_str:N \multicolumn.~You~can~go~on~but~your~line~will~
- probably~be~wrong.}
+ \token_to_str:N \multicolumn\ ~(but~you~can~use~\token_to_str:N \Hdotsfor\
+ ~instead).~You~can~go~on~but~your~matrix~may~be~wrong.}
% \end{macrocode}
%
+% \begin{macrocode}
+\msg_new:nnn {nicematrix}
+ {We~are~yet~in~an~environment~NiceArray}
+ {Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~
+ nested.~We~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~
+ result.}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnnn {nicematrix}
+ {Duplicate~name}
+ {The~name~"#1"~is~already~used~and~you~shouldn't~use~
+ the~same~environment~name~twice.~You~can~go~on,~but,~
+ maybe,~you~will~have~incorrect~results~especially~
+ if~you~use~"columns-width=auto".\\
+ For~a~list~of~the~names~already~used,~type~H~<return>.}
+ {The~names~already~defined~in~this~document~are:~
+ \seq_use:Nnnn~\g_@@_names_seq~{,~} {,~} {~and~}.}
+% \end{macrocode}
+%
+% \subsection{The environment \{NiceMatrixBlock\}}
+%
+% The following flag will be raised when all the columns of the environments of the block must have the same width
+% in ``auto'' mode.
+% \begin{macrocode}
+\bool_new:N \l_@@_block_auto_columns_width_bool
+% \end{macrocode}
+%
+% \bigskip
+% As of now, there is only one option available for the environment |{NiceMatrixBlock}|.
+% \begin{macrocode}
+\keys_define:nn {NiceMatrix/NiceMatrixBlock}
+ {auto-columns-width .code:n = {\bool_set_true:N \l_@@_block_auto_columns_width_bool
+ \dim_gzero_new:N \g_@@_max_cell_width_dim
+ \bool_set_true:N \l_@@_auto_columns_width_bool}}
+% \end{macrocode}
+%
% \bigskip
+% \begin{macrocode}
+\NewDocumentEnvironment {NiceMatrixBlock} {O{}}
+ {\keys_set:nn {NiceMatrix/NiceMatrixBlock} {#1}
+ \int_zero_new:N \l_@@_first_env_block_int
+ \int_set:Nn \l_@@_first_env_block_int {\g_@@_env_int + 1}}
+% \end{macrocode}
+%
+% \medskip
+% At the end of the environment |{NiceMatrixBlock}|, we write in the main |.aux| file instructions for the column
+% width of all the environments of the block (that's why we have stored the number of the first environment of the
+% block in the counter |\l_@@_first_env_block_int|).
+% \begin{macrocode}
+ {\bool_if:NT \l_@@_block_auto_columns_width_bool
+ {\iow_now:Nn \@mainaux {\ExplSyntaxOn}
+ \int_step_inline:nnn \l_@@_first_env_block_int \g_@@_env_int
+ {\iow_now:Nx \@mainaux
+ {\cs_gset:cpn {_@@_max_cell_width_##1}
+ {\dim_use:N \g_@@_max_cell_width_dim}}}
+ \iow_now:Nn \@mainaux {\ExplSyntaxOff}}}
+% \end{macrocode}
+%
% \subsection{The environment \{pNiceArrayC\} and its variants}
%
% The code in this section can be removed without affecting the previous code.
@@ -2088,19 +2768,31 @@ version 2005/12/01 or later.
\l_@@_auto_columns_width_bool}
{\dim_set:Nn \l_@@_columns_width_dim {#1}},
columns-width .value_required:n = true,
- unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~pNiceArrayC}}
+ name .code:n = {\seq_if_in:NnTF \g_@@_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g_@@_names_seq {#1}}
+ \tl_gset:Nn \g_@@_name_tl {#1}},
+ name .value_required:n = true,
+ code-after .tl_gset:N = \g_@@_code_after_tl,
+ code-after .initial:n = \c_empty_tl,
+ code-after .value_required:n = true,
+ unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArrayC}}
% \end{macrocode}
%
% \begin{macrocode}
\msg_new:nnnn {nicematrix}
- {Unknown~option~for~pNiceArrayC}
+ {Unknown~option~for~NiceArrayC}
{The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~
\{\@currenvir\}.\\
If~you~go~on,~it~will~be~ignored.\\
For~a~list~of~the~available~options,~type~H~<return>.}
{The~available~options~are~(in~alphabetic~order):~
+ code-after,~
code-for-last-col,~
columns-width,~
+ name,~
nullify-dots,~
parallelize-diags~
and~renew-dots.}
@@ -2113,37 +2805,45 @@ version 2005/12/01 or later.
% overlapping boxes.
%
% \medskip
-% The command |\@@_NiceArrayC:nn| will be used in the environment |{pNiceArrayC}| and its variants.
+% The command |\@@_NiceArrayC:n| will be used in |{NiceArrayCwithDelims}| but also in the environment
+% |{NiceArrayRCwithDelims}|.
% \begin{macrocode}
-\cs_new_protected:Nn \@@_NiceArrayC:nn
- {\dim_gzero_new:N \g_@@_width_last_col_dim
- \keys_set:nn {NiceMatrix/NiceArrayC} {#1}
- \bool_set_false:N \l_@@_exterior_arraycolsep_bool
- \tl_set:Nn \l_@@_pos_env_tl c
+\cs_new_protected:Nn \@@_NiceArrayC:n
+ {
\begin{NiceArray}
% \end{macrocode}
% The beginning of the preamble is the argument of the environment |{pNiceArrayC}|.
% \begin{macrocode}
- {#2
+ {#1
% \end{macrocode}
%
% However, we add a last column with its own specification. For a cell in this last column, the first operation is
% to store the content of the cell in the box |\l_tmpa_box|. This is allowed in \pkg{expl3} with the construction
% |\hbox_set:Nw \l_tmpa_box| ... |\hbox_set_end:|.
% \begin{macrocode}
- >{\int_gincr:N \g__nm_column_int
- \hbox_set:Nw \l_tmpa_box
- \l_@@_code_for_last_col_tl
- \tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
- \node [anchor=base] (nm-\int_use:N \g__nm_env_int-
- \int_use:N \g__nm_row_int-
- \int_use:N \g__nm_column_int)
+ >{\int_gincr:N \g_@@_column_int
+ \hbox_set:Nw \l_tmpa_box
+ \tl_if_empty:NTF \g_@@_name_tl
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor=base,
+ name = nm-\int_use:N \g_@@_env_int-
+ \int_use:N \g_@@_row_int-
+ \int_use:N \g_@@_column_int] }
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor=base,
+ name = nm-\int_use:N \g_@@_env_int-
+ \int_use:N \g_@@_row_int-
+ \int_use:N \g_@@_column_int,
+ alias = \g_@@_name_tl-
+ \int_use:N \g_@@_row_int-
+ \int_use:N \g_@@_column_int] }
\bgroup $ % $
+ \l_@@_code_for_last_col_tl
}
l
% \end{macrocode}
%
-% We actualize the value of |\g_@@with_last_col_dim| which, at the end of the array, will contains the maximal width
+% We actualize the value of |\g_@@_with_last_col_dim| which, at the end of the array, will contain the maximal width
% of the cells of the last column (thus, it will be equal to the width of the last column).
% \begin{macrocode}
<{ $ % $
@@ -2152,10 +2852,10 @@ version 2005/12/01 or later.
\dim_gset:Nn \g_@@_width_last_col_dim
{\dim_max:nn \g_@@_width_last_col_dim
{\box_wd:N \l_tmpa_box}}
- \tl_gput_right:Nn \g__nm_preamble_aux_tl {#1}
+ \tl_gput_right:Nn \g_@@_preamble_aux_tl {#1}
\skip_horizontal:n {-2\arraycolsep}
% \end{macrocode}
-% The content of the cell is inserted in a overlapping position.
+% The content of the cell is inserted in an overlapping position.
% \begin{macrocode}
\hbox_overlap_right:n
{\skip_horizontal:n {2\arraycolsep}
@@ -2164,55 +2864,268 @@ version 2005/12/01 or later.
% This ends the preamble of the array that will be constructed (a rather long preamble, indeed).
%
% \bigskip
-% The command |\@@_after_last_col:| will be used to insert, after the construction of the array (and after the
-% insertion of the right parenthesis, brace, bracket, etc.), an horizontal space in order to compensate for the
-% overlapping boxes.
+% All the environments of the type of |{pNiceArrayC}| will be constructed over |{NiceArrayCwithDelims}|. The first
+% two arguments of this environment are the left and the right delimiter.
+% \begin{macrocode}
+\NewDocumentEnvironment{NiceArrayCwithDelims} {mm O{} m O{}}
+ {\bool_set_false:N \l_@@_direct_NiceArray_bool
+ \tl_gclear:N \g_@@_code_after_tl
+ \dim_gzero_new:N \g_@@_width_last_col_dim
+ \keys_set:nn {NiceMatrix/NiceArrayC} {#3,#5}
+ \bool_set_false:N \l_@@_exterior_arraycolsep_bool
+ \tl_set:Nn \l_@@_pos_env_tl c
+ \left#1
+ \@@_NiceArrayC:n {#4}}
+ {\end{NiceArray}
+ \right#2
+ \skip_horizontal:n \g_@@_width_last_col_dim
+ }
+% \end{macrocode}
+%
+%
+% \bigskip
+% In the following environments, we don't use the form with |\begin{...}| and |\end{...}| because we use
+% |\@currenvir| in the error message for an unknown option.
% \begin{macrocode}
-\cs_new:Nn \@@_after_last_col:
- {\dim_compare:nNnF \g_@@_width_last_col_dim = \c_zero_dim
- {\skip_horizontal:n {\g_@@_width_last_col_dim}{}}}
+\NewDocumentEnvironment {pNiceArrayC} {}
+ {\NiceArrayCwithDelims{(}{)}}
+ {\endNiceArrayCwithDelims}
% \end{macrocode}
%
-% \bigskip
% \begin{macrocode}
-\NewDocumentEnvironment {pNiceArrayC} {O{} m O{}}
- {\left(
- \@@_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right)
- \@@_after_last_col:}
-
-\NewDocumentEnvironment {vNiceArrayC} {O{} m O{}}
- {\left|
- \@@_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right|
- \@@_after_last_col:}
-
-\NewDocumentEnvironment {VNiceArrayC} {O{} m O{}}
- {\left\|
- \@@_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right\|
- \@@_after_last_col:}
-
-\NewDocumentEnvironment {bNiceArrayC} {O{} m O{}}
- {\left[
- \@@_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right]
- \@@_after_last_col:}
-
-\NewDocumentEnvironment {BNiceArrayC} {O{} m O{}}
- {\left\{
- \@@_NiceArrayC:nn {#1,#3} {#2}}
+\NewDocumentEnvironment {vNiceArrayC} {}
+ {\NiceArrayCwithDelims{|}{|}}
+ {\endNiceArrayCwithDelims}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentEnvironment {VNiceArrayC} {}
+ {\NiceArrayCwithDelims{\|}{\|}}
+ {\endNiceArrayCwithDelims}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentEnvironment {bNiceArrayC} {}
+ {\NiceArrayCwithDelims{[}{]}}
+ {\endNiceArrayCwithDelims}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentEnvironment {BNiceArrayC} {}
+ {\NiceArrayCwithDelims{\{}{\}}}
+ {\endNiceArrayCwithDelims}
+% \end{macrocode}
+%
+%
+% \subsection{The environment \{pNiceArrayRC\}}
+%
+% The code in this section can be removed without affecting the previous code.
+%
+% \medskip
+%
+% If the environment is used with the option |columns-width=auto|, the construction
+%
+% \begin{Verbatim}
+% \begin{pNiceArrayRC}{~slshape#preamble@}[columns-width=auto]
+% ~slshape#first row@ \\
+% ~slshape#second row@ \\
+% ~slshape#third row@ \\
+% ~slshape#etc.@ \\
+% \end{pNiceArrayRC}
+% \end{Verbatim}
+%
+% is transformed in the following construction :
+%
+% \begin{Verbatim}
+% \begin{NiceMatrixBlock}[auto-columns-width]
+% \vbox{\hbox{\hphantom{~slshape#an open parenthesis@}
+% $\begin{NiceArray}{~slshape#preamble@}
+% ~slshape#first row@ \\
+% \end{NiceArray}$}
+% \hbox{$\begin{pNiceArrayC}{~slshape#preamble@}
+% ~slshape#second row@ \\
+% ~slshape#third row@ \\
+% ~slshape#etc.@ \\
+% \end{pNiceArrayC}$}}
+% \end{NiceMatrixBlock}
+% \end{Verbatim}
+%
+%
+% \bigskip
+% If the environment is used with a numerical value for the option |columns-width|, the construction
+%
+% \begin{Verbatim}
+% \begin{pNiceArrayRC}{~slshape#preamble@}[columns-width=~slshape#value@]
+% ~slshape#first row@ \\
+% ~slshape#second row@ \\
+% ~slshape#third row@ \\
+% ~slshape#etc.@ \\
+% \end{pNiceArrayRC}
+% \end{Verbatim}
+%
+% is transformed in the following contruction :
+%
+% \begin{Verbatim}
+% \NiceMatrixOptions{columns-width=~slshape#value@}
+% \vbox{\hbox{~slshape#skip of the width of a parenthesis@
+% $\begin{NiceArray}{~slshape#preamble@}
+% ~slshape#first row@ \\
+% \end{NiceArray}$}
+% \hbox{$\begin{pNiceArrayC}{~slshape#preamble@}
+% ~slshape#second row@ \\
+% ~slshape#third row@ \\
+% ~slshape#etc.@ \\
+% \end{pNiceArrayC}$}}
+% \end{Verbatim}
+%
+% (in the group created by the environment).
+%
+% \bigskip
+% \begin{macrocode}
+\keys_define:nn {NiceMatrix/NiceArrayRC}
+ {parallelize-diags .bool_set:N = \l_@@_parallelize_diags_bool,
+ parallelize-diags .default:n = true,
+ renew-dots .bool_set:N = \l_@@_renew_dots_bool,
+ renew-dots .default:n = true,
+ nullify-dots .bool_set:N = \l_@@_nullify_dots_bool ,
+ nullify-dots .default:n = true,
+ code-for-first-row .tl_set:N = \l_@@_code_for_first_row_tl,
+ code-for-last-col .tl_set:N = \l_@@_code_for_last_col_tl,
+ code-for-last-col .value_required:n = true,
+ columns-width .tl_set:N = \l_@@_columns_width_tl,
+ name .code:n = {\seq_if_in:NnTF \g_@@_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g_@@_names_seq {#1}}
+ \tl_gset:Nn \l_@@_name_tl {#1}},
+ code-after .tl_set:N = \l_@@_code_after_tl,
+ unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArrayRC}}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnnn {nicematrix}
+ {Unknown~option~for~NiceArrayRC}
+ {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~
+ \{\@currenvir\}.\\
+ If~you~go~on,~it~will~be~ignored.\\
+ For~a~list~of~the~available~options,~type~H~<return>.}
+ {The~available~options~are~(in~alphabetic~order):~
+ code-after,~
+ code-for-last-col,~
+ code-for-first-row,~
+ columns-width~(in~fact~mandatory),~
+ name,~
+ nullify-dots,~
+ parallelize-diags~
+ and~renew-dots.}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnn {nicematrix}
+ {The~key~columns-width~is~mandatory}
+ {In~the~environment~\{\@currenvir\}~you~must~use~the~
+ key~"columns-width"~either~with~a~numerical~value~
+ or~the~special~value~"auto".\\
+ If~you~go~on,~the~value~"auto"~will~be~used~for~
+ "columns-width".}
+% \end{macrocode}
+%
+% The first and the second argument of the environment |{NiceArrayRCwithDelims}| are the delimiters which will be
+% used in the array. Usually, the final user will not use directly this environment |{NiceArrayRCwithDelims}|
+% because he will use one of the variants |{pNiceArrayRC}|, |{vNiceArrayRC}|, etc.
+% \begin{macrocode}
+\NewDocumentEnvironment{NiceArrayRCwithDelims} {mm O{} m O{}}
+ {\tl_clear_new:N \l_@@_columns_width_tl
+ \tl_clear_new:N \l_@@_name_tl
+ \tl_clear_new:N \l_@@_code_after_tl
+ \keys_set:nn {NiceMatrix/NiceArrayRC} {#3,#5}
+ \tl_gset_eq:NN \g_@@_name_tl \l_@@_name_tl
+ \tl_if_empty:NT \l_@@_columns_width_tl
+ {\msg_error:nn {nicematrix} {The~key~columns-width~is~mandatory}
+ \tl_set:Nn \l_@@_columns_width_tl {auto}}
+ \str_if_eq:nVTF {auto} \l_@@_columns_width_tl
+ {\begin{NiceMatrixBlock}[auto-columns-width]}
+ {\NiceMatrixOptions{columns-width = \l_@@_columns_width_tl} }
+ \vbox\bgroup\hbox\bgroup
+% \end{macrocode}
+% Here, it would be possible to use a |\hphantom| but we prefer to use \pkg{expl3} instructions.
+% \begin{macrocode}
+ \hbox_set:Nn \l_tmpa_box {$\left#1\vbox_to_ht:nn{2cm}{}\right.$}
+ \skip_horizontal:n {\box_wd:N \l_tmpa_box - \nulldelimiterspace}
+% \end{macrocode}
+% We give the value $-1$ to |\l_@@_number_of_first_row_int| and, therefore, the first row of the array will have
+% the number $0$ (the final user will use this value when using, for example, the command |\line| in |code-after|).
+% \begin{macrocode}
+ \int_set:Nn \l_@@_number_of_first_row_int {-1}
+ \tl_set_eq:NN \l_@@_code_for_cell_tl \l_@@_code_for_first_row_tl
+% \end{macrocode}
+% We read staticly the first row of the array given by the user because we will use the first row to
+% construct an environment |{NiceArray}|. \emph{We read until the first control sequence} |\\|. Therefore, it's not
+% possible to use a sub-array with this control sequence in the first row of the array.
+% \begin{macrocode}
+ \cs_set:Npn \@@_replace_first_line ##1\\{
+ $\begin{NiceArray}{*\c@MaxMatrixCols{C}}
+ ##1
+ \end{NiceArray}$
+ \egroup \hbox\bgroup
+% \end{macrocode}
+% We decrement the number of the environment because we want the same number for both constructed environments.
+% \begin{macrocode}
+ \int_gdecr:N \g_@@_env_int
+ \tl_gset_eq:NN \g_@@_name_tl \l_@@_name_tl
+ \tl_gset_eq:NN \g_@@_code_after_tl \l_@@_code_after_tl
+ \bool_set_false:N \l_@@_direct_NiceArray_bool
+ \dim_gzero_new:N \g_@@_width_last_col_dim
+ \bool_set_false:N \l_@@_exterior_arraycolsep_bool
+ \tl_set:Nn \l_@@_pos_env_tl c
+ $\left#1 % $
+ \@@_NiceArrayC:n {#4}}
+ \@@_replace_first_line
+ }
{\end{NiceArray}
- \right\}
- \@@_after_last_col:}
+ \right#2$ % $
+ \skip_horizontal:n \g_@@_width_last_col_dim
+ \egroup\egroup
+ \str_if_eq:nVT {auto} \l_@@_columns_width_tl
+ {\end{NiceMatrixBlock}} }
+% \end{macrocode}
+%
+% \bigskip
+% In the following environments, we don't use the form with |\begin{...}| and |\end{...}| because we use
+% |\@currenvir| in the error message for an unknown option.
+% \begin{macrocode}
+\NewDocumentEnvironment {pNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{(}{)}}
+ {\endNiceArrayRCwithDelims}
% \end{macrocode}
%
+% \begin{macrocode}
+\NewDocumentEnvironment {bNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{[}{]}}
+ {\endNiceArrayRCwithDelims}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentEnvironment {vNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{|}{|}}
+ {\endNiceArrayRCwithDelims}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentEnvironment {VNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{\|}{\|}}
+ {\endNiceArrayRCwithDelims}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\NewDocumentEnvironment {BNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{\{}{\}}}
+ {\endNiceArrayRCwithDelims}
+% \end{macrocode}
+%
+%
%
-%
% \section{History}
%
% \subsection{Changes between versions 1.0 and 1.1}
@@ -2231,7 +3144,7 @@ version 2005/12/01 or later.
%
% New environment |{pNiceArrayC}| and its variants.
%
-% We decrement |\g_@@_row_int| in |\@@_draw_arrows:| to have the exact number of rows.
+% We decrement |\g_@@_row_int| in |\@@_draw_lines:| to have the exact number of rows.
%
% Correction of a bug in the definition of |{BNiceMatrix}|, |{vNiceMatrix}| and |{VNiceMatrix}| (in fact, it was a
% typo).
@@ -2249,6 +3162,13 @@ version 2005/12/01 or later.
%
% New option |columns-width| to fix the same width for all the columns of the array.
%
+%
+% \subsection{Changes between version 1.4 and 2.0}
+%
+% The versions 1.0 to 1.4 of \pkg{nicematrix} were focused on the continuous dotted lines whereas the version 2.0 of
+% \pkg{nicematrix} provides differents features to improve the typesetting of mathematical matrices.
+%
+%
% \endinput
% Local Variables:
% TeX-fold-mode: nil
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
index ca85ddf7d2b..a449b3af8c1 100644
--- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
+++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
@@ -18,8 +18,8 @@
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
-\def\myfileversion{1.4}
-\def\myfiledate{2018/04/16}
+\def\myfileversion{2.0}
+\def\myfiledate{2018/07/06}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
{nicematrix}
@@ -39,34 +39,41 @@
\raise 7\p@ \vbox{\kern 7pt
\hbox{.}}
\mkern 1mu}}
-\cs_new_protected:Nn \__nm_multicolumn:nn
+\cs_new_protected:Nn \__nicem_multicolumn:nn
{\msg_error:nn {nicematrix} {Multicolumn~forbidden}}
-\int_new:N \g__nm_env_int
-\dim_new:N \l__nm_columns_width_dim
-\tl_new:N \l__nm_pos_env_tl
-\tl_set:Nn \l__nm_pos_env_tl c
-\bool_new:N \l__nm_exterior_arraycolsep_bool
-\bool_new:N \l__nm_parallelize_diags_bool
-\bool_set_true:N \l__nm_parallelize_diags_bool
-\bool_new:N \l__nm_nullify_dots_bool
-\bool_new:N \l__nm_renew_matrix_bool
-\bool_new:N \l__nm_auto_columns_width_bool
-\tl_new:N \l__nm_code_for_last_col_tl
+\int_new:N \g__nicem_env_int
+\dim_new:N \l__nicem_columns_width_dim
+\seq_new:N \g__nicem_names_seq
+\int_new:N \l__nicem_number_of_first_row_int
+\bool_new:N \l__nicem_direct_NiceArray_bool
+\bool_set_true:N \l__nicem_direct_NiceArray_bool
+\tl_new:N \l__nicem_code_for_cell_tl
+\tl_new:N \l__nicem_pos_env_tl
+\tl_set:Nn \l__nicem_pos_env_tl c
+\bool_new:N \l__nicem_exterior_arraycolsep_bool
+\bool_new:N \l__nicem_parallelize_diags_bool
+\bool_set_true:N \l__nicem_parallelize_diags_bool
+\bool_new:N \l__nicem_nullify_dots_bool
+\bool_new:N \l__nicem_renew_matrix_bool
+\bool_new:N \l__nicem_auto_columns_width_bool
+\tl_new:N \l__nicem_code_for_last_col_tl
+
+\tl_new:N \g__nicem_name_tl
\keys_define:nn {NiceMatrix/NiceMatrixOptions}
- {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool,
+ {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool,
parallelize-diags .default:n = true,
ParallelizeDiagonals .meta:n = parallelize-diags,
- renew-dots .bool_set:N = \l__nm_renew_dots_bool,
+ renew-dots .bool_set:N = \l__nicem_renew_dots_bool,
renew-dots .default:n = true,
RenewDots .meta:n = renew-dots,
renew-matrix .code:n = {\cs_set_eq:NN \env@matrix \NiceMatrix
- \bool_set_true:N \l__nm_renew_matrix_bool},
+ \bool_set_true:N \l__nicem_renew_matrix_bool},
renew-matrix .value_forbidden:n = true,
RenewMatrix .meta:n = renew-matrix,
transparent .meta:n = {renew-dots,renew-matrix},
transparent .value_forbidden:n = true,
Transparent .meta:n = transparent,
- nullify-dots .bool_set:N = \l__nm_nullify_dots_bool ,
+ nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool ,
nullify-dots .default:n = true,
NullifyDots .meta:n = nullify-dots,
silent .code:n = {\msg_redirect_name:nnn {nicematrix}
@@ -74,10 +81,14 @@
{none}} ,
silent .value_forbidden:n = true,
Silent .meta:n = silent,
- code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl,
+ code-for-last-col .tl_set:N = \l__nicem_code_for_last_col_tl,
code-for-last-col .value_required:n = true,
- exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool ,
+ exterior-arraycolsep .bool_set:N = \l__nicem_exterior_arraycolsep_bool ,
exterior-arraycolsep .default:n = true,
+ columns-width .code:n = \str_if_eq:nnTF {#1} {auto}
+ {\msg_error:nn {nicematrix}
+ {Option~auto~for~columns-width}}
+ {\dim_set:Nn \l__nicem_columns_width_dim {#1}},
unknown .code:n = \msg_error:nn {nicematrix} {Unknown~key~for~NiceMatrixOptions}}
\msg_new:nnnn {nicematrix}
{Unknown~key~for~NiceMatrixOptions}
@@ -93,19 +104,33 @@
renew-dots,~
renew-matrix~
and~transparent}
+\msg_new:nnn {nicematrix}
+ {Option~auto~for~columns-width}
+ {You~can't~give~the~value~"auto"~to~the~option~"columns-width"~here.~
+ If~you~go~on,~the~option~will~be~ignored.}
\NewDocumentCommand \NiceMatrixOptions {m}
{\keys_set:nn {NiceMatrix/NiceMatrixOptions} {#1}}
\keys_define:nn {NiceMatrix/NiceMatrix}
- {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool,
+ {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool,
parallelize-diags .default:n = true,
- renew-dots .bool_set:N = \l__nm_renew_dots_bool,
+ renew-dots .bool_set:N = \l__nicem_renew_dots_bool,
renew-dots .default:n = true,
- nullify-dots .bool_set:N = \l__nm_nullify_dots_bool ,
+ nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool ,
nullify-dots .default:n = true,
columns-width .code:n = \str_if_eq:nnTF {#1} {auto}
{\bool_set_true:N
- \l__nm_auto_columns_width_bool}
- {\dim_set:Nn \l__nm_columns_width_dim {#1}},
+ \l__nicem_auto_columns_width_bool}
+ {\dim_set:Nn \l__nicem_columns_width_dim {#1}},
+ name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g__nicem_names_seq {#1}}
+ \tl_gset:Nn \g__nicem_name_tl {#1}},
+ name .value_required:n = true,
+ code-after .tl_gset:N = \g__nicem_code_after_tl,
+ code-after .initial:n = \c_empty_tl,
+ code-after .value_required:n = true,
unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceMatrix}}
\msg_new:nnnn {nicematrix}
{Unknown~option~for~NiceMatrix}
@@ -114,26 +139,38 @@
If~you~go~on,~it~will~be~ignored.\\
For~a~list~of~the~available~options,~type~H~<return>.}
{The~available~options~are~(in~alphabetic~order):~
+ code-after,~
columns-width,~
+ name,~
nullify-dots,~
parallelize-diags~
and~renew-dots.}
\keys_define:nn {NiceMatrix/NiceArray}
- {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool,
+ {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool,
parallelize-diags .default:n = true,
- renew-dots .bool_set:N = \l__nm_renew_dots_bool,
+ renew-dots .bool_set:N = \l__nicem_renew_dots_bool,
renew-dots .default:n = true,
- nullify-dots .bool_set:N = \l__nm_nullify_dots_bool ,
+ nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool ,
nullify-dots .default:n = true,
- exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool ,
+ exterior-arraycolsep .bool_set:N = \l__nicem_exterior_arraycolsep_bool ,
exterior-arraycolsep .default:n = true,
columns-width .code:n = \str_if_eq:nnTF {#1} {auto}
- {\bool_set_true:N \l__nm_auto_columns_width_bool}
- {\dim_set:Nn \l__nm_columns_width_dim {#1}},
+ {\bool_set_true:N \l__nicem_auto_columns_width_bool}
+ {\dim_set:Nn \l__nicem_columns_width_dim {#1}},
columns-width .value_required:n = true,
- c .code:n = \tl_set:Nn \l__nm_pos_env_tl c,
- t .code:n = \tl_set:Nn \l__nm_pos_env_tl t,
- b .code:n = \tl_set:Nn \l__nm_pos_env_tl b,
+ name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g__nicem_names_seq {#1}}
+ \tl_gset:Nn \g__nicem_name_tl {#1}},
+ name .value_required:n = true,
+ c .code:n = \tl_set:Nn \l__nicem_pos_env_tl c,
+ t .code:n = \tl_set:Nn \l__nicem_pos_env_tl t,
+ b .code:n = \tl_set:Nn \l__nicem_pos_env_tl b,
+ code-after .tl_gset:N = \g__nicem_code_after_tl,
+ code-after .initial:n = \c_empty_tl,
+ code-after .value_required:n = true,
unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArray}}
\msg_new:nnnn {nicematrix}
{Unknown~option~for~NiceArray}
@@ -144,111 +181,140 @@
{The~available~options~are~(in~alphabetic~order):~
b,~
c,~
+ code-after,~
columns-width,~
exterior-arraycolsep,~
+ name,~
nullify-dots,~
parallelize-diags,~
renew-dots~
and~t.}
-\cs_new_protected:Nn \__nm_Cell:n
- {\tl_gput_right:Nn \g__nm_preamble_aux_tl {#1}
- \int_gincr:N \g__nm_column_int
- \hbox_set:Nw \l_tmpa_box $} % $
-\cs_new_protected:Nn \__nm_end_Cell:
+\cs_new_protected:Nn \__nicem_Cell:n
+ {\tl_gput_right:Nn \g__nicem_preamble_aux_tl {#1}
+ \int_gincr:N \g__nicem_column_int
+ \hbox_set:Nw \l_tmpa_box $ % $
+ \l__nicem_code_for_cell_tl }
+\cs_new_protected:Nn \__nicem_end_Cell:
{$ % $
\hbox_set_end:
- \dim_gset:Nn \g__nm_max_cell_width_dim
- {\dim_max:nn \g__nm_max_cell_width_dim {\box_wd:N \l_tmpa_box}}
- \tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
- \node [anchor=base] (nm-\int_use:N \g__nm_env_int-
- \int_use:N \g__nm_row_int-
- \int_use:N \g__nm_column_int)
+ \dim_gset:Nn \g__nicem_max_cell_width_dim
+ {\dim_max:nn \g__nicem_max_cell_width_dim {\box_wd:N \l_tmpa_box}}
+ \tl_if_empty:NTF \g__nicem_name_tl
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor = base,
+ name = nm-\int_use:N \g__nicem_env_int-
+ \int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int] }
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor = base,
+ name = nm-\int_use:N \g__nicem_env_int-
+ \int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int,
+ alias = \tl_use:N \g__nicem_name_tl-
+ \int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int] }
\bgroup
\box_use:N \l_tmpa_box
\egroup ;}
\NewDocumentEnvironment {NiceMatrix} {O{}}
- {\keys_set:nn {NiceMatrix/NiceMatrix} {#1}
- \tl_set:Nn \l__nm_pos_env_tl c
- \bool_set_false:N \l__nm_exterior_arraycolsep_bool
+ {\bool_set_false:N \l__nicem_direct_NiceArray_bool
+ \tl_gclear:N \g__nicem_code_after_tl
+ \keys_set:nn {NiceMatrix/NiceMatrix} {#1}
+ \tl_set:Nn \l__nicem_pos_env_tl c
+ \bool_set_false:N \l__nicem_exterior_arraycolsep_bool
\NiceArray{*\c@MaxMatrixCols{C}}
}
{\endarray
\skip_horizontal:n {-\arraycolsep}}
\cs_generate_variant:Nn \dim_set:Nn {Nx}
\NewDocumentEnvironment {NiceArray} {O{} m O{}}
- {\aftergroup \__nm_write_max_cell_width:
- \aftergroup \__nm_draw_lines:
- \int_gincr:N \g__nm_env_int
- \dim_gzero_new:N \g__nm_max_cell_width_dim
+ {\cs_if_exist:NT \__nicem_in_NiceArray:
+ {\msg_error:nn {nicematrix} {We~are~yet~in~an~environment~NiceArray}}
+ \cs_set:Npn \__nicem_in_NiceArray: {--Void--}
+ \aftergroup \__nicem_draw_lines:
+ \int_gincr:N \g__nicem_env_int
+ \bool_if:NF \l__nicem_block_auto_columns_width_bool
+ {\dim_gzero_new:N \g__nicem_max_cell_width_dim}
+ \bool_if:NT \l__nicem_direct_NiceArray_bool
+ {\tl_gclear:N \g__nicem_code_after_tl}
\keys_set:nn {NiceMatrix/NiceArray} {#1,#3}
- \bool_if:NT \l__nm_auto_columns_width_bool
- {\cs_if_free:cTF {__nm_max_cell_width_\int_use:N \g__nm_env_int}
- {\dim_set:Nn \l__nm_columns_width_dim \c_zero_dim}
- {\dim_set:Nx \l__nm_columns_width_dim
- {\use:c {__nm_max_cell_width_\int_use:N \g__nm_env_int}}}}
+ \bool_if:NT \l__nicem_auto_columns_width_bool
+ {\aftergroup \__nicem_write_max_cell_width:
+ \cs_if_free:cTF {__nicem_max_cell_width_\int_use:N \g__nicem_env_int}
+ {\dim_set:Nn \l__nicem_columns_width_dim \c_zero_dim}
+ {\dim_set:Nx \l__nicem_columns_width_dim
+ {\use:c {__nicem_max_cell_width_\int_use:N \g__nicem_env_int}}}
+ \tl_if_empty:NF \g__nicem_name_tl
+ {\cs_if_free:cF {__nicem_max_cell_width_\g__nicem_name_tl}
+ {\dim_set:Nx \l__nicem_columns_width_dim
+ {\use:c {__nicem_max_cell_width_\g__nicem_name_tl}}}}
+ }
\cs_set:Npn \ialign
- {\everycr{\noalign{\int_gincr:N \g__nm_row_int
- \int_gzero:N \g__nm_column_int
- \int_compare:nNnT {\tl_count:N \g__nm_preamble_aux_tl}
- > {\tl_count:N \g__nm_preamble_tl}
- {\tl_gset_eq:NN \g__nm_preamble_tl \g__nm_preamble_aux_tl}
- \tl_gclear:N \g__nm_preamble_aux_tl}}
+ {\everycr{\noalign{\int_gincr:N \g__nicem_row_int
+ \int_gzero:N \g__nicem_column_int
+ \int_compare:nNnT {\tl_count:N \g__nicem_preamble_aux_tl}
+ > {\tl_count:N \g__nicem_preamble_tl}
+ {\tl_gset_eq:NN \g__nicem_preamble_tl \g__nicem_preamble_aux_tl}
+ \tl_gclear:N \g__nicem_preamble_aux_tl}}
\skip_zero:N \tabskip
\cs_set:Npn \ialign {\everycr{}
\skip_zero:N \tabskip
\halign}
\halign}
- \dim_compare:nNnTF \l__nm_columns_width_dim = \c_zero_dim
- {\newcolumntype{L}{>{\__nm_Cell:n l}l<{\__nm_end_Cell:}}
- \newcolumntype{C}{>{\__nm_Cell:n c}c<{\__nm_end_Cell:}}
- \newcolumntype{R}{>{\__nm_Cell:n r}r<{\__nm_end_Cell:}}}
- {\newcolumntype{L}{wl{\dim_use:N \l__nm_columns_width_dim}}
- \newcolumntype{C}{wc{\dim_use:N \l__nm_columns_width_dim}}
- \newcolumntype{R}{wr{\dim_use:N \l__nm_columns_width_dim}}}
+ \dim_compare:nNnTF \l__nicem_columns_width_dim = \c_zero_dim
+ {\newcolumntype{L}{>{\__nicem_Cell:n l}l<{\__nicem_end_Cell:}}
+ \newcolumntype{C}{>{\__nicem_Cell:n c}c<{\__nicem_end_Cell:}}
+ \newcolumntype{R}{>{\__nicem_Cell:n r}r<{\__nicem_end_Cell:}}}
+ {\newcolumntype{L}{wl{\dim_use:N \l__nicem_columns_width_dim}}
+ \newcolumntype{C}{wc{\dim_use:N \l__nicem_columns_width_dim}}
+ \newcolumntype{R}{wr{\dim_use:N \l__nicem_columns_width_dim}}}
\cs_set_eq:NN \NC@find@w \relax
\cs_set_eq:NN \NC@find@W \relax
\newcolumntype{w}[2]
{>{\hbox_set:Nw \l_tmpa_box
- \__nm_Cell:n ##1}
+ \__nicem_Cell:n ##1}
c
- <{\__nm_end_Cell:
+ <{\__nicem_end_Cell:
\hbox_set_end:
\makebox[##2][##1]{\box_use:N \l_tmpa_box}}}
\newcolumntype{W}[2]
{>{\hbox_set:Nw \l_tmpa_box
- \__nm_Cell:n ##1}
+ \__nicem_Cell:n ##1}
c
- <{\__nm_end_Cell:
+ <{\__nicem_end_Cell:
\hbox_set_end:
\cs_set_eq:NN \hss \hfil
\makebox[##2][##1]{\box_use:N \l_tmpa_box}}}
- \cs_set_eq:NN \Ldots \__nm_Ldots
- \cs_set_eq:NN \Cdots \__nm_Cdots
- \cs_set_eq:NN \Vdots \__nm_Vdots
- \cs_set_eq:NN \Ddots \__nm_Ddots
- \cs_set_eq:NN \Iddots \__nm_Iddots
- \cs_set_eq:NN \Hspace \__nm_Hspace:
- \cs_set_eq:NN \NiceMatrixEndPoint \__nm_NiceMatrixEndPoint:
- \bool_if:NT \l__nm_renew_dots_bool
- {\cs_set_eq:NN \ldots \__nm_Ldots
- \cs_set_eq:NN \cdots \__nm_Cdots
- \cs_set_eq:NN \vdots \__nm_Vdots
- \cs_set_eq:NN \ddots \__nm_Ddots
- \cs_set_eq:NN \iddots \__nm_Iddots}
- \bool_if:NF \l__nm_renew_matrix_bool
- {\cs_set_eq:NN \multicolumn \__nm_multicolumn:nn}
- \tl_clear_new:N \g__nm_preamble_tl
- \tl_clear_new:N \g__nm_preamble_aux_tl
- \seq_gclear_new:N \g__nm_empty_cells_seq
- \int_gzero_new:N \g__nm_instruction_int
- \int_gzero_new:N \g__nm_row_int
- \int_gzero_new:N \g__nm_column_int
+ \cs_set_eq:NN \Ldots \__nicem_Ldots
+ \cs_set_eq:NN \Cdots \__nicem_Cdots
+ \cs_set_eq:NN \Vdots \__nicem_Vdots
+ \cs_set_eq:NN \Ddots \__nicem_Ddots
+ \cs_set_eq:NN \Iddots \__nicem_Iddots
+ \cs_set_eq:NN \Hspace \__nicem_Hspace:
+ \cs_set_eq:NN \NiceMatrixEndPoint \__nicem_NiceMatrixEndPoint:
+ \cs_set_eq:NN \Hdotsfor \__nicem_Hdotsfor
+ \bool_if:NT \l__nicem_renew_dots_bool
+ {\cs_set_eq:NN \ldots \__nicem_Ldots
+ \cs_set_eq:NN \cdots \__nicem_Cdots
+ \cs_set_eq:NN \vdots \__nicem_Vdots
+ \cs_set_eq:NN \ddots \__nicem_Ddots
+ \cs_set_eq:NN \iddots \__nicem_Iddots
+ \cs_set_eq:NN \hdotsfor \__nicem_Hdotsfor}
+ \bool_if:NF \l__nicem_renew_matrix_bool
+ {\cs_set_eq:NN \multicolumn \__nicem_multicolumn:nn}
+ \tl_clear_new:N \g__nicem_preamble_tl
+ \tl_clear_new:N \g__nicem_preamble_aux_tl
+ \seq_gclear_new:N \g__nicem_empty_cells_seq
+ \int_gzero_new:N \g__nicem_instruction_int
+ \int_gzero_new:N \g__nicem_row_int
+ \int_gset_eq:NN \g__nicem_row_int \l__nicem_number_of_first_row_int
+ \int_gzero_new:N \g__nicem_column_int
\cs_set_eq:NN \@ifnextchar \new@ifnextchar
- \bool_if:NF \l__nm_exterior_arraycolsep_bool
+ \bool_if:NF \l__nicem_exterior_arraycolsep_bool
{\skip_horizontal:n {-\arraycolsep}}
- \array[\l__nm_pos_env_tl]{#2}}
+ \array[\l__nicem_pos_env_tl]{#2}}
{\endarray
- \bool_if:NF \l__nm_exterior_arraycolsep_bool
+ \bool_if:NF \l__nicem_exterior_arraycolsep_bool
{\skip_horizontal:n {-\arraycolsep}}}
\NewDocumentEnvironment {pNiceMatrix} {}
{\left(\begin{NiceMatrix}}
@@ -265,21 +331,24 @@
\NewDocumentEnvironment {VNiceMatrix} {}
{\left\lVert\begin{NiceMatrix}}
{\end{NiceMatrix}\right\rVert}
-\cs_new:Nn \__nm_write_max_cell_width:
- {\iow_now:Nx \@mainaux
- {\ExplSyntaxOn
- \cs_gset:cpn {__nm_max_cell_width_\int_use:N \g__nm_env_int}
- {\dim_use:N \g__nm_max_cell_width_dim}
- \ExplSyntaxOff}}
-\prg_set_conditional:Npnn \__nm_if_not_empty_cell:nn #1#2 {T}
- {\cs_if_exist:cTF {pgf@sh@ns@nm-\int_use:N \g__nm_env_int-
+\cs_new_protected:Nn \__nicem_write_max_cell_width:
+ {\bool_if:NF \l__nicem_block_auto_columns_width_bool
+ {\iow_now:Nn \@mainaux {\ExplSyntaxOn}
+ \iow_now:Nx \@mainaux {\cs_gset:cpn {__nicem_max_cell_width_\int_use:N \g__nicem_env_int}
+ {\dim_use:N \g__nicem_max_cell_width_dim} }
+ \iow_now:Nx \@mainaux {\cs_gset:cpn {__nicem_max_cell_width_\g__nicem_name_tl}
+ {\dim_use:N \g__nicem_max_cell_width_dim} }
+ \iow_now:Nn \@mainaux {\ExplSyntaxOff}}
+ \tl_gclear:N \g__nicem_name_tl}
+\prg_set_conditional:Npnn \__nicem_if_not_empty_cell:nn #1#2 {T}
+ {\cs_if_exist:cTF {pgf@sh@ns@nm-\int_use:N \g__nicem_env_int-
\int_use:N #1-
\int_use:N #2}
- {\seq_if_in:NxTF \g__nm_empty_cells_seq
+ {\seq_if_in:NxTF \g__nicem_empty_cells_seq
{\int_use:N #1-\int_use:N #2}
{\prg_return_false:}
{\begin{pgfpicture}
- \tl_set:Nx \l_tmpa_tl {nm-\int_use:N \g__nm_env_int-
+ \tl_set:Nx \l_tmpa_tl {nm-\int_use:N \g__nicem_env_int-
\int_use:N #1-
\int_use:N #2}
\pgfpointanchor \l_tmpa_tl {east}
@@ -293,257 +362,282 @@
}}
{\prg_return_false:}
}
-\cs_new_protected:Nn \__nm_instruction_of_type:n
- {\int_gincr:N \g__nm_instruction_int
+\cs_new_protected:Nn \__nicem_instruction_of_type:n
+ {\int_gincr:N \g__nicem_instruction_int
\prop_put:Nnn \l_tmpa_prop {type} {#1}
- \prop_put:NnV \l_tmpa_prop {row} \g__nm_row_int
- \prop_put:NnV \l_tmpa_prop {column} \g__nm_column_int
+ \prop_put:NnV \l_tmpa_prop {row} \g__nicem_row_int
+ \prop_put:NnV \l_tmpa_prop {column} \g__nicem_column_int
\prop_gclear_new:c
- {g__nm_instruction_\int_use:N\g__nm_instruction_int _prop}
+ {g__nicem_instruction_\int_use:N\g__nicem_instruction_int _prop}
\prop_gset_eq:cN
- {g__nm_instruction_\int_use:N\g__nm_instruction_int _prop}
+ {g__nicem_instruction_\int_use:N\g__nicem_instruction_int _prop}
\l_tmpa_prop
}
-
-\cs_new_protected:Nn \__nm_draw_lines:
+\cs_new_protected:Nn \__nicem_draw_lines:
{
- \int_decr:N \g__nm_row_int
- \int_set:Nn \g__nm_column_int {\tl_count:N \g__nm_preamble_tl}
- \seq_clear_new:N \l__nm_yet_drawn_seq
- \int_zero_new:N \l__nm_type_int
- \int_zero_new:N \l__nm_row_int
- \int_zero_new:N \l__nm_column_int
- \int_zero_new:N \l__nm_di_int
- \int_zero_new:N \l__nm_dj_int
- \bool_if:NT \l__nm_parallelize_diags_bool
- {\int_zero_new:N \l__nm_ddots_int
- \int_zero_new:N \l__nm_iddots_int
- \dim_zero_new:N \l__nm_delta_x_one_dim
- \dim_zero_new:N \l__nm_delta_y_one_dim
- \dim_zero_new:N \l__nm_delta_x_two_dim
- \dim_zero_new:N \l__nm_delta_y_two_dim}
- \int_zero_new:N \l__nm_instruction_int
- \int_incr:N \l__nm_instruction_int
- \int_until_do:nNnn \l__nm_instruction_int > \g__nm_instruction_int
+ \int_decr:N \g__nicem_row_int
+ \int_set:Nn \g__nicem_column_int {\tl_count:N \g__nicem_preamble_tl}
+ \seq_clear_new:N \l__nicem_yet_drawn_seq
+ \int_zero_new:N \l__nicem_type_int
+ \int_zero_new:N \l__nicem_row_int
+ \int_zero_new:N \l__nicem_column_int
+ \int_zero_new:N \l__nicem_di_int
+ \int_zero_new:N \l__nicem_dj_int
+ \bool_if:NT \l__nicem_parallelize_diags_bool
+ {\int_zero_new:N \l__nicem_ddots_int
+ \int_zero_new:N \l__nicem_iddots_int
+ \dim_zero_new:N \l__nicem_delta_x_one_dim
+ \dim_zero_new:N \l__nicem_delta_y_one_dim
+ \dim_zero_new:N \l__nicem_delta_x_two_dim
+ \dim_zero_new:N \l__nicem_delta_y_two_dim}
+ \int_zero_new:N \l__nicem_instruction_int
+ \int_incr:N \l__nicem_instruction_int
+ \int_until_do:nNnn \l__nicem_instruction_int > \g__nicem_instruction_int
{
- \prop_get:cnN {g__nm_instruction_\int_use:N \l__nm_instruction_int _prop}
+ \prop_get:cnN {g__nicem_instruction_\int_use:N \l__nicem_instruction_int _prop}
{type} \l_tmpa_tl
- \int_set:Nn \l__nm_type_int {\l_tmpa_tl}
- \prop_get:cnN {g__nm_instruction_\int_use:N \l__nm_instruction_int _prop}
+ \int_set:Nn \l__nicem_type_int {\l_tmpa_tl}
+ \prop_get:cnN {g__nicem_instruction_\int_use:N \l__nicem_instruction_int _prop}
{row} \l_tmpa_tl
- \int_set:Nn \l__nm_row_int {\l_tmpa_tl}
- \prop_get:cnN {g__nm_instruction_\int_use:N \l__nm_instruction_int _prop}
+ \int_set:Nn \l__nicem_row_int {\l_tmpa_tl}
+ \prop_get:cnN {g__nicem_instruction_\int_use:N \l__nicem_instruction_int _prop}
{column} \l_tmpa_tl
- \int_set:Nn \l__nm_column_int {\l_tmpa_tl}
- \int_case:nn \l__nm_type_int
- { 0 {\int_set:Nn \l__nm_di_int 0
- \int_set:Nn \l__nm_dj_int 1}
- 1 {\int_set:Nn \l__nm_di_int 0
- \int_set:Nn \l__nm_dj_int 1}
- 2 {\int_set:Nn \l__nm_di_int 1
- \int_set:Nn \l__nm_dj_int 0}
- 3 {\int_set:Nn \l__nm_di_int 1
- \int_set:Nn \l__nm_dj_int 1}
- 4 {\int_set:Nn \l__nm_di_int 1
- \int_set:Nn \l__nm_dj_int {-1}}}
- \bool_if_exist:NTF \l__nm_impossible_instruction_bool
- {\bool_set_false:N \l__nm_impossible_instruction_bool}
- {\bool_new:N \l__nm_impossible_instruction_bool}
- \int_zero_new:N \l__nm_final_i_int
- \int_zero_new:N \l__nm_final_j_int
- \int_set:Nn \l__nm_final_i_int \l__nm_row_int
- \int_set:Nn \l__nm_final_j_int \l__nm_column_int
- \bool_if_exist:NTF \l__nm_stop_loop_bool
- {\bool_set_false:N \l__nm_stop_loop_bool}
- {\bool_new:N \l__nm_stop_loop_bool}
- \bool_do_until:Nn \l__nm_stop_loop_bool
- {\int_add:Nn \l__nm_final_i_int \l__nm_di_int
- \int_add:Nn \l__nm_final_j_int \l__nm_dj_int
- \bool_if:nTF { \int_compare_p:nNn \l__nm_final_i_int < 1
- || \int_compare_p:nNn \l__nm_final_i_int > \g__nm_row_int
- || \int_compare_p:nNn \l__nm_final_j_int < 1
- || \int_compare_p:nNn \l__nm_final_j_int > \g__nm_column_int}
- {\bool_set_true:N \l__nm_impossible_instruction_bool
- \bool_set_true:N \l__nm_stop_loop_bool}
- {\__nm_if_not_empty_cell:nnT \l__nm_final_i_int \l__nm_final_j_int
- {\bool_set_true:N \l__nm_stop_loop_bool}}
+ \int_set:Nn \l__nicem_column_int {\l_tmpa_tl}
+ \int_case:nn \l__nicem_type_int
+ { 0 {\int_set:Nn \l__nicem_di_int 0
+ \int_set:Nn \l__nicem_dj_int 1}
+ 1 {\int_set:Nn \l__nicem_di_int 0
+ \int_set:Nn \l__nicem_dj_int 1}
+ 2 {\int_set:Nn \l__nicem_di_int 1
+ \int_set:Nn \l__nicem_dj_int 0}
+ 3 {\int_set:Nn \l__nicem_di_int 1
+ \int_set:Nn \l__nicem_dj_int 1}
+ 4 {\int_set:Nn \l__nicem_di_int 1
+ \int_set:Nn \l__nicem_dj_int {-1}}}
+ \bool_if_exist:NTF \l__nicem_impossible_instruction_bool
+ {\bool_set_false:N \l__nicem_impossible_instruction_bool}
+ {\bool_new:N \l__nicem_impossible_instruction_bool}
+ \int_zero_new:N \l__nicem_final_i_int
+ \int_zero_new:N \l__nicem_final_j_int
+ \int_set:Nn \l__nicem_final_i_int \l__nicem_row_int
+ \int_set:Nn \l__nicem_final_j_int \l__nicem_column_int
+ \bool_if_exist:NTF \l__nicem_stop_loop_bool
+ {\bool_set_false:N \l__nicem_stop_loop_bool}
+ {\bool_new:N \l__nicem_stop_loop_bool}
+ \bool_do_until:Nn \l__nicem_stop_loop_bool
+ {\int_add:Nn \l__nicem_final_i_int \l__nicem_di_int
+ \int_add:Nn \l__nicem_final_j_int \l__nicem_dj_int
+ \bool_if:nTF { \int_compare_p:nNn \l__nicem_final_i_int < \l__nicem_number_of_first_row_int
+ || \int_compare_p:nNn \l__nicem_final_i_int > \g__nicem_row_int
+ || \int_compare_p:nNn \l__nicem_final_j_int < 1
+ || \int_compare_p:nNn \l__nicem_final_j_int > \g__nicem_column_int}
+ {\bool_set_true:N \l__nicem_impossible_instruction_bool
+ \bool_set_true:N \l__nicem_stop_loop_bool}
+ {\__nicem_if_not_empty_cell:nnT \l__nicem_final_i_int \l__nicem_final_j_int
+ {\bool_set_true:N \l__nicem_stop_loop_bool}}
}
- \int_zero_new:N \l__nm_initial_i_int
- \int_zero_new:N \l__nm_initial_j_int
- \int_set:Nn \l__nm_initial_i_int \l__nm_row_int
- \int_set:Nn \l__nm_initial_j_int \l__nm_column_int
- \bool_set_eq:NN \l__nm_stop_loop_bool \l__nm_impossible_instruction_bool
- \bool_do_until:Nn \l__nm_stop_loop_bool
- {\int_sub:Nn \l__nm_initial_i_int \l__nm_di_int
- \int_sub:Nn \l__nm_initial_j_int \l__nm_dj_int
+ \int_zero_new:N \l__nicem_initial_i_int
+ \int_zero_new:N \l__nicem_initial_j_int
+ \int_set:Nn \l__nicem_initial_i_int \l__nicem_row_int
+ \int_set:Nn \l__nicem_initial_j_int \l__nicem_column_int
+ \bool_set_eq:NN \l__nicem_stop_loop_bool \l__nicem_impossible_instruction_bool
+ \bool_do_until:Nn \l__nicem_stop_loop_bool
+ {\int_sub:Nn \l__nicem_initial_i_int \l__nicem_di_int
+ \int_sub:Nn \l__nicem_initial_j_int \l__nicem_dj_int
\bool_if:nTF
- { \int_compare_p:nNn \l__nm_initial_i_int < 1
- || \int_compare_p:nNn \l__nm_initial_i_int > \g__nm_row_int
- || \int_compare_p:nNn \l__nm_initial_j_int < 1
- || \int_compare_p:nNn \l__nm_initial_j_int > \g__nm_column_int}
- {\bool_set_true:N \l__nm_impossible_instruction_bool
- \bool_set_true:N \l__nm_stop_loop_bool}
- {\__nm_if_not_empty_cell:nnT \l__nm_initial_i_int \l__nm_initial_j_int
- {\bool_set_true:N \l__nm_stop_loop_bool}}
+ { \int_compare_p:nNn \l__nicem_initial_i_int < \l__nicem_number_of_first_row_int
+ || \int_compare_p:nNn \l__nicem_initial_i_int > \g__nicem_row_int
+ || \int_compare_p:nNn \l__nicem_initial_j_int < 1
+ || \int_compare_p:nNn \l__nicem_initial_j_int > \g__nicem_column_int}
+ {\bool_set_true:N \l__nicem_impossible_instruction_bool
+ \bool_set_true:N \l__nicem_stop_loop_bool}
+ {\__nicem_if_not_empty_cell:nnT \l__nicem_initial_i_int \l__nicem_initial_j_int
+ {\bool_set_true:N \l__nicem_stop_loop_bool}}
}
- \bool_if:NTF \l__nm_impossible_instruction_bool
+ \bool_if:NTF \l__nicem_impossible_instruction_bool
{\msg_error:nn {nicematrix} {Impossible~instruction}}
- {\tl_set:Nx \l_tmpa_tl {\int_use:N \l__nm_initial_i_int-
- \int_use:N \l__nm_initial_j_int-
- \int_use:N \l__nm_final_i_int-
- \int_use:N \l__nm_final_j_int}
- \seq_if_in:NVF \l__nm_yet_drawn_seq \l_tmpa_tl
- {\seq_put_left:NV \l__nm_yet_drawn_seq \l_tmpa_tl
- \dim_zero_new:N \g__nm_x_initial_dim
- \dim_zero_new:N \g__nm_y_initial_dim
- \dim_zero_new:N \g__nm_x_final_dim
- \dim_zero_new:N \g__nm_y_final_dim
- \int_case:nn \l__nm_type_int
- {0 \__nm_draw_ldots_line:
- 1 \__nm_draw_cdots_line:
- 2 \__nm_draw_vdots_line:
- 3 \__nm_draw_ddots_line:
- 4 \__nm_draw_iddots_line:}}}
- \int_incr:N \l__nm_instruction_int
+ {\tl_set:Nx \l_tmpa_tl {\int_use:N \l__nicem_initial_i_int-
+ \int_use:N \l__nicem_initial_j_int-
+ \int_use:N \l__nicem_final_i_int-
+ \int_use:N \l__nicem_final_j_int}
+ \seq_if_in:NVF \l__nicem_yet_drawn_seq \l_tmpa_tl
+ {\seq_put_left:NV \l__nicem_yet_drawn_seq \l_tmpa_tl
+ \dim_zero_new:N \g__nicem_x_initial_dim
+ \dim_zero_new:N \g__nicem_y_initial_dim
+ \dim_zero_new:N \g__nicem_x_final_dim
+ \dim_zero_new:N \g__nicem_y_final_dim
+ \int_case:nn \l__nicem_type_int
+ {0 \__nicem_draw_ldots_line:
+ 1 \__nicem_draw_cdots_line:
+ 2 \__nicem_draw_vdots_line:
+ 3 \__nicem_draw_ddots_line:
+ 4 \__nicem_draw_iddots_line:}}}
+ \int_incr:N \l__nicem_instruction_int
}
+ \group_begin:
+ \tikzset{every~picture/.style = {overlay,
+ remember~picture,
+ name~prefix = nm-\int_use:N \g__nicem_env_int-}}
+ \cs_set_eq:NN \line \__nicem_line:nn
+ \g__nicem_code_after_tl
+ \group_end:
}
-\cs_new_protected:Nn \__nm_retrieve_coords:nn
+\cs_new_protected:Nn \__nicem_retrieve_coords:nn
{\begin{tikzpicture}[remember~picture]
\tikz@parse@node\pgfutil@firstofone
- (nm-\int_use:N \g__nm_env_int-
- \int_use:N \l__nm_initial_i_int-
- \int_use:N \l__nm_initial_j_int.#1)
- \dim_gset:Nn \g__nm_x_initial_dim \pgf@x
- \dim_gset:Nn \g__nm_y_initial_dim \pgf@y
+ (nm-\int_use:N \g__nicem_env_int-
+ \int_use:N \l__nicem_initial_i_int-
+ \int_use:N \l__nicem_initial_j_int.#1)
+ \dim_gset:Nn \g__nicem_x_initial_dim \pgf@x
+ \dim_gset:Nn \g__nicem_y_initial_dim \pgf@y
\tikz@parse@node\pgfutil@firstofone
- (nm-\int_use:N \g__nm_env_int-
- \int_use:N \l__nm_final_i_int-
- \int_use:N \l__nm_final_j_int.#2)
- \dim_gset:Nn \g__nm_x_final_dim \pgf@x
- \dim_gset:Nn \g__nm_y_final_dim \pgf@y
+ (nm-\int_use:N \g__nicem_env_int-
+ \int_use:N \l__nicem_final_i_int-
+ \int_use:N \l__nicem_final_j_int.#2)
+ \dim_gset:Nn \g__nicem_x_final_dim \pgf@x
+ \dim_gset:Nn \g__nicem_y_final_dim \pgf@y
\end{tikzpicture} }
-\cs_new_protected:Nn \__nm_draw_ldots_line:
- {\__nm_retrieve_coords:nn {south~east} {south~west}
- \__nm_draw_tikz_line:}
-\cs_new_protected:Nn \__nm_draw_cdots_line:
- {\__nm_retrieve_coords:nn {mid~east} {mid~west}
- \__nm_draw_tikz_line:}
-\cs_new_protected:Nn \__nm_draw_vdots_line:
- {\__nm_retrieve_coords:nn {south} {north}
- \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \g__nm_preamble_tl \l__nm_initial_j_int}
- \tl_set:Nn \l_tmpb_tl {l}
- \tl_if_eq:NNT \l_tmpa_tl \l_tmpb_tl
- {\dim_set:Nn \l_tmpa_dim {\dim_min:nn \g__nm_x_initial_dim \g__nm_x_final_dim}
- \dim_set_eq:NN \g__nm_x_initial_dim \l_tmpa_dim
- \dim_set_eq:NN \g__nm_x_final_dim \l_tmpa_dim}
- \tl_set:Nn \l_tmpb_tl {r}
- \tl_if_eq:NNT \l_tmpa_tl \l_tmpb_tl
- {\dim_set:Nn \l_tmpa_dim {\dim_max:nn \g__nm_x_initial_dim \g__nm_x_final_dim}
- \dim_set_eq:NN \g__nm_x_initial_dim \l_tmpa_dim
- \dim_set_eq:NN \g__nm_x_final_dim \l_tmpa_dim}
- \__nm_draw_tikz_line:}
-\cs_new_protected:Nn \__nm_draw_ddots_line:
- {\__nm_retrieve_coords:nn {south~east} {north~west}
- \bool_if:NT \l__nm_parallelize_diags_bool
- {\int_incr:N \l__nm_ddots_int
- \int_compare:nNnTF \l__nm_ddots_int = 1
- {\dim_set:Nn \l__nm_delta_x_one_dim {\g__nm_x_final_dim - \g__nm_x_initial_dim }
- \dim_set:Nn \l__nm_delta_y_one_dim {\g__nm_y_final_dim - \g__nm_y_initial_dim }}
- {\dim_gset:Nn \g__nm_y_final_dim
- {\g__nm_y_initial_dim +
- (\g__nm_x_final_dim - \g__nm_x_initial_dim)
- * \dim_ratio:nn \l__nm_delta_y_one_dim \l__nm_delta_x_one_dim }}}
- \__nm_draw_tikz_line:}
-\cs_new_protected:Nn \__nm_draw_iddots_line:
- {\__nm_retrieve_coords:nn {south~west} {north~east}
- \bool_if:NT \l__nm_parallelize_diags_bool
- {\int_incr:N \l__nm_iddots_int
- \int_compare:nNnTF \l__nm_iddots_int = 1
- {\dim_set:Nn \l__nm_delta_x_two_dim {\g__nm_x_final_dim - \g__nm_x_initial_dim }
- \dim_set:Nn \l__nm_delta_y_two_dim {\g__nm_y_final_dim - \g__nm_y_initial_dim }}
- {\dim_gset:Nn \g__nm_y_final_dim
- {\g__nm_y_initial_dim +
- (\g__nm_x_final_dim - \g__nm_x_initial_dim)
- * \dim_ratio:nn \l__nm_delta_y_two_dim \l__nm_delta_x_two_dim }}}
- \__nm_draw_tikz_line:}
-\cs_new_protected:Nn \__nm_draw_tikz_line:
- {
- \dim_zero_new:N \l__nm_l_dim
- \dim_set:Nn \l__nm_l_dim
- { \fp_to_dim:n
- { sqrt( ( \dim_use:N \g__nm_x_final_dim
- -\dim_use:N \g__nm_x_initial_dim) ^2
- +( \dim_use:N \g__nm_y_final_dim
- -\dim_use:N \g__nm_y_initial_dim) ^2 )}
- }
- \int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l__nm_l_dim - 0.54em}
- {0.45em}}
- \dim_set:Nn \l_tmpa_dim { (\g__nm_x_final_dim - \g__nm_x_initial_dim)
- * \dim_ratio:nn {0.45em} \l__nm_l_dim}
- \dim_set:Nn \l_tmpb_dim { (\g__nm_y_final_dim - \g__nm_y_initial_dim)
- * \dim_ratio:nn {0.45em} \l__nm_l_dim}
- \dim_gadd:Nn \g__nm_x_initial_dim
- { (\g__nm_x_final_dim - \g__nm_x_initial_dim)
- * \dim_ratio:nn {\l__nm_l_dim - 0.45 em * \l_tmpa_int}
- {\l__nm_l_dim * 2}}
- \dim_gadd:Nn \g__nm_y_initial_dim
- { (\g__nm_y_final_dim - \g__nm_y_initial_dim)
- * \dim_ratio:nn {\l__nm_l_dim - 0.45 em * \l_tmpa_int}
- {\l__nm_l_dim * 2}}
- \begin{tikzpicture}[overlay]
- \int_step_inline:nnnn 0 1 \l_tmpa_int
- { \pgfpathcircle{\pgfpoint{\g__nm_x_initial_dim}
- {\g__nm_y_initial_dim}}
- {0.53pt}
- \pgfusepath{fill}
- \dim_gadd:Nn \g__nm_x_initial_dim \l_tmpa_dim
- \dim_gadd:Nn \g__nm_y_initial_dim \l_tmpb_dim }
- \end{tikzpicture}
+\cs_new_protected:Nn \__nicem_draw_ldots_line:
+ {\__nicem_retrieve_coords:nn {south~east} {south~west}
+ \__nicem_draw_tikz_line:}
+\cs_new_protected:Nn \__nicem_draw_cdots_line:
+ {\__nicem_retrieve_coords:nn {mid~east} {mid~west}
+ \__nicem_draw_tikz_line:}
+\cs_new_protected:Nn \__nicem_draw_vdots_line:
+ {\__nicem_retrieve_coords:nn {south} {north}
+ \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \g__nicem_preamble_tl \l__nicem_initial_j_int}
+ \str_if_eq:VnT \l_tmpa_tl {l}
+ {\dim_set:Nn \g__nicem_x_initial_dim {\dim_min:nn \g__nicem_x_initial_dim \g__nicem_x_final_dim}
+ \dim_set_eq:NN \g__nicem_x_final_dim \g__nicem_x_initial_dim}
+ \str_if_eq:VnT \l_tmpa_tl {r}
+ {\dim_set:Nn \g__nicem_x_initial_dim {\dim_max:nn \g__nicem_x_initial_dim \g__nicem_x_final_dim}
+ \dim_set_eq:NN \g__nicem_x_final_dim \g__nicem_x_initial_dim}
+ \__nicem_draw_tikz_line:}
+\cs_new_protected:Nn \__nicem_draw_ddots_line:
+ {\__nicem_retrieve_coords:nn {south~east} {north~west}
+ \bool_if:NT \l__nicem_parallelize_diags_bool
+ {\int_incr:N \l__nicem_ddots_int
+ \int_compare:nNnTF \l__nicem_ddots_int = 1
+ {\dim_set:Nn \l__nicem_delta_x_one_dim {\g__nicem_x_final_dim - \g__nicem_x_initial_dim }
+ \dim_set:Nn \l__nicem_delta_y_one_dim {\g__nicem_y_final_dim - \g__nicem_y_initial_dim }}
+ {\dim_gset:Nn \g__nicem_y_final_dim
+ {\g__nicem_y_initial_dim +
+ (\g__nicem_x_final_dim - \g__nicem_x_initial_dim)
+ * \dim_ratio:nn \l__nicem_delta_y_one_dim \l__nicem_delta_x_one_dim }}}
+ \__nicem_draw_tikz_line:}
+\cs_new_protected:Nn \__nicem_draw_iddots_line:
+ {\__nicem_retrieve_coords:nn {south~west} {north~east}
+ \bool_if:NT \l__nicem_parallelize_diags_bool
+ {\int_incr:N \l__nicem_iddots_int
+ \int_compare:nNnTF \l__nicem_iddots_int = 1
+ {\dim_set:Nn \l__nicem_delta_x_two_dim {\g__nicem_x_final_dim - \g__nicem_x_initial_dim }
+ \dim_set:Nn \l__nicem_delta_y_two_dim {\g__nicem_y_final_dim - \g__nicem_y_initial_dim }}
+ {\dim_gset:Nn \g__nicem_y_final_dim
+ {\g__nicem_y_initial_dim +
+ (\g__nicem_x_final_dim - \g__nicem_x_initial_dim)
+ * \dim_ratio:nn \l__nicem_delta_y_two_dim \l__nicem_delta_x_two_dim }}}
+ \__nicem_draw_tikz_line:}
+\cs_new_protected:Nn \__nicem_draw_tikz_line:
+ {
+ \dim_zero_new:N \l__nicem_l_dim
+ \dim_set:Nn \l__nicem_l_dim
+ { \fp_to_dim:n
+ { sqrt( ( \dim_use:N \g__nicem_x_final_dim
+ -\dim_use:N \g__nicem_x_initial_dim) ^2
+ +( \dim_use:N \g__nicem_y_final_dim
+ -\dim_use:N \g__nicem_y_initial_dim) ^2 )}
+ }
+ \dim_compare:nNnF \l__nicem_l_dim = \c_zero_dim
+ {\int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l__nicem_l_dim - 0.54em}
+ {0.45em}}
+ \dim_set:Nn \l_tmpa_dim { (\g__nicem_x_final_dim - \g__nicem_x_initial_dim)
+ * \dim_ratio:nn {0.45em} \l__nicem_l_dim}
+ \dim_set:Nn \l_tmpb_dim { (\g__nicem_y_final_dim - \g__nicem_y_initial_dim)
+ * \dim_ratio:nn {0.45em} \l__nicem_l_dim}
+ \dim_gadd:Nn \g__nicem_x_initial_dim
+ { (\g__nicem_x_final_dim - \g__nicem_x_initial_dim)
+ * \dim_ratio:nn {\l__nicem_l_dim - 0.45 em * \l_tmpa_int}
+ {\l__nicem_l_dim * 2}}
+ \dim_gadd:Nn \g__nicem_y_initial_dim
+ { (\g__nicem_y_final_dim - \g__nicem_y_initial_dim)
+ * \dim_ratio:nn {\l__nicem_l_dim - 0.45 em * \l_tmpa_int}
+ {\l__nicem_l_dim * 2}}
+ \begin{tikzpicture}[overlay]
+ \int_step_inline:nnn 0 \l_tmpa_int
+ { \pgfpathcircle{\pgfpoint{\g__nicem_x_initial_dim}
+ {\g__nicem_y_initial_dim}}
+ {0.53pt}
+ \pgfusepath{fill}
+ \dim_gadd:Nn \g__nicem_x_initial_dim \l_tmpa_dim
+ \dim_gadd:Nn \g__nicem_y_initial_dim \l_tmpb_dim }
+ \end{tikzpicture}}
}
-\cs_set_eq:NN \__nm_ldots \ldots
-\cs_set_eq:NN \__nm_cdots \cdots
-\cs_set_eq:NN \__nm_vdots \vdots
-\cs_set_eq:NN \__nm_ddots \ddots
-\cs_set_eq:NN \__nm_iddots \iddots
-\cs_new_protected:Nn \__nm_add_to_empty_cells:
- {\seq_gput_right:Nx \g__nm_empty_cells_seq
- {\int_use:N \g__nm_row_int-
- \int_use:N \g__nm_column_int}}
-\NewDocumentCommand \__nm_Ldots {s}
- {\IfBooleanF {#1} {\__nm_instruction_of_type:n 0}
- \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_ldots}
- \__nm_add_to_empty_cells:}
-\NewDocumentCommand \__nm_Cdots {s}
- {\IfBooleanF {#1} {\__nm_instruction_of_type:n 1}
- \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_cdots}
- \__nm_add_to_empty_cells:}
-\NewDocumentCommand \__nm_Vdots {s}
- {\IfBooleanF {#1} {\__nm_instruction_of_type:n 2}
- \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_vdots}
- \__nm_add_to_empty_cells:}
-\NewDocumentCommand \__nm_Ddots {s}
- {\IfBooleanF {#1} {\__nm_instruction_of_type:n 3}
- \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_ddots}
- \__nm_add_to_empty_cells:}
-\NewDocumentCommand \__nm_Iddots {s}
- {\IfBooleanF {#1} {\__nm_instruction_of_type:n 4}
- \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_iddots}
- \__nm_add_to_empty_cells:}
-\cs_new_protected:Nn \__nm_Hspace:
- {\__nm_add_to_empty_cells:
+\cs_set_eq:NN \__nicem_ldots \ldots
+\cs_set_eq:NN \__nicem_cdots \cdots
+\cs_set_eq:NN \__nicem_vdots \vdots
+\cs_set_eq:NN \__nicem_ddots \ddots
+\cs_set_eq:NN \__nicem_iddots \iddots
+\cs_new_protected:Nn \__nicem_add_to_empty_cells:
+ {\seq_gput_right:Nx \g__nicem_empty_cells_seq
+ {\int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int}}
+\NewDocumentCommand \__nicem_Ldots {s}
+ {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 0}
+ \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_ldots}
+ \__nicem_add_to_empty_cells:}
+\NewDocumentCommand \__nicem_Cdots {s}
+ {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 1}
+ \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_cdots}
+ \__nicem_add_to_empty_cells:}
+\NewDocumentCommand \__nicem_Vdots {s}
+ {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 2}
+ \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_vdots}
+ \__nicem_add_to_empty_cells:}
+\NewDocumentCommand \__nicem_Ddots {s}
+ {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 3}
+ \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_ddots}
+ \__nicem_add_to_empty_cells:}
+\NewDocumentCommand \__nicem_Iddots {s}
+ {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 4}
+ \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_iddots}
+ \__nicem_add_to_empty_cells:}
+\cs_new_protected:Nn \__nicem_Hspace:
+ {\__nicem_add_to_empty_cells:
\hspace}
-\cs_new_protected:Nn \__nm_NiceMatrixEndPoint:
+\cs_new_protected:Nn \__nicem_NiceMatrixEndPoint:
{\kern 0.5pt}
+\NewDocumentCommand \__nicem_Hdotsfor {O{} m}
+ {\int_set:Nn \l_tmpa_int {\g__nicem_column_int - 1}
+ \int_set:Nn \l_tmpb_int {\g__nicem_column_int + #2}
+ \tl_gput_right:Nx \g__nicem_code_after_tl
+ {\exp_not:N \line {\int_use:N\g__nicem_row_int-\int_use:N\l_tmpa_int}
+ {\int_use:N\g__nicem_row_int-\int_use:N\l_tmpb_int}}
+ \prg_replicate:nn {#2-1} {&}}
\ProcessKeysOptions {NiceMatrix}
+\cs_new_protected:Nn \__nicem_line:nn
+ {\dim_zero_new:N \g__nicem_x_initial_dim
+ \dim_zero_new:N \g__nicem_y_initial_dim
+ \dim_zero_new:N \g__nicem_x_final_dim
+ \dim_zero_new:N \g__nicem_y_final_dim
+ \begin{tikzpicture}
+ \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ;
+ \tikz@parse@node\pgfutil@firstofone (i)
+ \dim_gset:Nn \g__nicem_x_initial_dim \pgf@x
+ \dim_gset:Nn \g__nicem_y_initial_dim \pgf@y
+ \tikz@parse@node\pgfutil@firstofone (f)
+ \dim_gset:Nn \g__nicem_x_final_dim \pgf@x
+ \dim_gset:Nn \g__nicem_y_final_dim \pgf@y
+ \end{tikzpicture}
+ \__nicem_draw_tikz_line:}
\msg_new:nnnn {nicematrix}
{Impossible~instruction}
{It's~not~possible~to~execute~the~instruction~
- \int_case:nn \l__nm_type_int
+ \int_case:nn \l__nicem_type_int
{0 {\token_to_str:N \Ldots}
1 {\token_to_str:N \Cdots}
2 {\token_to_str:N \Vdots}
- 3 {\token_to_str:N \Ddots}}~in~the~row~\int_use:N\l__nm_row_int\
- ~and~the~column~\int_use:N\l__nm_column_int\space of~the~matrix~
+ 3 {\token_to_str:N \Ddots}}~in~the~row~\int_use:N\l__nicem_row_int\
+ ~and~the~column~\int_use:N\l__nicem_column_int\space of~the~matrix~
because~it's~impossible~to~find~one~of~its~extremities~
(both~extremities~must~be~non~empty~cells~of~the~matrix).~
If~you~go~on,~the~instruction~will~be~ignored.}
@@ -552,103 +646,238 @@
\msg_new:nnn {nicematrix}
{Multicolumn~forbidden}
{The~command~\token_to_str:N \multicolumn\
- is~forbidden~in~the~environment~\{NiceMatrix\}~
+ is~forbidden~in~the~environment~\{\@currenvir\}~
and~its~variants.~The~command~\token_to_str:N \hdotsfor\
of~amsmath~is~also~forbidden~since~it~uses~
- \token_to_str:N \multicolumn.~You~can~go~on~but~your~line~will~
- probably~be~wrong.}
+ \token_to_str:N \multicolumn\ ~(but~you~can~use~\token_to_str:N \Hdotsfor\
+ ~instead).~You~can~go~on~but~your~matrix~may~be~wrong.}
+\msg_new:nnn {nicematrix}
+ {We~are~yet~in~an~environment~NiceArray}
+ {Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~
+ nested.~We~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~
+ result.}
+\msg_new:nnnn {nicematrix}
+ {Duplicate~name}
+ {The~name~"#1"~is~already~used~and~you~shouldn't~use~
+ the~same~environment~name~twice.~You~can~go~on,~but,~
+ maybe,~you~will~have~incorrect~results~especially~
+ if~you~use~"columns-width=auto".\\
+ For~a~list~of~the~names~already~used,~type~H~<return>.}
+ {The~names~already~defined~in~this~document~are:~
+ \seq_use:Nnnn~\g__nicem_names_seq~{,~} {,~} {~and~}.}
+\bool_new:N \l__nicem_block_auto_columns_width_bool
+\keys_define:nn {NiceMatrix/NiceMatrixBlock}
+ {auto-columns-width .code:n = {\bool_set_true:N \l__nicem_block_auto_columns_width_bool
+ \dim_gzero_new:N \g__nicem_max_cell_width_dim
+ \bool_set_true:N \l__nicem_auto_columns_width_bool}}
+\NewDocumentEnvironment {NiceMatrixBlock} {O{}}
+ {\keys_set:nn {NiceMatrix/NiceMatrixBlock} {#1}
+ \int_zero_new:N \l__nicem_first_env_block_int
+ \int_set:Nn \l__nicem_first_env_block_int {\g__nicem_env_int + 1}}
+ {\bool_if:NT \l__nicem_block_auto_columns_width_bool
+ {\iow_now:Nn \@mainaux {\ExplSyntaxOn}
+ \int_step_inline:nnn \l__nicem_first_env_block_int \g__nicem_env_int
+ {\iow_now:Nx \@mainaux
+ {\cs_gset:cpn {__nicem_max_cell_width_##1}
+ {\dim_use:N \g__nicem_max_cell_width_dim}}}
+ \iow_now:Nn \@mainaux {\ExplSyntaxOff}}}
\keys_define:nn {NiceMatrix/NiceArrayC}
- {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool,
+ {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool,
parallelize-diags .default:n = true,
- renew-dots .bool_set:N = \l__nm_renew_dots_bool,
+ renew-dots .bool_set:N = \l__nicem_renew_dots_bool,
renew-dots .default:n = true,
- nullify-dots .bool_set:N = \l__nm_nullify_dots_bool ,
+ nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool ,
nullify-dots .default:n = true,
- code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl,
+ code-for-last-col .tl_set:N = \l__nicem_code_for_last_col_tl,
code-for-last-col .value_required:n = true,
columns-width .code:n = \str_if_eq:nnTF {#1} {auto}
{\bool_set_true:N
- \l__nm_auto_columns_width_bool}
- {\dim_set:Nn \l__nm_columns_width_dim {#1}},
+ \l__nicem_auto_columns_width_bool}
+ {\dim_set:Nn \l__nicem_columns_width_dim {#1}},
columns-width .value_required:n = true,
- unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~pNiceArrayC}}
+ name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g__nicem_names_seq {#1}}
+ \tl_gset:Nn \g__nicem_name_tl {#1}},
+ name .value_required:n = true,
+ code-after .tl_gset:N = \g__nicem_code_after_tl,
+ code-after .initial:n = \c_empty_tl,
+ code-after .value_required:n = true,
+ unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArrayC}}
\msg_new:nnnn {nicematrix}
- {Unknown~option~for~pNiceArrayC}
+ {Unknown~option~for~NiceArrayC}
{The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~
\{\@currenvir\}.\\
If~you~go~on,~it~will~be~ignored.\\
For~a~list~of~the~available~options,~type~H~<return>.}
{The~available~options~are~(in~alphabetic~order):~
+ code-after,~
code-for-last-col,~
columns-width,~
+ name,~
nullify-dots,~
parallelize-diags~
and~renew-dots.}
-\cs_new_protected:Nn \__nm_NiceArrayC:nn
- {\dim_gzero_new:N \g__nm_width_last_col_dim
- \keys_set:nn {NiceMatrix/NiceArrayC} {#1}
- \bool_set_false:N \l__nm_exterior_arraycolsep_bool
- \tl_set:Nn \l__nm_pos_env_tl c
+\cs_new_protected:Nn \__nicem_NiceArrayC:n
+ {
\begin{NiceArray}
- {#2
- >{\int_gincr:N \g__nm_column_int
+ {#1
+ >{\int_gincr:N \g__nicem_column_int
\hbox_set:Nw \l_tmpa_box
- \l__nm_code_for_last_col_tl
- \tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
- \node [anchor=base] (nm-\int_use:N \g__nm_env_int-
- \int_use:N \g__nm_row_int-
- \int_use:N \g__nm_column_int)
+ \tl_if_empty:NTF \g__nicem_name_tl
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor=base,
+ name = nm-\int_use:N \g__nicem_env_int-
+ \int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int] }
+ {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline]
+ \node [anchor=base,
+ name = nm-\int_use:N \g__nicem_env_int-
+ \int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int,
+ alias = \g__nicem_name_tl-
+ \int_use:N \g__nicem_row_int-
+ \int_use:N \g__nicem_column_int] }
\bgroup $ % $
+ \l__nicem_code_for_last_col_tl
}
l
<{ $ % $
\egroup ;
\hbox_set_end:
- \dim_gset:Nn \g__nm_width_last_col_dim
- {\dim_max:nn \g__nm_width_last_col_dim
+ \dim_gset:Nn \g__nicem_width_last_col_dim
+ {\dim_max:nn \g__nicem_width_last_col_dim
{\box_wd:N \l_tmpa_box}}
- \tl_gput_right:Nn \g__nm_preamble_aux_tl {#1}
+ \tl_gput_right:Nn \g__nicem_preamble_aux_tl {#1}
\skip_horizontal:n {-2\arraycolsep}
\hbox_overlap_right:n
{\skip_horizontal:n {2\arraycolsep}
\box_use:N \l_tmpa_box}}}}
-\cs_new:Nn \__nm_after_last_col:
- {\dim_compare:nNnF \g__nm_width_last_col_dim = \c_zero_dim
- {\skip_horizontal:n {\g__nm_width_last_col_dim}{}}}
-\NewDocumentEnvironment {pNiceArrayC} {O{} m O{}}
- {\left(
- \__nm_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right)
- \__nm_after_last_col:}
-
-\NewDocumentEnvironment {vNiceArrayC} {O{} m O{}}
- {\left|
- \__nm_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right|
- \__nm_after_last_col:}
-
-\NewDocumentEnvironment {VNiceArrayC} {O{} m O{}}
- {\left\|
- \__nm_NiceArrayC:nn {#1,#3} {#2}}
- {\end{NiceArray}
- \right\|
- \__nm_after_last_col:}
-
-\NewDocumentEnvironment {bNiceArrayC} {O{} m O{}}
- {\left[
- \__nm_NiceArrayC:nn {#1,#3} {#2}}
+\NewDocumentEnvironment{NiceArrayCwithDelims} {mm O{} m O{}}
+ {\bool_set_false:N \l__nicem_direct_NiceArray_bool
+ \tl_gclear:N \g__nicem_code_after_tl
+ \dim_gzero_new:N \g__nicem_width_last_col_dim
+ \keys_set:nn {NiceMatrix/NiceArrayC} {#3,#5}
+ \bool_set_false:N \l__nicem_exterior_arraycolsep_bool
+ \tl_set:Nn \l__nicem_pos_env_tl c
+ \left#1
+ \__nicem_NiceArrayC:n {#4}}
{\end{NiceArray}
- \right]
- \__nm_after_last_col:}
-
-\NewDocumentEnvironment {BNiceArrayC} {O{} m O{}}
- {\left\{
- \__nm_NiceArrayC:nn {#1,#3} {#2}}
+ \right#2
+ \skip_horizontal:n \g__nicem_width_last_col_dim
+ }
+\NewDocumentEnvironment {pNiceArrayC} {}
+ {\NiceArrayCwithDelims{(}{)}}
+ {\endNiceArrayCwithDelims}
+\NewDocumentEnvironment {vNiceArrayC} {}
+ {\NiceArrayCwithDelims{|}{|}}
+ {\endNiceArrayCwithDelims}
+\NewDocumentEnvironment {VNiceArrayC} {}
+ {\NiceArrayCwithDelims{\|}{\|}}
+ {\endNiceArrayCwithDelims}
+\NewDocumentEnvironment {bNiceArrayC} {}
+ {\NiceArrayCwithDelims{[}{]}}
+ {\endNiceArrayCwithDelims}
+\NewDocumentEnvironment {BNiceArrayC} {}
+ {\NiceArrayCwithDelims{\{}{\}}}
+ {\endNiceArrayCwithDelims}
+\keys_define:nn {NiceMatrix/NiceArrayRC}
+ {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool,
+ parallelize-diags .default:n = true,
+ renew-dots .bool_set:N = \l__nicem_renew_dots_bool,
+ renew-dots .default:n = true,
+ nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool ,
+ nullify-dots .default:n = true,
+ code-for-first-row .tl_set:N = \l__nicem_code_for_first_row_tl,
+ code-for-last-col .tl_set:N = \l__nicem_code_for_last_col_tl,
+ code-for-last-col .value_required:n = true,
+ columns-width .tl_set:N = \l__nicem_columns_width_tl,
+ name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1}
+ {\msg_error:nnn {nicematrix}
+ {Duplicate~name}
+ {#1}}
+ {\seq_gput_left:Nn \g__nicem_names_seq {#1}}
+ \tl_gset:Nn \l__nicem_name_tl {#1}},
+ code-after .tl_set:N = \l__nicem_code_after_tl,
+ unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArrayRC}}
+\msg_new:nnnn {nicematrix}
+ {Unknown~option~for~NiceArrayRC}
+ {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~
+ \{\@currenvir\}.\\
+ If~you~go~on,~it~will~be~ignored.\\
+ For~a~list~of~the~available~options,~type~H~<return>.}
+ {The~available~options~are~(in~alphabetic~order):~
+ code-after,~
+ code-for-last-col,~
+ code-for-first-row,~
+ columns-width~(in~fact~mandatory),~
+ name,~
+ nullify-dots,~
+ parallelize-diags~
+ and~renew-dots.}
+\msg_new:nnn {nicematrix}
+ {The~key~columns-width~is~mandatory}
+ {In~the~environment~\{\@currenvir\}~you~must~use~the~
+ key~"columns-width"~either~with~a~numerical~value~
+ or~the~special~value~"auto".\\
+ If~you~go~on,~the~value~"auto"~will~be~used~for~
+ "columns-width".}
+\NewDocumentEnvironment{NiceArrayRCwithDelims} {mm O{} m O{}}
+ {\tl_clear_new:N \l__nicem_columns_width_tl
+ \tl_clear_new:N \l__nicem_name_tl
+ \tl_clear_new:N \l__nicem_code_after_tl
+ \keys_set:nn {NiceMatrix/NiceArrayRC} {#3,#5}
+ \tl_gset_eq:NN \g__nicem_name_tl \l__nicem_name_tl
+ \tl_if_empty:NT \l__nicem_columns_width_tl
+ {\msg_error:nn {nicematrix} {The~key~columns-width~is~mandatory}
+ \tl_set:Nn \l__nicem_columns_width_tl {auto}}
+ \str_if_eq:nVTF {auto} \l__nicem_columns_width_tl
+ {\begin{NiceMatrixBlock}[auto-columns-width]}
+ {\NiceMatrixOptions{columns-width = \l__nicem_columns_width_tl} }
+ \vbox\bgroup\hbox\bgroup
+ \hbox_set:Nn \l_tmpa_box {$\left#1\vbox_to_ht:nn{2cm}{}\right.$}
+ \skip_horizontal:n {\box_wd:N \l_tmpa_box - \nulldelimiterspace}
+ \int_set:Nn \l__nicem_number_of_first_row_int {-1}
+ \tl_set_eq:NN \l__nicem_code_for_cell_tl \l__nicem_code_for_first_row_tl
+ \cs_set:Npn \__nicem_replace_first_line ##1\\{
+ $\begin{NiceArray}{*\c@MaxMatrixCols{C}}
+ ##1
+ \end{NiceArray}$
+ \egroup \hbox\bgroup
+ \int_gdecr:N \g__nicem_env_int
+ \tl_gset_eq:NN \g__nicem_name_tl \l__nicem_name_tl
+ \tl_gset_eq:NN \g__nicem_code_after_tl \l__nicem_code_after_tl
+ \bool_set_false:N \l__nicem_direct_NiceArray_bool
+ \dim_gzero_new:N \g__nicem_width_last_col_dim
+ \bool_set_false:N \l__nicem_exterior_arraycolsep_bool
+ \tl_set:Nn \l__nicem_pos_env_tl c
+ $\left#1 % $
+ \__nicem_NiceArrayC:n {#4}}
+ \__nicem_replace_first_line
+ }
{\end{NiceArray}
- \right\}
- \__nm_after_last_col:}
+ \right#2$ % $
+ \skip_horizontal:n \g__nicem_width_last_col_dim
+ \egroup\egroup
+ \str_if_eq:nVT {auto} \l__nicem_columns_width_tl
+ {\end{NiceMatrixBlock}} }
+\NewDocumentEnvironment {pNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{(}{)}}
+ {\endNiceArrayRCwithDelims}
+\NewDocumentEnvironment {bNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{[}{]}}
+ {\endNiceArrayRCwithDelims}
+\NewDocumentEnvironment {vNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{|}{|}}
+ {\endNiceArrayRCwithDelims}
+\NewDocumentEnvironment {VNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{\|}{\|}}
+ {\endNiceArrayRCwithDelims}
+\NewDocumentEnvironment {BNiceArrayRC} {}
+ {\NiceArrayRCwithDelims{\{}{\}}}
+ {\endNiceArrayRCwithDelims}
\endinput
%%
%% End of file `nicematrix.sty'.