summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/nicematrix/nicematrix.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-11-09 03:01:20 +0000
committerNorbert Preining <norbert@preining.info>2020-11-09 03:01:20 +0000
commit789b6713c1344b831e5e000bf7fb98700caa5e14 (patch)
tree01d0e5e3e367abfd26a0b912a52ba1eb56847876 /macros/latex/contrib/nicematrix/nicematrix.dtx
parent3021c3d95971e522d22cf5c8aba3410a06d8a84f (diff)
CTAN sync 202011090301
Diffstat (limited to 'macros/latex/contrib/nicematrix/nicematrix.dtx')
-rw-r--r--macros/latex/contrib/nicematrix/nicematrix.dtx649
1 files changed, 462 insertions, 187 deletions
diff --git a/macros/latex/contrib/nicematrix/nicematrix.dtx b/macros/latex/contrib/nicematrix/nicematrix.dtx
index 0383626f2f..a8427171e2 100644
--- a/macros/latex/contrib/nicematrix/nicematrix.dtx
+++ b/macros/latex/contrib/nicematrix/nicematrix.dtx
@@ -15,8 +15,8 @@
%
% \fi
% \iffalse
-\def\myfileversion{5.5}
-\def\myfiledate{2020/10/20}
+\def\myfileversion{5.6}
+\def\myfiledate{2020/11/08}
%
%
%<*batchfile>
@@ -165,9 +165,9 @@ version 2005/12/01 or later.
%
% \bigskip
% This package requires and \textbf{loads} the packages \pkg{l3keys2e},
-% \pkg{xparse}, \pkg{array}, \pkg{amsmath}, \pkg{pgfcore} and the module
-% \pkg{shapes} of \textsc{pgf} (\pkg{tikz}, which is a layer over \textsc{pgf}
-% is \emph{not} loaded). The final user only has to load the package with
+% \pkg{array}, \pkg{amsmath}, \pkg{pgfcore} and the module \pkg{shapes} of
+% \textsc{pgf} (\pkg{tikz}, which is a layer over \textsc{pgf} is \emph{not}
+% loaded). The final user only has to load the package with
% |\usepackage{nicematrix}|.
%
%
@@ -452,13 +452,23 @@ version 2005/12/01 or later.
% cells of the array.
%
% The command |\Block| must be used in the upper leftmost cell of the array with
-% two arguments. The first argument is the size of the block with the syntax
+% two arguments.
+%
+% \begin{itemize}
+% \item The first argument is the size of the block with the syntax
% $i$\verb|-|$j$ where $i$ is the number of rows of the block and $j$ its number
-% of columns. The second argument is the content of the block.
+% of columns.
%
-% In |{NiceTabular}| the content of the block is composed in text mode. In the
-% other environments, it is composed in math mode.
+% \colorbox{yellow!50}{\bfseries New 5.6}\enskip If this argument is empty, its
+% default value is |1-1|. If the number of rows is not specified, the block
+% extends until the last row (idem for the columns).
%
+% \item The second argument is the content of the block. It's possible to use
+% |\\| in that content to have a content on several lines. In |{NiceTabular}|
+% the content of the block is composed in text mode whereas, in the other
+% environments, it is composed in math mode.
+% \end{itemize}
+%
%
% \interitem
% Here is an example of utilisation of the command |\Block| in mathematical matrices.
@@ -487,7 +497,9 @@ version 2005/12/01 or later.
% possible to use directly a command like |\large|, |\Large| and |\LARGE|.
% That's why the command |\Block| provides an option between angle brackets to
% specify some TeX code which will be inserted before the beginning of the
-% math mode.
+% math mode.\footnote{This argument between angular brackets may also be used to
+% insert a command of font such as |\bfseries| when the command |\\| is used in
+% the content of the block.}
%
% \medskip
% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm]
@@ -510,8 +522,8 @@ version 2005/12/01 or later.
% \end{scope}
%
% \medskip
-% \colorbox{yellow!30}{New 5.3}\enskip It's possible to set the
-% horizontal position of the block with one of the keys |l|, |c| and |r|.
+% It's possible to set the horizontal position of the block with one of the keys
+% |l|, |c| and |r|.
%
%
% \medskip
@@ -534,8 +546,9 @@ version 2005/12/01 or later.
%
%
% \interitem
-% {\bfseries One must remark that, by default, the commands |\Blocks| don't create space}
-% (excepted, to some extent, the mono-column blocks: see below).
+% {\bfseries One must remark that, by default, the commands |\Blocks| don't create space}.
+% There is exception only for the blocks mono-row and the blocks mono-column as
+% explained just below.
%
% \medskip
% In the following example, we have had to enlarge by hand the columns 2 and 3
@@ -613,6 +626,53 @@ version 2005/12/01 or later.
% \end{scope}
%
%
+% \subsection{The mono-row blocks}
+%
+% \colorbox{yellow!50}{\textbf{New 5.6}}\enskip For the mono-row blocks, the
+% natural height and depth are taken into account for the height and depth of
+% the current row (as does a standard |\multicolumn| of LaTeX).
+%
+% \subsection{The mono-cell blocks}
+%
+% A mono-cell block inherits all the properties of the mono-row blocks and
+% mono-column blocks.
+%
+% \medskip
+% There are two reasons to use a mono-column block:
+% \begin{itemize}
+% \item It's possible to use the command |\\| in a (mono-cell) block.
+%
+% \item It's possible to use the option of horizontal alignment of the block in
+% derogation of the type of column given in the preamble of the array.
+% \end{itemize}
+%
+% \bigskip
+% \begin{BVerbatim}[baseline=c,boxwidth=10cm]
+% \begin{NiceTabular}{cc}
+% \toprule
+% Write & ~emphase#\Block[l]{}{year\\ of birth}@ \\
+% \midrule
+% Hugo & 1802 \\
+% Balzac & 1799 \\
+% \bottomrule
+% \end{NiceTabular}
+% \end{BVerbatim}
+% \begin{NiceTabular}{cc}
+% \toprule
+% Write & \Block[l]{}{year\\ of birth} \\
+% \midrule
+% Hugo & 1802 \\
+% Balzac & 1799 \\
+% \bottomrule
+% \end{NiceTabular}
+%
+% \medskip
+% We recall that if the first mandatory argument of |\Block| is left blank, the
+% block is mono-cell.\footnote{One may consider that the default value of the
+% first mandatory argument of |\Block| is |1-1|}
+%
+%
+%
%
% \subsection{A small remark}
%
@@ -2898,7 +2958,18 @@ version 2005/12/01 or later.
% of the considered array. These nodes are used to draw the dotted lines between
% the cells of the matrix (inter alia).
%
+%
% \smallskip
+% \textbf{Caution} : By default, no node is created in a empty cell.
+%
+% \smallskip
+% \colorbox{yellow!50}{\textbf{New 5.6}}\enskip
+% However, it's possible to impose the creation of a node with the command |\NotEmpty|.
+% \footnote{One should note that, with that command, the cell is considered as
+% non-empty, which has consequencies for the continuous dotted lines (cf.
+% p.~\pageref{Cdots}).}
+%
+% \medskip
% The nodes of a document must have distinct names. That's why the names of the
% nodes created by \pkg{nicematrix} contains the number of the current
% environment. Indeed, the environments of \pkg{nicematrix} are numbered by a
@@ -2921,6 +2992,7 @@ version 2005/12/01 or later.
% possible to use these nodes with \textsc{pgf} but the final user will
% probably prefer to use Tikz (which is a convenient layer upon \textsc{pgf}).
% However, one should remind that \pkg{nicematrix} doesn't load Tikz by default.
+% In the following examples, we assume that Tikz has been loaded.
%
% \bigskip
% \begin{BVerbatim}[baseline=c,boxwidth=11cm]
@@ -2944,9 +3016,9 @@ version 2005/12/01 or later.
% Don't forget the options |remember picture| and |overlay|.
%
% \bigskip
-% In the |code-after|, and if Tikz is loaded, the things are easier. One may
-% design the nodes with the form $i$-$j$: there is no need to indicate the
-% environment which is of course the current environment.
+% In the |code-after|, the things are easier : one must refer to the nodes with
+% the form $i$-$j$ (we don't have to indicate the environment which is of
+% course the current environment).
%
%
% \medskip
@@ -3304,7 +3376,7 @@ version 2005/12/01 or later.
% cell (with an optional argument between brackets for the color). It's possible
% to program such command |\hatchcell| as follows, explicitely using the public
% variable |\g_nicematrix_code_before_tl| (this code requires the Tikz library
-% \pkg{patterns}).
+% \pkg{patterns}: |\usetikzlibrary{patterns}|).
%
%
% \begin{scope}
@@ -3497,22 +3569,17 @@ version 2005/12/01 or later.
%
% \end{scope}
%
-% \colorbox{yellow!30}{New 5.3}\enskip It's possible to specify the
-% instruction |\Ddots| which will be drawn first (and which will be used to draw
-% the other diagonal dotted lines when the parallelization is in force) with the
-% key |draw-first|: |\Ddots[draw-first]|.
+% It's possible to specify the instruction |\Ddots| which will be drawn first
+% (and which will be used to draw the other diagonal dotted lines when the
+% parallelization is in force) with the key |draw-first|: |\Ddots[draw-first]|.
%
% \subsection{The ``empty'' cells}
%
% \label{empty-cells}
% An instruction like |\Ldots|, |\Cdots|, etc. tries to determine the first
-% non-empty cells on both sides. However, an empty cell is not necessarily a
+% non-empty cell on both sides. However, an ``empty cell'' is not necessarily a
% cell with no TeX content (that is to say a cell with no token between the two
-% ampersands~|&|). Indeed, a cell which only contains |\hspace*{1cm}| may be
-% considered as empty.
-%
-% \interitem
-% For \pkg{nicematrix}, the precise rules are as follow.
+% ampersands~|&|). The precise rules are as follow.
%
% \begin{itemize}
% \item An implicit cell is empty. For example, in the following matrix:
@@ -3529,6 +3596,9 @@ version 2005/12/01 or later.
% \medskip
% \item Each cell whose TeX ouput has a width equal to zero is empty.
%
+% \medskip
+% \item A cell containing the command |\NotEmpty| is not empty (and a PGF/Tikz
+% node) is created in that cell.
%
% \medskip
% \item A cell with a command |\Hspace| (or |\Hspace*|) is empty. This command
@@ -4487,9 +4557,9 @@ version 2005/12/01 or later.
%
% \bigskip
% We define a command |\iddots| similar to |\ddots| ($\ddots$) but with dots
-% going forward ($\iddots$). We use |\ProvideDocumentCommand| of \pkg{xparse},
-% and so, if the command |\iddots| has already been defined (for example by the
-% package \pkg{mathdots}), we don't define it again.
+% going forward ($\iddots$). We use |\ProvideDocumentCommand| and so, if the
+% command |\iddots| has already been defined (for example by the package
+% \pkg{mathdots}), we don't define it again.
%
% \begin{macrocode}
\ProvideDocumentCommand \iddots { }
@@ -4927,14 +4997,21 @@ version 2005/12/01 or later.
% \bigskip
% When there is a mono-column block (created by the command |\Block|), we want
% to take into account the width of that block for the width of the column.
-% That's why we compute the width of that block in the |\g_@@_blocks_width_dim|
+% That's why we compute the width of that block in the |\g_@@_blocks_wd_dim|
% and, after the construction of the box |\l_@@_cell_box|, we change the width
-% of that box to take into account the length |\g_@@_blocks_width_dim|.
+% of that box to take into account the length |\g_@@_blocks_wd_dim|.
% \begin{macrocode}
-\dim_new:N \g_@@_blocks_width_dim
+\dim_new:N \g_@@_blocks_wd_dim
% \end{macrocode}
%
% \bigskip
+% Idem pour the blocks mono-row.
+% \begin{macrocode}
+\dim_new:N \g_@@_blocks_ht_dim
+\dim_new:N \g_@@_blocks_dp_dim
+% \end{macrocode}
+%
+% \bigskip
% The sequence |\g_@@_names_seq| will be the list of all the names of
% environments used (via the option |name|) in the document: two environments
% must not have the same name. However, it's possible to use the option
@@ -5033,7 +5110,7 @@ version 2005/12/01 or later.
%
% \bigskip
% 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|).
+% possible to set the value of that parameter with the keyword |\CodeAfter|).
% \begin{macrocode}
\tl_new:N \g_nicematrix_code_after_tl
% \end{macrocode}
@@ -5078,6 +5155,13 @@ version 2005/12/01 or later.
\bool_new:N \g_@@_row_of_col_done_bool
% \end{macrocode}
%
+% \bigskip
+% It's possible to use the command |\NotEmpty| to specify explicitely that a
+% cell must be considered as non empty by \pkg{nicematrix} (the Tikz nodes are
+% constructed only the non empty cells).
+% \begin{macrocode}
+\bool_new:N \g_@@_not_empty_cell_bool
+% \end{macrocode}
%
% \bigskip
% |\l_@@_code_before_tl| may contain two types of informations:
@@ -6371,13 +6455,25 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new_protected:Npn \@@_adjust_width_box:
+\cs_new_protected:Npn \@@_adjust_size_box:
{
- \dim_compare:nNnT \g_@@_blocks_width_dim > \c_zero_dim
+ \dim_compare:nNnT \g_@@_blocks_wd_dim > \c_zero_dim
{
\box_set_wd:Nn \l_@@_cell_box
- { \dim_max:nn { \box_wd:N \l_@@_cell_box } \g_@@_blocks_width_dim }
- \dim_gzero:N \g_@@_blocks_width_dim
+ { \dim_max:nn { \box_wd:N \l_@@_cell_box } \g_@@_blocks_wd_dim }
+ \dim_gzero:N \g_@@_blocks_wd_dim
+ }
+ \dim_compare:nNnT \g_@@_blocks_dp_dim > \c_zero_dim
+ {
+ \box_set_dp:Nn \l_@@_cell_box
+ { \dim_max:nn { \box_dp:N \l_@@_cell_box } \g_@@_blocks_dp_dim }
+ \dim_gzero:N \g_@@_blocks_dp_dim
+ }
+ \dim_compare:nNnT \g_@@_blocks_ht_dim > \c_zero_dim
+ {
+ \box_set_ht:Nn \l_@@_cell_box
+ { \dim_max:nn { \box_ht:N \l_@@_cell_box } \g_@@_blocks_ht_dim }
+ \dim_gzero:N \g_@@_blocks_ht_dim
}
}
% \end{macrocode}
@@ -6388,7 +6484,7 @@ version 2005/12/01 or later.
\@@_math_toggle_token:
\hbox_set_end:
\bool_if:NT \g_@@_rotate_bool \@@_rotate_cell_box:
- \@@_adjust_width_box:
+ \@@_adjust_size_box:
% \end{macrocode}
%
% \begin{macrocode}
@@ -6438,11 +6534,14 @@ version 2005/12/01 or later.
\bool_if:NTF \g_@@_empty_cell_bool
{ \box_use_drop:N \l_@@_cell_box }
{
- \dim_compare:nNnTF { \box_wd:N \l_@@_cell_box } > \c_zero_dim
+ \bool_lazy_or:nnTF
+ \g_@@_not_empty_cell_bool
+ { \dim_compare_p:nNn { \box_wd:N \l_@@_cell_box } > \c_zero_dim }
\@@_node_for_the_cell:
{ \box_use_drop:N \l_@@_cell_box }
}
\bool_gset_false:N \g_@@_empty_cell_bool
+ \bool_gset_false:N \g_@@_not_empty_cell_bool
}
% \end{macrocode}
%
@@ -6832,6 +6931,7 @@ version 2005/12/01 or later.
\cs_set_eq:NN \dotfill \@@_old_dotfill:
\cs_set_eq:NN \CodeAfter \@@_CodeAfter:
\cs_set_eq:NN \diagbox \@@_diagbox:nn
+ \cs_set_eq:NN \NotEmpty \@@_NotEmpty:
\bool_if:NT \l_@@_colortbl_like_bool \@@_colortbl_like:
\bool_if:NT \l_@@_renew_dots_bool \@@_renew_dots:
% \end{macrocode}
@@ -7496,7 +7596,7 @@ version 2005/12/01 or later.
}
{ \tl_gclear:N \g_@@_preamble_tl }
% \end{macrocode}
-% The counter |\l_tmpa_int| will be count the number of consecutive occurrences
+% The counter |\l_tmpa_int| will count the number of consecutive occurrences
% of the symbole \verb+|+.
% \begin{macrocode}
\int_zero:N \l_tmpa_int
@@ -7706,7 +7806,7 @@ version 2005/12/01 or later.
> {
\hbox_set:Nw \l_@@_cell_box
\@@_Cell:
- \tl_set:Nn \l_@@_cell_type_tl { #1 }
+ \tl_set:Nn \l_@@_cell_type_tl { #3 }
}
c
< {
@@ -7714,7 +7814,7 @@ version 2005/12/01 or later.
#1
\hbox_set_end:
\bool_if:NT \g_@@_rotate_bool \@@_rotate_cell_box:
- \@@_adjust_width_box:
+ \@@_adjust_size_box:
\makebox [ #4 ] [ #3 ] { \box_use_drop:N \l_@@_cell_box }
}
}
@@ -8445,7 +8545,7 @@ version 2005/12/01 or later.
\@@_math_toggle_token:
\hbox_set_end:
\bool_if:NT \g_@@_rotate_bool \@@_rotate_cell_box:
- \@@_adjust_width_box:
+ \@@_adjust_size_box:
\@@_update_for_first_and_last_row:
% \end{macrocode}
% We actualise the width of the ``first column'' because we will use this width
@@ -8515,7 +8615,7 @@ version 2005/12/01 or later.
\@@_math_toggle_token:
\hbox_set_end:
\bool_if:NT \g_@@_rotate_bool \@@_rotate_cell_box:
- \@@_adjust_width_box:
+ \@@_adjust_size_box:
\@@_update_for_first_and_last_row:
% \end{macrocode}
% We actualise the width of the ``last column'' because we will use this width
@@ -8628,6 +8728,14 @@ version 2005/12/01 or later.
% \end{macrocode}
%
% \bigskip
+% The following command will be linked to |\NotEmpty| in the environments of
+% \pkg{nicematrix}.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_NotEmpty:
+ { \bool_gset_true:N \g_@@_not_empty_cell_bool }
+% \end{macrocode}
+%
+% \bigskip
% \subsection*{The environments \{NiceTabular\} and \{NiceTabular*\}}
%
% \begin{macrocode}
@@ -8845,6 +8953,13 @@ version 2005/12/01 or later.
% \begin{macrocode}
\@@_compute_corners:
% \end{macrocode}
+%
+% \bigskip
+% The sequence |\g_@@_pos_of_blocks_seq| must be ``adjusted'' (for the case
+% where the user have written something like |\Block{1-}|).
+% \begin{macrocode}
+ \@@_adjust_pos_of_blocks_seq:
+% \end{macrocode}
%
% \bigskip
% The following code is only for efficiency. We determine whether the potential
@@ -8950,6 +9065,40 @@ version 2005/12/01 or later.
% \end{macrocode}
%
%
+% \bigskip
+% We remind that the first mandatory argument of the command |\Block| is the
+% size of the block with the special format $i$|-|$j$. However, the user is
+% allowed to omit $i$ or $j$ (or both). This will be interpreted as: the last
+% row (resp. column) of the block will be the last row (resp. column) of the
+% block (without the potential exterior row---resp. column---of the array). By
+% convention, this is stored in |\g_@@_pos_of_blocks_seq| (and
+% |\g_@@_blocks_seq|) as a number of rows (resp. columns) for the block equal to
+% 100. It's possible, after the construction of the array, to replace these
+% values by the correct ones (since we know the number of rows and columns of
+% the array).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_adjust_pos_of_blocks_seq:
+ {
+ \seq_gclear:N \g_tmpa_seq
+ \seq_map_inline:Nn \g_@@_pos_of_blocks_seq
+ { \@@_adjust_pos_of_blocks_seq_i:nnnn ##1 }
+ \seq_gset_eq:NN \g_@@_pos_of_blocks_seq \g_tmpa_seq
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_adjust_pos_of_blocks_seq_i:nnnn #1 #2 #3 #4
+ {
+ \int_compare:nNnTF { #3 } > { 99 }
+ { \int_set_eq:NN \l_tmpa_int \c@iRow }
+ { \int_set:Nn \l_tmpa_int { #3 } }
+ \int_compare:nNnTF { #4 } > { 99 }
+ { \int_set_eq:NN \l_tmpb_int \c@jCol }
+ { \int_set:Nn \l_tmpb_int { #4 } }
+ \seq_gput_right:Nx \g_tmpa_seq
+ { { #1 } { #2 } { \int_use:N \l_tmpa_int } { \int_use:N \l_tmpb_int } }
+ }
+% \end{macrocode}
%
% \bigskip
% We recall that, when externalization is used, |\tikzpicture| and
@@ -10242,8 +10391,8 @@ version 2005/12/01 or later.
% \end{macrocode}
%
%
-% The command |\@@_Hdotsfor_i| is defined with the tools of \pkg{xparse} because
-% it has an optional argument. Note that such a command defined by
+% The command |\@@_Hdotsfor_i| is defined with |\NewDocumentCommand| because it
+% has an optional argument. Note that such a command defined by
% |\NewDocumentCommand| is protected and that's why we have put the
% |\multicolumn| before (in the definition of |\@@_Hdotsfor:|).
% \begin{macrocode}
@@ -11179,7 +11328,7 @@ version 2005/12/01 or later.
% \subsection*{The horizontal rules}
%
% \bigskip
-% The following command will be executed in the |internal-code-after|. The row
+% The following command will be executed in the |internal-code-after|. The rule
% will be drawn \emph{before} the row |#1|. |#2| is the number of consecutive
% occurrences of |\Hline|.
% \begin{macrocode}
@@ -11196,7 +11345,7 @@ version 2005/12/01 or later.
{
% \end{macrocode}
% |\l_tmpa_tl| is the number of row and |\l_tmpb_tl| the number of column. Whe,
-% we have found a column corresponding to a rule to draw, we note its numver in
+% we have found a column corresponding to a rule to draw, we note its number in
% |\l_tmpc_tl|.
% \begin{macrocode}
\tl_set:Nn \l_tmpa_tl { #1 }
@@ -12251,7 +12400,8 @@ version 2005/12/01 or later.
%
% \bigskip
% The options of the command |\Block| will be analyzed first in the cell of the
-% array (and once again when the block will be put in the array in the |code-after|).
+% array (and once again when the block will be put in the array in the
+% |code-after|). Here is the set of keys for the first pass.
% \begin{macrocode}
\keys_define:nn { NiceMatrix / Block / FirstPass }
{
@@ -12265,21 +12415,28 @@ version 2005/12/01 or later.
% \end{macrocode}
%
%
-% The following command will be linked to |\Block| in the environments of
-% \pkg{nicematrix}. We define it with |\NewDocumentCommand| of \pkg{xparse}
-% because it has an optional argument between |<| and |>| (for TeX instructions
-% put before the math mode of the label)
+% The following command |\@@_Block:| will be linked to |\Block| in the
+% environments of \pkg{nicematrix}. We define it with
+% |\NewExpandableDocumentCommand| because it has an optional argument between
+% |<| and |>| (for TeX instructions put before the math mode of the label). It's
+% mandatory to use an expandable command.
%
-% It's mandatory to use an expandable command (why?).
% \begin{macrocode}
\NewExpandableDocumentCommand \@@_Block: { O { } m D < > { } m }
- { \@@_Block_i #2 \q_stop { #1 } { #3 } { #4 } }
+ {
+% \end{macrocode}
+% If the first mandatory argument of the command (which is the size of the block
+% with the syntax $i$|-|$j$) has not be provided by the user, you use |1-1|
+% (that is to say a block of only one cell).
+% \begin{macrocode}
+ \tl_if_blank:nTF { #2 } { \@@_Block_i 1-1 \q_stop } { \@@_Block_i #2 \q_stop }
+ { #1 } { #3 } { #4 }
+ }
% \end{macrocode}
%
% \medskip
-% The first mandatory argument of |\@@_Block:| has a special syntax. It must be
-% of the form $i$|-|$j$ where $i$ and $j$ are the size (in rows and columns) of
-% the block.
+% With the following construction, we extract the values of $i$ and $j$ in the
+% first mandatory argument of the command.
% \begin{macrocode}
\cs_new:Npn \@@_Block_i #1-#2 \q_stop { \@@_Block_ii:nnnnn { #1 } { #2 } }
% \end{macrocode}
@@ -12299,19 +12456,34 @@ version 2005/12/01 or later.
{ \tl_set:Nn \l_@@_pos_of_block_tl c }
{ \tl_set_eq:NN \l_@@_pos_of_block_tl \l_@@_cell_type_tl }
% \end{macrocode}
+%
% \medskip
% \begin{macrocode}
\keys_set_known:nn { NiceMatrix / Block / FirstPass } { #3 }
% \end{macrocode}
%
% \medskip
+% We recall that |#1| and |#2| have been extracted from the first mandatory
+% argument of |\Block| (which is of the syntax $i$|-|$j$). However, the user is
+% allowed to omit $i$ or $j$ (or both). We detect that situation by replacing a
+% missing value by 100 (it's a convention: when the block will actually be drawn
+% these values will be detected and interpreted as \emph{maximal possible value}).
+% \begin{macrocode}
+ \tl_if_empty:nTF { #1 }
+ { \int_set:Nn \l_tmpa_int { 100 } }
+ { \int_set:Nn \l_tmpa_int { #1 } }
+ \tl_if_empty:nTF { #2 }
+ { \int_set:Nn \l_tmpb_int { 100 } }
+ { \int_set:Nn \l_tmpb_int { #2 } }
+% \end{macrocode}
+%
% \begin{macrocode}
\tl_set:Nx \l_tmpa_tl
{
{ \int_use:N \c@iRow }
{ \int_use:N \c@jCol }
- { \int_eval:n { \c@iRow + #1 - 1 } }
- { \int_eval:n { \c@jCol + #2 - 1 } }
+ { \int_eval:n { \c@iRow + \l_tmpa_int - 1 } }
+ { \int_eval:n { \c@jCol + \l_tmpb_int - 1 } }
}
% \end{macrocode}
% Now, |\l_tmpa_tl| contains an ``object'' corresponding to the position of the
@@ -12332,41 +12504,62 @@ version 2005/12/01 or later.
% |{|\textsl{imin}|}{|\textsl{jmin}|}{|\textsl{imax}|}{|\textsl{jmax}|}{|\textsl{options}|}{|\textsl{contents}|}|.
%
% \medskip
-% If the block is mono-column, we have a special treatment.
+% If the block is mono-column or mono-row, we have a special treatment. That's
+% why we have two macros: |\@@_Block_iii:nnnnn| and |\@@_Block_iv:nnnnn| (the five
+% arguments of those macros are provided by curryfication).
% \begin{macrocode}
- \int_compare:nNnTF { #2 } = 1
+ \bool_lazy_or:nnTF
+ { \int_compare_p:nNn { \l_tmpa_int } = 1 }
+ { \int_compare_p:nNn { \l_tmpb_int } = 1 }
+ { \exp_args:Nxx \@@_Block_iii:nnnnn }
+ { \exp_args:Nxx \@@_Block_iv:nnnnn }
+ { \l_tmpa_int } { \l_tmpb_int } { #3 } { #4 } { #5 }
+ }
+% \end{macrocode}
+%
+%
+% \bigskip
+% The following macro is for the case of a |\Block| which is mono-row or
+% mono-column (or both). In that case, the content of the block is composed
+% right now in a box (because we have to take into account the dimensions of
+% that box for the width of the current column or the height and the depth of the
+% current row). However, that box will be put in the array \emph{after the
+% construction of the array} (by using \textsc{pgf}).
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_Block_iii:nnnnn #1 #2 #3 #4 #5
+ {
+ \int_gincr:N \g_@@_block_box_int
+ \cs_set_protected_nopar:Npn \diagbox ##1 ##2
{
- \int_gincr:N \g_@@_block_box_int
- \cs_set_protected_nopar:Npn \diagbox ##1 ##2
- {
- \tl_gput_right:Nx \g_@@_internal_code_after_tl
- {
- \@@_actually_diagbox:nnnnnn
- { \int_use:N \c@iRow }
- { \int_use:N \c@jCol }
- { \int_eval:n { \c@iRow + #1 - 1 } }
- { \int_eval:n { \c@jCol + #2 - 1 } }
- { \exp_not:n { ##1 } } { \exp_not:n { ##2 } }
- }
- }
- \box_gclear_new:c
- { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
- \hbox_gset:cn
- { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ \tl_gput_right:Nx \g_@@_internal_code_after_tl
{
+ \@@_actually_diagbox:nnnnnn
+ { \int_use:N \c@iRow }
+ { \int_use:N \c@jCol }
+ { \int_eval:n { \c@iRow + #1 - 1 } }
+ { \int_eval:n { \c@jCol + #2 - 1 } }
+ { \exp_not:n { ##1 } } { \exp_not:n { ##2 } }
+ }
+ }
+ \box_gclear_new:c
+ { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ \hbox_gset:cn
+ { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ {
% \end{macrocode}
-% If the user has specified a color for the column in the preamble of the array,
-% we want to fix that color in the box we construct. We do that with
-% |\set@color| and not |\color_ensure_current:| because that command seems to be
-% bugged: it doesn't work in XeLaTeX when \pkg{fontspec} is loaded.
+% For a mono-column block, if the user has specified a color for the column in
+% the preamble of the array, we want to fix that color in the box we construct.
+% We do that with |\set@color| and not |\color_ensure_current:| because that
+% command seems to be bugged: it doesn't work in XeLaTeX when \pkg{fontspec} is
+% loaded.
% \begin{macrocode}
- \set@color
- \bool_if:NTF \l_@@_NiceTabular_bool
- {
- \group_begin:
- \cs_set:Npn \arraystretch { 1 }
- \dim_set_eq:NN \extrarowheight \c_zero_dim
- #4
+ \int_compare:nNnT { #2 } = 1 \set@color
+ \bool_if:NTF \l_@@_NiceTabular_bool
+ {
+ \group_begin:
+ \cs_set:Npn \arraystretch { 1 }
+ \dim_set_eq:NN \extrarowheight \c_zero_dim
+ #4
% \end{macrocode}
% If the box is rotated (the key |\rotate| may be in the previous |#4|), the
% tabular used for the content of the cell will be constructed with a format
@@ -12375,49 +12568,81 @@ version 2005/12/01 or later.
% the tabular is the same as the external alignment of the tabular (that is to
% say the position of the block in its zone of merged cells).
% \begin{macrocode}
- \bool_if:NT \g_@@_rotate_bool
- { \tl_set:Nn \l_@@_pos_of_block_tl c }
- \exp_args:Nnx \begin { tabular }
- { @ { } \l_@@_pos_of_block_tl @ { } }
- #5
- \end { tabular }
- \group_end:
- }
- {
- \group_begin:
- \cs_set:Npn \arraystretch { 1 }
- \dim_set_eq:NN \extrarowheight \c_zero_dim
- #4
- \bool_if:NT \g_@@_rotate_bool
- { \tl_set:Nn \l_@@_pos_of_block_tl c }
- \c_math_toggle_token
- \exp_args:Nnx \begin { array }
- { @ { } \l_@@_pos_of_block_tl @ { } }
- #5
- \end { array }
- \c_math_toggle_token
- \group_end:
- }
- }
- \bool_if:NT \g_@@_rotate_bool
- {
- \box_grotate:cn
- { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
- { 90 }
- \bool_gset_false:N \g_@@_rotate_bool
+ \bool_if:NT \g_@@_rotate_bool
+ { \tl_set:Nn \l_@@_pos_of_block_tl c }
+ \exp_args:Nnx \begin { tabular }
+ { @ { } \l_@@_pos_of_block_tl @ { } }
+ #5
+ \end { tabular }
+ \group_end:
+ }
+ {
+ \group_begin:
+ \cs_set:Npn \arraystretch { 1 }
+ \dim_set_eq:NN \extrarowheight \c_zero_dim
+ #4
+ \bool_if:NT \g_@@_rotate_bool
+ { \tl_set:Nn \l_@@_pos_of_block_tl c }
+ \c_math_toggle_token
+ \exp_args:Nnx \begin { array }
+ { @ { } \l_@@_pos_of_block_tl @ { } }
+ #5
+ \end { array }
+ \c_math_toggle_token
+ \group_end:
}
- \dim_gset:Nn \g_@@_blocks_width_dim
+ }
+ \bool_if:NT \g_@@_rotate_bool
+ {
+ \box_grotate:cn
+ { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ { 90 }
+ \bool_gset_false:N \g_@@_rotate_bool
+ }
+% \end{macrocode}
+% If we are in a mono-column block, we take into account the width of that block
+% for the width of the column.
+% \begin{macrocode}
+ \int_compare:nNnT { #2 } = 1
+ {
+ \dim_gset:Nn \g_@@_blocks_wd_dim
{
\dim_max:nn
- \g_@@_blocks_width_dim
+ \g_@@_blocks_wd_dim
{
\box_wd:c
{ g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
}
- }
- \seq_gput_right:Nx \g_@@_blocks_seq
- {
- \l_tmpa_tl
+ }
+ }
+% \end{macrocode}
+% If we are in a mono-row block, we take into account the height and the
+% depth of that block for the height and the depth of the row.
+% \begin{macrocode}
+ \int_compare:nNnT { #1 } = 1
+ {
+ \dim_gset:Nn \g_@@_blocks_ht_dim
+ {
+ \dim_max:nn
+ \g_@@_blocks_ht_dim
+ {
+ \box_ht:c
+ { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ }
+ }
+ \dim_gset:Nn \g_@@_blocks_dp_dim
+ {
+ \dim_max:nn
+ \g_@@_blocks_dp_dim
+ {
+ \box_dp:c
+ { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ }
+ }
+ }
+ \seq_gput_right:Nx \g_@@_blocks_seq
+ {
+ \l_tmpa_tl
% \end{macrocode}
% In the list of options |#3|, maybe there is a key for the horizontal alignment
% (|l|, |r| or |c|). In that case, that key has been read and stored in
@@ -12425,30 +12650,36 @@ version 2005/12/01 or later.
% alignement and that's why we put a key corresponding to the value of
% |\l_@@_pos_of_block_tl|, which is fixed by the type of current column.
% \begin{macrocode}
- { #3 , \l_@@_pos_of_block_tl }
- {
- \box_use_drop:c
- { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
- }
- }
- }
+ { #3 , \l_@@_pos_of_block_tl }
+ {
+ \box_use_drop:c
+ { g_@@_ block _ box _ \int_use:N \g_@@_block_box_int _ box }
+ }
+ }
+ }
% \end{macrocode}
-% In the standard case, that is to say a |\Block| which is \emph{not} mono-column.
+%
+% \bigskip
+% The following macro is for the standard case, where the block is not mono-row
+% and not mono-column. In that case, the content of the block is \emph{not}
+% composed right now in a box. The composition in a box will be done further,
+% just after the construction of the array.
% \begin{macrocode}
- {
- \seq_gput_right:Nx \g_@@_blocks_seq
- {
- \l_tmpa_tl
- { #3 }
- \exp_not:n
- {
- {
- \bool_if:NTF \l_@@_NiceTabular_bool
- {
- \group_begin:
- \cs_set:Npn \arraystretch { 1 }
- \dim_set_eq:NN \extrarowheight \c_zero_dim
- #4
+\cs_new_protected:Npn \@@_Block_iv:nnnnn #1 #2 #3 #4 #5
+ {
+ \seq_gput_right:Nx \g_@@_blocks_seq
+ {
+ \l_tmpa_tl
+ { #3 }
+ \exp_not:n
+ {
+ {
+ \bool_if:NTF \l_@@_NiceTabular_bool
+ {
+ \group_begin:
+ \cs_set:Npn \arraystretch { 1 }
+ \dim_set_eq:NN \extrarowheight \c_zero_dim
+ #4
% \end{macrocode}
% If the box is rotated (the key |\rotate| may be in the previous |#4|), the
% tabular used for the content of the cell will be constructed with a format
@@ -12457,36 +12688,39 @@ version 2005/12/01 or later.
% the tabular is the same as the external alignment of the tabular (that is to
% say the position of the block in its zone of merged cells).
% \begin{macrocode}
- \bool_if:NT \g_@@_rotate_bool
- { \tl_set:Nn \l_@@_pos_of_block_tl c }
- \exp_args:Nnx \begin { tabular }
- { @ { } \l_@@_pos_of_block_tl @ { } }
- #5
- \end { tabular }
- \group_end:
- }
- {
- \group_begin:
- \cs_set:Npn \arraystretch { 1 }
- \dim_set_eq:NN \extrarowheight \c_zero_dim
- #4
- \bool_if:NT \g_@@_rotate_bool
- { \tl_set:Nn \l_@@_pos_of_block_tl c }
- \c_math_toggle_token
- \exp_args:Nnx \begin { array }
- { @ { } \l_@@_pos_of_block_tl @ { } } #5 \end { array }
- \c_math_toggle_token
- \group_end:
- }
+ \bool_if:NT \g_@@_rotate_bool
+ { \tl_set:Nn \l_@@_pos_of_block_tl c }
+ \exp_args:Nnx \begin { tabular }
+ { @ { } \l_@@_pos_of_block_tl @ { } }
+ #5
+ \end { tabular }
+ \group_end:
}
- }
- }
- }
- }
+ {
+ \group_begin:
+ \cs_set:Npn \arraystretch { 1 }
+ \dim_set_eq:NN \extrarowheight \c_zero_dim
+ #4
+ \bool_if:NT \g_@@_rotate_bool
+ { \tl_set:Nn \l_@@_pos_of_block_tl c }
+ \c_math_toggle_token
+ \exp_args:Nnx \begin { array }
+ { @ { } \l_@@_pos_of_block_tl @ { } } #5 \end { array }
+ \c_math_toggle_token
+ \group_end:
+ }
+ }
+ }
+ }
+ }
% \end{macrocode}
-%
%
% \bigskip
+% We recall that the options of the command |\Block| are analyzed twice: first
+% in the cell of the array and once again when the block will be put in the
+% array \emph{after the construction of the array} (by using \textsc{pgf}).
+%
+% \medskip
% The key |tikz| is for Tikz options used when the \textsc{pgf} node of the
% block is created (the ``normal'' block node and not the ``short'' one nor the
% ``medium'' one). \textbf{In fact, as of now, it is \emph{not} documented}. Is
@@ -12531,6 +12765,29 @@ version 2005/12/01 or later.
\keys_set:nn { NiceMatrix / Block / SecondPass} { #5 }
% \end{macrocode}
%
+% The integer |\l_@@_last_row_int| will be the last row of the block and
+% |\l_@@_last_col_int| it's last column.
+% \begin{macrocode}
+ \int_zero_new:N \l_@@_last_row_int
+ \int_zero_new:N \l_@@_last_col_int
+% \end{macrocode}
+%
+% We remind that the first mandatory argument of the command |\Block| is the
+% size of the block with the special format $i$|-|$j$. However, the user is
+% allowed to omit $i$ or $j$ (or both). This will be interpreted as: the last
+% row (resp. column) of the block will be the last row (resp. column) of the
+% block (without the potential exterior row---resp. column---of the array). By
+% convention, this is stored in |\g_@@_blocks_seq| as a number of rows (resp.
+% columns) for the block equal to 100. That's what we detect now.
+% \begin{macrocode}
+ \int_compare:nNnTF { #3 } > { 99 }
+ { \int_set_eq:NN \l_@@_last_row_int \c@iRow }
+ { \int_set:Nn \l_@@_last_row_int { #3 } }
+ \int_compare:nNnTF { #4 } > { 99 }
+ { \int_set_eq:NN \l_@@_last_col_int \c@jCol }
+ { \int_set:Nn \l_@@_last_col_int { #4 } }
+% \end{macrocode}
+%
% \begin{macrocode}
\tl_if_empty:NF \l_@@_color_tl
{
@@ -12539,7 +12796,7 @@ version 2005/12/01 or later.
\exp_not:N \rectanglecolor
{ \l_@@_color_tl }
{ #1 - #2 }
- { #3 - #4 }
+ { \int_use:N \l_@@_last_row_int - \int_use:N \l_@@_last_col_int }
}
}
% \end{macrocode}
@@ -12551,7 +12808,10 @@ version 2005/12/01 or later.
\tl_gput_right:Nx \g_@@_internal_code_after_tl
{
\@@_actually_diagbox:nnnnnn
- { #1 } { #2 } { #3 } { #4 }
+ { #1 }
+ { #2 }
+ { \int_use:N \l_@@_last_row_int }
+ { \int_use:N \l_@@_last_col_int }
{ \exp_not:n { ##1 } } { \exp_not:n { ##2 } }
}
}
@@ -12560,8 +12820,8 @@ version 2005/12/01 or later.
% \medskip
% \begin{macrocode}
\bool_lazy_or:nnTF
- { \int_compare_p:nNn { #3 } > \g_@@_row_total_int }
- { \int_compare_p:nNn { #4 } > \g_@@_col_total_int }
+ { \int_compare_p:nNn \l_@@_last_row_int > \g_@@_row_total_int }
+ { \int_compare_p:nNn \l_@@_last_col_int > \g_@@_col_total_int }
{ \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } }
{
\hbox_set:Nn \l_@@_cell_box { #6 }
@@ -12625,9 +12885,9 @@ version 2005/12/01 or later.
\dim_set_eq:NN \l_tmpa_dim \pgf@y
\@@_qpoint:n { col - #2 }
\dim_set_eq:NN \l_tmpb_dim \pgf@x
- \@@_qpoint:n { row - \@@_succ:n { #3 } }
+ \@@_qpoint:n { row - \@@_succ:n { \l_@@_last_row_int } }
\dim_set_eq:NN \l_tmpc_dim \pgf@y
- \@@_qpoint:n { col - \@@_succ:n { #4 } }
+ \@@_qpoint:n { col - \@@_succ:n { \l_@@_last_col_int } }
\dim_set_eq:NN \l_tmpd_dim \pgf@x
% \end{macrocode}
%
@@ -12678,18 +12938,20 @@ version 2005/12/01 or later.
\int_step_inline:nnn \l_@@_first_row_int \g_@@_row_total_int
{
\cs_if_exist:cT
- { pgf @ sh @ ns @ \@@_env: - ##1 - #4 }
+ { pgf @ sh @ ns @ \@@_env: - ##1 - \int_use:N \l_@@_last_col_int }
{
\seq_if_in:NnF \g_@@_multicolumn_cells_seq { ##1 - #2 }
{
- \pgfpointanchor { \@@_env: - ##1 - #4 } { east }
+ \pgfpointanchor
+ { \@@_env: - ##1 - \int_use:N \l_@@_last_col_int }
+ { east }
\dim_set:Nn \l_tmpd_dim { \dim_max:nn \l_tmpd_dim \pgf@x }
}
}
}
\dim_compare:nNnT \l_tmpd_dim = { - \c_max_dim }
{
- \@@_qpoint:n { col - \@@_succ:n { #4 } }
+ \@@_qpoint:n { col - \@@_succ:n { \l_@@_last_col_int } }
\dim_set_eq:NN \l_tmpd_dim \pgf@x
}
\@@_pgf_rect_node:nnnnn
@@ -12707,7 +12969,14 @@ version 2005/12/01 or later.
\@@_pgf_rect_node:nnn
{ \@@_env: - #1 - #2 - block - medium }
{ \pgfpointanchor { \@@_env: - #1 - #2 - medium } { north~west } }
- { \pgfpointanchor { \@@_env: - #3 - #4 - medium } { south~east } }
+ {
+ \pgfpointanchor
+ { \@@_env:
+ - \int_use:N \l_@@_last_row_int
+ - \int_use:N \l_@@_last_col_int - medium
+ }
+ { south~east }
+ }
}
% \end{macrocode}
% \medskip
@@ -14205,12 +14474,18 @@ version 2005/12/01 or later.
%
% Different behaviour for the mono-column blocks.
%
-% \subsection*{Changes between versions 5.3 and 5.4}
+% \subsection*{Changes between versions 5.4 and 5.5}
%
% The user must never put |\omit| before |\CodeAfter|.
%
% Correction of a bug: the tabular notes |\tabularnotes| were not composed when
% present in a block (except a mono-column block).
+%
+% \subsection*{Changes between versions 5.5 and 5.6}
+%
+% Different behaviour for the mono-row blocks.
+%
+% New command |\NotEmpty|.
%
% \PrintIndex
%