summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/nicematrix/nicematrix.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/nicematrix/nicematrix.dtx')
-rw-r--r--macros/latex/contrib/nicematrix/nicematrix.dtx1910
1 files changed, 1236 insertions, 674 deletions
diff --git a/macros/latex/contrib/nicematrix/nicematrix.dtx b/macros/latex/contrib/nicematrix/nicematrix.dtx
index 4f023e6f6d..c2856d51a2 100644
--- a/macros/latex/contrib/nicematrix/nicematrix.dtx
+++ b/macros/latex/contrib/nicematrix/nicematrix.dtx
@@ -15,8 +15,8 @@
%
% \fi
% \iffalse
-\def\myfileversion{5.0}
-\def\myfiledate{2020/07/15}
+\def\myfileversion{5.1}
+\def\myfiledate{2020/07/31}
%
%
%<*batchfile>
@@ -191,7 +191,7 @@ version 2005/12/01 or later.
% \bigskip
% {\bfseries \color{red} Important
%
-% In this version 5.0 of \pkg{nicematrix}, one must use the letters |l|, |c| and
+% Since the version 5.0 of \pkg{nicematrix}, one must use the letters |l|, |c| and
% |r| in the preambles of the environments and no longer the letters |L|, |C| and
% |R|.
%
@@ -212,12 +212,12 @@ version 2005/12/01 or later.
% \begin{ttfamily}
% \setlength{\tabcolsep}{3mm}
% \begin{tabular}{llll}
-% \{NiceTabular\} & \{NiceArray\} & \{NiceMatrix\} \\
-% & \{pNiceArray\} & \{pNiceMatrix\} \\
-% & \{bNiceArray\} & \{bNiceMatrix\} \\
-% & \{BNiceArray\} & \{BNiceMatrix\} \\
-% & \{vNiceArray\} & \{vNiceMatrix\} \\
-% & \{VNiceArray\} & \{VNiceMatrix\}
+% \{NiceTabular\} & \{NiceArray\} & \{NiceMatrix\} \\
+% \{NiceTabular*\} & \{pNiceArray\} & \{pNiceMatrix\} \\
+% & \{bNiceArray\} & \{bNiceMatrix\} \\
+% & \{BNiceArray\} & \{BNiceMatrix\} \\
+% & \{vNiceArray\} & \{vNiceMatrix\} \\
+% & \{VNiceArray\} & \{VNiceMatrix\}
% \end{tabular}
% \end{ttfamily}
%
@@ -225,13 +225,9 @@ version 2005/12/01 or later.
%
%
% \medskip
-% The environments |{NiceArray}| and |{NiceTabular}| are similar to the
-% environments |{array}| and |{tabular}| of the package \pkg{array} (which is
-% loaded by \pkg{nicematrix}).
-%
-% However, in |{NiceArray}| (and its variants), the columns of type |w| (e.g.:
-% |wc{1cm}|) are composed in math mode whereas, in |{array}| of \pkg{array},
-% they are composed in text mode.
+% The environments |{NiceArray}|, |{NiceTabular}| and |{NiceTabular*}| are
+% similar to the environments |{array}|, |{tabular}| and |{tabular*}| of the
+% package \pkg{array} (which is loaded by \pkg{nicematrix}).
%
% \medskip
% The environments |{pNiceArray}|, |{bNiceArray}|, etc. have no equivalent in
@@ -318,7 +314,7 @@ version 2005/12/01 or later.
% \section{The vertical position of the arrays}
%
% The package \pkg{nicematrix} provides a option |baseline| for the vertical
-% position of the arrays. This option takes as value an integer which is the
+% position of the arrays. This option takes in as value an integer which is the
% number of the row on which the array will be aligned.
%
% \medskip
@@ -348,8 +344,7 @@ version 2005/12/01 or later.
% immediately after an |\item| of list. One should remark that the presence of a
% |\hline| at the beginning of the array doesn't prevent the alignment of the
% baseline with the baseline of the first row (with |{tabular}| or |{array}| of
-% \pkg{array}, one must use |\firsthline|\footnote{It's also possible to use
-% |\firsthline| in the environments of \pkg{nicematrix}.}).
+% \pkg{array}, one must use |\firsthline|.
%
% \medskip
% \begin{BVerbatim}[baseline=c,boxwidth=9cm]
@@ -545,61 +540,81 @@ version 2005/12/01 or later.
% \section{The rules}
%
% The usual techniques for the rules may be used in the environments of
-% \pkg{nicematrix} (excepted |\vline|).
+% \pkg{nicematrix} (excepted |\vline|). However, there is some small differences
+% with the classical environments.
%
+% \bigskip
+% \subsection{Some differences with the classical environments}
%
-% \subsection{The thickness and the color of the rules}
-%
-% The environments of \pkg{nicematrix} provide a key |rules/width| to set the
-% width (in fact the thickness) of the rules in the current environment. In
-% fact, this key merely sets the value of the length |\arrayrulewidth|.
-%
-% \smallskip
-% It's well known that \pkg{colortbl} provides the command |\arrayrulecolor| in
-% order to specify the color of the rules.
+% \subsubsection{The vertical rules}
%
-% \smallskip
-% With \pkg{nicematrix}, it's possible to specify the color of the rules even
-% when \pkg{colortbl} is not loaded. For sake of compatibility, the command is
-% also named |\arrayrulecolor|. The environments of \pkg{nicematrix} also
-% provide a key |rules/color| to fix the color of the rules in the current
-% environment.
-%
-% \medskip
-% \begin{scope}
-% \hfuzz=10cm
-% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm]
-% \begin{NiceTabular}{|ccc|}[~emphase#rules/color=[gray]{0.9},rules/width=1pt@]
-% \hline
-% rose & tulipe & lys \\
-% arum & iris & violette \\
-% muguet & dahlia & souci \\
-% \hline
+% In the environments of \pkg{nicematrix}, the vertical rules specified by
+% \verb+|+ in the preambles of the environments are never broken, even by an
+% incomplete row or by a double horizontal rule specified by |\hline\hline|
+% (there is no need to use \pkg{hhline}). \footnote{This is the behaviour since
+% the version 5.1 of \pkg{nicematrix}. Prior to that version, the behaviour was
+% the standard behaviour of \pkg{array}.}
+%
+% \bigskip
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
+% \begin{NiceTabular}{|c|c|} \hline
+% First & Second \\ ~emphase#\hline\hline@
+% Peter \\ \hline
+% Mary & George\\ \hline
% \end{NiceTabular}
% \end{BVerbatim}
-% \begin{NiceTabular}{|ccc|}[rules/color=[gray]{0.9},rules/width=1pt]
-% \hline
-% rose & tulipe & lys \\
-% arum & iris & violette \\
-% muguet & dahlia & souci \\
-% \hline
+% \begin{NiceTabular}{|c|c|}[c] \hline
+% First & Second \\ \hline\hline
+% Peter \\ \hline
+% Mary & George \\ \hline
% \end{NiceTabular}
-% \end{scope}
+%
+% \bigskip
+% If you use \pkg{booktabs} (which provides |\toprule|, |\midrule|,
+% |\bottomrule|, etc.) and if you really want to add vertical rules (which is
+% not in the spirit of \pkg{booktabs}), you should notice that the vertical rules
+% drawn by \pkg{nicematrix} are compatible with \pkg{booktabs}.
%
% \medskip
-% If one wishes to define new specifiers for columns in order to draw vertical
-% rules (for example with a specific color or thicker than the standard rules),
-% he should consider the command |\OnlyMainNiceMatrix| described on
-% page~\pageref{OnlyMainNiceMatrix}.
+% \begin{BVerbatim}[baseline=c,boxwidth=10.5cm]
+% $\begin{NiceArray}{~emphase#|cccc|@} \toprule
+% a & b & c & d \\ \midrule
+% 1 & 2 & 3 & 4 \\
+% 1 & 2 & 3 & 4 \\ \bottomrule
+% \end{NiceArray}$
+% \end{BVerbatim}
+% $\begin{NiceArray}{|cccc|}
+% \toprule
+% a & b & c & d \\
+% \midrule
+% 1 & 2 & 3 & 4 \\
+% 1 & 2 & 3 & 4 \\
+% \bottomrule
+% \end{NiceArray}$
+%
+% \bigskip
+% However, it's still possible to define a specifier (named, for instance, |I|)
+% to draw vertical rules with the standard behaviour of \pkg{array}.
+%
+% \begin{Verbatim}
+% \newcolumntype{I}{!{\vrule}}
+% \end{Verbatim}
+%
+% However, in this case, it is probably more clever to add a command
+% |\OnlyMainNiceMatrix| (cf. p.~\pageref{OnlyMainNiceMatrix}):
+% \begin{Verbatim}
+% \newcolumntype{I}{!{\OnlyMainNiceMatrix{\vrule}}}
+% \end{Verbatim}
%
%
% \bigskip
-% \subsection{A remark about \textbackslash cline}
+% \subsubsection{The command \textbackslash cline}
%
%\label{remark-cline}
%
% The horizontal and vertical rules drawn by |\hline| and the specifier
-% ``\verb+|+'' make the array larger or wider by a quantity equal to the width of the rule.
+% ``\verb+|+'' make the array larger or wider by a quantity equal to the width
+% of the rule (with \pkg{array} and also with \pkg{nicematrix}).
%
% \smallskip
% For historical reasons, this is not the case with the command |\cline|, as
@@ -647,6 +662,53 @@ version 2005/12/01 or later.
% \end{NiceTabular}
% \end{scope}
%
+%
+% \subsection{The thickness and the color of the rules}
+%
+% The environments of \pkg{nicematrix} provide a key |rules/width| to set the
+% width (in fact the thickness) of the rules in the current environment. In
+% fact, this key merely sets the value of the length |\arrayrulewidth|.
+%
+% \smallskip
+% It's well known that \pkg{colortbl} provides the command |\arrayrulecolor| in
+% order to specify the color of the rules.
+%
+% \smallskip
+% With \pkg{nicematrix}, it's possible to specify the color of the rules even
+% when \pkg{colortbl} is not loaded. For sake of compatibility, the command is
+% also named |\arrayrulecolor|. The environments of \pkg{nicematrix} also
+% provide a key |rules/color| to fix the color of the rules in the current
+% environment.
+%
+% \medskip
+% \begin{scope}
+% \hfuzz=10cm
+% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm]
+% \begin{NiceTabular}{|ccc|}[~emphase#rules/color=[gray]{0.9},rules/width=1pt@]
+% \hline
+% rose & tulipe & lys \\
+% arum & iris & violette \\
+% muguet & dahlia & souci \\
+% \hline
+% \end{NiceTabular}
+% \end{BVerbatim}
+% \begin{NiceTabular}{|ccc|}[rules/color=[gray]{0.9},rules/width=1pt]
+% \hline
+% rose & tulipe & lys \\
+% arum & iris & violette \\
+% muguet & dahlia & souci \\
+% \hline
+% \end{NiceTabular}
+% \end{scope}
+%
+% \medskip
+% If one wishes to define new specifiers for columns in order to draw vertical
+% rules (for example with a specific color or thicker than the standard rules),
+% he should consider the command |\OnlyMainNiceMatrix| described on
+% page~\pageref{OnlyMainNiceMatrix}.
+%
+%
+%
% \subsection{The keys hlines and vlines}
%
% The key |hlines| draws all the horizontal rules and the key |vlines| draws all
@@ -668,52 +730,6 @@ version 2005/12/01 or later.
% 1 & 2 & 3 & 4 & 5 & 6
% \end{pNiceMatrix}$
%
-% \bigskip
-% However, there is a difference between the key |vlines| and the use of
-% the specifier ``"|"'' in the preamble of the environment: the rules drawn by
-% |vlines| completely cross the double-rules drawn by |\hline\hline| (you don't
-% need \pkg{hhline}).
-%
-% \medskip
-% \begin{BVerbatim}[baseline=c,boxwidth=11.5cm]
-% $\begin{NiceMatrix}[~emphase#vlines@] \hline
-% a & b & c & d \\ \hline \hline
-% 1 & 2 & 3 & 4 \\
-% 1 & 2 & 3 & 4 \\ \hline
-% \end{NiceMatrix}$
-% \end{BVerbatim}
-% $\begin{NiceMatrix}[vlines]
-% \hline
-% a & b & c & d \\
-% \hline \hline
-% 1 & 2 & 3 & 4 \\
-% 1 & 2 & 3 & 4 \\
-% \hline
-% \end{NiceMatrix}$
-%
-%
-% \bigskip
-% If you use \pkg{booktabs} (which provides |\toprule|, |midrule|, |bottomrule|,
-% etc.) and you really want to draw vertical rules (something opposed to the
-% spirit of \pkg{booktabs}), you should remark that the key |vlines| in
-% compatible with \pkg{booktabs}.
-%
-% \medskip
-% \begin{BVerbatim}[baseline=c,boxwidth=11.5cm]
-% $\begin{NiceMatrix}[~emphase#vlines@] \toprule
-% a & b & c & d \\ \midrule
-% 1 & 2 & 3 & 4 \\
-% 1 & 2 & 3 & 4 \\ \bottomrule
-% \end{NiceMatrix}$
-% \end{BVerbatim}
-% $\begin{NiceMatrix}[vlines]
-% \toprule
-% a & b & c & d \\
-% \midrule
-% 1 & 2 & 3 & 4 \\
-% 1 & 2 & 3 & 4 \\
-% \bottomrule
-% \end{NiceMatrix}$
%
%
% \subsection{The key hvlines}
@@ -888,37 +904,54 @@ version 2005/12/01 or later.
% \emph{Remark} : In the package \pkg{array} (on which the package
% \pkg{nicematrix} relies), horizontal and vertical rules make the array larger
% or wider by a quantity equal to the width of the rule\footnote{In fact, this
-% is true only for |\hline| and ``"|"'' but not for |\cline|.}. In
-% \pkg{nicematrix}, the dotted lines drawn by |\hdottedline| and ``|:|'' do
-% likewise.
+% is true only for |\hline| and ``"|"'' but not for |\cline|: cf
+% p.~\pageref{remark-cline}}. In \pkg{nicematrix}, the dotted lines drawn by
+% |\hdottedline| and ``|:|'' do likewise.
%
%
%
%\section{The color of the rows and columns}
%
-% With the classical package \pkg{colortbl}, it's possible to color the cells,
-% rows and columns of a tabular. However, the resulting \textsc{pdf} is not
-% always perfectly displayed by the \textsc{pdf} viewers, in particular in
-% conjonction with rules. With some \textsc{pdf} viewers, some vertical rules
-% seem to vanish. On the other side, some thin horizontal white lines may appear
-% in some circonstances.
+% \subsection{Utilisation of colortbl}
%
+% We recall that the package \pkg{colortbl} can be loaded directly with
+% |\usepackage{colortbl}| or by loading \pkg{xcolor} with the key |table|:
+% |\usepackage[table]{xcolor}|.
%
% \medskip
-% The package \pkg{nicematrix} provides similar tools which do not present these
-% drawbacks. It provides a key |code-before|\footnote{There is also a key
-% |code-after| : see p.~\pageref{code-after}.} for some code which will be
-% executed \emph{before} the drawing of the tabular. In this |code-before|, new
-% commands are available: |\cellcolor|, |\rectanglecolor|, |\rowcolor|,
-% |\columncolor|, |\rowcolors| and |\chessboardcolors|.
-% \label{code-before}
+% Since the package \pkg{nicematrix} is based on \pkg{array}, it's possible to
+% use \pkg{colortbl} with \pkg{nicematrix}.
%
% \medskip
-% These commands are independent of \pkg{colortbl}.\footnote{Thus, it's possible
-% to color the rules, the cells, the rows, the columns, etc. without loading
-% \pkg{colortbl}.}
+% However, there is two drawbacks:
+% \begin{itemize}
+% \item The package \pkg{colortbl} patches \pkg{array}, leading to some
+% incompatibilities (for example with the command |\hdotsfor|).
+%
+% \item The package \pkg{colortbl} constructs the array row by row, alterning
+% colored rectangles, rules and contents of the cells. The resulting
+% \textsc{pdf} is difficult to interpret by some \textsc{pdf} viewers and may
+% lead to artefacts on the screen : some rules seem to disappear and on the
+% other side, some thin white lines appear. The package \pkg{nicematrix}
+% provides some tools without those drawbacks.
+% \end{itemize}
+%
+% \subsection{The tools of nicematrix in the code-before}
+%
+% The package \pkg{nicematrix} provides some tools (independent of
+% \pkg{colortbl}) to draw the colored panels first, and, then, the content
+% of the cells and the rules. This strategy is more conform to the ``painting
+% model'' of the formats PostScript and \textsc{pdf} and is more suitable for
+% the \textsc{pdf} viewers. However, it requires several compilations.
%
% \medskip
+% The extension \pkg{nicematrix} provides a key |code-before| for some code that
+% will be executed before the drawing of the tabular. In this |code-before|, new
+% commands are available: |\cellcolor|, |\rectanglecolor|, |\rowcolor|,
+% |\columncolor|, |\rowcolors| and |\chessboardcolors|.
+% \label{code-before}
+%
+% \medskip
% All these commands accept an optional argument (between square brackets and
% in first position) which is the color model for the specification of the colors.
%
@@ -927,8 +960,8 @@ version 2005/12/01 or later.
% \item The command |\cellcolor| takes its name from the command |\cellcolor| of
% \pkg{colortbl}.
%
-% This command takes in mandatory arguments a color and a list of cells, each of
-% which with the format $i$-$j$ where $i$ is the number of row and $j$ the
+% This command takes in as mandatory arguments a color and a list of cells, each
+% of which with the format $i$-$j$ where $i$ is the number of row and $j$ the
% number of colummn of the cell.
%
%
@@ -1027,7 +1060,7 @@ version 2005/12/01 or later.
% \bigskip
% \item The command |\rowcolors| (with a \emph{s}) takes its name from the
% command |\rowcolors| of \pkg{xcolor}\footnote{The command |\rowcolors| of
-% \pkg{color} is available when \pkg{xcolor} is loaded with the
+% \pkg{xcolor} is available when \pkg{xcolor} is loaded with the
% option~|table|.}. The \emph{s} emphasizes the fact that there is \emph{two}
% colors. This command colors alternately the rows of the tabular, beginning
% with the row whose number is given in first (mandatory) argument. The two
@@ -1057,8 +1090,8 @@ version 2005/12/01 or later.
% \end{scope}
%
% \bigskip
-% \item The command |\chessboardcolors| takes in mandatory arguments two colors
-% and colors the cells of the tabular in quincunx with these colors.
+% \item The command |\chessboardcolors| takes in as mandatory arguments two colors
+% and it colors the cells of the tabular in quincunx with these colors.
%
% \medskip
% \begin{scope}
@@ -1091,7 +1124,7 @@ version 2005/12/01 or later.
% \begin{scope}
% \hfuzz=10cm
% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm]
-% \begin{NiceTabular}[c]{lssss}%
+% \begin{NiceTabular}[c]{lSSSS}%
% [code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}]
% ~emphase#\toprule@
% \Block{2-1}{Product} \\
@@ -1108,7 +1141,7 @@ version 2005/12/01 or later.
% ~emphase#\bottomrule@
% \end{NiceTabular}
% \end{BVerbatim}
-% \begin{NiceTabular}[c]{lssss}[code-before = \rowcolor{red!15}{1-2}
+% \begin{NiceTabular}[c]{lSSSS}[code-before = \rowcolor{red!15}{1-2}
% \rowcolors{3}{blue!15}{}]
% \toprule
% \Block{2-1}{Product} &
@@ -1129,15 +1162,63 @@ version 2005/12/01 or later.
% \medskip
% We have used the type of column |S| of \pkg{siunitx}.
%
+%
+% \subsection{Color tools with the syntax of colortbl}
+%
+% It's possible to access the preceding tools with a syntax close to the syntax
+% of \pkg{colortbl}. For that, one must use the key |colortbl-like| in the
+% current environment.\footnote{As of now, this key is not available in |\NiceMatrixOptions|.}
+%
+% There are three commands available (they are inspired by \pkg{colortbl} but
+% are \emph{independent} of \pkg{colortbl}):
+% \begin{itemize}
+% \item |\cellcolor| which colorizes a cell;
+% \item |\rowcolor| which must be used in a cell and which colorizes the end of
+% the row;
+% \item |\columncolor| which must be used in the preamble of the environment
+% with the same syntax as the corresponding command of
+% \pkg{colortbl}\footnote{Unlike the command |\columncolor| of \pkg{colortbl},
+% this command |\columncolor| can appear within another command, itself used in the
+% preamble.}.
+% \end{itemize}
+%
+% \medskip
+% \begin{Verbatim}
+% \begin{NiceTabular}[colortbl-like]{>{~emphase#\columncolor{blue!15}}@ccc}
+% \toprule
+% ~emphase#\rowcolor{red!15}@
+% Last name & First name & Birth day \\
+% \midrule
+% Achard & Jacques & 5 juin 1962 \\
+% Lefebvre & Mathilde & 23 mai 1988 \\
+% Vanesse & Stephany & 30 octobre 1994 \\
+% Dupont & Chantal & 15 janvier 1998 \\
+% \bottomrule
+% \end{NiceTabular}
+% \end{Verbatim}
+%
+%
+% \begin{center}
+% \begin{NiceTabular}[colortbl-like]{>{\columncolor{blue!15}}ccc}
+% \toprule
+% \rowcolor{red!15}
+% Last name & First name & Birth day \\
+% \midrule
+% Achard & Jacques & 5 juin 1962 \\
+% Lefebvre & Mathilde & 23 mai 1988 \\
+% Vanesse & Stephany & 30 octobre 1994 \\
+% Dupont & Chantal & 15 janvier 1998 \\
+% \bottomrule
+% \end{NiceTabular}
+% \end{center}
+%
+%
% \section{The width of the columns}
% \label{width}
%
% In the environments with an explicit preamble (like |{NiceTabular}|,
% |{NiceArray}|, etc.), it's possible to fix the width of a given column with
-% the standard letters |w| and |W| of the package \pkg{array}. In
-% |{NiceTabular}|, the cells of such columns are composed in text mode but, in
-% |{NiceArray}|, |{pNiceArray}|, etc., they are composed in math mode (whereas,
-% in |{array}| of \pkg{array}, they are composed in text mode).
+% the standard letters |w| and |W| of the package \pkg{array}.
%
% \medskip
% \begin{BVerbatim}[baseline=c,boxwidth=9cm]
@@ -1486,10 +1567,8 @@ version 2005/12/01 or later.
% \end{bNiceMatrix}$
%
% \bigskip
-% In the first column of this exemple, there are two instructions |\Vdots| but
-% only one dotted line is drawn (there is no overlapping graphic objects in the
-% resulting \textsc{pdf}\footnote{And it's not possible to draw a |\Ldots| and a
-% |\Cdots| line between the same cells.}).
+% In the first column of this exemple, there are two instructions |\Vdots| but,
+% of course, only one dotted line is drawn.
%
% \bigskip
% In fact, in this example, it would be possible to draw the same matrix more
@@ -1616,7 +1695,7 @@ version 2005/12/01 or later.
%
%
%
-% \subsection{The command \textbackslash Hdotsfor}
+% \subsection{The commands \textbackslash Hdotsfor and \textbackslash Vdotsfor}
%
% Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to
% draw horizontal dotted lines in a matrix. In the environments of
@@ -1668,6 +1747,44 @@ version 2005/12/01 or later.
% |\Hdotsfor| may be used when the package \pkg{colortbl} is loaded (but you
% might have problem if you use |\rowcolor| on the same row as |\Hdotsfor|).
%
+% \bigskip
+% The package \pkg{nicematrix} also provides a command |\Vdotsfor| similar to
+% |\Hdotsfor| but for the vertical dotted lines.
+% \bigskip
+% The following example uses both |\Hdotsfor| and |\Vdotsfor|:
+%
+% \begin{Verbatim}[formatcom=\small\color{gray}]
+% \begin{bNiceMatrix}
+% C[a_1,a_1] & \Cdots & C[a_1,a_n]
+% & \hspace*{20mm} & C[a_1,a_1^{(p)}] & \Cdots & C[a_1,a_n^{(p)}] \\
+% \Vdots & \Ddots & \Vdots
+% & ~emphase#\Hdotsfor{1}@ & \Vdots & \Ddots & \Vdots \\
+% C[a_n,a_1] & \Cdots & C[a_n,a_n]
+% & & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
+% \rule{0pt}{15mm} & ~emphase#\Vdotsfor{1}@ & & \Ddots & & ~emphase#\Vdotsfor{1}@ \\
+% C[a_1^{(p)},a_1] & \Cdots & C[a_1^{(p)},a_n]
+% & & C[a_1^{(p)},a_1^{(p)}] & \Cdots & C[a_1^{(p)},a_n^{(p)}] \\
+% \Vdots & \Ddots & \Vdots
+% & ~emphase#\Hdotsfor{1}@ & \Vdots & \Ddots & \Vdots \\
+% C[a_n^{(p)},a_1] & \Cdots & C[a_n^{(p)},a_n]
+% & & C[a_n^{(p)},a_1^{(p)}] & \Cdots & C[a_n^{(p)},a_n^{(p)}]
+% \end{bNiceMatrix}
+% \end{Verbatim}
+%
+%
+% \[\begin{bNiceMatrix}
+% C[a_1,a_1] & \Cdots & C[a_1,a_n] & \hspace*{20mm} & C[a_1,a_1^{(p)}] & \Cdots & C[a_1,a_n^{(p)}] \\
+% \Vdots & \Ddots & \Vdots & \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
+% C[a_n,a_1] & \Cdots & C[a_n,a_n] & & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
+% \rule{0pt}{15mm} & \Vdotsfor{1} & & \Ddots & & \Vdotsfor{1} \\
+% C[a_1^{(p)},a_1] & \Cdots & C[a_1^{(p)},a_n] & & C[a_1^{(p)},a_1^{(p)}] & \Cdots & C[a_1^{(p)},a_n^{(p)}] \\
+% \Vdots & \Ddots & \Vdots & \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
+% C[a_n^{(p)},a_1] & \Cdots & C[a_n^{(p)},a_n] & & C[a_n^{(p)},a_1^{(p)}] & \Cdots & C[a_n^{(p)},a_n^{(p)}]
+% \end{bNiceMatrix}\]
+
+
+
+%
% \subsection{How to generate the continuous dotted lines transparently}
%
% The package \pkg{nicematrix} provides an option called |transparent| for using
@@ -1995,7 +2112,8 @@ version 2005/12/01 or later.
% \begin{itemize}
% \item If you have several successive commands |\tabularnote{...}| \emph{with no
% space at all between them}, the labels of the corresponding notes are composed
-% together, separated by commas.
+% together, separated by commas (this is similar to the option |multiple| of
+% \pkg{footmisc} for the footnotes).
%
% \item If a command |\tabularnote{...}| is exactly at the end of a cell (with
% no space at all after), the label of the note is composed in an overlapping
@@ -2086,7 +2204,7 @@ version 2005/12/01 or later.
% \item |notes/code-before|
% \end{itemize}
% For sake of commodity, it is also possible to set these keys in
-% |\NiceMatrixOptions| via a key |notes| which takes as value a list of
+% |\NiceMatrixOptions| via a key |notes| which takes in as value a list of
% pairs \textsl{key=value} where the name of the keys need no longer be
% prefixed by |notes|:
% \begin{center}
@@ -2191,7 +2309,7 @@ version 2005/12/01 or later.
% corresponds to the type of list used when the option |para| is in force. Of
% course, when the option |para| is used, a list of type |inline| (as called by
% \pkg{enumitem}) is used and the pairs \textsl{key=value} should correspond to
-% such a list of type |inline| .
+% such a list of type |inline|.
%
% Initial value:\quad |afterlabel = \nobreak, itemjoin = \quad|
%
@@ -2270,9 +2388,8 @@ version 2005/12/01 or later.
% \label{key-R}
%
% The environments without preamble (|{NiceMatrix}|, |{pNiceMatrix}|,
-% |{bNiceMatrix}|, etc.) provide two options |l| and |r| (equivalent at |L| and
-% |R|) which generate all the columns aligned leftwards (or
-% rightwards).
+% |{bNiceMatrix}|, etc.) provide two options |l| and |r| which generate all the
+% columns aligned leftwards (or rightwards).
%
%
% \medskip
@@ -2451,7 +2568,7 @@ version 2005/12/01 or later.
% |\AutoNiceMatrix|, |\pAutoNiceMatrix|, |\bAutoNiceMatrix|, |\vAutoNiceMatrix|,
% |\VAutoNiceMatrix| and |\BAutoNiceMatrix|.
%
-% These commands take two mandatory arguments. The first is the format of the
+% These commands take in two mandatory arguments. The first is the format of the
% matrix, with the syntax $n$-$p$ where $n$ is the number of rows and $p$ the
% number of columns. The second argument is the pattern (it's a list of tokens
% which are inserted in each cell of the constructed matrix, excepted in the
@@ -2924,6 +3041,102 @@ version 2005/12/01 or later.
% 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
% \end{NiceMatrix}\]
%
+% \section{Tools for the developpers}
+%
+% As its name implies, the token list |\g_nicematrix_code_after_tl| is public
+% (according to the LaTeX3 conventions, each variable with name beginning with
+% |\g_nicematrix| ou |\l_nicematrix| is public and each variable with name
+% beginning with |\g__nicematrix| or |\l__nicematrix| is private).
+%
+%
+% \medskip
+% This variable contains the code of what we have called the ``|code-after|''.
+% The developper can use it to add code from a cell of the array (the
+% affectation must be global, allowing to exit the cell, which is a TeX group).
+%
+% \medskip
+% \emph{Example} : We want to write a command |\crossbox| to draw a cross in the
+% current cell. This command will take in an optional argument between square
+% brackets for a list of pairs \textsl{key}-\textsl{value} which will be given to
+% Tikz before the drawing.
+%
+% It's possible to program such command |\crossbox| as follows, explicitely
+% using the public variable |\g_nicematrix_code_after_tl|.
+%
+%
+% \begin{scope}
+% \fvset{commandchars=\§\¤\μ}
+% \begin{Verbatim}
+% \ExplSyntaxOn
+% \cs_new_protected:Nn \__pantigny_crossbox:nnn
+% {
+% \begin { tikzpicture }
+% \draw [ #3 ]
+% ( row-#1 -| col-\int_eval:n { #2 + 1 } )
+% -- ( row-\int_eval:n { #1 + 1 } -| col-#2 )
+% ( row-#1 -| col-\int_eval:n #2 )
+% -- ( row-\int_eval:n { #1 + 1 } -| col-\int_eval:n { #2 + 1 } ) ;
+% \end { tikzpicture }
+% }
+%
+%
+% \NewDocumentCommand \crossbox { ! O { } }
+% {
+% \tl_gput_right:Nx §emphase¤\g_nicematrix_code_after_tlμ
+% {
+% \__pantigny_crossbox:nnn
+% { \int_use:c { c@iRow } }
+% { \int_use:c { c@jCol } }
+% { \exp_not:n { #1 } }
+% }
+% }
+% \ExplSyntaxOff
+% \end{Verbatim}
+% \end{scope}
+%
+%
+% \ExplSyntaxOn
+% \cs_new_protected:Nn \__pantigny_crossbox:nnn
+% {
+% \begin { tikzpicture }
+% \draw [ #3 ]
+% ( row-#1 -| col-\int_eval:n { #2 + 1 } )
+% -- ( row-\int_eval:n { #1 + 1 } -| col-#2 )
+% ( row-#1 -| col-\int_eval:n #2 )
+% -- ( row-\int_eval:n { #1 + 1 } -| col-\int_eval:n { #2 + 1 } ) ;
+% \end { tikzpicture }
+% }
+%
+%
+% \NewDocumentCommand \crossbox { ! O { } }
+% {
+% \tl_gput_right:Nx \g_nicematrix_code_after_tl
+% {
+% \__pantigny_crossbox:nnn
+% { \int_use:c { c@iRow } }
+% { \int_use:c { c@jCol } }
+% { \exp_not:n { #1 } }
+% }
+% }
+% \ExplSyntaxOff
+%
+% \bigskip
+% Here is an example of utilisation:
+%
+% \medskip
+% \begin{BVerbatim}[baseline=c,boxwidth=9cm]
+% \begin{NiceTabular}{ccc}[hvlines]
+% Tokyo & Paris & London \\
+% Cap Town & ~emphase#\crossbox[red]@ & Miami \\
+% Los Angeles & Madrid & Roma
+% \end{NiceTabular}
+% \end{BVerbatim}
+% \begin{NiceTabular}{ccc}[hvlines]
+% Tokyo & Paris & London \\
+% Cap Town & \crossbox[red] & Miami \\
+% Los Angeles & Madrid & Roma
+% \end{NiceTabular}
+%
%
% \section{Technical remarks}
%
@@ -2944,7 +3157,9 @@ version 2005/12/01 or later.
% \newcolumntype{?}{!{\OnlyMainNiceMatrix{\vrule width 1 pt}}}
% \end{Verbatim}
%
-% The heavy vertical rule won't extend in the exterior rows:
+% The heavy vertical rule won't extend in the exterior rows.\footnote{Of course,
+% such rule is defined by the classical technics of \pkg{nicematrix} and, for
+% this reason, won't cross the double rules of |\hline\hline|.}
% \medskip
% \begin{scope}
% \newcolumntype{?}{!{\OnlyMainNiceMatrix{\vrule width 1 pt}}}
@@ -3128,8 +3343,8 @@ version 2005/12/01 or later.
%
% \medskip
% First, we write a command |\stars| similar the well-known commands
-% |\arabic|, |\alph|, |\Alph|, etc. which produce a number of stars equal to its argument
-% \footnote{In fact: the value of its argument.}
+% |\arabic|, |\alph|, |\Alph|, etc. which produces a number of stars equal to
+% its argument \footnote{In fact: the value of its argument.}
% \begin{Verbatim}
% \ExplSyntaxOn
% \NewDocumentCommand ~emphase#\stars@ { m }
@@ -3419,7 +3634,7 @@ version 2005/12/01 or later.
% { last-col,code-for-last-col = \color{blue}\scriptstyle,light-syntax}
% \setlength{\extrarowheight}{1mm}
% $\begin{pNiceArray}{cccc:c}
-% 1 1 1 1 1 ;
+% 1 1 1 1 1 {} ;
% 2 4 8 16 9 ;
% 3 9 27 81 36 ;
% 4 16 64 256 100
@@ -3443,7 +3658,7 @@ version 2005/12/01 or later.
% \setlength{\extrarowheight}{1mm}
%
% \enskip $\begin{pNiceArray}{cccc:c}
-% 1 1 1 1 1 ;
+% 1 1 1 1 1 {} ;
% 2 4 8 16 9 ;
% 3 9 27 81 36 ;
% 4 16 64 256 100
@@ -3975,6 +4190,7 @@ version 2005/12/01 or later.
\cs_new_protected:Npn \@@_error:nn { \msg_error:nnn { nicematrix } }
\cs_new_protected:Npn \@@_error:nnn { \msg_error:nnnn { nicematrix } }
\cs_new_protected:Npn \@@_fatal:n { \msg_fatal:nn { nicematrix } }
+\cs_new_protected:Npn \@@_fatal:nn { \msg_fatal:nnn { nicematrix } }
\cs_new_protected:Npn \@@_msg_new:nn { \msg_new:nnn { nicematrix } }
\cs_new_protected:Npn \@@_msg_new:nnn { \msg_new:nnnn { nicematrix } }
% \end{macrocode}
@@ -4360,6 +4576,32 @@ version 2005/12/01 or later.
}
% \end{macrocode}
%
+% \bigskip
+% The following regex will be used to modify the preamble of the array when the
+% key |colortbl-like| is used.
+% \begin{macrocode}
+\regex_const:Nn \c_@@_columncolor_regex { \c { columncolor } }
+% \end{macrocode}
+%
+% \bigskip
+% If the final user uses \pkg{nicematrix}, PGF/Tikz will write instruction
+% |\pgfsyspdfmark| in the |aux| file. If he changes its mind and no longer loads
+% \pkg{nicematrix}, an error may occur at the next compilation because of
+% remanent instructions |\pgfsyspdfmark| in the |aux| file. With the following
+% code, we avoid that situation.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_provide_pgfsyspdfmark:
+ {
+ \iow_now:Nn \@mainaux
+ {
+ \ExplSyntaxOn
+ \cs_if_free:NT \pgfsyspdfmark
+ { \cs_set_eq:NN \pgfsyspdfmark \use:nnn }
+ \ExplSyntaxOff
+ }
+ \cs_gset_eq:NN \@@_provide_pgfsyspdfmark: \prg_do_nothing:
+ }
+% \end{macrocode}
%
% \subsection*{Parameters}
%
@@ -4380,7 +4622,7 @@ version 2005/12/01 or later.
\newcolumntype C c
\newcolumntype R r
}
-% \end{document}
+% \end{macrocode}
%
% \bigskip
% The following counter will count the environments |{NiceArray}|. The value of
@@ -4419,7 +4661,7 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
-% the following counter will count the environments |{NiceMatrixBlock}|.
+% The following counter will count the environments |{NiceMatrixBlock}|.
% \begin{macrocode}
\int_new:N \g_@@_NiceMatrixBlock_int
% \end{macrocode}
@@ -4457,10 +4699,26 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
-% If the user uses |{NiceTabular}|, we will raise the following flag.
+% If the user uses |{NiceTabular}| or |{NiceTabular*}|, we will raise the
+% following flag.
% \begin{macrocode}
\bool_new:N \l_@@_NiceTabular_bool
% \end{macrocode}
+%
+% \bigskip
+% If the user uses |{NiceTabular*}|, the width of the tabular (in the first
+% argument of the environment |{NiceTabular*}|) will be stored in the following
+% dimension.
+% \begin{macrocode}
+\dim_new:N \l_@@_tabular_width_dim
+% \end{macrocode}
+%
+% \bigskip
+% If the user uses an environment without preamble, we will raise the following
+% flag.
+% \begin{macrocode}
+\bool_new:N \l_@@_Matrix_bool
+% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
@@ -4512,15 +4770,15 @@ version 2005/12/01 or later.
% The following token list corresponds to the option |code-after| (it's also
% possible to set the value of that parameter with the command |\CodeAfter|).
% \begin{macrocode}
-\tl_new:N \g_@@_code_after_tl
+\tl_new:N \g_nicematrix_code_after_tl
% \end{macrocode}
%
% \bigskip
-% The following token list has a function similar to |\g_@@_code_after_tl| but
-% it is used internally by \pkg{nicematrix}. In fact, we have to distinguish
-% between |\g_@@_code_after_tl| and |\g_@@_internal_code_after_tl| because we
-% must take care of the order in which instructions stored in that paremeters
-% are executed.
+% The following token list has a function similar to
+% |\g_nicematrix_code_after_tl| but it is used internally by \pkg{nicematrix}.
+% In fact, we have to distinguish between |\g_nicematrix_code_after_tl| and
+% |\g_@@_internal_code_after_tl| because we must take care of the order in which
+% instructions stored in that paremeters are executed.
% \begin{macrocode}
\tl_new:N \g_@@_internal_code_after_tl
% \end{macrocode}
@@ -4556,11 +4814,18 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
-% The following flag will be raised when the key |code-before| is used in the
-% environment. Indeed, if there is a |code-before| in the environment, we will
-% manage to have the |row| nodes and the |col| nodes available \emph{before} the
-% creation of the array.
+% |\l_@@_code_before_tl| may contain two types of informations:
+% \begin{itemize}
+% \item A |code-before| written in the |aux| file by a previous run. When the
+% |aux| file is read, this |code-before| is stored in
+% |\g_@@_code_before_|\textsl{i}|_tl| (where \textsl{i} is the number of the
+% environment) and, at the beginning of the environment, it will be put in
+% |\l_@@_code_before_tl|.
+% \item The final user can explicitely add material in |\l_@@_code_before_tl| by
+% using the key |code-before|.
+% \end{itemize}
% \begin{macrocode}
+\tl_new:N \l_@@_code_before_tl
\bool_new:N \l_@@_code_before_bool
% \end{macrocode}
%
@@ -4640,7 +4905,19 @@ version 2005/12/01 or later.
% required by the key |hvlines| (these rules won't be drawn within the virtual
% blocks corresponding to the dotted lines).
%
-%
+% \medskip
+% We are able to determine the number of columns specified in the preamble (for
+% the environments with explicit preamble, of course and without the potential
+% exterior columns).
+% \begin{macrocode}
+\int_new:N \g_@@_static_num_of_col_int
+% \end{macrocode}
+%
+% \medskip
+% Used for the color of the blocks.
+% \begin{macrocode}
+\tl_new:N \l_@@_color_tl
+% \end{macrocode}
%
% \bigskip
% \textbf{Variables for the exterior rows and columns}\par\nobreak
@@ -4704,11 +4981,12 @@ version 2005/12/01 or later.
% \item \textbf{Last column}\par\nobreak
%
% For the potential ``last column'', we use an integer. A value of $-2$ means
-% that there is no last column. A value of $-1$ means that there is a last
-% column but we don't know its value because the user has used the option
-% |last-col| without value (it's possible in an environment without preamble
-% like |{pNiceMatrix}|). A value of $0$ means that the option |last-col| has
-% been used in an environment with preamble (like |{pNiceArray}|).
+% that there is no last column. A value of $-1$ means that we are in an
+% environment without preamble (e.g. |{bNiceMatrix}|) and there is a last column
+% but we don't know its value because the user has used the option |last-col|
+% without value. A value of $0$ means that the option |last-col| has been used
+% in an environment with preamble (like |{pNiceArray}|): in this case, the key
+% was necessary without argument.
% \begin{macrocode}
\int_new:N \l_@@_last_col_int
\int_set:Nn \l_@@_last_col_int { -2 }
@@ -4717,7 +4995,7 @@ version 2005/12/01 or later.
% However, we have also a boolean. Consider the following code:
% \begin{center}
% \begin{BVerbatim}
-% \begin{pNiceArray}{CC}[last-col]
+% \begin{pNiceArray}{cc}[last-col]
% 1 & 2 \\
% 3 & 4
% \end{pNiceArray}
@@ -4984,6 +5262,15 @@ version 2005/12/01 or later.
% \bigskip
% \subsection*{The options}
%
+% By default, the commands |\cellcolor| and |\rowcolor| are available for the
+% user in the cells of the tabular (the user may use the commands provided by
+% |\colortbl|). However, if the key |colortbl-like| is used, these
+% commands are available.
+% \begin{macrocode}
+\bool_new:N \l_@@_colortbl_like_bool
+% \end{macrocode}
+%
+% \bigskip
% By default, the behaviour of |\cline| is changed in the environments of
% \pkg{nicematrix}: a |\cline| spreads the array by an amount equal to
% |\arrayrulewidht|. It's possible to disable this feature with the key
@@ -5075,9 +5362,9 @@ version 2005/12/01 or later.
% \bigskip
% The flag |\l_@@_hlines_bool| corresponds to the key |hlines|, the flag
% |\l_@@_vlines_bool| to the key |vlines| and the flag |hvlines| to the key
-% |hvlines|. Since version 4.1, the key |hvlines| is no longer a mere alias for
-% the conjonction of |hlines| and |vlines|. Indeed, with |hvlines|, the vertical
-% and horizontal rules are \emph{not} drawn within the blocks (created by |\Block|).
+% |hvlines|. The key |hvlines| is not a mere alias for the conjonction of
+% |hlines| and |vlines|. Indeed, with |hvlines|, the vertical and horizontal
+% rules are \emph{not} drawn within the blocks (created by |\Block|).
% \begin{macrocode}
\bool_new:N \l_@@_hlines_bool
\bool_new:N \l_@@_vlines_bool
@@ -5295,7 +5582,7 @@ version 2005/12/01 or later.
extra-right-margin .dim_set:N = \l_@@_extra_right_margin_dim ,
extra-margin .meta:n =
{ extra-left-margin = #1 , extra-right-margin = #1 } ,
- extra-margin .value_required:n = true
+ extra-margin .value_required:n = true ,
}
% \end{macrocode}
%
@@ -5311,7 +5598,7 @@ version 2005/12/01 or later.
{
\tl_if_empty:nF { #1 }
{
- \tl_set:Nn \l_@@_code_before_tl { #1 }
+ \tl_put_right:Nn \l_@@_code_before_tl { #1 }
\bool_set_true:N \l_@@_code_before_bool
}
} ,
@@ -5345,8 +5632,12 @@ version 2005/12/01 or later.
\str_set_eq:NN \l_@@_name_str \l_tmpa_str
} ,
name .value_required:n = true ,
- code-after .tl_gset:N = \g_@@_code_after_tl ,
+ code-after .tl_gset:N = \g_nicematrix_code_after_tl ,
code-after .value_required:n = true ,
+ colortbl-like .code:n =
+ \bool_set_true:N \l_@@_colortbl_like_bool
+ \bool_set_true:N \l_@@_code_before_bool ,
+ colortbl-like .value_forbidden:n = true
}
% \end{macrocode}
%
@@ -5412,9 +5703,7 @@ version 2005/12/01 or later.
\keys_define:nn { NiceMatrix }
{
NiceMatrixOptions .inherit:n =
- {
- NiceMatrix / Global ,
- } ,
+ { NiceMatrix / Global } ,
NiceMatrixOptions / xdots .inherit:n = NiceMatrix / xdots ,
NiceMatrixOptions / rules .inherit:n = NiceMatrix / rules ,
NiceMatrixOptions / notes .inherit:n = NiceMatrix / notes ,
@@ -5556,8 +5845,6 @@ version 2005/12/01 or later.
{ \int_set:Nn \l_@@_last_col_int { #1 } } ,
l .code:n = \tl_set:Nn \l_@@_type_of_col_tl l ,
r .code:n = \tl_set:Nn \l_@@_type_of_col_tl r ,
- L .code:n = \tl_set:Nn \l_@@_type_of_col_tl l ,
- R .code:n = \tl_set:Nn \l_@@_type_of_col_tl r ,
S .code:n = \bool_if:NTF \c_@@_siunitx_loaded_bool
{ \tl_set:Nn \l_@@_type_of_col_tl S }
{ \@@_error:n { option~S~without~siunitx } } ,
@@ -5900,17 +6187,34 @@ version 2005/12/01 or later.
% redefinition of |\array| incompatible with our use of |\array|.
%
% \begin{macrocode}
+\cs_new_protected:Npn \@@_revtex_array:
+ {
+ \cs_set_eq:NN \@acoll \@arrayacol
+ \cs_set_eq:NN \@acolr \@arrayacol
+ \cs_set_eq:NN \@acol \@arrayacol
+ \cs_set:Npn \@halignto { }
+ \@array@array
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
\cs_new_protected:Npn \@@_array:
{
\bool_if:NTF \c_@@_revtex_bool
+ \@@_revtex_array:
{
- \cs_set_eq:NN \@acoll \@arrayacol
- \cs_set_eq:NN \@acolr \@arrayacol
- \cs_set_eq:NN \@acol \@arrayacol
- \cs_set:Npn \@halignto { }
- \@array@array
+ \bool_if:NTF \l_@@_NiceTabular_bool
+ { \dim_set_eq:NN \col@sep \tabcolsep }
+ { \dim_set_eq:NN \col@sep \arraycolsep }
+ \dim_compare:nNnTF \l_@@_tabular_width_dim = \c_zero_dim
+ { \cs_set:Npn \@halignto { } }
+ { \cs_set:Npx \@halignto { to \dim_use:N \l_@@_tabular_width_dim } }
+% \end{macrocode}
+% It \pkg{colortbl} is loaded, |\@tabarray| has been redefined to incorporate
+% |\CT@start|.
+% \begin{macrocode}
+ \@tabarray
}
- \array
% \end{macrocode}
% |\l_@@_baseline_str| may have the value |t|, |c| or |b|. However, if the value
% is |b|, we compose the |\array| (of \pkg{array}) with the option |t| and the
@@ -6008,12 +6312,10 @@ version 2005/12/01 or later.
% \bigskip
% The command |\@@_newcolumntype| is the command |\newcolumntype| of
% \pkg{array} without the warnings for redefinitions of columns types (we will
-% use it to redefine the columns types |w|, |W|, |p|, |m| and |b|).
+% use it to redefine the columns types |w| and |W|).
% \begin{macrocode}
\cs_set_protected:Npn \@@_newcolumntype #1
{
- % \cs_if_free:cT { NC @ find @ #1 }
- % { \NC@list \exp_after:wN { \the \NC@list \NC@do #1 } }
\cs_set:cpn { NC @ find @ #1 } ##1 #1 { \NC@ { ##1 } }
\peek_meaning:NTF [
{ \newcol@ #1 }
@@ -6023,31 +6325,29 @@ version 2005/12/01 or later.
%
%
% \bigskip
-% The following command will be used to redefine the column types |p|, |m| and
-% |b|. That means that it will be used three times. The first argument is the
-% letter of the column type (|p|, |m| or |b|). The second is the letter of
-% position for the environment |{minipage}| (|t|, |c| or |b|).
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_define_columntype:nn #1 #2
- {
-% \end{macrocode}
-% We don't want a warning for redefinition of the column type. That's why we use
-% |\@@_newcolumntype| and not |\newcolumntype|.
+% When the key |renew-dots| is used, the following code will be executed.
% \begin{macrocode}
- \@@_newcolumntype #1 [ 1 ]
- {
- > {
- \@@_Cell:
- \begin { minipage } [ #2 ] { ##1 }
- \mode_leave_vertical: \box_use:N \@arstrutbox
- }
+\cs_set_protected:Npn \@@_renew_dots:
+ {
+ \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 \dots \@@_Ldots
+ \cs_set_eq:NN \hdotsfor \@@_Hdotsfor:
+ }
% \end{macrocode}
-% Here, we put |c| but we would have the result with |l| or |r|.
+%
+% \bigskip
+% When the key |colortbl-like| is used, the following code will be executed.
% \begin{macrocode}
- c
- < { \box_use:N \@arstrutbox \end { minipage } \@@_end_Cell: }
+\cs_new_protected:Npn \@@_colortbl_like:
+ {
+ \cs_set_eq:NN \cellcolor \@@_cellcolor_tabular
+ \cs_set_eq:NN \rowcolor \@@_rowcolor_tabular
+ \cs_set_eq:NN \columncolor \@@_columncolor_preamble
}
- }
% \end{macrocode}
%
% \bigskip
@@ -6103,8 +6403,6 @@ version 2005/12/01 or later.
% \begin{macrocode}
\cs_set:Npn \ialign
{
- \bool_if:NT \l_@@_NiceTabular_bool
- { \dim_set_eq:NN \arraycolsep \@@_old_arraycolsep_dim }
\bool_if:NTF \c_@@_colortbl_loaded_bool
{
\CT@everycr
@@ -6159,8 +6457,6 @@ version 2005/12/01 or later.
\cs_set_eq:NN \@@_old_vdots \vdots
\cs_set_eq:NN \@@_old_ddots \ddots
\cs_set_eq:NN \@@_old_iddots \iddots
- \cs_set_eq:NN \firsthline \hline
- \cs_set_eq:NN \lasthline \hline
\bool_if:NTF \l_@@_standard_cline_bool
{ \cs_set_eq:NN \cline \@@_standard_cline }
{ \cs_set_eq:NN \cline \@@_cline }
@@ -6180,16 +6476,8 @@ version 2005/12/01 or later.
\cs_set_eq:NN \dotfill \@@_dotfill:
\cs_set_eq:NN \CodeAfter \@@_CodeAfter:n
\cs_set_eq:NN \diagbox \@@_diagbox:nn
- \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 \dots \@@_Ldots
- \cs_set_eq:NN \hdotsfor \@@_Hdotsfor:
- }
+ \bool_if:NT \l_@@_colortbl_like_bool \@@_colortbl_like:
+ \bool_if:NT \l_@@_renew_dots_bool \@@_renew_dots:
% \end{macrocode}
%
%
@@ -6231,135 +6519,11 @@ version 2005/12/01 or later.
\cs_set_eq:NN \@ifnextchar \new@ifnextchar
% \end{macrocode}
%
-%
-% \bigskip
-% We redefine the column types |p|, |m| and |b|. The command
-% |\@@_define_columntype:nn| is only used here.
-% \begin{macrocode}
- \@@_define_columntype:nn p t
- \@@_define_columntype:nn m c
- \@@_define_columntype:nn b b
-% \end{macrocode}
-%
-% \bigskip
-% We redefine the column types |w| and |W|. We use |\@@_newcolumntype| instead
-% of |\newcolumtype| because we don't want warnings for column types already
-% defined.
-% \begin{macrocode}
- \@@_newcolumntype w [ 2 ]
- {
- > {
- \hbox_set:Nw \l_@@_cell_box
- \@@_Cell:
- }
-% \end{macrocode}
-% |\@@_true_c:| will be replaced statically by |c| at the end of the construction
-% of the preamble.
-% \begin{macrocode}
- \@@_true_c:
- < {
- \@@_end_Cell:
- \hbox_set_end:
-% \end{macrocode}
-% The construction with |\@@_foldcase:| (defined below) should be replaced by
-% |\str_foldcase:n| when that command of \pkg{expl3} will be widespread. That
-% construction is only for giving the user the ability to write |wC{1cm}|
-% instead of |wc{1cm}| for homogeneity with the letters |L|, |C| and |R| used
-% elsewhere in the preamble instead of |l|, |c| and |r|.
-% \begin{macrocode}
- \tl_set:Nn \l_tmpa_tl { ##1 }
- \makebox [ ##2 ] [ \@@_foldcase: ]
- { \box_use_drop:N \l_@@_cell_box }
- }
- }
- \@@_newcolumntype W [ 2 ]
- {
- > {
- \hbox_set:Nw \l_@@_cell_box
- \@@_Cell:
- }
-% \end{macrocode}
-% |\@@_true_c:| will be replaced statically by |c| at the end of the construction
-% of the preamble.
-% \begin{macrocode}
- \@@_true_c:
- < {
- \@@_end_Cell:
- \hbox_set_end:
- \cs_set_eq:NN \hss \hfil
- \tl_set:Nn \l_tmpa_tl { ##1 }
- \makebox [ ##2 ] [ \@@_foldcase: ]
- { \box_use_drop:N \l_@@_cell_box }
- }
- }
-% \end{macrocode}
-%
-% \bigskip
-% By default, the letter used to specify a dotted line in the preamble of an
-% environment of \pkg{nicematrix} (for example in |{pNiceArray}|) is the letter
-% |:|. However, this letter is used by some packages, for example
-% \pkg{arydshln}. That's why it's possible to change the letter used by
-% \pkg{nicematrix} with the option |letter-for-dotted-lines| which changes the
-% value of |\l_@@_letter_for_dotted_lines_str|. We rescan this string (which is
-% always of length~1) in particular for the case where |pdflatex| is used with
-% \pkg{french-babel} (the colon is activated by \pkg{french-babel} at the
-% beginning of the document).
% \begin{macrocode}
- \tl_set_rescan:Nno
- \l_@@_letter_for_dotted_lines_str { } \l_@@_letter_for_dotted_lines_str
- \exp_args:NV \newcolumntype \l_@@_letter_for_dotted_lines_str
- {
- !
- {
+ \@@_renew_NC@rewrite@S:
% \end{macrocode}
%
-% \medskip
-% The following code because we want the dotted line to have exactly the same
-% position as a vertical rule drawn by ``"|"'' (considering the rule having a
-% width equal to the diameter of the dots).
-% \begin{macrocode}
- \int_compare:nNnF \c@iRow = 0
- {
- \int_compare:nNnF \c@iRow = \l_@@_last_row_int
- { \skip_horizontal:N 2\l_@@_radius_dim }
- }
-% \end{macrocode}
-%
-% \medskip
-% Consider the following code:
-% \begin{center}
-% \begin{BVerbatim}
-% \begin{NiceArray}{C:CC:C}
-% a & b
-% c & d \\
-% e & f & g & h \\
-% i & j & k & l
-% \end{NiceArray}
-% \end{BVerbatim}
-% \end{center}
-% The first ``|:|'' in the preamble will be encountered during the first row of
-% the environment |{NiceArray}| but the second one will be encountered only in
-% the third row. We have to issue a command |\vdottedline:n| in the |code-after|
-% only one time for each ``|:|'' in the preamble. That's why we keep a counter
-% |\g_@@_last_vdotted_col_int| and with this counter, we know whether a letter
-% ``|:|'' encountered during the parsing has already been taken into account in
-% the |code-after|.
-% \begin{macrocode}
- \int_compare:nNnT \c@jCol > \g_@@_last_vdotted_col_int
- {
- \int_gset_eq:NN \g_@@_last_vdotted_col_int \c@jCol
- \tl_gput_right:Nx \g_@@_internal_code_after_tl
-% \end{macrocode}
-% The command |\@@_vdottedline:n| is protected, and, therefore, won't be
-% expanded before writing on |\g_@@_internal_code_after_tl|.
% \begin{macrocode}
- { \@@_vdottedline:n { \int_use:N \c@jCol } }
- }
- }
- }
- \int_gzero_new:N \g_@@_last_vdotted_col_int
- \@@_renew_NC@rewrite@S:
- \int_gset:Nn \g_@@_last_vdotted_col_int { -1 }
\bool_gset_false:N \g_@@_last_col_found_bool
% \end{macrocode}
%
@@ -6374,24 +6538,15 @@ version 2005/12/01 or later.
\tl_gclear_new:N \g_@@_Ddots_lines_tl
\tl_gclear_new:N \g_@@_Iddots_lines_tl
\tl_gclear_new:N \g_@@_HVdotsfor_lines_tl
- }
% \end{macrocode}
%
% \medskip
-% The following command will be deleted when we will consider |\str_lowercase:n|
-% as widespread.
% \begin{macrocode}
-\cs_set:Npn \@@_foldcase:
- {
- \tl_case:NnF \l_tmpa_tl
- {
- C { c }
- L { l }
- R { r }
- }
- { \l_tmpa_tl }
+ \tl_gclear_new:N \g_@@_code_before_tl
}
% \end{macrocode}
+% This is the end of |\@@_pre_array:|.
+%
%
% \bigskip
% \subsection*{The environment \{NiceArrayWithDelims\}}
@@ -6399,7 +6554,8 @@ version 2005/12/01 or later.
% \begin{macrocode}
\NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } }
{
- \bool_if:NT \c_@@_footnote_bool { \begin { savenotes } }
+ \@@_provide_pgfsyspdfmark:
+ \bool_if:NT \c_@@_footnote_bool \savenotes
% \end{macrocode}
% The aim of the following |\bgroup| (the corresponding |\egroup| is, of course,
% at the end of the environment) is to be able to put an exposant to a matrix in
@@ -6467,6 +6623,14 @@ version 2005/12/01 or later.
% In fact, the sequence |\g_@@_pos_of_blocks_seq| will also contain the
% positions of the cells with a |\diagbox|.
%
+% \begin{macrocode}
+ \tl_if_exist:cT { g_@@_code_before_ \int_use:N \g_@@_env_int _ tl }
+ {
+ \bool_set_true:N \l_@@_code_before_bool
+ \exp_args:NNv \tl_put_right:Nn \l_@@_code_before_tl
+ { g_@@_code_before_ \int_use:N \g_@@_env_int _ tl }
+ }
+% \end{macrocode}
%
% The set of keys is not exactly the same for |{NiceArray}| and for the variants
% of |{NiceArray}| (|{pNiceArray}|, |{bNiceArray}|, etc.) because, for
@@ -6485,7 +6649,6 @@ version 2005/12/01 or later.
% \end{macrocode}
%
%
-%
% \bigskip
% If the key |code-before| is used, we have to create the |col| nodes and the
% |row| nodes before the creation of the array. First, we have to test whether
@@ -6678,13 +6841,6 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
-% We construct the preamble of the array in |\l_tmpa_tl|.
-% \begin{macrocode}
- \tl_set:Nn \l_tmpa_tl { #4 }
-% \end{macrocode}
-%
-%
-% \bigskip
% If the user has loaded |nicematrix| with the option |define-L-C-R|, he will be
% able to use |L|, |C| and |R| instead of |l|, |c| and |r| in the preambles of
% the environments of \pkg{nicematrix} (it's a compatibility mode since |L|, |C|
@@ -6692,74 +6848,14 @@ version 2005/12/01 or later.
% \begin{macrocode}
\bool_if:NT \c_@@_define_L_C_R_bool \@@_define_L_C_R:
% \end{macrocode}
-%
-% \bigskip
-% We will do an ``expansion''\footnote{This ``expansion'' expands all the
-% constructions with |*| and with the new column types defined by
-% |\newcolumntype|.} of the preamble (with the tools of \pkg{array}
-% itself) and a replacement of the specifiers |c|, |l| and |r| by the specifiers
-% |C|, |L| and |R|.
-%
-%
-% We store our preamble in the token register |\@temptokena| (those
-% ``token registers'' are not supported by \pkg{expl3}).
-% \begin{macrocode}
- \@temptokena \exp_after:wN { \l_tmpa_tl }
-% \end{macrocode}
-% Initialisation of a flag used by \pkg{array} to detect the end of the expansion.
-% \begin{macrocode}
- \@tempswatrue
-% \end{macrocode}
-% The following line actually does the expansion (it's has been copied from
-% |array.sty|).
-% \begin{macrocode}
- \@whilesw \if@tempswa \fi { \@tempswafalse \the \NC@list }
-% \end{macrocode}
-% We put back the preamble in our token list |\l_tmpa_tl|.
-% \begin{macrocode}
- \tl_gset:NV \l_tmpa_tl \@temptokena
-% \end{macrocode}
-%
-% We do the replacement of letters |c|, |l| and |r| (these column types can't be
-% redefined by |\newcolumtype| of \pkg{array} and that's why we have to do the
-% job ``by hand'' after expansion of the preamble).
-% \begin{macrocode}
- \tl_replace_all:Nnn \l_tmpa_tl c { > \@@_Cell: c < \@@_end_Cell: }
- \tl_replace_all:Nnn \l_tmpa_tl l { > \@@_Cell: l < \@@_end_Cell: }
- \tl_replace_all:Nnn \l_tmpa_tl r { > \@@_Cell: r < \@@_end_Cell: }
- \tl_replace_all:Nnn \l_tmpa_tl \@@_true_c: c
-% \end{macrocode}
%
% \bigskip
-% We complete the preamble with the potential ``exterior columns''.
+% The preamble will be constructed in |\g_@@_preamble_tl|.
% \begin{macrocode}
- \int_compare:nNnTF \l_@@_first_col_int = 0
- { \tl_put_left:NV \l_tmpa_tl \c_@@_preamble_first_col_tl }
- {
- \bool_lazy_all:nT
- {
- \l_@@_NiceArray_bool
- { \bool_not_p:n \l_@@_NiceTabular_bool }
- { \bool_not_p:n \l_@@_vlines_bool }
- { \bool_not_p:n \l_@@_exterior_arraycolsep_bool }
- }
- { \tl_put_left:Nn \l_tmpa_tl { @ { } } }
- }
- \int_compare:nNnTF \l_@@_last_col_int > { -1 }
- { \tl_put_right:NV \l_tmpa_tl \c_@@_preamble_last_col_tl }
- {
- \bool_lazy_all:nT
- {
- \l_@@_NiceArray_bool
- { \bool_not_p:n \l_@@_NiceTabular_bool }
- { \bool_not_p:n \l_@@_vlines_bool }
- { \bool_not_p:n \l_@@_exterior_arraycolsep_bool }
- }
- { \tl_put_right:Nn \l_tmpa_tl { @ { } } }
- }
- \tl_put_right:Nn \l_tmpa_tl { > { \@@_error_too_much_cols: } l }
+ \@@_construct_preamble:n { #4 }
% \end{macrocode}
-% Now, the preamble is constructed in |\l_tmpa_tl|
+%
+% Now, the preamble is constructed in |\g_@@_preamble_tl|
%
%
%
@@ -6768,38 +6864,9 @@ version 2005/12/01 or later.
% |\hbox_set_end:| corresponding to this |\hbox_set:Nw| will be in the second
% part of the environment (and the closing |\c_math_toggle_token| also).
% \begin{macrocode}
- \hbox_set:Nw \l_@@_the_array_box
-% \end{macrocode}
-% Here is a trick. We will call |\array| and, at the beginning, |\array| will set
-% |\col@sep| equal to the current value of |\arraycolsep|. In we are in an
-% environment |{NiceTabular}|, we would like that |\array| sets |\col@sep| equal
-% to the current value of |\tabcolsep|. That's why we set |\arraycolsep| equal
-% to |\tabcolsep|. However, the value of |\tabcolsep| in each cell of the array
-% should be equal to the current value of |\tabcolsep| outside |{NiceTabular}|.
-% That's why we save the current value of |\arraycolsep| and we will restore the
-% value just before the |\halign|. It's possible because we do a redefinition of
-% |\ialign| (see just below).
-% \begin{macrocode}
- \bool_if:NT \l_@@_NiceTabular_bool
- {
- \dim_set_eq:NN \@@_old_arraycolsep_dim \arraycolsep
- \dim_set_eq:NN \arraycolsep \tabcolsep
- }
-% \end{macrocode}
-% If the key |\vlines| is used, we increase |\arraycolsep| by
-% |0.5\arrayrulewidth| in order to reserve space for the width of the vertical
-% rules drawn with Tikz after the end of the array. However, the first
-% |\arraycolsep| is used once (between columns, |\arraycolsep| is used twice).
-% That's why we add a |0.5\arrayrulewidth| more.
-% \begin{macrocode}
- \bool_if:NT \l_@@_vlines_bool
- {
- \dim_add:Nn \arraycolsep { 0.5 \arrayrulewidth }
- \skip_horizontal:N 0.5\arrayrulewidth
- }
+ \hbox_set:Nw \l_@@_the_array_box
% \end{macrocode}
%
-%
% \begin{macrocode}
\skip_horizontal:N \l_@@_left_margin_dim
\skip_horizontal:N \l_@@_extra_left_margin_dim
@@ -6819,14 +6886,6 @@ version 2005/12/01 or later.
\c_math_toggle_token
\skip_horizontal:N \l_@@_right_margin_dim
\skip_horizontal:N \l_@@_extra_right_margin_dim
-% \end{macrocode}
-% If the key |\vlines| is used, we have increased |\arraycolsep| by
-% |0.5\arrayrulewidth| in order to reserve space for the width of the vertical
-% rules drawn with Tikz after the end of the array. However, the last
-% |\arraycolsep| is used once (between columns, |\arraycolsep| is used twice).
-% That's why we add a |0.5 \arrayrulewidth| more.
-% \begin{macrocode}
- \bool_if:NT \l_@@_vlines_bool { \skip_horizontal:N 0.5\arrayrulewidth }
\hbox_set_end:
% \end{macrocode}
% End of the construction of the array (in the box |\l_@@_the_array_box|).
@@ -6856,7 +6915,17 @@ version 2005/12/01 or later.
% has the number~$0$.}
% \begin{macrocode}
\int_gset_eq:NN \c@jCol \g_@@_col_total_int
- \bool_if:nT \g_@@_last_col_found_bool { \int_gdecr:N \c@jCol }
+ \bool_if:nTF \g_@@_last_col_found_bool
+ { \int_gdecr:N \c@jCol }
+ {
+ \int_compare:nNnT \l_@@_last_col_int > { -1 }
+ { \@@_error:n { last~col~not~used } }
+ }
+ \bool_if:NF \l_@@_Matrix_bool
+ {
+ \int_compare:nNnT \c@jCol < \g_@@_static_num_of_col_int
+ { \@@_error:n { columns~not~used } }
+ }
% \end{macrocode}
%
% We fix also the value of |\c@iRow| and |\g_@@_row_total_int| with the
@@ -6883,68 +6952,17 @@ version 2005/12/01 or later.
%
% The construction of the real box is different when |\l_@@_NiceArray_bool| is
% true (|{NiceArray}| or |{NiceTabular}|) and in the other environments because,
-% in |{NiceArray}| or |{NiceTabular}|, we have to take into account the value of
-% |baseline| and we have no delimiter to put. We begin with this case.
+% in |{NiceArray}| or |{NiceTabular}|, we have no delimiter to put. We begin
+% with this case.
% \begin{macrocode}
\bool_if:NTF \l_@@_NiceArray_bool
{
-% \end{macrocode}
-% Remember that, when the key |b| is used, the |{array}| (of \pkg{array}) is
-% constructed with the option |t| (and not |b|). Now, we do the translation to
-% take into account the option |b|.
-% \begin{macrocode}
- \str_if_eq:VnTF \l_@@_baseline_str { b }
+ \str_case:VnF \l_@@_baseline_str
{
- \pgfpicture
- \@@_qpoint:n { row - 1 }
- \dim_gset_eq:NN \g_tmpa_dim \pgf@y
- \@@_qpoint:n { row - \int_use:N \c@iRow - base }
- \dim_gsub:Nn \g_tmpa_dim \pgf@y
- \endpgfpicture
- \dim_gadd:Nn \g_tmpa_dim \arrayrulewidth
- \int_compare:nNnT \l_@@_first_row_int = 0
- {
- \dim_gadd:Nn \g_tmpa_dim \g_@@_ht_row_zero_dim
- \dim_gadd:Nn \g_tmpa_dim \g_@@_dp_row_zero_dim
- }
- \box_move_up:nn \g_tmpa_dim { \@@_use_array_box_with_notes: }
- }
- {
- \str_if_eq:VnTF \l_@@_baseline_str { c }
- { \@@_use_array_box_with_notes: }
- {
-% \end{macrocode}
-% We convert a value of |t| to a value of |1|.
-% \begin{macrocode}
- \str_if_eq:VnT \l_@@_baseline_str { t }
- { \str_set:Nn \l_@@_baseline_str { 1 } }
-% \end{macrocode}
-% Now, we convert the value of |\l_@@_baseline_str| (which should represent an
-% integer) to an integer stored in |\l_tmpa_int|.
-% \begin{macrocode}
- \int_set:Nn \l_tmpa_int \l_@@_baseline_str
- \bool_lazy_or:nnT
- { \int_compare_p:nNn \l_tmpa_int < \l_@@_first_row_int }
- { \int_compare_p:nNn \l_tmpa_int > \g_@@_row_total_int }
- {
- \@@_error:n { bad~value~for~baseline }
- \int_set:Nn \l_tmpa_int 1
- }
- \pgfpicture
- \@@_qpoint:n { row - 1 }
- \dim_gset_eq:NN \g_tmpa_dim \pgf@y
- \@@_qpoint:n { row - \int_use:N \l_tmpa_int - base }
- \dim_gsub:Nn \g_tmpa_dim \pgf@y
- \endpgfpicture
- \dim_gadd:Nn \g_tmpa_dim \arrayrulewidth
- \int_compare:nNnT \l_@@_first_row_int = 0
- {
- \dim_gadd:Nn \g_tmpa_dim \g_@@_ht_row_zero_dim
- \dim_gadd:Nn \g_tmpa_dim \g_@@_dp_row_zero_dim
- }
- \box_move_up:nn \g_tmpa_dim { \@@_use_array_box_with_notes: }
- }
+ b \@@_use_arraybox_with_notes_b:
+ c \@@_use_arraybox_with_notes_c:
}
+ \@@_use_arraybox_with_notes:
}
% \end{macrocode}
%
@@ -6994,7 +7012,7 @@ version 2005/12/01 or later.
\bool_if:NTF \l_@@_NiceTabular_bool
{ \skip_horizontal:N -\tabcolsep }
{ \skip_horizontal:N -\arraycolsep }
- \@@_use_array_box_with_notes:
+ \@@_use_arraybox_with_notes_c:
\bool_if:NTF \l_@@_NiceTabular_bool
{ \skip_horizontal:N -\tabcolsep }
{ \skip_horizontal:N -\arraycolsep }
@@ -7033,13 +7051,355 @@ version 2005/12/01 or later.
}
\@@_after_array:
\egroup
- \bool_if:NT \c_@@_footnote_bool { \end { savenotes } }
+ \bool_if:NT \c_@@_footnote_bool \endsavenotes
}
% \end{macrocode}
% This is the end of the environment |{NiceArrayWithDelims}|.
%
%
+% \subsection*{We construct the preamble of the array}
+%
+% The transformation of the preamble is an operation in several steps.
+%
+% \bigskip
+% The argument of |\@@_construct_preamble:n| is the preamble as given by the
+% final user to the environement |{NiceTabular}| (or a variant). The preamble
+% will be constructed in |\g_@@_preamble_tl|.
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_construct_preamble:n #1
+ {
+% \end{macrocode}
+% First, we will do an ``expansion'' of the preamble with the tools of the
+% package \pkg{array} itself. This ``expansion'' will expand all the constructions
+% with |*| and with all column types (defined by the user or by various packages
+% using |\newcolumntype|).
+%
+% Since we use the tools of \pkg{array} to do this expansion, we will have a
+% programmation which is not in the style of \pkg{expl3}.
+%
+%
+% \bigskip
+% We redefine the column types |w| and |W|. We use |\@@_newcolumntype| instead
+% of |\newcolumtype| because we don't want warnings for column types already
+% defined. These redefinitions are in fact \emph{protections} of the letters |w|
+% and |W|. We don't want these columns type expanded because we will do the
+% patch ourselves after. We want to be able the standard column types |w| and
+% |W| in potential |{tabular}| of \pkg{array} in some cells of our array. That's
+% why we do those redefinitions in a TeX group.
+% \begin{macrocode}
+ \group_begin:
+% \end{macrocode}
+%
+% If we are in an environment without explicit preamble, we have nothing to do
+% (excepted the treatment on both sides of the preamble which will be done at
+% the end).
+% \begin{macrocode}
+ \bool_if:NTF \l_@@_Matrix_bool
+ { \tl_gset:Nn \g_@@_preamble_tl { #1 } }
+ {
+ \@@_newcolumntype w [ 2 ] { \@@_w: { ##1 } { ##2 } }
+ \@@_newcolumntype W [ 2 ] { \@@_W: { ##1 } { ##2 } }
+% \end{macrocode}
+%
+% First, we have to store our preamble in the token register |\@temptokena|
+% (those ``token registers'' are not supported by \pkg{expl3}).
+% \begin{macrocode}
+ \@temptokena { #1 }
+% \end{macrocode}
+% Initialisation of a flag used by \pkg{array} to detect the end of the expansion.
+% \begin{macrocode}
+ \@tempswatrue
+% \end{macrocode}
+% The following line actually does the expansion (it's has been copied from
+% |array.sty|).
+% \begin{macrocode}
+ \@whilesw \if@tempswa \fi { \@tempswafalse \the \NC@list }
+% \end{macrocode}
+%
+% \bigskip
+% Now, we have to ``patch'' that preamble by transforming some columns.
+% We will insert in the TeX flow the preamble in its actual form (that is to say
+% after the ``expansion'') following by a marker |\q_stop| and we will consume
+% these tokens constructing the (new form of the) preamble in
+% |\g_@@_preamble_tl|. This is done recursively with the command
+% |\@@_patch_preamble:n|. In the same time, we will count the columns with the
+% counter |\c@jCol|.
+% \begin{macrocode}
+ \int_gzero_new:N \c@jCol
+ \bool_if:NTF \l_@@_vlines_bool
+ {
+ \tl_gset:Nn \g_@@_preamble_tl
+ { ! { \skip_horizontal:N \arrayrulewidth } }
+ }
+ { \tl_gclear:N \g_@@_preamble_tl }
+% \end{macrocode}
+% The counter |\l_tmpa_int| will be count the number of consecutive occurrences
+% of the symbole \verb+|+.
+% \begin{macrocode}
+ \int_zero:N \l_tmpa_int
+% \end{macrocode}
+% Now, we actually patch the preamble (and it is constructed in
+% |\g_@@_preamble_tl|).
+% \begin{macrocode}
+ \exp_after:wN \@@_patch_preamble:n \the \@temptokena \q_stop
+ \int_gset_eq:NN \g_@@_static_num_of_col_int \c@jCol
+ }
+% \end{macrocode}
+%
+% \medskip
+% Now, we replace |\columncolor| by |\@@_columncolor_preamble|.
+% \begin{macrocode}
+ \bool_if:NT \l_@@_colortbl_like_bool
+ {
+ \regex_replace_all:NnN
+ \c_@@_columncolor_regex
+ { \c { @@_columncolor_preamble } }
+ \g_@@_preamble_tl
+ }
+% \end{macrocode}
+%
+% \bigskip
+% We complete the preamble with the potential ``exterior columns''.
+% \begin{macrocode}
+ \int_compare:nNnTF \l_@@_first_col_int = 0
+ { \tl_gput_left:NV \g_@@_preamble_tl \c_@@_preamble_first_col_tl }
+ {
+ \bool_lazy_all:nT
+ {
+ \l_@@_NiceArray_bool
+ { \bool_not_p:n \l_@@_NiceTabular_bool }
+ { \bool_not_p:n \l_@@_vlines_bool }
+ { \bool_not_p:n \l_@@_exterior_arraycolsep_bool }
+ }
+ { \tl_gput_left:Nn \g_@@_preamble_tl { @ { } } }
+ }
+ \int_compare:nNnTF \l_@@_last_col_int > { -1 }
+ { \tl_gput_right:NV \g_@@_preamble_tl \c_@@_preamble_last_col_tl }
+ {
+ \bool_lazy_all:nT
+ {
+ \l_@@_NiceArray_bool
+ { \bool_not_p:n \l_@@_NiceTabular_bool }
+ { \bool_not_p:n \l_@@_vlines_bool }
+ { \bool_not_p:n \l_@@_exterior_arraycolsep_bool }
+ }
+ { \tl_gput_right:Nn \g_@@_preamble_tl { @ { } } }
+ }
+% \end{macrocode}
+% We add a last column to raise a good error message when the user put more
+% columns than allowed by its preamble. However, for technical reasons, it's not
+% possible to do that in |{NiceTabular*}| (|\l_@@_tabular_width_dim|=0pt).
+% \begin{macrocode}
+ \dim_compare:nNnT \l_@@_tabular_width_dim = \c_zero_dim
+ {
+ \tl_gput_right:Nn
+ \g_@@_preamble_tl
+ { > { \@@_error_too_much_cols: } l }
+ }
+% \end{macrocode}
+%
+% \medskip
+% Now, we have to close the TeX group which was opened for the redefinition of
+% the columns of type |w| and |W|.
+% \begin{macrocode}
+ \group_end:
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble:n #1
+ {
+ \str_case:nnF { #1 }
+ {
+ c { \@@_patch_preamble_i:n #1 }
+ l { \@@_patch_preamble_i:n #1 }
+ r { \@@_patch_preamble_i:n #1 }
+ > { \@@_patch_preamble_ii:nn #1 }
+ < { \@@_patch_preamble_ii:nn #1 }
+ ! { \@@_patch_preamble_ii:nn #1 }
+ @ { \@@_patch_preamble_ii:nn #1 }
+ | { \@@_patch_preamble_iii:n #1 }
+ p { \@@_patch_preamble_iv:nnn t #1 }
+ m { \@@_patch_preamble_iv:nnn c #1 }
+ b { \@@_patch_preamble_iv:nnn b #1 }
+ \@@_w: { \@@_patch_preamble_v:nnnn { } #1 }
+ \@@_W: { \@@_patch_preamble_v:nnnn { \cs_set_eq:NN \hss \hfil } #1 }
+ \@@_true_c: { \@@_patch_preamble_vi:n #1 }
+ \q_stop { }
+ }
+ {
+ \str_if_eq:VnTF \l_@@_letter_for_dotted_lines_str { #1 }
+ { \@@_patch_preamble_vii:n #1 }
+ { \@@_fatal:nn { unknown~column~type } { #1 } }
+ }
+ }
+% \end{macrocode}
+%
+% \medskip
+% For |c|, |l| and |r|
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_i:n #1
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl { > \@@_Cell: #1 < \@@_end_Cell: }
+% \end{macrocode}
+% We increment the counter of columns.
+% \begin{macrocode}
+ \int_gincr:N \c@jCol
+ \bool_if:NT \l_@@_vlines_bool
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl
+ { ! { \skip_horizontal:N \arrayrulewidth } }
+ }
+ \@@_patch_preamble:n
+ }
+% \end{macrocode}
+%
+% \medskip
+% For |>|, |<|, |!| and |@|
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_ii:nn #1 #2
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl { #1 { #2 } }
+ \@@_patch_preamble:n
+ }
+% \end{macrocode}
+%
+%
+% \medskip
+% For \verb+|+
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_iii:n #1
+ {
+% \end{macrocode}
+% |\l_tmpa_int| is the number of successive occurrences of \verb+|+
+% \begin{macrocode}
+ \int_incr:N \l_tmpa_int
+ \@@_patch_preamble_iii_i:n
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_iii_i:n #1
+ {
+ \str_if_eq:nnTF { #1 } |
+ { \@@_patch_preamble_iii:n | }
+ {
+ \tl_gput_right:Nx \g_@@_preamble_tl
+ {
+ \exp_not:N !
+ {
+ \skip_horizontal:n
+ {
+ \dim_eval:n
+ {
+ \arrayrulewidth * \l_tmpa_int
+ + \doublerulesep * ( \l_tmpa_int - 1)
+ }
+ }
+ }
+ }
+ \tl_gput_right:Nx \g_@@_internal_code_after_tl
+ { \@@_vline:nn { \int_use:N \c@jCol } { \int_use:N \l_tmpa_int } }
+ \int_zero:N \l_tmpa_int
+ \@@_patch_preamble:n #1
+ }
+ }
+% \end{macrocode}
+%
+%
+% \medskip
+% For |p|, |m| and |b|
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_iv:nnn #1 #2 #3
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl
+ {
+ > {
+ \@@_Cell:
+ \begin { minipage } [ #1 ] { #3 }
+ \mode_leave_vertical:
+ \box_use:N \@arstrutbox
+ }
+ c
+ < { \box_use:N \@arstrutbox \end { minipage } \@@_end_Cell: }
+ }
+% \end{macrocode}
+% We increment the counter of columns.
+% \begin{macrocode}
+ \int_gincr:N \c@jCol
+ \@@_patch_preamble:n
+ }
+% \end{macrocode}
+%
+% \medskip
+% For |w| and |W|
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_v:nnnn #1 #2 #3 #4
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl
+ {
+ > {
+ \hbox_set:Nw \l_@@_cell_box
+ \@@_Cell:
+ }
+ c
+ < {
+ \@@_end_Cell:
+ #1
+ \hbox_set_end:
+ \makebox [ #4 ] [ #3 ] { \box_use_drop:N \l_@@_cell_box }
+ }
+ }
+% \end{macrocode}
+% We increment the counter of columns.
+% \begin{macrocode}
+ \int_gincr:N \c@jCol
+ \@@_patch_preamble:n
+ }
+% \end{macrocode}
+%
+% \medskip
+% For |\@@_true_c:| which will appear in our redefinition of the columns of type
+% |S| (of \pkg{siunitx}).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_vi:n #1
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl { c }
+% \end{macrocode}
+% We increment the counter of columns.
+% \begin{macrocode}
+ \int_gincr:N \c@jCol
+ \bool_if:NT \l_@@_vlines_bool
+ {
+ \tl_gput_right:Nn \g_@@_preamble_tl
+ { ! { \skip_horizontal:N \arrayrulewidth } }
+ }
+ \@@_patch_preamble:n
+ }
+% \end{macrocode}
%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_vii:n #1
+ {
+% \end{macrocode}
+% Here, we have a problem in the cases of the use in the first column or the ``last
+% one''.
+% \begin{macrocode}
+ \tl_gput_right:Nn \g_@@_preamble_tl
+ { ! { \skip_horizontal:N 2\l_@@_radius_dim } }
+% \end{macrocode}
+% The command |\@@_vdottedline:n| is protected, and, therefore, won't be
+% expanded before writing on |\g_@@_internal_code_after_tl|.
+% \begin{macrocode}
+ \tl_gput_right:Nx \g_@@_internal_code_after_tl
+ { \@@_vdottedline:n { \int_use:N \c@jCol } }
+ \@@_patch_preamble:n
+ }
+% \end{macrocode}
+%
+%
% \bigskip
% The command |\@@_put_box_in_flow:| puts the box |\l_tmpa_box| (which contains
% the array) in the flow. It is used for the environments with delimiters.
@@ -7107,7 +7467,7 @@ version 2005/12/01 or later.
%
% \bigskip
% \begin{macrocode}
-\cs_new_protected:Npn \@@_use_array_box_with_notes:
+\cs_new_protected:Npn \@@_use_arraybox_with_notes_c:
{
\int_compare:nNnTF \c@tabularnote = 0
{ \box_use_drop:N \l_@@_the_array_box }
@@ -7169,6 +7529,68 @@ version 2005/12/01 or later.
}
% \end{macrocode}
%
+% \medskip
+% The case of |baseline| equal to |b|. Remember that, when the key |b| is used,
+% the |{array}| (of \pkg{array}) is constructed with the option |t| (and not
+% |b|). Now, we do the translation to take into account the option |b|.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_use_arraybox_with_notes_b:
+ {
+ \pgfpicture
+ \@@_qpoint:n { row - 1 }
+ \dim_gset_eq:NN \g_tmpa_dim \pgf@y
+ \@@_qpoint:n { row - \int_use:N \c@iRow - base }
+ \dim_gsub:Nn \g_tmpa_dim \pgf@y
+ \endpgfpicture
+ \dim_gadd:Nn \g_tmpa_dim \arrayrulewidth
+ \int_compare:nNnT \l_@@_first_row_int = 0
+ {
+ \dim_gadd:Nn \g_tmpa_dim \g_@@_ht_row_zero_dim
+ \dim_gadd:Nn \g_tmpa_dim \g_@@_dp_row_zero_dim
+ }
+ \box_move_up:nn \g_tmpa_dim { \@@_use_arraybox_with_notes_c: }
+ }
+% \end{macrocode}
+%
+% \medskip
+% Now, the general case (hence the |g| in the name).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_use_arraybox_with_notes:
+ {
+% \end{macrocode}
+% We convert a value of |t| to a value of |1|.
+% \begin{macrocode}
+ \str_if_eq:VnT \l_@@_baseline_str { t }
+ { \str_set:Nn \l_@@_baseline_str { 1 } }
+% \end{macrocode}
+% Now, we convert the value of |\l_@@_baseline_str| (which should represent an
+% integer) to an integer stored in |\l_tmpa_int|.
+% \begin{macrocode}
+ \int_set:Nn \l_tmpa_int \l_@@_baseline_str
+ \bool_lazy_or:nnT
+ { \int_compare_p:nNn \l_tmpa_int < \l_@@_first_row_int }
+ { \int_compare_p:nNn \l_tmpa_int > \g_@@_row_total_int }
+ {
+ \@@_error:n { bad~value~for~baseline }
+ \int_set:Nn \l_tmpa_int 1
+ }
+ \pgfpicture
+ \@@_qpoint:n { row - 1 }
+ \dim_gset_eq:NN \g_tmpa_dim \pgf@y
+ \@@_qpoint:n { row - \int_use:N \l_tmpa_int - base }
+ \dim_gsub:Nn \g_tmpa_dim \pgf@y
+ \endpgfpicture
+ \dim_gadd:Nn \g_tmpa_dim \arrayrulewidth
+ \int_compare:nNnT \l_@@_first_row_int = 0
+ {
+ \dim_gadd:Nn \g_tmpa_dim \g_@@_ht_row_zero_dim
+ \dim_gadd:Nn \g_tmpa_dim \g_@@_dp_row_zero_dim
+ }
+ \box_move_up:nn \g_tmpa_dim { \@@_use_arraybox_with_notes_c: }
+ }
+% \end{macrocode}
+%
+%
%
% \bigskip
% The command |\@@_put_box_in_flow_bis:| is used when the option
@@ -7226,9 +7648,9 @@ version 2005/12/01 or later.
% \interitem
% The construction of the array in the environment |{NiceArrayWithDelims}| is,
% in fact, done by the environment |{@@-light-syntax}| or by the environment
-% |{@@-normal-syntax}| (whether the option |light-syntax| is used or not). When
-% the key |light-syntax| is not used, the construction is a standard
-% environment (and, thus, it's possible to use verbatim in the arrray).
+% |{@@-normal-syntax}| (whether the option |light-syntax| is in force or not).
+% When the key |light-syntax| is not used, the construction is a standard
+% environment (and, thus, it's possible to use verbatim in the array).
% \begin{macrocode}
\NewDocumentEnvironment { @@-normal-syntax } { }
% \end{macrocode}
@@ -7239,13 +7661,12 @@ version 2005/12/01 or later.
% by LaTeX for incorrect nested environments).
% \begin{macrocode}
{
- \peek_meaning_ignore_spaces:NTF \end
- { \@@_analyze_end:Nn }
+ \peek_meaning_ignore_spaces:NTF \end \@@_analyze_end:Nn
% \end{macrocode}
% Here is the call to |\array| (we have a dedicated macro |\@@_array:| because
% of compatibility with the classes \cls{revtex4-1} and \cls{revtex4-2}).
% \begin{macrocode}
- { \exp_args:NV \@@_array: \l_tmpa_tl }
+ { \exp_args:NV \@@_array: \g_@@_preamble_tl }
}
{
\@@_create_col_nodes:
@@ -7255,8 +7676,8 @@ version 2005/12/01 or later.
%
%
% \bigskip
-% When the key |light-syntax| is used, we use an environment which takes its whole
-% body as an argument (with the specifier |b| of \pkg{xparse}).
+% When the key |light-syntax| is in force, we use an environment which takes its
+% whole body as an argument (with the specifier |b| of \pkg{xparse}).
% % \label{code-light-syntax}
% \begin{macrocode}
\NewDocumentEnvironment { @@-light-syntax } { b }
@@ -7275,12 +7696,13 @@ version 2005/12/01 or later.
{ \@@_fatal:n { double-backslash~in~light-syntax } }
}
% \end{macrocode}
-% Now, you extract the |code-after| or the body of the environment. Maybe, there
+% Now, you extract the |code-after| of the body of the environment. Maybe, there
% is no command |\CodeAfter| in the body. That's why you put a marker
% |\CodeAfter| after |#1|. If there is yet a |\CodeAfter| in |#1|, this second
% (or third...) |\CodeAfter| will be catched in the value of
-% |\g_@@_code_after_tl|. That doesn't matter because |\CodeAfter| will be set to
-% \textsl{no-op} before the execution of |\g_@@_code_after_tl|.
+% |\g_nicematrix_code_after_tl|. That doesn't matter because |\CodeAfter| will
+% be set to \textsl{no-op} before the execution of
+% |\g_nicematrix_code_after_tl|.
% \begin{macrocode}
\@@_light_syntax_i #1 \CodeAfter \q_stop
}
@@ -7296,7 +7718,7 @@ version 2005/12/01 or later.
% \begin{macrocode}
\cs_new_protected:Npn \@@_light_syntax_i #1\CodeAfter #2\q_stop
{
- \tl_gput_right:Nn \g_@@_code_after_tl { #2 }
+ \tl_gput_right:Nn \g_nicematrix_code_after_tl { #2 }
% \end{macrocode}
% The body of the array, which is stored in the argument |#1|, is now
% splitted into items (and \emph{not} tokens).
@@ -7316,7 +7738,7 @@ version 2005/12/01 or later.
% Here is the call to |\array| (we have a dedicated macro |\@@_array:| because
% of compatibility with the classes \cls{revtex4-1} and \cls{revtex4-2}).
% \begin{macrocode}
- \exp_args:NV \@@_array: \l_tmpa_tl
+ \exp_args:NV \@@_array: \g_@@_preamble_tl
% \end{macrocode}
% We need a global affectation because, when executing |\l_tmpa_tl|, we will
% exit the first cell of the array.
@@ -7700,80 +8122,36 @@ version 2005/12/01 or later.
% We create the variants of the environment |{NiceArrayWithDelims}|.
%
% \begin{macrocode}
-\NewDocumentEnvironment { pNiceArray } { }
- {
- \str_if_empty:NT \g_@@_name_env_str
- { \str_gset:Nn \g_@@_name_env_str { pNiceArray } }
- \@@_test_if_math_mode:
- \NiceArrayWithDelims ( )
- }
- { \endNiceArrayWithDelims }
-% \end{macrocode}
-%
-% \begin{macrocode}
-\NewDocumentEnvironment { bNiceArray } { }
- {
- \str_if_empty:NT \g_@@_name_env_str
- { \str_gset:Nn \g_@@_name_env_str { bNiceArray } }
- \@@_test_if_math_mode:
- \NiceArrayWithDelims [ ]
- }
- { \endNiceArrayWithDelims }
-% \end{macrocode}
-%
-% \begin{macrocode}
-\NewDocumentEnvironment { BNiceArray } { }
- {
- \str_if_empty:NT \g_@@_name_env_str
- { \str_gset:Nn \g_@@_name_env_str { BNiceArray } }
- \@@_test_if_math_mode:
- \NiceArrayWithDelims \{ \}
- }
- { \endNiceArrayWithDelims }
-% \end{macrocode}
-%
-% \begin{macrocode}
-\NewDocumentEnvironment { vNiceArray } { }
+\cs_new_protected:Npn \@@_def_env:nnn #1 #2 #3
{
- \str_if_empty:NT \g_@@_name_env_str
- { \str_gset:Nn \g_@@_name_env_str { vNiceArray } }
- \@@_test_if_math_mode:
- \NiceArrayWithDelims | |
+ \NewDocumentEnvironment { #1 NiceArray } { }
+ {
+ \str_if_empty:NT \g_@@_name_env_str
+ { \str_gset:Nn \g_@@_name_env_str { #1 NiceArray } }
+ \@@_test_if_math_mode:
+ \NiceArrayWithDelims #2 #3
+ }
+ { \endNiceArrayWithDelims }
}
- { \endNiceArrayWithDelims }
% \end{macrocode}
%
% \begin{macrocode}
-\NewDocumentEnvironment { VNiceArray } { }
- {
- \str_if_empty:NT \g_@@_name_env_str
- { \str_gset:Nn \g_@@_name_env_str { VNiceArray } }
- \@@_test_if_math_mode:
- \NiceArrayWithDelims \| \|
- }
- { \endNiceArrayWithDelims }
+\@@_def_env:nnn p ( )
+\@@_def_env:nnn b [ ]
+\@@_def_env:nnn B \{ \}
+\@@_def_env:nnn v | |
+\@@_def_env:nnn V \| \|
% \end{macrocode}
+%
%
% \bigskip
% \subsection*{The environment \{NiceMatrix\} and its variants}
%
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_define_env:n #1
- {
- \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } }
- {
- \str_gset:Nn \g_@@_name_env_str { #1 NiceMatrix }
- \tl_set:Nn \l_@@_type_of_col_tl c
- \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
- \exp_args:Nnx \@@_begin_of_NiceMatrix:nn { #1 } \l_@@_type_of_col_tl
- }
- { \use:c { end #1 NiceArray } }
- }
-% \end{macrocode}
%
% \begin{macrocode}
\cs_new_protected:Npn \@@_begin_of_NiceMatrix:nn #1 #2
{
+ \bool_set_true:N \l_@@_Matrix_bool
\use:c { #1 NiceArray }
{
*
@@ -7782,22 +8160,28 @@ version 2005/12/01 or later.
\c@MaxMatrixCols
{ \@@_pred:n \l_@@_last_col_int }
}
- #2
+ { > \@@_Cell: #2 < \@@_end_Cell: }
}
}
% \end{macrocode}
%
% \begin{macrocode}
-\@@_define_env:n { }
-\@@_define_env:n p
-\@@_define_env:n b
-\@@_define_env:n B
-\@@_define_env:n v
-\@@_define_env:n V
+\clist_map_inline:nn { { } , p , b , B , v , V }
+ {
+ \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } }
+ {
+ \str_gset:Nn \g_@@_name_env_str { #1 NiceMatrix }
+ \tl_set:Nn \l_@@_type_of_col_tl c
+ \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
+ \exp_args:Nnx \@@_begin_of_NiceMatrix:nn { #1 } \l_@@_type_of_col_tl
+ }
+ { \use:c { end #1 NiceArray } }
+ }
% \end{macrocode}
%
% \bigskip
-% \subsection*{The environment \{NiceTabular\}}
+% \subsection*{The environments \{NiceTabular\} and \{NiceTabular*\}}
+%
% \begin{macrocode}
\NewDocumentEnvironment { NiceTabular } { O { } m ! O { } }
{
@@ -7808,7 +8192,20 @@ version 2005/12/01 or later.
}
{ \endNiceArray }
% \end{macrocode}
-%
+%
+% \bigskip
+% \begin{macrocode}
+\NewDocumentEnvironment { NiceTabular* } { m O { } m ! O { } }
+ {
+ \str_gset:Nn \g_@@_name_env_str { NiceTabular* }
+ \dim_set:Nn \l_@@_tabular_width_dim { #1 }
+ \keys_set:nn { NiceMatrix / NiceTabular } { #2 , #4 }
+ \bool_set_true:N \l_@@_NiceTabular_bool
+ \NiceArray { #3 }
+ }
+ { \endNiceArray }
+% \end{macrocode}
+%
%
% \bigskip
% \subsection*{After the construction of the array}
@@ -7924,6 +8321,8 @@ version 2005/12/01 or later.
\iow_now:Nn \@mainaux \ExplSyntaxOff
}
% \end{macrocode}
+%
+%
%
% By default, the diagonal lines will be parallelized\footnote{It's possible to
% use the option |parallelize-diags| to disable this parallelization.}. There
@@ -8025,16 +8424,49 @@ version 2005/12/01 or later.
% \end{macrocode}
% When |light-syntax| is used, we insert systematically a |\CodeAfter| in the
% flow. Thus, it's possible to have two instructions |\CodeAfter| and the second
-% one may be present in |\g_@@_code_after_tl|. That's why we set
+% may be in |\g_nicematrix_code_after_tl|. That's why we set
% |\Code-after| to be \textsl{no-op} now.
% \begin{macrocode}
\cs_set_eq:NN \CodeAfter \prg_do_nothing:
% \end{macrocode}
% And here's the |code-after|:
% \begin{macrocode}
- \g_@@_code_after_tl
- \tl_gclear:N \g_@@_code_after_tl
+ \g_nicematrix_code_after_tl
+ \tl_gclear:N \g_nicematrix_code_after_tl
\group_end:
+% \end{macrocode}
+%
+%
+% \medskip
+% |\g_@@_code_before_tl| is for instructions in the cells of the array such as
+% |\rowcolor| and |\cellcolor| (when the key |colortbl-like| is in
+% force). These instructions will be written on the |aux| file to be added to
+% the |code-before| in the next run.
+% \begin{macrocode}
+ \tl_if_empty:NF \g_@@_code_before_tl
+ {
+% \end{macrocode}
+% The command |\rowcolor| in tabular will in fact use |\rectanglecolor| in order
+% to follow the behaviour of |\rowcolor| of \pkg{colortbl}. That's why there may
+% be a command |\rectanglecolor| in |\g_@@_code_before_tl|. In order to avoid an
+% error during the expansion, we define a protected version of |\rectanglecolor|.
+% \begin{macrocode}
+ \cs_set_protected:Npn \rectanglecolor { }
+ \cs_set_protected:Npn \columncolor { }
+ \iow_now:Nn \@mainaux \ExplSyntaxOn
+ \iow_now:Nx \@mainaux
+ {
+ \tl_gset:cn
+ { g_@@_code_before_ \int_use:N \g_@@_env_int _ tl }
+ { \g_@@_code_before_tl }
+ }
+ \iow_now:Nn \@mainaux \ExplSyntaxOff
+ \bool_set_true:N \l_@@_code_before_bool
+ }
+% \end{macrocode}
+%
+% \medskip
+% \begin{macrocode}
\str_gclear:N \g_@@_name_env_str
\@@_restore_iRow_jCol:
% \end{macrocode}
@@ -9264,7 +9696,7 @@ version 2005/12/01 or later.
\@@_old_multicolumn
{ #1 }
% \end{macrocode}
-% We will have to replace |\tl_lower_case:n| in some times
+% We will have to replace |\tl_lower_case:n| in the future
% since |\tl_lower_case:n| seems to be deprecated.
% \begin{macrocode}
{
@@ -9671,7 +10103,7 @@ version 2005/12/01 or later.
% lines must be parallelized).
%
% \bigskip
-% \subsection*{Commands available in the code-before}
+% \subsection*{Colors of cells, rows and columns}
%
% In the beginning of the |code-before|, the command |\@@_rowcolor:nn| will be
% linked to |\rowcolor| and the command |\@@_columncolor:nn| to |\columncolor|.
@@ -9893,6 +10325,48 @@ version 2005/12/01 or later.
}
}
% \end{macrocode}
+%
+% \bigskip
+% When the user uses the key |colortbl-like|, the following command will
+% be linked to |\cellcolor| in the tabular.
+% \begin{macrocode}
+\NewDocumentCommand \@@_cellcolor_tabular { O { } m }
+ {
+ \tl_gput_right:Nx \g_@@_code_before_tl
+ { \cellcolor [ #1 ] { #2 } { \int_use:N \c@iRow - \int_use:N \c@jCol } }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% When the user uses the key |rowcolor-in-tabular|, the following command will
+% be linked to |\rowcolor| in the tabular.
+% \begin{macrocode}
+\NewDocumentCommand \@@_rowcolor_tabular { O { } m }
+ {
+ \tl_gput_right:Nx \g_@@_code_before_tl
+ {
+ \exp_not:N \rectanglecolor [ #1 ] { #2 }
+ { \int_use:N \c@iRow - \int_use:N \c@jCol }
+ { \int_use:N \c@iRow - \exp_not:n { \int_use:N \c@jCol } }
+ }
+ }
+% \end{macrocode}
+%
+% \bigskip
+% \begin{macrocode}
+\NewDocumentCommand \@@_columncolor_preamble { O { } m }
+ {
+ \int_compare:nNnT \c@iRow = 1
+ {
+% \end{macrocode}
+% You use |gput_left| because we want the specification of colors for the
+% columns drawn before the specifications of color for the rows (and the cells).
+% \begin{macrocode}
+ \tl_gput_left:Nx \g_@@_code_before_tl
+ { \exp_not:N \columncolor [ #1 ] { #2 } { \int_use:N \c@jCol } }
+ }
+ }
+% \end{macrocode}
%
% \bigskip
% \subsection*{The vertical rules}
@@ -9951,36 +10425,54 @@ version 2005/12/01 or later.
% |\int_compare:nNnT \c@iRow < \l_@@_last_row_int|).
%
%
-% \medskip
-% In fact, independently of |\OnlyMainNiceMatrix|, which is a convenience given
-% to the user, we have to modify the behaviour of the standard specifier ``"|"''.
%
-%
-% Remark first that the natural way to do that would be to redefine the
-% specifier ``"|"'' with |\newcolumntype|:
-% \begin{Verbatim}[commandchars=\~\#\+]
-% \newcolumntype { | } { ! { \OnlyMainNiceMatrix \vline } }
-% \end{Verbatim}
-%
-% However, this code fails if the user uses "\DefineShortVerb{\|}" of
-% \pkg{fancyvrb}. Moreover, it would not be able to deal correctly with two
-% consecutive specifiers ``"|"'' (in a preambule like "ccc||ccc").
-%
-% That's why we have done a redefinition of the macro |\@arrayrule| of
-% \pkg{array} and this redefinition will add |\@@_vline:| instead of |\vline|
-% in the preamble (that definition is in the beginning of
-% |{NiceArrayWithDelims}|).
-%
-% Here is the definition of |\@@_vline:|. This definition \emph{must} be
-% protected because you don't want that macro expanded during the construction
-% of the preamble (the tests in |\@@_OnlyMainNiceMatrix:n| must be effective in
-% each row and not once for all when the preamble is constructed). The command
-% |\CT@arc@| is a command of \pkg{colortbl} which sets the color of the rules in
-% the array. The package \pkg{nicematrix} uses it even if \pkg{colortbl} is not
-% loaded.
+%
+% \bigskip
+% The following command will be executed in the |internal-code-after|. |#1| is
+% the number the column where to draw the rule and |#2| is the number of
+% consecutive occurrences of \verb+|+.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_vline:
- { \@@_OnlyMainNiceMatrix:n { { \CT@arc@ \vline } } }
+\cs_new_protected:Npn \@@_vline:nn #1 #2
+ {
+ \bool_if:NTF \c_@@_tikz_loaded_bool
+ {
+ \tikzpicture
+ \@@_vline_i:nn { #1 } { #2 }
+ \endtikzpicture
+ }
+ {
+ \pgfpicture
+ \@@_vline_i:nn { #1 } { #2 }
+ \endpgfpicture
+ }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_vline_i:nn #1 #2
+ {
+ \CT@arc@
+ \pgfrememberpicturepositiononpagetrue
+ \pgf@relevantforpicturesizefalse
+ \pgfsetlinewidth { 1.1 \arrayrulewidth }
+ \pgfsetrectcap
+ \@@_qpoint:n { row - 1 }
+ \dim_set_eq:NN \l_tmpa_dim \pgf@y
+ \@@_qpoint:n { col - \int_eval:n { #1 + 1 } }
+ \dim_set_eq:NN \l_tmpb_dim \pgf@x
+ \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
+ \@@_qpoint:n { row - \@@_succ:n \c@iRow }
+ \dim_set_eq:NN \l_tmpc_dim \pgf@y
+ \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
+ \prg_replicate:nn { #2 - 1 }
+ {
+ \dim_sub:Nn \l_tmpb_dim \arrayrulewidth
+ \dim_sub:Nn \l_tmpb_dim \doublerulesep
+ \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
+ \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
+ }
+ \pgfusepathqstroke
+ }
% \end{macrocode}
%
% \bigskip
@@ -10454,7 +10946,7 @@ version 2005/12/01 or later.
\cs_new_protected:Npn \@@_hdottedline_i:
{
% \end{macrocode}
-% We write in the code-after the instruction that will potentially draw the
+% We write in the code-after the instruction that will actually draw the
% dotted line. It's not possible to draw this dotted line now because we don't
% know the length of the line (we don't even know the number of columns).
% \begin{macrocode}
@@ -11145,6 +11637,8 @@ version 2005/12/01 or later.
{
tikz .tl_set:N = \l_@@_tikz_tl ,
tikz .value_required:n = true ,
+ color .tl_set:N = \l_@@_color_tl ,
+ color .value_required:n = true ,
}
% \end{macrocode}
%
@@ -11160,13 +11654,25 @@ version 2005/12/01 or later.
\cs_new_protected:Npn \@@_Block_iii:nnnnnn #1 #2 #3 #4 #5 #6
{
% \end{macrocode}
-% The group is for the keys (even if, as of now, there is only one key, called
-% |tikz| and not documented).
+% The group is for the keys.
% \begin{macrocode}
\group_begin:
\keys_set:nn { NiceMatrix / Block } { #5 }
% \end{macrocode}
%
+% \begin{macrocode}
+ \tl_if_empty:NF \l_@@_color_tl
+ {
+ \tl_gput_right:Nx \g_@@_code_before_tl
+ {
+ \exp_not:N \rectanglecolor
+ { \l_@@_color_tl }
+ { #1 - #2 }
+ { #3 - #4 }
+ }
+ }
+% \end{macrocode}
+%
% \medskip
% \begin{macrocode}
\cs_set_protected:Npn \diagbox ##1 ##2
@@ -11174,7 +11680,8 @@ version 2005/12/01 or later.
\tl_gput_right:Nx \g_@@_internal_code_after_tl
{
\@@_actually_diagbox:nnnnnn
- { #1 } { #2 } { #3 } { #4 } { ##1 } { ##2 }
+ { #1 } { #2 } { #3 } { #4 }
+ { \exp_not:n { ##1 } } { \exp_not:n { ##2 } }
}
}
% \end{macrocode}
@@ -11258,7 +11765,7 @@ version 2005/12/01 or later.
%
% We construct the node for the block with the name |(#1-#2-block)|.
%
-% The function |\@@_pgf_rect_node:nnnnn| takes as arguments the name of the node
+% The function |\@@_pgf_rect_node:nnnnn| takes in as arguments the name of the node
% and the four coordinates of two opposite corner points of the rectangle.
% \begin{macrocode}
\begin { pgfscope }
@@ -11318,7 +11825,7 @@ version 2005/12/01 or later.
%
% \medskip
% If the creation of the ``medium nodes'' is required, we create a ``medium
-% node'' for the block. The function |\@@_pgf_rect_node:nnnnn| takes as
+% node'' for the block. The function |\@@_pgf_rect_node:nnnnn| takes in as
% arguments the name of the node and two \textsc{pgf} points.
% \begin{macrocode}
\bool_if:NT \l_@@_medium_nodes_bool
@@ -11528,8 +12035,8 @@ version 2005/12/01 or later.
{ \int_use:N \c@jCol }
{ \int_use:N \c@iRow }
{ \int_use:N \c@jCol }
- { #1 }
- { #2 }
+ { \exp_not:n { #1 } }
+ { \exp_not:n { #2 } }
}
% \end{macrocode}
% We put the cell with |\diagbox| in the sequence |\g_@@_pos_of_blocks_seq|
@@ -11611,7 +12118,7 @@ version 2005/12/01 or later.
% \begin{macrocode}
\cs_new_protected:Npn \@@_CodeAfter:n #1 \end
{
- \tl_gput_right:Nn \g_@@_code_after_tl { #1 }
+ \tl_gput_right:Nn \g_nicematrix_code_after_tl { #1 }
\@@_CodeAfter_i:n
}
% \end{macrocode}
@@ -11628,11 +12135,11 @@ version 2005/12/01 or later.
{ \end { #1 } }
% \end{macrocode}
% If this is not the |\end| we are looking for, we put those tokens in
-% |\g_@@_code_after_tl| and we go on searching for the next command |\end| with
-% a recursive call to the command |\@@_CodeAfter:n|.
+% |\g_nicematrix_code_after_tl| and we go on searching for the next command
+% |\end| with a recursive call to the command |\@@_CodeAfter:n|.
% \begin{macrocode}
{
- \tl_gput_right:Nn \g_@@_code_after_tl { \end { #1 } }
+ \tl_gput_right:Nn \g_nicematrix_code_after_tl { \end { #1 } }
\@@_CodeAfter:n
}
}
@@ -11767,15 +12274,26 @@ version 2005/12/01 or later.
% \bigskip
% \subsection*{Error messages of the package}
%
+% The following command converts all the elements of a sequence (which are token
+% lists) into strings.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_convert_to_str_seq:N #1
+ {
+ \seq_clear:N \l_tmpa_seq
+ \seq_map_inline:Nn #1
+ {
+ \seq_put_left:Nx \l_tmpa_seq { \tl_to_str:n { ##1 } }
+ }
+ \seq_set_eq:NN #1 \l_tmpa_seq
+ }
+% \end{macrocode}
%
-% The following command creates a sequence of strings (|str|) from a |clist|. Be
-% careful: we use |\seq_set_map:NNn| and the name of that function will maybe
-% change to |\eq_set_map_x:NNn|.
+% The following command creates a sequence of strings (|str|) from a |clist|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_set_seq_of_str_from_clist:Nn #1 #2
{
\seq_set_from_clist:Nn #1 { #2 }
- \seq_set_map:NNn #1 #1 { \tl_to_str:n { ##1 } }
+ \@@_convert_to_str_seq:N #1
}
% \end{macrocode}
%
@@ -11824,8 +12342,8 @@ version 2005/12/01 or later.
{
You~try~to~use~more~columns~than~allowed~by~your~
\@@_full_name_env:.\@@_message_hdotsfor:\ The~maximal~number~of~
- columns~is~\int_eval:n { \l_@@_last_col_int - 1 }~(plus~the~potential~
- exterior~ones).~This~error~is~fatal.
+ columns~is~\int_eval:n { \l_@@_last_col_int - 1 }~(plus~the~
+ exterior~columns).~This~error~is~fatal.
}
% \end{macrocode}
%
@@ -11837,7 +12355,7 @@ version 2005/12/01 or later.
\@@_full_name_env:.\@@_message_hdotsfor:\ Recall~that~the~maximal~
number~of~columns~for~a~matrix~is~fixed~by~the~LaTeX~counter~
'MaxMatrixCols'.~Its~actual~value~is~\int_use:N \c@MaxMatrixCols.~
- This~error~is~fatal.
+ This~error~is~fatal.
}
% \end{macrocode}
%
@@ -11850,12 +12368,32 @@ version 2005/12/01 or later.
{
You~try~to~use~more~columns~than~allowed~by~your~
\@@_full_name_env:.\@@_message_hdotsfor:\ The~maximal~number~of~columns~is~
- \int_eval:n { \c@jCol - 1 }~(plus~the~potential~exterior~ones).~
+ \int_use:N \g_@@_static_num_of_col_int\
+ ~(plus~the~potential~exterior~ones).~
This~error~is~fatal.
}
% \end{macrocode}
%
% \begin{macrocode}
+\@@_msg_new:nn { last~col~not~used }
+ {
+ The~key~'last-col'~is~in~force~but~you~have~not~used~that~last~column~
+ in~your~\@@_full_name_env:.~However,~you~can~go~on.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\@@_msg_new:nn { columns~not~used }
+ {
+ The~preamble~of~your~\@@_full_name_env:\ announces~\int_use:N
+ \g_@@_static_num_of_col_int\
+ columns~but~you~use~only~\int_use:N \c@jCol.\\
+ However,~you~can~go~on.
+ }
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
\@@_msg_new:nn { in~first~col }
{
You~can't~use~the~command~#1 in~the~first~column~(number~0)~of~the~array.\\
@@ -11998,6 +12536,15 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \begin{macrocode}
+\@@_msg_new:nn { unknown~column~type }
+ {
+ The~column~type~'#1'~in~your~\@@_full_name_env:\
+ is~unknown. \\
+ This~error~is~fatal.
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
\@@_msg_new:nn { angle~option~in~NiceTabular }
{
You~should~not~the~option~between~angle~brackets~(<~and~>)~for~a~command~
@@ -12100,9 +12647,9 @@ version 2005/12/01 or later.
{
The~available~options~are~(in~alphabetic~order):~
allow-duplicate-names,~
- code-for-first-col,~
cell-space-bottom-limit,~
cell-space-top-limit,~
+ code-for-first-col,~
code-for-first-row,~
code-for-last-col,~
code-for-last-row,~
@@ -12154,6 +12701,7 @@ version 2005/12/01 or later.
code-for-first-row,~
code-for-last-col,~
code-for-last-row,~
+ colortbl-like,~
columns-width,~
create-extra-nodes,~
create-medium-nodes,~
@@ -12209,6 +12757,7 @@ version 2005/12/01 or later.
code-for-first-row,~
code-for-last-col,~
code-for-last-row,~
+ colortbl-like,~
columns-width,~
create-extra-nodes,~
create-medium-nodes,~
@@ -12219,14 +12768,14 @@ version 2005/12/01 or later.
first-row,~
hlines,~
hvlines,~
- l~(=L),~
+ l,~
last-col,~
last-row,~
left-margin,~
light-syntax,~
name,~
nullify-dots,~
- r~(=R),~
+ r,~
renew-dots,~
right-margin,~
rules/color,~
@@ -12261,6 +12810,7 @@ version 2005/12/01 or later.
code-for-first-row,~
code-for-last-col,~
code-for-last-row,~
+ colortbl-like,~
columns-width,~
create-extra-nodes,~
create-medium-nodes,~
@@ -12647,6 +13197,18 @@ version 2005/12/01 or later.
%
% Command |\tabularnote|
%
+% \subsection*{Changes between versions 5.0 and 5.1}
+%
+% The vertical rules specified by \verb+|+ in the preamble are not broken by
+% |\hline\hline| (and other).
+%
+% Environment |{NiceTabular*}|
+%
+% Command |\Vdotsfor| similar to |\Hdotsfor|
+%
+% The variable |\g_nicematrix_code_after_tl| is now public.
+%
+%
% \PrintIndex
%
% \tableofcontents