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.dtx586
1 files changed, 397 insertions, 189 deletions
diff --git a/macros/latex/contrib/nicematrix/nicematrix.dtx b/macros/latex/contrib/nicematrix/nicematrix.dtx
index 3b0f3fcad4..9ccfc120b5 100644
--- a/macros/latex/contrib/nicematrix/nicematrix.dtx
+++ b/macros/latex/contrib/nicematrix/nicematrix.dtx
@@ -15,8 +15,8 @@
%
% \fi
% \iffalse
-\def\myfileversion{3.8}
-\def\myfiledate{2020/01/02}
+\def\myfileversion{3.9}
+\def\myfiledate{2020/01/10}
%
%
%<*batchfile>
@@ -26,7 +26,7 @@
\usedir{tex/latex/nicematrix}
\preamble
-Copyright (C) 2018-2019 by F. Pantigny
+Copyright (C) 2018-2020 by F. Pantigny
-----------------------------------
This file may be distributed and/or modified under the
@@ -590,6 +590,8 @@ c & c & b & a & e
%
% \section{The Tikz nodes created by nicematrix}
%
+% \label{name}
+%
% The package \pkg{nicematrix} creates a Tikz node for each cell of the
% considered array. These nodes are used to draw the dotted lines between the
% cells of the matrix. However, the user may wish to use directly these nodes.
@@ -632,9 +634,12 @@ c & c & b & a & e
%
%
% \bigskip
-% In fact, the package \pkg{nicematrix} can create ``extra nodes''. These new
-% nodes are created if the option |create-extra-nodes| is used. There are two
-% series of extra nodes: the ``medium nodes'' and the ``large nodes''.
+% In fact, the package \pkg{nicematrix} can create ``extra nodes'': the ``medium
+% nodes'' and the ``large nodes''. The first ones
+% are created with the option |create-medium-nodes| and the second ones with the
+% option |create-large-nodes|.\footnote{There is also an option
+% |create-extra-nodes| which is an alias for the conjonction of
+% |create-medium-nodes| and |create-large-nodes|.}
%
% \medskip
% The names of the ``medium nodes'' are constructed by adding the suffix
@@ -642,7 +647,7 @@ c & c & b & a & e
% we have underlined the ``medium nodes''. We consider that this example is
% self-explanatory.
% \[\begin{pNiceMatrix}[
-% create-extra-nodes,
+% create-medium-nodes,
% code-after = {\begin{tikzpicture}
% [every node/.style = {fill = red!15,
% blend mode = multiply,
@@ -672,7 +677,7 @@ c & c & b & a & e
% rows and columns (for these rows and columns, cf. p.~\pageref{exterior}).}
%
% \[\begin{pNiceMatrix}[
-% create-extra-nodes,
+% create-large-nodes,
% code-after = {\begin{tikzpicture}
% [every node/.style = {blend mode = multiply,
% inner sep = -\pgflinewidth/2},
@@ -704,7 +709,7 @@ c & c & b & a & e
% default: 5~pt). There is also an option |margin| to fix both |left-margin| and
% |right-margin| to the same value.}
% \[\begin{pNiceMatrix}[
-% create-extra-nodes,left-margin,right-margin,
+% create-large-nodes,left-margin,right-margin,
% code-after = {\begin{tikzpicture}
% [every node/.style = {blend mode = multiply,
% inner sep = -\pgflinewidth/2},
@@ -731,7 +736,7 @@ c & c & b & a & e
% option |extra-margin| and, in the following example, we use |extra-margin|
% with the value $3$~pt.
% \[\begin{pNiceMatrix}[
-% create-extra-nodes,margin,extra-margin=3pt,
+% create-large-nodes,margin,extra-margin=3pt,
% code-after = {\begin{tikzpicture}
% [every node/.style = {blend mode = multiply,
% inner sep = -\pgflinewidth/2},
@@ -755,7 +760,7 @@ c & c & b & a & e
% In this case, if we want a control over the height of the rows, we can add a
% |\strut| in each row of the array.
% \[\begin{pNiceMatrix}[
-% create-extra-nodes,left-margin,right-margin,extra-right-margin=3pt,
+% create-large-nodes,left-margin,right-margin,extra-right-margin=3pt,
% extra-left-margin=3pt,
% code-after = {\begin{tikzpicture}
% [every node/.style = {blend mode = multiply,
@@ -941,9 +946,9 @@ c & c & b & a & e
% computed from the preamble of the array.
% \item For the potential last row, the option |last-row| may, in fact, be used
% without value. In this case, \pkg{nicematrix} computes, during the first
-% compilation, the number of row of the array and writes that information in the
-% |.aux| file for the second run. In the following example, the option
-% |last-row| will be used without value.
+% compilation, the number of rows of the array and writes that information in
+% the |.aux| file for the second run. In the following example, the option
+% |last-row| will be used without value.
% \end{itemize}
%
% \bigskip
@@ -995,9 +1000,14 @@ c & c & b & a & e
% rows.\footnote{The latter is not true when the extension \pkg{arydshln} is
% loaded besides \pkg{nicematrix}. In fact, \pkg{nicematrix} and \pkg{arydhsln}
% are not totally compatible because \pkg{arydshln} redefines many internals of
-% \pkg{array}. On another note, if one really wants a vertical rule running in
+% \pkg{array}. On another hand, if one really wants a vertical rule running in
% the first and in the last row, he should use |!{\vline}| instead of \verb+|+
% in the preamble of the array.}
+%
+% If one wishes to define new specifiers for columns in order to draw vertical
+% rules (for example thicker than the standard rules), he should consider the
+% command |\OnlyMainNiceMatrix| described on page~\pageref{OnlyMainNiceMatrix}.
+%
% \item Logically, the potential option |columns-width| (described
% p.~\pageref{width}) doesn't apply to the ``first column'' and ``last column''.
% \item For technical reasons, it's not possible to use the option of the
@@ -1356,9 +1366,9 @@ c & c & b & a & e
% \medskip
% In fact, the option |small| corresponds to the following tuning:
% \begin{itemize}
-% \item the cells of the array are composed with \verb|\scriptstyle| ;
-% \item \verb|\arraystretch| is set to $0.47$ ;
-% \item \verb|\arraycolsep| is set to $1.45$~pt ;
+% \item the cells of the array are composed with \verb|\scriptstyle|;
+% \item \verb|\arraystretch| is set to $0.47$;
+% \item \verb|\arraycolsep| is set to $1.45$~pt;
% \item the characteristics of the dotted lines are also modified.
% \end{itemize}
%
@@ -1466,15 +1476,59 @@ c & c & b & a & e
% 7.2 & 0 & \Cdots & 0
% \end{pNiceArray}$
%
+% \medskip
% On the other hand, the |d| columns of the package \pkg{dcolumn} are not
% supported by \pkg{nicematrix}.
%
% \section{Technical remarks}
+%
+% \subsection{Definition of new column types}
+%
+% \label{OnlyMainNiceMatrix}
+%
+% The extension \pkg{nicematrix} provides the command |\OnlyMainNiceMatrix|
+% which is meant to be used in definitions of new column types. Its argument is
+% evaluated if and only if we are in the main part of the array, that is to say
+% not in an eventual exterior row.
%
+% For example, one may wish to define a new column type |?| in order to draw a
+% thick rule of width 1~pt. The following definition will do the job:
+%
+% \begin{Verbatim}
+% \newcolumntype{?}{!{\OnlyMainNiceMatrix{\vrule width 1 pt}}}
+% \end{Verbatim}
+%
+% The thick vertical rule won't extend in the exterior rows:
+% \medskip
+% \begin{scope}
+% \newcolumntype{?}{!{\OnlyMainNiceMatrix{\vrule width 1 pt}}}
+%
+% \begin{BVerbatim}[baseline = c, boxwidth = 10.5cm]
+% $\begin{pNiceArray}{CC?CC}[first-row,last-row]
+% C_1 & C_2 & C_3 & C_4 \\
+% a & b & c & d \\
+% e & f & g & h \\
+% C_1 & C_2 & C_3 & C_4
+% \end{pNiceArray}$
+% \end{BVerbatim}
+% $\begin{pNiceArray}{CC?CC}[first-row,last-row]
+% C_1 & C_2 & C_3 & C_4 \\
+% a & b & c & d \\
+% e & f & g & h \\
+% C_1 & C_2 & C_3 & C_4
+% \end{pNiceArray}$
+% \end{scope}
+%
+% \medskip
+% The specifier |?| may be used in a standard environment |{array}| (of the
+% package \pkg{array}) and, in this case, the command |\OnlyMainNiceMatrix| is
+% no-op.
+%
+%
% \subsection{Intersections of dotted lines}
%
% Since the version 3.1 of \pkg{nicematrix}, the dotted lines created by
-% |\Cdots|, |\Ldots|, |\Vdots|, etc. can't intersect.\footnote{Of the contrary,
+% |\Cdots|, |\Ldots|, |\Vdots|, etc. can't intersect.\footnote{On the contrary,
% dotted lines created by |\hdottedline|, the letter ``|:|'' in the preamble
% of the array and the command |\line| in the |code-after| can have
% intersections with other dotted lines.}
@@ -1506,7 +1560,23 @@ c & c & b & a & e
% & \Cdots & & & \\
% \end{pNiceMatrix}$
%
+% \subsection{The names of the Tikz nodes created by nicematrix}
+%
+% We have said that, when a name is given to an environment of \pkg{nicematrix},
+% it's possible to access the Tikz nodes through this name (cf.
+% p.~\pageref{name}).
+%
+% That's the recommended way to access these nodes. However, we describe now the
+% internal names of these nodes.
+%
+% The environments created by \pkg{nicematrix} are numbered by an internal
+% global counter. The command |\NiceMatrixLastEnv| provides the number of the
+% last environment of \pkg{nicematrix} (for LaTeX, it's a —fully expandable—
+% command and not a counter).
%
+% For the environment of number~$n$, the node in row~$i$ and column~$j$ has the
+% name |nm-|$n$|-|$i$|-|$j$. The |medium| and |large| have the same name, suffixed by
+% |-medium| and |-large|.
%
%
% \subsection{Diagonal lines}
@@ -1747,7 +1817,7 @@ c & c & b & a & e
% used. It's still possible to use these environments by loading
% \pkg{nicematrix} with the option |obsolete-environments|.
%
-% However, these environments will probably be completely deleted in future
+% However, these environments will probably be completely deleted in a future
% version of \pkg{nicematrix}.
%
% \section{Examples}
@@ -2033,7 +2103,7 @@ c & c & b & a & e
%
% \begin{Verbatim}
% $\begin{pNiceArray}{>{\strut}CCCC}%
-% [create-extra-nodes,margin,extra-margin = 2pt ,
+% [create-large-nodes,margin,extra-margin = 2pt ,
% code-after = {\begin{tikzpicture}
% [~emphase#name suffix = -large@,
% every node/.style = {draw,
@@ -2052,7 +2122,7 @@ c & c & b & a & e
%
%
% \[\begin{pNiceArray}{>{\strut}CCCC}[
-% create-extra-nodes,margin,extra-margin = 2pt,
+% create-large-nodes,margin,extra-margin = 2pt,
% code-after = {\begin{tikzpicture}[name suffix = -large,
% every node/.style = {draw,
% inner sep = -\pgflinewidth/2}]
@@ -2135,15 +2205,15 @@ c & c & b & a & e
%
% \medskip
% \begin{Verbatim}
-% $\begin{pNiceArray}{CCC}[~emphase#name=example@,last-col,create-extra-nodes]
-% a & a + b & a + b + c & L_1\\
+% $\begin{pNiceArray}{CCC}[~emphase#name=example@,last-col,create-medium-nodes]
+% a & a + b & a + b + c & L_1 \\
% a & a & a + b & L_2 \\
% a & a & a & L_3
% \end{pNiceArray}$
% \end{Verbatim}
%
% \[\begin{pNiceArray}{CCC}[last-col]
-% a & a + b & a + b + c & L_1\\
+% a & a + b & a + b + c & L_1 \\
% a & a & a + b & L_2 \\
% a & a & a & L_3
% \end{pNiceArray}\]
@@ -2182,7 +2252,6 @@ c & c & b & a & e
%
% \[\begin{pNiceArray}{CCC}[
% last-col,
-% create-extra-nodes,
% code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15,
% blend mode = multiply,
% inner sep = 0pt}]
@@ -2212,7 +2281,7 @@ c & c & b & a & e
%
% \[\begin{pNiceArray}{CCC}[
% last-col,
-% create-extra-nodes,
+% create-medium-nodes,
% code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15,
% blend mode = multiply,
% inner sep = 0pt},
@@ -2233,7 +2302,7 @@ c & c & b & a & e
% the matrix.\par\nobreak
% \begin{Verbatim}
% \begin{pNiceArray}{>{\strut}CCCC}%
-% [create-extra-nodes,margin,extra-margin=2pt,
+% [create-large-nodes,margin,extra-margin=2pt,
% code-after = {\tikz \path [~emphase#name suffix = -large@,
% fill = red!15,
% blend mode = multiply]
@@ -2251,7 +2320,7 @@ c & c & b & a & e
% \end{Verbatim}
%
% \[ \begin{pNiceArray}{>{\strut}CCCC}[
-% create-extra-nodes,margin,extra-margin=2pt,
+% create-large-nodes,margin,extra-margin=2pt,
% code-after = {\tikz \path [name suffix = -large,
% fill = red!15,
% blend mode = multiply]
@@ -2941,11 +3010,13 @@ c & c & b & a & e
% \end{macrocode}
%
% \bigskip
-% The boolean |\l_@@_extra_nodes_bool| will be used to indicate whether the
-% ``medium nodes'' and ``large nodes'' are created in the array.
+% The boolean |\l_@@_extra_medium_bool| will be used to indicate whether the
+% ``medium nodes'' are created in the array. Idem for the ``large nodes''.
% \begin{macrocode}
-\bool_new:N \l_@@_extra_nodes_bool
-\bool_new:N \g_@@_extra_nodes_bool
+\bool_new:N \l_@@_medium_nodes_bool
+\bool_new:N \g_@@_medium_nodes_bool
+\bool_new:N \l_@@_large_nodes_bool
+\bool_new:N \g_@@_large_nodes_bool
% \end{macrocode}
%
% \bigskip
@@ -2990,17 +3061,17 @@ c & c & b & a & e
% |\Vdots| and |\Ddots|.
% \begin{macrocode}
renew-dots .bool_set:N = \l_@@_renew_dots_bool ,
-
nullify-dots .bool_set:N = \l_@@_nullify_dots_bool ,
% \end{macrocode}
%
% \bigskip
-% An option to test whether the extra nodes will be created (these nodes are the
-% ``medium nodes'' and the ``large nodes''). In some circonstancies, the extra
-% nodes are created automatically, for example when a dotted line has an
-% ``open'' extremity.
+% In some circonstancies, the ``medium nodes'' are created automatically, for
+% example when a dotted line has an ``open'' extremity (idem for the ``large nodes'').
% \begin{macrocode}
- create-extra-nodes .bool_set:N = \l_@@_extra_nodes_bool ,
+ create-medium-nodes .bool_set:N = \l_@@_medium_nodes_bool ,
+ create-large-nodes .bool_set:N = \l_@@_large_nodes_bool ,
+ create-extra-nodes .meta:n =
+ { create-medium-nodes , create-large-nodes } ,
left-margin .dim_set:N = \l_@@_left_margin_dim ,
left-margin .default:n = \arraycolsep ,
right-margin .dim_set:N = \l_@@_right_margin_dim ,
@@ -3623,12 +3694,12 @@ c & c & b & a & e
%
%
% \medskip
-% We switch to a global version of the boolean |\g_@@_extra_nodes_bool|,
-% because, in some circonstancies, the boolean will be raised from inside a
-% cell of the |\halign| (in particular in a column of type~|w|).
-%
+% We switch to a global version of the |\l_@@_medium_nodes_bool| and
+% |\l_@@_large_nodes_bool| because these booleans may be raised in cells of the
+% array (for exemple in commands |\Block|).
% \begin{macrocode}
- \bool_gset_eq:NN \g_@@_extra_nodes_bool \l_@@_extra_nodes_bool
+ \bool_gset_eq:NN \g_@@_medium_nodes_bool \l_@@_medium_nodes_bool
+ \bool_gset_eq:NN \g_@@_large_nodes_bool \l_@@_large_nodes_bool
% \end{macrocode}
%
% \bigskip
@@ -3710,6 +3781,7 @@ c & c & b & a & e
\cs_set_eq:NN \Hdotsfor \@@_Hdotsfor:
\cs_set_eq:NN \multicolumn \@@_multicolumn:nnn
\cs_set_eq:NN \Block \@@_Block:
+ \cs_set_eq:NN \OnlyMainNiceMatrix \@@_OnlyMainNiceMatrix:n
\bool_if:NT \l_@@_renew_dots_bool
{
\cs_set_eq:NN \ldots \@@_Ldots
@@ -3741,9 +3813,10 @@ c & c & b & a & e
% \end{macrocode}
%
% At the end of the environment |{array}|, |\c@iRow| will be the total
-% number de rows and |\g_@@_row_total_int| will be the number or rows excepted
-% the last row (if |\l_@@_last_row_bool| has been raised with the option
-% |last-row|).
+% number de rows.
+%
+% |\g_@@_row_total_int| will be the number or rows excepted the last row (if
+% |\l_@@_last_row_bool| has been raised with the option |last-row|).
% \begin{macrocode}
\int_gzero_new:N \g_@@_row_total_int
% \end{macrocode}
@@ -3799,7 +3872,7 @@ c & c & b & a & e
\l_@@_auto_columns_width_bool
|| \dim_compare_p:nNn \l_@@_columns_width_dim > \c_zero_dim
}
- { \bool_gset_true:N \g_@@_extra_nodes_bool }
+ { \bool_gset_true:N \g_@@_large_nodes_bool }
% \end{macrocode}
%
% \medskip
@@ -4769,12 +4842,21 @@ c & c & b & a & e
}
% \end{macrocode}
%
-% If the user has used the option |create-extra-nodes|, the ``medium nodes'' and
-% ``large nodes'' are created. We recall that the command
-% |\@@_create_extra_nodes:|, when used once, becomes no-op (in the current TeX
-% group).
+% The booleans |\g_@@_medium_nodes_bool| and |\g_@@_large_nodes_bool| may be
+% raised directly in cells of the array (for example in commands |\Block|) but
+% also because the user has used the options |create-medium-nodes| and
+% |create-large-nodes| (these options raise the booleans
+% |\l_@@_medium_nodes_bool| and |\l_@@_large_nodes_bool| but theses booleans are
+% converted into the global version |\g_@@_medium_nodes_bool| and
+% |\g_@@_large_nodes_bool| before the creation of the array).
% \begin{macrocode}
- \bool_if:NT \g_@@_extra_nodes_bool \@@_create_extra_nodes:
+ \bool_if:nTF \g_@@_medium_nodes_bool
+ {
+ \bool_if:NTF \g_@@_large_nodes_bool
+ \@@_create_medium_and_large_nodes:
+ \@@_create_medium_nodes:
+ }
+ { \bool_if:NT \g_@@_large_nodes_bool \@@_create_large_nodes: }
\int_zero_new:N \l_@@_initial_i_int
\int_zero_new:N \l_@@_initial_j_int
\int_zero_new:N \l_@@_final_i_int
@@ -4844,9 +4926,8 @@ c & c & b & a & e
% a & a+b & a+b+c
% \end{pNiceMatrix}\]
% For a closed extremity, we use the normal node and for a open one, we use the
-% ``medium node'' or, if it exists, the |w|~node (the medium and large nodes are
-% created with |\@@_create_extra_nodes:| if they have not been created yet).
-% \[ \begin{pNiceMatrix}[create-extra-nodes,
+% ``medium node'' or, if it exists, the |w|~node.
+% \[ \begin{pNiceMatrix}[create-medium-nodes,
% code-after = {\begin{tikzpicture}
% \node [highlight, fit={(2-1)}] {} ;
% \node [highlight, fit={(2-3-medium)}] {};
@@ -5070,10 +5151,10 @@ c & c & b & a & e
% matrix\footnote{We should change this. Indeed, for an open extremity of an
% \emph{horizontal} dotted line, we use the |w|~node, if, it exists, and not the
% ``medium node''.}. We remind that, when used once, the command
-% |\@@_create_extra_nodes:| becomes no-op in the current TeX group.
+% |\@@_create_medium_nodes:| becomes no-op in the current TeX group.
% \begin{macrocode}
- \bool_if:nT \l_@@_initial_open_bool \@@_create_extra_nodes:
- \bool_if:NT \l_@@_final_open_bool \@@_create_extra_nodes:
+ \bool_if:nT \l_@@_initial_open_bool \@@_create_medium_nodes:
+ \bool_if:NT \l_@@_final_open_bool \@@_create_medium_nodes:
}
% \end{macrocode}
%
@@ -5461,6 +5542,18 @@ c & c & b & a & e
}
% \end{macrocode}
%
+%
+% \bigskip
+% The command |\NiceMatrixLastEnv| is not used by the package \pkg{nicematrix}.
+% It's only a facility given to the final user. It gives the number of the last
+% environment (in fact the number of the current environment but it's meant to
+% be used after the environment in order to refer to that environment --- and
+% its nodes --- without having to give it a name).
+% \begin{macrocode}
+\NewExpandableDocumentCommand \NiceMatrixLastEnv { }
+ { \int_use:N \g_@@_env_int }
+% \end{macrocode}
+%
% \bigskip
% \subsection{The actual instructions for drawing the dotted line with Tikz}
%
@@ -5796,7 +5889,7 @@ c & c & b & a & e
}
}
\bool_if:nT { \l_@@_initial_open_bool || \l_@@_final_open_bool }
- \@@_create_extra_nodes:
+ \@@_create_medium_nodes:
\@@_actually_draw_Ldots:
% \end{macrocode}
% We declare all the cells concerned by the |\Hdotsfor| as ``dotted'' (for the
@@ -5944,7 +6037,7 @@ c & c & b & a & e
{
\noalign
{
- \bool_gset_true:N \g_@@_extra_nodes_bool
+ \bool_gset_true:N \g_@@_large_nodes_bool
\cs_if_exist:cTF { @@_width_ \int_use:N \g_@@_env_int }
{ \dim_set_eq:Nc \l_tmpa_dim { @@_width_ \int_use:N \g_@@_env_int } }
{ \dim_set:Nn \l_tmpa_dim { 5 mm } }
@@ -6068,7 +6161,7 @@ c & c & b & a & e
% { ! { \int_compare:nNnF \c@iRow = \c_zero_int \vline } }
% \end{Verbatim}
%
-% However, this code fails is the user uses "\DefineShortVerb{\|}" of
+% 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").
%
@@ -6132,13 +6225,41 @@ c & c & b & a & e
% \end{macrocode}
%
% \medskip
-% If \pkg{colortbl} is loaded, the following macro will redefined (in a
+% If \pkg{colortbl} is loaded, the following macro will be redefined (in a
% |\AtBeginDocument|) to take into account the color fixed by |\arrayrulecolor|
% of \pkg{colortbl}.
% \begin{macrocode}
\cs_set_eq:NN \@@_vline_i: \vline
% \end{macrocode}
%
+% \bigskip
+% We give now the definition of |\OnlyMainNiceMatrix|. Internally, it is not
+% used by \pkg{nicematrix}. It's only a facility given to the final user, which
+% may be useful in the definitions of new columns types (with |\newcolumntype|).
+%
+% \smallskip
+% First, we give the definition of |\OnlyMainNiceMatrix| in the general case:
+% it's no-op (thus, a definition of column type may be used outside the
+% environments of \pkg{nicematrix}, in |{array}|, etc.).
+% \begin{macrocode}
+\cs_set_eq:NN \OnlyMainNiceMatrix \use:n
+% \end{macrocode}
+%
+% \medskip
+% Now, we give the definition of |\OnlyMainNiceMatrix| which will be used
+% in the environments of \pkg{nicematrix}. This command
+% |\@@_OnlyMainNiceMatrix:n| will be linked to |\OnlyMainNiceMatrix| in
+% |\@@_pre_array:|. This command is ``fully expandable'' and that's why we have
+% not protected it, even tough this characteristic will probably not be used.
+% \begin{macrocode}
+\cs_new:Npn \@@_OnlyMainNiceMatrix:n #1
+ {
+ \int_compare:nNnF \c@iRow = \c_zero_int
+ { \int_compare:nNnF \c@iRow = \l_@@_last_row_int { #1 } }
+ }
+% \end{macrocode}
+%
+%
% \bigskip
% \subsection{The environment \{NiceMatrixBlock\}}
%
@@ -6212,11 +6333,21 @@ c & c & b & a & e
% \end{macrocode}
%
% \bigskip
-% The macro |\@@_create_extra_nodes:| must \emph{not} be used in the
-% |code-after| because the |code-after| is executed in a scope of |prefix name|.
-%
+% We have three macros of creation of nodes: |\@@_create_medium_nodes:|, |\@@_create_large_nodes:| and
+% |\@@_create_medium_and_large_nodes:|. They must \emph{not} be used in the
+% |code-after| because the |code-after| is executed in a scope of |prefix name|
+% of Tikz.
%
% \bigskip
+% We have to compute the mathematical coordinates of the ``medium nodes''. These
+% mathematical coordinates are also used to compute the mathematical coordinates
+% of the ``large nodes''. That's why we write a command
+% |\@@_computations_for_medium_nodes:| to do these computations.
+%
+% \bigskip
+% The command |\@@_computations_for_medium_nodes:| must be used in a
+% |{tikzpicture}|.
+% \medskip
% For each row $i$, we compute two dimensions
% \texttt{l_@@_row_\textsl{i}_min_dim} and \texttt{l_@@_row_\textsl{i}_max_dim}.
% The dimension \texttt{l_@@_row_\textsl{i}_min_dim} is the minimal
@@ -6234,68 +6365,81 @@ c & c & b & a & e
% Since these dimensions will be computed as maximum or minimum, we initialize
% them to |\c_max_dim| or |-\c_max_dim|.
% \begin{macrocode}
-\cs_new_protected:Nn \@@_create_extra_nodes:
+\cs_new_protected:Npn \@@_computations_for_medium_nodes:
{
- \begin { tikzpicture } [ remember~picture , overlay ]
- \int_step_variable:nnNn \l_@@_first_row_int \g_@@_row_total_int \@@_i:
- {
- \dim_zero_new:c { l_@@_row_\@@_i: _min_dim }
- \dim_set_eq:cN { l_@@_row_\@@_i: _min_dim } \c_max_dim
- \dim_zero_new:c { l_@@_row_\@@_i: _max_dim }
- \dim_set:cn { l_@@_row_\@@_i: _max_dim } { - \c_max_dim }
- }
- \int_step_variable:nnNn \l_@@_first_col_int \g_@@_col_total_int \@@_j:
- {
- \dim_zero_new:c { l_@@_column_\@@_j: _min_dim }
- \dim_set_eq:cN { l_@@_column_\@@_j: _min_dim } \c_max_dim
- \dim_zero_new:c { l_@@_column_\@@_j: _max_dim }
- \dim_set:cn { l_@@_column_\@@_j: _max_dim } { - \c_max_dim }
- }
+ \int_step_variable:nnNn \l_@@_first_row_int \g_@@_row_total_int \@@_i:
+ {
+ \dim_zero_new:c { l_@@_row_\@@_i: _min_dim }
+ \dim_set_eq:cN { l_@@_row_\@@_i: _min_dim } \c_max_dim
+ \dim_zero_new:c { l_@@_row_\@@_i: _max_dim }
+ \dim_set:cn { l_@@_row_\@@_i: _max_dim } { - \c_max_dim }
+ }
+ \int_step_variable:nnNn \l_@@_first_col_int \g_@@_col_total_int \@@_j:
+ {
+ \dim_zero_new:c { l_@@_column_\@@_j: _min_dim }
+ \dim_set_eq:cN { l_@@_column_\@@_j: _min_dim } \c_max_dim
+ \dim_zero_new:c { l_@@_column_\@@_j: _max_dim }
+ \dim_set:cn { l_@@_column_\@@_j: _max_dim } { - \c_max_dim }
+ }
% \end{macrocode}
% We begin the two nested loops over the rows and the columns of the array.
% \begin{macrocode}
- \int_step_variable:nnNn \l_@@_first_row_int \g_@@_row_total_int \@@_i:
- {
- \int_step_variable:nnNn
- \l_@@_first_col_int \g_@@_col_total_int \@@_j:
+ \int_step_variable:nnNn \l_@@_first_row_int \g_@@_row_total_int \@@_i:
+ {
+ \int_step_variable:nnNn
+ \l_@@_first_col_int \g_@@_col_total_int \@@_j:
% \end{macrocode}
% Maybe the cell ($i$-$j$) is an implicit cell (that is to say a cell after
% implicit ampersands |&|). In this case, of course, we don't update the
% dimensions we want to compute.
% \begin{macrocode}
- { \cs_if_exist:cT
- { pgf@sh@ns@nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: }
+ { \cs_if_exist:cT
+ { pgf@sh@ns@nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: }
% \end{macrocode}
% We retrieve the coordinates of the anchor |south west| of the (normal) node of
% the cell ($i$-$j$). They will be stored in |\pgf@x| and |\pgf@y|.
% \begin{macrocode}
- {
- \tikz@parse@node \pgfutil@firstofone
- ( nm - \int_use:N \g_@@_env_int
- - \@@_i: - \@@_j: .south~west )
- \dim_set:cn { l_@@_row_\@@_i: _min_dim}
- { \dim_min:vn { l_@@_row _ \@@_i: _min_dim } \pgf@y }
- \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i: - \@@_j: }
- {
- \dim_set:cn { l_@@_column _ \@@_j: _min_dim}
- { \dim_min:vn { l_@@_column _ \@@_j: _min_dim } \pgf@x }
- }
+ {
+ \tikz@parse@node \pgfutil@firstofone
+ ( nm - \int_use:N \g_@@_env_int
+ - \@@_i: - \@@_j: .south~west )
+ \dim_set:cn { l_@@_row_\@@_i: _min_dim}
+ { \dim_min:vn { l_@@_row _ \@@_i: _min_dim } \pgf@y }
+ \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i: - \@@_j: }
+ {
+ \dim_set:cn { l_@@_column _ \@@_j: _min_dim}
+ { \dim_min:vn { l_@@_column _ \@@_j: _min_dim } \pgf@x }
+ }
% \end{macrocode}
% We retrieve the coordinates of the anchor |north east| of the (normal) node of
% the cell ($i$-$j$). They will be stored in |\pgf@x| and |\pgf@y|.
% \begin{macrocode}
- \tikz@parse@node \pgfutil@firstofone
- ( nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: .north~east )
- \dim_set:cn { l_@@_row _ \@@_i: _ max_dim }
- { \dim_max:vn { l_@@_row _ \@@_i: _ max_dim } \pgf@y }
- \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i: - \@@_j: }
- {
- \dim_set:cn { l_@@_column _ \@@_j: _ max_dim }
- { \dim_max:vn { l_@@_column _ \@@_j: _max_dim } \pgf@x }
- }
- }
- }
- }
+ \tikz@parse@node \pgfutil@firstofone
+ ( nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: .north~east )
+ \dim_set:cn { l_@@_row _ \@@_i: _ max_dim }
+ { \dim_max:vn { l_@@_row _ \@@_i: _ max_dim } \pgf@y }
+ \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i: - \@@_j: }
+ {
+ \dim_set:cn { l_@@_column _ \@@_j: _ max_dim }
+ { \dim_max:vn { l_@@_column _ \@@_j: _max_dim } \pgf@x }
+ }
+ }
+ }
+ }
+ }
+% \end{macrocode}
+%
+%
+% \bigskip
+% Here is the command |\@@_create_medium_nodes:|. When this command is used, the
+% ``medium nodes'' are created. These nodes won't be constructed twice because
+% when used once, this command becomes no-op.
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_create_medium_nodes:
+ {
+ \begin { tikzpicture } [ remember~picture , overlay ]
+ \@@_computations_for_medium_nodes:
% \end{macrocode}
% Now, we can create the ``medium nodes''. We use a command |\@@_create_nodes:|
% because this command will also be used for the creation of the ``large nodes''
@@ -6303,93 +6447,115 @@ c & c & b & a & e
% \begin{macrocode}
\tikzset { name~suffix = -medium }
\@@_create_nodes:
+ \end { tikzpicture }
+ \cs_set_protected:Npn \@@_create_medium_nodes: { }
+ \cs_set_protected:Npn \@@_create_medium_and_large_nodes:
+ { \@@_create_large_nodes: }
+ }
% \end{macrocode}
%
+%
+% \medskip
+% The command |\@@_create_large_nodes:| must be used when we want to create only
+% the ``large nodes'' and not the medium ones (if we want to create both, we
+% have to use the command |\@@_create_medium_and_large_nodes:|). However, the
+% computation of the mathematical coordinates of the ``large nodes'' needs the
+% computation of the mathematical coordinates of the ``medium nodes''. That's
+% why we use first |\@@_computations_for_medium_nodes:| and then the command
+% |\@@_computations_for_large_nodes:|.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_create_large_nodes:
+ {
+ \begin { tikzpicture } [ remember~picture , overlay ]
+ \@@_computations_for_medium_nodes:
+ \@@_computations_for_large_nodes:
+ \tikzset { name~suffix = -large }
+ \@@_create_nodes:
+ \end { tikzpicture }
+ \@@_compute_width_of_array:
+ \cs_set_protected:Npn \@@_create_large_nodes: { }
+ \cs_set_protected:Npn \@@_create_medium_and_large_nodes:
+ { \@@_create_medium_nodes: }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_create_medium_and_large_nodes:
+ {
+ \begin { tikzpicture } [ remember~picture , overlay ]
+ \@@_computations_for_medium_nodes:
+% Now, we can create the ``medium nodes''. We use a command |\@@_create_nodes:|
+% because this command will also be used for the creation of the ``large nodes''
+% (after changing the value of |name-suffix|).
+% \begin{macrocode}
+ \tikzset { name~suffix = -medium }
+ \@@_create_nodes:
+ \@@_computations_for_large_nodes:
+ \tikzset { name~suffix = -large }
+ \@@_create_nodes:
+ \@@_compute_width_of_array:
+ \end { tikzpicture }
+ \@@_compute_width_of_array:
+ \cs_set_protected:Npn \@@_create_medium_and_large_nodes: { }
+ \cs_set_protected:Npn \@@_create_medium_nodes: { }
+ \cs_set_protected:Npn \@@_create_large_nodes: { }
+ }
+% \end{macrocode}
+%
+%
% \bigskip
-% For ``large nodes'', the exterior rows and columns don't interfer.
-% That's why the loop over the rows will start at 1 and the loop over the
-% columns will stop at $|\c@jCol|$ (and not |\g_@@_col_total_int|). Idem
-% for the rows.
+% For ``large nodes'', the exterior rows and columns don't interfer. That's why
+% the loop over the columns will start at 1 and stop at $|\c@jCol|$ (and not
+% |\g_@@_col_total_int|). Idem for the rows.
% \begin{macrocode}
- \int_set:Nn \l_@@_first_row_int 1
- \int_set:Nn \l_@@_first_col_int 1
+\cs_new_protected:Npn \@@_computations_for_large_nodes:
+ {
+ \int_set:Nn \l_@@_first_row_int 1
+ \int_set:Nn \l_@@_first_col_int 1
% \end{macrocode}
% We have to change the values of all the dimensions
% \texttt{l_@@_row_\textsl{i}_min_dim}, \texttt{l_@@_row_\textsl{i}_max_dim},
% \texttt{l_@@_column_\textsl{j}_min_dim} and
% \texttt{l_@@_column_\textsl{j}_max_dim}.
% \begin{macrocode}
- \int_step_variable:nNn { \c@iRow - 1 } \@@_i:
- {
- \dim_set:cn { l_@@_row _ \@@_i: _ min _ dim }
- {
- (
- \dim_use:c { l_@@_row _ \@@_i: _ min _ dim } +
- \dim_use:c { l_@@_row _ \int_eval:n { \@@_i: + 1 } _ max _ dim }
- )
- / 2
- }
- \dim_set_eq:cc { l_@@_row _ \int_eval:n { \@@_i: + 1 } _ max _ dim }
- { l_@@_row_\@@_i: _min_dim }
- }
- \int_step_variable:nNn { \c@jCol - 1 } \@@_j:
- {
- \dim_set:cn { l_@@_column _ \@@_j: _ max _ dim }
- {
- (
- \dim_use:c
- { l_@@_column _ \@@_j: _ max _ dim } +
- \dim_use:c
- { l_@@_column _ \int_eval:n { \@@_j: + 1 } _ min _ dim }
- )
- / 2
- }
- \dim_set_eq:cc { l_@@_column _ \int_eval:n { \@@_j: + 1 } _ min _ dim }
- { l_@@_column _ \@@_j: _ max _ dim }
- }
- \dim_sub:cn
- { l_@@_column _ 1 _ min _ dim }
- \l_@@_left_margin_dim
- \dim_add:cn
- { l_@@_column _ \int_use:N \c@jCol _ max _ dim }
- \l_@@_right_margin_dim
-% \end{macrocode}
-% Now, we can actually create the ``large nodes''.
-% \begin{macrocode}
- \tikzset { name~suffix = -large }
- \@@_create_nodes:
- \end{tikzpicture}
-% \end{macrocode}
-%
-% \medskip
-% When used once, the command |\@@_create_extra_nodes:| must become no-op (in
-% the current TeX group). That's why we put a nullification of the command.
-% \begin{macrocode}
- \cs_set:Npn \@@_create_extra_nodes: { }
-% \end{macrocode}
-%
-% \medskip
-% We can now compute the width of the array (used by |\hdottedline|).
-% \begin{macrocode}
- \begin { tikzpicture } [ remember~picture , overlay ]
- \tikz@parse@node \pgfutil@firstofone
- ( nm - \int_use:N \g_@@_env_int - 1 - 1 - large .north~west )
- \dim_gset:Nn \g_tmpa_dim \pgf@x
- \tikz@parse@node \pgfutil@firstofone
- ( nm - \int_use:N \g_@@_env_int - 1 -
- \int_use:N \c@jCol - large .north~east )
- \dim_gset:Nn \g_tmpb_dim \pgf@x
- \end { tikzpicture }
- \iow_now:Nn \@mainaux \ExplSyntaxOn
- \iow_now:Nx \@mainaux
- {
- \cs_gset:cpn { @@_width_ \int_use:N \g_@@_env_int }
- { \dim_eval:n { \g_tmpb_dim - \g_tmpa_dim } }
- }
- \iow_now:Nn \@mainaux \ExplSyntaxOff
+ \int_step_variable:nNn { \c@iRow - 1 } \@@_i:
+ {
+ \dim_set:cn { l_@@_row _ \@@_i: _ min _ dim }
+ {
+ (
+ \dim_use:c { l_@@_row _ \@@_i: _ min _ dim } +
+ \dim_use:c { l_@@_row _ \int_eval:n { \@@_i: + 1 } _ max _ dim }
+ )
+ / 2
+ }
+ \dim_set_eq:cc { l_@@_row _ \int_eval:n { \@@_i: + 1 } _ max _ dim }
+ { l_@@_row_\@@_i: _min_dim }
+ }
+ \int_step_variable:nNn { \c@jCol - 1 } \@@_j:
+ {
+ \dim_set:cn { l_@@_column _ \@@_j: _ max _ dim }
+ {
+ (
+ \dim_use:c
+ { l_@@_column _ \@@_j: _ max _ dim } +
+ \dim_use:c
+ { l_@@_column _ \int_eval:n { \@@_j: + 1 } _ min _ dim }
+ )
+ / 2
+ }
+ \dim_set_eq:cc { l_@@_column _ \int_eval:n { \@@_j: + 1 } _ min _ dim }
+ { l_@@_column _ \@@_j: _ max _ dim }
+ }
+ \dim_sub:cn
+ { l_@@_column _ 1 _ min _ dim }
+ \l_@@_left_margin_dim
+ \dim_add:cn
+ { l_@@_column _ \int_use:N \c@jCol _ max _ dim }
+ \l_@@_right_margin_dim
}
% \end{macrocode}
-%
+%
+%
%
% \bigskip
% The control sequence |\@@_create_nodes:| is used twice: for the construction
@@ -6401,7 +6567,7 @@ c & c & b & a & e
% ``medium nodes'' and the ``large nodes'', the values of these dimensions are
% changed.
% \begin{macrocode}
-\cs_new_protected:Nn \@@_create_nodes:
+\cs_new_protected:Npn \@@_create_nodes:
{
\int_step_variable:nnNn \l_@@_first_row_int \g_@@_row_total_int \@@_i:
{
@@ -6452,6 +6618,34 @@ c & c & b & a & e
% \end{macrocode}
%
%
+%
+% \medskip
+% We can now compute the width of the array (used by |\hdottedline|). We should
+% modify this point because it's a waste to construct all the ``large nodes'' only
+% for computing the width of the array.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_compute_width_of_array:
+ {
+ \begin { tikzpicture } [ remember~picture , overlay ]
+ \tikz@parse@node \pgfutil@firstofone
+ ( nm - \int_use:N \g_@@_env_int - 1 - 1 - large .north~west )
+ \dim_gset:Nn \g_tmpa_dim \pgf@x
+ \tikz@parse@node \pgfutil@firstofone
+ ( nm - \int_use:N \g_@@_env_int - 1 -
+ \int_use:N \c@jCol - large .north~east )
+ \dim_gset:Nn \g_tmpb_dim \pgf@x
+ \end { tikzpicture }
+ \iow_now:Nn \@mainaux \ExplSyntaxOn
+ \iow_now:Nx \@mainaux
+ {
+ \cs_gset:cpn { @@_width_ \int_use:N \g_@@_env_int }
+ { \dim_eval:n { \g_tmpb_dim - \g_tmpa_dim } }
+ }
+ \iow_now:Nn \@mainaux \ExplSyntaxOff
+ }
+% \end{macrocode}
+%
+% \bigskip
% \begin{macrocode}
\cs_new_protected:Npn \@@_extract_coords: #1 - #2 \q_stop
{
@@ -6542,7 +6736,7 @@ c & c & b & a & e
- \int_use:N \c@jCol ) ;
\end { tikzpicture }
}
- \bool_gset_true:N \g_@@_extra_nodes_bool
+ \bool_gset_true:N \g_@@_medium_nodes_bool
% \end{macrocode}
% We write an instruction in the |code-after|. We write the instruction in the
% beginning of the |code-after| (the |left| in |\tl_gput_left:Nx|) because we
@@ -6867,6 +7061,9 @@ c & c & b & a & e
code-for-first-row,~
code-for-last-col,~
code-for-last-row,~
+ create-extra-nodes,~
+ create-medium-nodes,~
+ create-large-nodes,~
exterior-arraycolsep,~
hlines,~
left-margin,~
@@ -6900,6 +7097,8 @@ c & c & b & a & e
code-for-last-row,~
columns-width,~
create-extra-nodes,~
+ create-medium-nodes,~
+ create-large-nodes,~
extra-left-margin,~
extra-right-margin,~
first-col,~
@@ -6920,7 +7119,7 @@ c & c & b & a & e
%
% \medskip
% This error message is used for the set of keys |NiceMatrix/NiceMatrix| and
-% |NiceMatrix/pNiceArray| (but not by |NiceMatrix/NiceArray| (because, for this
+% |NiceMatrix/pNiceArray| (but not by |NiceMatrix/NiceArray| because, for this
% set of keys, there is also the options |t|, |c| and~|b|).
% \begin{macrocode}
\@@_msg_new:nnn { Unknown~option~for~NiceMatrix }
@@ -6939,6 +7138,8 @@ c & c & b & a & e
code-for-last-row,~
columns-width,~
create-extra-nodes,~
+ create-medium-nodes,~
+ create-large-nodes,~
extra-left-margin,~
extra-right-margin,~
first-col,~
@@ -7374,6 +7575,13 @@ c & c & b & a & e
%
% An error is raised when an obsolete environment is used.
%
+%
+% \subsection*{Changes between version 3.8 and 3.9}
+%
+% New commands |\NiceMatrixLastEnv| and |\OnlyMainNiceMatrix|.
+%
+% New options |create-medium-nodes| and |create-large-nodes|.
+%
% \PrintIndex
%
% \tableofcontents