From 4a62bf962f41ebc77a4b8feac7a91dd31a20998f Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 15 Mar 2020 21:32:14 +0000 Subject: nicematrix (15mar20) git-svn-id: svn://tug.org/texlive/trunk@54330 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 2126 +++++++++++--------- 1 file changed, 1196 insertions(+), 930 deletions(-) (limited to 'Master/texmf-dist/tex/latex/nicematrix') diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index bfa03a3231f..a3b169cfa85 100644 --- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty +++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty @@ -18,17 +18,17 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{3.12} -\def\myfiledate{2020/02/28} -\RequirePackage{tikz} -\usetikzlibrary{fit} +\def\myfileversion{3.13} +\def\myfiledate{2020/03/15} +\RequirePackage{pgfcore} +\usepgfmodule{shapes} \RequirePackage{expl3}[2020/02/08] \RequirePackage{l3keys2e} \ProvidesExplPackage {nicematrix} {\myfiledate} {\myfileversion} - {Mathematical matrices with TikZ} + {Mathematical matrices with PGF/TikZ} \msg_new:nnn { nicematrix } { expl3~too~old } { Your~version~of~LaTeX~(especially~expl3)~is~too~old.~ @@ -53,6 +53,20 @@ \cs_new_protected:Npn \__nicematrix_msg_new:nnn { \msg_new:nnnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_msg_redirect_name:nn { \msg_redirect_name:nnn { nicematrix } } +\bool_new:N \c__nicematrix_tikz_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { tikz } + { + \bool_set_true:N \c__nicematrix_tikz_loaded_bool + \tl_const:Nn \c__nicematrix_pgfortikzpicture_tl { \exp_not:N \tikzpicture } + \tl_const:Nn \c__nicematrix_endpgfortikzpicture_tl { \exp_not:N \endtikzpicture } + } + { + \tl_const:Nn \c__nicematrix_pgfortikzpicture_tl { \exp_not:N \pgfpicture } + \tl_const:Nn \c__nicematrix_endpgfortikzpicture_tl { \exp_not:N \endpgfpicture } + } + } \bool_new:N \c__nicematrix_revtex_bool \@ifclassloaded { revtex4-1 } { \bool_set_true:N \c__nicematrix_revtex_bool } @@ -62,8 +76,7 @@ { } \__nicematrix_msg_new:nn { Draft~mode } { The~compilation~is~in~draft~mode:~the~dotted~lines~won't~be~drawn. } -\bool_if:NT \c__nicematrix_draft_bool - { \msg_warning:nn { nicematrix } { Draft~mode } } +\bool_if:NT \c__nicematrix_draft_bool { \msg_warning:nn { nicematrix } { Draft~mode } } \ProvideDocumentCommand \iddots { } { \mathinner @@ -79,6 +92,9 @@ } } \int_new:N \g__nicematrix_env_int +\cs_new:Npn \__nicematrix_env: { nm - \int_use:N \g__nicematrix_env_int } +\cs_new_protected:Npn \__nicematrix_qpoint: #1 + { \pgfpointanchor { \__nicematrix_env: - #1 } { center } } \int_new:N \g__nicematrix_NiceMatrixBlock_int \dim_new:N \l__nicematrix_columns_width_dim \seq_new:N \g__nicematrix_names_seq @@ -91,7 +107,6 @@ \__nicematrix_fatal:n { Outside~math~mode } \fi: } -\bool_new:N \l__nicematrix_impossible_line_bool \bool_new:N \c__nicematrix_colortbl_loaded_bool \AtBeginDocument { @@ -102,12 +117,12 @@ } { } } -\cs_set_protected:Npn \__nicematrix_extract_coords:w - { \tikz@parse@node \pgfutil@firstofone } +\colorlet { nicematrix-last-col } { . } +\colorlet { nicematrix-last-row } { . } \dim_new:N \l__nicematrix_inter_dots_dim \dim_set:Nn \l__nicematrix_inter_dots_dim { 0.45 em } -\dim_new:N \l__nicematrix_dotted_lines_margin_dim -\dim_set:Nn \l__nicematrix_dotted_lines_margin_dim { 0.3 em } +\dim_new:N \l__nicematrix_xdots_shorten_dim +\dim_set:Nn \l__nicematrix_xdots_shorten_dim { 0.3 em } \dim_new:N \l__nicematrix_radius_dim \dim_set:Nn \l__nicematrix_radius_dim { 0.53 pt } \str_new:N \g__nicematrix_name_env_str @@ -119,10 +134,25 @@ { command \space \c_backslash_str \g__nicematrix_name_env_str } { environment \space \{ \g__nicematrix_name_env_str \} } } +\tl_new:N \g__nicematrix_internal_code_after_tl \tl_new:N \g__nicematrix_code_after_tl \int_new:N \l__nicematrix_save_iRow_int \int_new:N \l__nicematrix_save_jCol_int \bool_new:N \g__nicematrix_row_of_col_done_bool +\tl_new:N \l__nicematrix_initial_suffix_tl +\tl_new:N \l__nicematrix_initial_anchor_tl +\tl_new:N \l__nicematrix_final_suffix_tl +\tl_new:N \l__nicematrix_final_anchor_tl +\dim_new:N \l__nicematrix_x_initial_dim +\dim_new:N \l__nicematrix_y_initial_dim +\dim_new:N \l__nicematrix_x_final_dim +\dim_new:N \l__nicematrix_y_final_dim +\dim_new:N \l_tmpc_dim +\dim_new:N \l_tmpd_dim +\bool_new:N \g__nicematrix_empty_cell_bool +\tl_new:N \l__nicematrix_xdots_line_style_tl +\tl_const:Nn \c__nicematrix_standard_tl { standard } +\tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl \int_new:N \l__nicematrix_first_row_int \int_set:Nn \l__nicematrix_first_row_int 1 \int_new:N \l__nicematrix_first_col_int @@ -172,6 +202,7 @@ \NC@find } } +\cs_new:Npn \__nicematrix_succ:N #1 { \the \numexpr #1 + 1 \relax } \bool_new:N \l__nicematrix_light_syntax_bool \str_new:N \l__nicematrix_baseline_str \str_set:Nn \l__nicematrix_baseline_str c @@ -184,9 +215,7 @@ \bool_new:N \l__nicematrix_auto_columns_width_bool \str_new:N \l__nicematrix_name_str \bool_new:N \l__nicematrix_medium_nodes_bool -\bool_new:N \g__nicematrix_medium_nodes_bool \bool_new:N \l__nicematrix_large_nodes_bool -\bool_new:N \g__nicematrix_large_nodes_bool \dim_new:N \l__nicematrix_left_margin_dim \dim_new:N \l__nicematrix_right_margin_dim \dim_new:N \g__nicematrix_width_last_col_dim @@ -195,12 +224,29 @@ \dim_new:N \l__nicematrix_extra_right_margin_dim \tl_new:N \l__nicematrix_end_of_row_tl \tl_set:Nn \l__nicematrix_end_of_row_tl { ; } +\tl_new:N \l__nicematrix_xdots_color_tl \bool_new:N \l__nicematrix_max_delimiter_width_bool +\keys_define:nn { NiceMatrix / xdots } + { + line-style .code:n = + { + \bool_lazy_or:nnTF + { \cs_if_exist_p:N \tikzpicture } + { \str_if_eq_p:nn { #1 } { standard } } + { \tl_set:Nn \l__nicematrix_xdots_line_style_tl { #1 } } + { \__nicematrix_error:n { bad~option~for~line-style } } + } , + line-style .value_required:n = true , + color .tl_set:N = \l__nicematrix_xdots_color_tl , + color .value_required:n = true , + shorten .dim_set:N = \l__nicematrix_xdots_shorten_dim , + shorten .value_required:n = true , + unknown .code:n = \__nicematrix_error:n { Unknown~option~for~xdots } + } \keys_define:nn { NiceMatrix / Global } { + xdots .code:n = \keys_set:nn { NiceMatrix / xdots } { #1 } , max-delimiter-width .bool_set:N = \l__nicematrix_max_delimiter_width_bool , - dotted-lines-margin .dim_set:N = \l__nicematrix_dotted_lines_margin_dim , - dotted-lines-margin .value_required:n = true , light-syntax .bool_set:N = \l__nicematrix_light_syntax_bool , light-syntax .default:n = true , end-of-row .tl_set:N = \l__nicematrix_end_of_row_tl , @@ -234,7 +280,8 @@ extra-left-margin .dim_set:N = \l__nicematrix_extra_left_margin_dim , extra-right-margin .dim_set:N = \l__nicematrix_extra_right_margin_dim , extra-margin .meta:n = - { extra-left-margin = #1 , extra-right-margin = #1 } + { extra-left-margin = #1 , extra-right-margin = #1 } , + extra-margin .value_required:n = true } \keys_define:nn { NiceMatrix / Env } { @@ -266,21 +313,25 @@ { NiceMatrix / Global , } , + NiceMatrixOptions / xdots .inherit:n = NiceMatrix / xdots , NiceMatrix .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Env , } , + NiceMatrix / xdots .inherit:n = NiceMatrix / xdots , NiceArray .inherit:n = { NiceMatrix / Global , NiceMatrix / Env , } , + NiceArray / xdots .inherit:n = NiceMatrix / xdots , pNiceArray .inherit:n = { NiceMatrix / Global , NiceMatrix / Env , - } + } , + pNiceArray / xdots .inherit:n = NiceMatrix / xdots } \keys_define:nn { NiceMatrix / NiceMatrixOptions } { @@ -314,6 +365,10 @@ last-col .code:n = \tl_if_empty:nTF {#1} { \__nicematrix_error:n { last-col~empty~for~NiceMatrix } } { \int_set:Nn \l__nicematrix_last_col_int { #1 } } , + l .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl L , + r .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl R , + L .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl L , + R .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl R , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceMatrix } } \keys_define:nn { NiceMatrix / NiceArray } @@ -343,20 +398,25 @@ { \int_gincr:N \c@jCol \int_compare:nNnT \c@jCol = 1 - { - \int_compare:nNnT \l__nicematrix_first_col_int = 1 - \__nicematrix_begin_of_row: - } - \int_gset:Nn \g__nicematrix_col_total_int - { \int_max:nn \g__nicematrix_col_total_int \c@jCol } + { \int_compare:nNnT \l__nicematrix_first_col_int = 1 \__nicematrix_begin_of_row: } + \int_gset:Nn \g__nicematrix_col_total_int { \int_max:nn \g__nicematrix_col_total_int \c@jCol } \hbox_set:Nw \l__nicematrix_cell_box \c_math_toggle_token \bool_if:NT \l__nicematrix_small_bool \scriptstyle \int_compare:nNnTF \c@iRow = 0 - { \int_compare:nNnT \c@jCol > 0 \l__nicematrix_code_for_first_row_tl } + { + \int_compare:nNnT \c@jCol > 0 + { + \l__nicematrix_code_for_first_row_tl + \xglobal \colorlet { nicematrix-first-row } { . } + } + } { \int_compare:nNnT \c@iRow = \l__nicematrix_last_row_int - \l__nicematrix_code_for_last_row_tl + { + \l__nicematrix_code_for_last_row_tl + \xglobal \colorlet { nicematrix-last-row } { . } + } } } \cs_new_protected:Npn \__nicematrix_begin_of_row: @@ -365,8 +425,18 @@ \dim_gset_eq:NN \g__nicematrix_dp_ante_last_row_dim \g__nicematrix_dp_last_row_dim \dim_gset:Nn \g__nicematrix_dp_last_row_dim { \box_dp:N \@arstrutbox } \dim_gset:Nn \g__nicematrix_ht_last_row_dim { \box_ht:N \@arstrutbox } - \tikz [ remember~picture , baseline ] \coordinate - ( nm - \int_use:N \g__nicematrix_env_int - row - \int_use:N \c@iRow - base ) ; + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate + { \__nicematrix_env: - row - \int_use:N \c@iRow - base } + \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \__nicematrix_env: - row - \int_use:N \c@iRow - base } + { \l__nicematrix_name_str - row - \int_use:N \c@iRow - base } + } + \endpgfpicture } \cs_new_protected:Npn \__nicematrix_update_for_first_and_last_row: { @@ -392,58 +462,54 @@ \dim_gset:Nn \g__nicematrix_max_cell_width_dim { \dim_max:nn \g__nicematrix_max_cell_width_dim { \box_wd:N \l__nicematrix_cell_box } } \__nicematrix_update_for_first_and_last_row: - \tikz - [ - remember~picture , - inner~sep = \c_zero_dim , - minimum~width = \c_zero_dim , - baseline - ] - \node - [ - anchor = base , - name = nm - \int_use:N \g__nicematrix_env_int - - \int_use:N \c@iRow - - \int_use:N \c@jCol , - alias = - \str_if_empty:NF \l__nicematrix_name_str - { - \l__nicematrix_name_str - - \int_use:N \c@iRow - - \int_use:N \c@jCol - } - ] - { \box_use_drop:N \l__nicematrix_cell_box } ; + \bool_if:NTF \g__nicematrix_empty_cell_bool + { + \box_use_drop:N \l__nicematrix_cell_box + \bool_gset_false:N \g__nicematrix_empty_cell_bool + } + { + \dim_compare:nNnTF { \box_wd:N \l__nicematrix_cell_box } > \c_zero_dim + \__nicematrix_node_for_the_cell: + { \box_use_drop:N \l__nicematrix_cell_box } + } + \bool_gset_false:N \g__nicematrix_empty_cell_bool } -\cs_generate_variant:Nn \dim_set:Nn { N x } -\cs_new_protected:Npn \__nicematrix_renewcolumntype:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_node_for_the_cell: { - \newcolumntype #1 [ 2 ] + \pgfpicture + \pgfsetbaseline \c_zero_dim + \pgfrememberpicturepositiononpagetrue + \pgfset { - > { - \hbox_set:Nw \l__nicematrix_cell_box - \__nicematrix_Cell: - } - c - < { - \__nicematrix_end_Cell: - \hbox_set_end: - #2 - \makebox [ ##2 ] [ ##1 ] { \box_use_drop:N \l__nicematrix_cell_box } - } + inner~sep = \c_zero_dim , + minimum~width = \c_zero_dim + } + \pgfnode + { rectangle } + { base } + { \box_use_drop:N \l__nicematrix_cell_box } + { \__nicematrix_env: - \int_use:N \c@iRow - \int_use:N \c@jCol } + { } + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \l__nicematrix_name_str - \int_use:N \c@iRow - \int_use:N \c@jCol } + { \__nicematrix_env: - \int_use:N \c@iRow - \int_use:N \c@jCol } } + \endpgfpicture } \bool_if:NTF \c__nicematrix_draft_bool - { \cs_set_protected:Npn \__nicematrix_instruction_of_type:n #1 { } } + { \cs_set_protected:Npn \__nicematrix_instruction_of_type:nn #1 #2 { } } { - \cs_new_protected:Npn \__nicematrix_instruction_of_type:n #1 + \cs_new_protected:Npn \__nicematrix_instruction_of_type:nn #1 #2 { \tl_gput_right:cx { g__nicematrix_ #1 _ lines _ tl } { - \use:c { __nicematrix _ draw _ #1 : nn } + \use:c { __nicematrix _ draw _ #1 : nnn } { \int_use:N \c@iRow } { \int_use:N \c@jCol } + { #2 } } } } @@ -465,11 +531,19 @@ \cs_new_protected:Npn \__nicematrix_everycr_i: { \int_gzero:N \c@jCol - \hbox:n + \hbox { - \tikz [ remember~picture ] - \coordinate - ( nm - \int_use:N \g__nicematrix_env_int - row - \int_eval:n { \c@iRow + 1 } ) ; + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate { \__nicematrix_env: - row - \__nicematrix_succ:N \c@iRow } + \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \__nicematrix_env: - row - \int_use:N \c@iRow - row } + { \l__nicematrix_name_str - row - \int_use:N \c@iRow - row } + } + \endpgfpicture } \bool_if:NT \l__nicematrix_hlines_bool { @@ -502,8 +576,6 @@ \cs_set:Npn \arraystretch { 0.47 } \dim_set:Nn \arraycolsep { 1.45 pt } } - \bool_gset_eq:NN \g__nicematrix_medium_nodes_bool \l__nicematrix_medium_nodes_bool - \bool_gset_eq:NN \g__nicematrix_large_nodes_bool \l__nicematrix_large_nodes_bool \cs_set:Npn \ialign { \bool_if:NTF \c__nicematrix_colortbl_loaded_bool @@ -533,6 +605,11 @@ \newcolumntype L { > \__nicematrix_Cell: l < \__nicematrix_end_Cell: } \newcolumntype C { > \__nicematrix_Cell: c < \__nicematrix_end_Cell: } \newcolumntype R { > \__nicematrix_Cell: r < \__nicematrix_end_Cell: } + \cs_set_eq:NN \__nicematrix_ldots \ldots + \cs_set_eq:NN \__nicematrix_cdots \cdots + \cs_set_eq:NN \__nicematrix_vdots \vdots + \cs_set_eq:NN \__nicematrix_ddots \ddots + \cs_set_eq:NN \__nicematrix_iddots \iddots \cs_set_eq:NN \firsthline \hline \cs_set_eq:NN \lasthline \hline \cs_set_eq:NN \Ldots \__nicematrix_Ldots @@ -565,8 +642,35 @@ \cs_set_eq:NN \@ifnextchar \new@ifnextchar \cs_set_eq:NN \NC@find@w \relax \cs_set_eq:NN \NC@find@W \relax - \__nicematrix_renewcolumntype:nn w { } - \__nicematrix_renewcolumntype:nn W { \cs_set_eq:NN \hss \hfil } + \newcolumntype w [ 2 ] + { + > { + \hbox_set:Nw \l__nicematrix_cell_box + \__nicematrix_Cell: + } + c + < { + \__nicematrix_end_Cell: + \hbox_set_end: + \makebox [ ##2 ] [ \str_lowercase:n { ##1 } ] + { \box_use_drop:N \l__nicematrix_cell_box } + } + } + \newcolumntype W [ 2 ] + { + > { + \hbox_set:Nw \l__nicematrix_cell_box + \__nicematrix_Cell: + } + c + < { + \__nicematrix_end_Cell: + \hbox_set_end: + \cs_set_eq:NN \hss \hfil + \makebox [ ##2 ] [ \str_lowercase:n { ##1 } ] + { \box_use_drop:N \l__nicematrix_cell_box } + } + } \tl_set_rescan:Nno \l__nicematrix_letter_for_dotted_lines_str { } \l__nicematrix_letter_for_dotted_lines_str \exp_args:NV \newcolumntype \l__nicematrix_letter_for_dotted_lines_str @@ -576,12 +680,12 @@ \int_compare:nNnF \c@iRow = 0 { \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - { \skip_horizontal:n { 2 \l__nicematrix_radius_dim } } + { \skip_horizontal:N 2\l__nicematrix_radius_dim } } \int_compare:nNnT \c@jCol > \g__nicematrix_last_vdotted_col_int { \int_gset_eq:NN \g__nicematrix_last_vdotted_col_int \c@jCol - \tl_gput_right:Nx \g__nicematrix_code_after_tl + \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl { \__nicematrix_vdottedline:n { \int_use:N \c@jCol } } } } @@ -599,6 +703,8 @@ } \NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } } { + \tl_set:Nn \l__nicematrix_left_delim_tl { #1 } + \tl_set:Nn \l__nicematrix_right_delim_tl { #2 } \bool_gset_false:N \g__nicematrix_row_of_col_done_bool \str_if_empty:NT \g__nicematrix_name_env_str { \str_gset:Nn \g__nicematrix_name_env_str { NiceArrayWithDelims } } @@ -658,56 +764,44 @@ \dim_gset:Nn \l__nicematrix_right_delim_dim { 2 \arraycolsep } } { - \hbox_set:Nn \l_tmpa_box - { - \c_math_toggle_token - \left #1 \vcenter to 3 cm { } \right. - \c_math_toggle_token - } - \dim_set:Nn \l__nicematrix_left_delim_dim - { \box_wd:N \l_tmpa_box - \nulldelimiterspace } - \hbox_set:Nn \l_tmpa_box - { - \c_math_toggle_token - \left. \vcenter to 3 cm { } \right #2 - \c_math_toggle_token - } - \dim_set:Nn \l__nicematrix_right_delim_dim - { \box_wd:N \l_tmpa_box - \nulldelimiterspace } + \hbox_set:Nn \l_tmpa_box { $ \bBigg@ 5 #1 $ } + \dim_set:Nn \l__nicematrix_left_delim_dim { \box_wd:N \l_tmpa_box } + \hbox_set:Nn \l_tmpa_box { $\bBigg@ 5 #2 $ } + \dim_set:Nn \l__nicematrix_right_delim_dim { \box_wd:N \l_tmpa_box } } \box_clear_new:N \l__nicematrix_the_array_box \tl_set:Nn \l_tmpa_tl { #4 } \int_compare:nNnTF \l__nicematrix_first_col_int = 0 { \tl_put_left:NV \l_tmpa_tl \c__nicematrix_preamble_first_col_tl } { - \bool_if:nT + \bool_lazy_all:nT { - \l__nicematrix_NiceArray_bool - && ! \l__nicematrix_vlines_bool - && ! \l__nicematrix_exterior_arraycolsep_bool + \l__nicematrix_NiceArray_bool + { \bool_not_p:n \l__nicematrix_vlines_bool } + { \bool_not_p:n \l__nicematrix_exterior_arraycolsep_bool } } { \tl_put_left:Nn \l_tmpa_tl { @ { } } } } \int_compare:nNnTF \l__nicematrix_last_col_int > { -1 } { \tl_put_right:NV \l_tmpa_tl \c__nicematrix_preamble_last_col_tl } { - \bool_if:nT + \bool_lazy_all:nT { - \l__nicematrix_NiceArray_bool - && ! \l__nicematrix_vlines_bool - && ! \l__nicematrix_exterior_arraycolsep_bool + \l__nicematrix_NiceArray_bool + { \bool_not_p:n \l__nicematrix_vlines_bool } + { \bool_not_p:n \l__nicematrix_exterior_arraycolsep_bool } } { \tl_put_right:Nn \l_tmpa_tl { @ { } } } } \tl_put_right:Nn \l_tmpa_tl { > { \__nicematrix_error_too_much_cols: } l } \hbox_set:Nw \l__nicematrix_the_array_box - \bool_if:NT \l__nicematrix_vlines_bool + \bool_if:NT \l__nicematrix_vlines_bool { \dim_add:Nn \arraycolsep { 0.5 \arrayrulewidth } - \skip_horizontal:n { 0.5 \arrayrulewidth } + \skip_horizontal:N 0.5\arrayrulewidth } - \skip_horizontal:n \l__nicematrix_left_margin_dim - \skip_horizontal:n \l__nicematrix_extra_left_margin_dim + \skip_horizontal:N \l__nicematrix_left_margin_dim + \skip_horizontal:N \l__nicematrix_extra_left_margin_dim \c_math_toggle_token \bool_if:NTF \l__nicematrix_light_syntax_bool { \begin { __nicematrix-light-syntax } } @@ -718,9 +812,9 @@ { \end { __nicematrix-light-syntax } } { \end { __nicematrix-normal-syntax } } \c_math_toggle_token - \skip_horizontal:n \l__nicematrix_right_margin_dim - \skip_horizontal:n \l__nicematrix_extra_right_margin_dim - \bool_if:NT \l__nicematrix_vlines_bool { \skip_horizontal:n { 0.5 \arrayrulewidth } } + \skip_horizontal:N \l__nicematrix_right_margin_dim + \skip_horizontal:N \l__nicematrix_extra_right_margin_dim + \bool_if:NT \l__nicematrix_vlines_bool { \skip_horizontal:N 0.5\arrayrulewidth } \hbox_set_end: \int_compare:nNnT \l__nicematrix_last_row_int > { -2 } { @@ -739,23 +833,19 @@ \int_compare:nNnT \l__nicematrix_last_row_int > { -1 } { \int_gdecr:N \c@iRow } \int_compare:nNnT \l__nicematrix_first_col_int = 0 { - \skip_horizontal:n \arraycolsep - \skip_horizontal:n \g__nicematrix_width_first_col_dim + \skip_horizontal:N \arraycolsep + \skip_horizontal:N \g__nicematrix_width_first_col_dim } \bool_if:NTF \l__nicematrix_NiceArray_bool { \str_if_eq:VnTF \l__nicematrix_baseline_str { b } { - \begin { tikzpicture } - \__nicematrix_extract_coords:w ( nm - \int_use:N \g__nicematrix_env_int - row - 1 ) + \pgfpicture + \__nicematrix_qpoint: { row - 1 } \dim_gset_eq:NN \g_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w - ( - nm - \int_use:N \g__nicematrix_env_int - - row - \int_use:N \c@iRow - base - ) + \__nicematrix_qpoint: { row - \int_use:N \c@iRow - base } \dim_gsub:Nn \g_tmpa_dim \pgf@y - \end { tikzpicture } + \endpgfpicture \int_compare:nNnT \l__nicematrix_first_row_int = 0 { \dim_gadd:Nn \g_tmpa_dim @@ -772,24 +862,19 @@ \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str \bool_if:nT { - \int_compare_p:nNn \l_tmpa_int < 0 + \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int || \int_compare_p:nNn \l_tmpa_int > \g__nicematrix_row_total_int } { \__nicematrix_error:n { bad~value~for~baseline } \int_set:Nn \l_tmpa_int 1 } - \begin { tikzpicture } - \__nicematrix_extract_coords:w - ( nm - \int_use:N \g__nicematrix_env_int - row - 1 ) + \pgfpicture + \__nicematrix_qpoint: { row - 1 } \dim_gset_eq:NN \g_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w - ( - nm - \int_use:N \g__nicematrix_env_int - - row - \int_use:N \l_tmpa_int- base - ) + \__nicematrix_qpoint: { row - \int_use:N \l_tmpa_int - base } \dim_gsub:Nn \g_tmpa_dim \pgf@y - \end { tikzpicture } + \endpgfpicture \int_compare:nNnT \l__nicematrix_first_row_int = 0 { \dim_gadd:Nn \g_tmpa_dim @@ -803,14 +888,14 @@ { \int_compare:nNnTF \l__nicematrix_first_row_int = 0 { - \dim_set:Nn \l_tmpa_dim - { \g__nicematrix_dp_row_zero_dim + \g__nicematrix_ht_row_zero_dim } + \dim_set_eq:NN \l_tmpa_dim \g__nicematrix_dp_row_zero_dim + \dim_add:Nn \l_tmpa_dim \g__nicematrix_ht_row_zero_dim } { \dim_zero:N \l_tmpa_dim } \int_compare:nNnTF \l__nicematrix_last_row_int > { -2 } { - \dim_set:Nn \l_tmpb_dim - { \g__nicematrix_ht_last_row_dim + \g__nicematrix_dp_last_row_dim } + \dim_set_eq:NN \l_tmpb_dim \g__nicematrix_ht_last_row_dim + \dim_add:Nn \l_tmpb_dim \g__nicematrix_dp_last_row_dim } { \dim_zero:N \l_tmpb_dim } \hbox_set:Nn \l_tmpa_box @@ -819,14 +904,14 @@ \left #1 \vcenter { - \skip_vertical:n { - \l_tmpa_dim } - \hbox:n + \skip_vertical:N -\l_tmpa_dim + \hbox { - \skip_horizontal:n { - \arraycolsep } + \skip_horizontal:N -\arraycolsep \box_use_drop:N \l__nicematrix_the_array_box - \skip_horizontal:n { - \arraycolsep } + \skip_horizontal:N -\arraycolsep } - \skip_vertical:n { - \l_tmpb_dim } + \skip_vertical:N -\l_tmpb_dim } \right #2 \c_math_toggle_token @@ -836,7 +921,10 @@ \__nicematrix_put_box_in_flow: } \bool_if:NT \g__nicematrix_last_col_found_bool - { \skip_horizontal:n { \g__nicematrix_width_last_col_dim + \arraycolsep } } + { + \skip_horizontal:N \g__nicematrix_width_last_col_dim + \skip_horizontal:N \arraycolsep + } \__nicematrix_after_array: } \cs_new_protected:Npn \__nicematrix_put_box_in_flow: @@ -876,9 +964,11 @@ } \dim_set:Nn \l__nicematrix_real_right_delim_dim { \box_wd:N \l_tmpb_box - \nulldelimiterspace } - \skip_horizontal:n { \l__nicematrix_left_delim_dim - \l__nicematrix_real_left_delim_dim } + \skip_horizontal:N \l__nicematrix_left_delim_dim + \skip_horizontal:N -\l__nicematrix_real_left_delim_dim \__nicematrix_put_box_in_flow: - \skip_horizontal:n { \l__nicematrix_right_delim_dim - \l__nicematrix_real_right_delim_dim } + \skip_horizontal:N \l__nicematrix_right_delim_dim + \skip_horizontal:N -\l__nicematrix_real_right_delim_dim } \NewDocumentEnvironment { __nicematrix-normal-syntax } { } { @@ -892,11 +982,13 @@ } \NewDocumentEnvironment { __nicematrix-light-syntax } { b } { - \tl_if_empty:nT { #1 } { \__nicematrix_fatal:n { empty~environment } } - \exp_args:NV \__nicematrix_array: \l_tmpa_tl + \tl_if_empty:nT { #1 } { \__nicematrix_fatal:n { empty~environment } } \seq_gclear_new:N \g__nicematrix_rows_seq \tl_set_rescan:Nno \l__nicematrix_end_of_row_tl { } \l__nicematrix_end_of_row_tl \exp_args:NNV \seq_gset_split:Nnn \g__nicematrix_rows_seq \l__nicematrix_end_of_row_tl { #1 } + \int_compare:nNnT \l__nicematrix_last_row_int = { -1 } + { \int_set:Nn \l__nicematrix_last_row_int { \seq_count:N \g__nicematrix_rows_seq } } + \exp_args:NV \__nicematrix_array: \l_tmpa_tl \seq_gpop_left:NN \g__nicematrix_rows_seq \l_tmpa_tl \exp_args:NV \__nicematrix_line_with_light_syntax_i:n \l_tmpa_tl \seq_map_function:NN \g__nicematrix_rows_seq \__nicematrix_line_with_light_syntax:n @@ -931,34 +1023,32 @@ \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & } \omit \bool_gset_true:N \g__nicematrix_row_of_col_done_bool - \tikz [ remember~picture ] - \coordinate ( nm - \int_use:N \g__nicematrix_env_int - col - 1 ) ; - \bool_if:nTF - { - \l__nicematrix_auto_columns_width_bool - || \dim_compare_p:nNn \l__nicematrix_columns_width_dim > \c_zero_dim - } - { - \bool_if:nTF - { - \l__nicematrix_auto_columns_width_bool - && ! \l__nicematrix_block_auto_columns_width_bool - } - { - \skip_gset:Nn \g_tmpa_skip - { \g__nicematrix_max_cell_width_dim + 2 \arraycolsep } - } - { - \skip_gset:Nn \g_tmpa_skip - { \l__nicematrix_columns_width_dim + 2 \arraycolsep } - } + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate { \__nicematrix_env: - col - 1 } \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { \pgfnodealias { \__nicematrix_env: - col - 1 } { \l__nicematrix_name_str - col - 1 } } + \endpgfpicture + \skip_gset:Nn \g_tmpa_skip { 0 pt~plus 1 fill } + \bool_if:NF \l__nicematrix_auto_columns_width_bool + { \dim_compare:nNnT \l__nicematrix_columns_width_dim > \c_zero_dim } + { + \bool_lazy_and:nnTF + \l__nicematrix_auto_columns_width_bool + { \bool_not_p:n \l__nicematrix_block_auto_columns_width_bool } + { \skip_gset_eq:NN \g_tmpa_skip \g__nicematrix_max_cell_width_dim } + { \skip_gset_eq:NN \g_tmpa_skip \l__nicematrix_columns_width_dim } + \skip_gadd:Nn \g_tmpa_skip { 2 \arraycolsep } } - { \skip_gset:Nn \g_tmpa_skip { 0 pt~plus 1 fill } } \skip_horizontal:N \g_tmpa_skip - \hbox:n + \hbox { - \tikz [ remember~picture ] - \coordinate ( nm - \int_use:N \g__nicematrix_env_int - col - 2 ) ; + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate { \__nicematrix_env: - col - 2 } \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { \pgfnodealias { \__nicematrix_env: - col - 2 } { \l__nicematrix_name_str - col - 2 } } + \endpgfpicture } \int_gset:Nn \g_tmpa_int 1 \bool_if:NTF \g__nicematrix_last_col_found_bool @@ -969,12 +1059,17 @@ \omit \int_gincr:N \g_tmpa_int \skip_horizontal:N \g_tmpa_skip - \tikz [ remember~picture ] - \coordinate - ( - nm - \int_use:N \g__nicematrix_env_int - - col - \int_eval:n { \g_tmpa_int + 1 } - ) ; + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate { \__nicematrix_env: - col - \__nicematrix_succ:N \g_tmpa_int } + \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \__nicematrix_env: - col - \__nicematrix_succ:N \g_tmpa_int } + { \l__nicematrix_name_str - col - \__nicematrix_succ:N \g_tmpa_int } + } + \endpgfpicture } \cr } @@ -986,17 +1081,17 @@ \hbox_set:Nw \l__nicematrix_cell_box \c_math_toggle_token \bool_if:NT \l__nicematrix_small_bool \scriptstyle - \bool_if:nT + \bool_lazy_and:nnT + { \int_compare_p:nNn \c@iRow > 0 } { - \int_compare_p:nNn \c@iRow > 0 - && - ( - \int_compare_p:nNn \l__nicematrix_last_row_int < 0 - || - \int_compare_p:nNn \c@iRow < \l__nicematrix_last_row_int - ) + \bool_lazy_or_p:nn + { \int_compare_p:nNn \l__nicematrix_last_row_int < 0 } + { \int_compare_p:nNn \c@iRow < \l__nicematrix_last_row_int } + } + { + \l__nicematrix_code_for_first_col_tl + \xglobal \colorlet { nicematrix-first-col } { . } } - { \l__nicematrix_code_for_first_col_tl } } l < @@ -1005,45 +1100,17 @@ \hbox_set_end: \__nicematrix_update_for_first_and_last_row: \dim_gset:Nn \g__nicematrix_width_first_col_dim - { - \dim_max:nn - \g__nicematrix_width_first_col_dim - { \box_wd:N \l__nicematrix_cell_box } - } + { \dim_max:nn \g__nicematrix_width_first_col_dim { \box_wd:N \l__nicematrix_cell_box } } \hbox_overlap_left:n { - \tikz - [ - remember~picture , - inner~sep = \c_zero_dim , - minimum~width = \c_zero_dim , - baseline - ] - \node - [ - anchor = base , - name = - nm - - \int_use:N \g__nicematrix_env_int - - \int_use:N \c@iRow - - 0 , - alias = - \str_if_empty:NF \l__nicematrix_name_str - { - \l__nicematrix_name_str - - \int_use:N \c@iRow - - 0 - } - ] - { \box_use_drop:N \l__nicematrix_cell_box } ; - \skip_horizontal:n - { - \l__nicematrix_left_delim_dim + - \l__nicematrix_left_margin_dim + - \l__nicematrix_extra_left_margin_dim - } + \dim_compare:nNnTF { \box_wd:N \l__nicematrix_cell_box } > \c_zero_dim + \__nicematrix_node_for_the_cell: + { \box_use_drop:N \l__nicematrix_cell_box } + \skip_horizontal:N \l__nicematrix_left_delim_dim + \skip_horizontal:N \l__nicematrix_left_margin_dim + \skip_horizontal:N \l__nicematrix_extra_left_margin_dim } - \skip_horizontal:n { - 2 \arraycolsep } + \skip_horizontal:N -2\arraycolsep } } \tl_const:Nn \c__nicematrix_preamble_last_col_tl @@ -1057,17 +1124,16 @@ \hbox_set:Nw \l__nicematrix_cell_box \c_math_toggle_token \bool_if:NT \l__nicematrix_small_bool \scriptstyle - \bool_if:nT + \int_compare:nNnT \c@iRow > 0 { - \int_compare_p:nNn \c@iRow > 0 - && - ( - \int_compare_p:nNn \l__nicematrix_last_row_int < 0 - || - \int_compare_p:nNn \c@iRow < \l__nicematrix_last_row_int - ) + \bool_lazy_or:nnT + { \int_compare_p:nNn \l__nicematrix_last_row_int < 0 } + { \int_compare_p:nNn \c@iRow < \l__nicematrix_last_row_int } + { + \l__nicematrix_code_for_last_col_tl + \xglobal \colorlet { nicematrix-last-col } { . } + } } - { \l__nicematrix_code_for_last_col_tl } } l < @@ -1076,44 +1142,17 @@ \hbox_set_end: \__nicematrix_update_for_first_and_last_row: \dim_gset:Nn \g__nicematrix_width_last_col_dim - { - \dim_max:nn - \g__nicematrix_width_last_col_dim - { \box_wd:N \l__nicematrix_cell_box } - } - \skip_horizontal:n { - 2 \arraycolsep } + { \dim_max:nn \g__nicematrix_width_last_col_dim { \box_wd:N \l__nicematrix_cell_box } } + \skip_horizontal:N -2\arraycolsep \hbox_overlap_right:n { - \skip_horizontal:n + \dim_compare:nNnT { \box_wd:N \l__nicematrix_cell_box } > \c_zero_dim { - \l__nicematrix_right_delim_dim + - \l__nicematrix_right_margin_dim + - \l__nicematrix_extra_right_margin_dim + \skip_horizontal:N \l__nicematrix_right_delim_dim + \skip_horizontal:N \l__nicematrix_right_margin_dim + \skip_horizontal:N \l__nicematrix_extra_right_margin_dim + \__nicematrix_node_for_the_cell: } - \tikz - [ - remember~picture , - inner~sep = \c_zero_dim , - minimum~width = \c_zero_dim , - baseline - ] - \node - [ - anchor = base , - name = - nm - - \int_use:N \g__nicematrix_env_int - - \int_use:N \c@iRow - - \int_use:N \c@jCol , - alias = - \str_if_empty:NF \l__nicematrix_name_str - { - \l__nicematrix_name_str - - \int_use:N \c@iRow - - \int_use:N \c@jCol - } - ] - { \box_use_drop:N \l__nicematrix_cell_box } ; } } } @@ -1170,19 +1209,24 @@ \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } } { \str_gset:Nn \g__nicematrix_name_env_str { #1 NiceMatrix } + \tl_set:Nn \l__nicematrix_type_of_col_tl C \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 } - \begin { #1 NiceArray } + \exp_args:Nnx \__nicematrix_begin_of_NiceMatrix:nn { #1 } \l__nicematrix_type_of_col_tl + } + { \end { #1 NiceArray } } + } +\cs_new_protected:Npn \__nicematrix_begin_of_NiceMatrix:nn #1 #2 + { + \begin { #1 NiceArray } + { + * { - * - { - \int_compare:nNnTF \l__nicematrix_last_col_int = { -1 } - \c@MaxMatrixCols - { \int_eval:n { \l__nicematrix_last_col_int - 1 } } - } - C + \int_compare:nNnTF \l__nicematrix_last_col_int = { -1 } + \c@MaxMatrixCols + { \int_eval:n { \l__nicematrix_last_col_int - 1 } } } + #2 } - { \end { #1 NiceArray } } } \__nicematrix_define_env:n { } \__nicematrix_define_env:n p @@ -1190,63 +1234,17 @@ \__nicematrix_define_env:n B \__nicematrix_define_env:n v \__nicematrix_define_env:n V -\prg_set_conditional:Npnn \__nicematrix_if_not_empty_cell:nn #1 #2 { T , TF } - { - \bool_set_false:N \l_tmpa_bool - \cs_if_exist:cTF - { __nicematrix _ dotted _ \int_use:N #1 - \int_use:N #2 } - \prg_return_true: - { - \cs_if_free:cTF - { - pgf@sh@ns@nm - - \int_use:N \g__nicematrix_env_int - - \int_use:N #1 - - \int_use:N #2 - } - { \prg_return_false: } - { - \bool_set_false:N \l_tmpa_bool - \cs_if_exist:cT - { __nicematrix _ empty _ \int_use:N #1 - \int_use:N #2 } - { - \int_compare:nNnT - { \use:c { __nicematrix _ empty _ \int_use:N #1 - \int_use:N #2 } } - = - \g__nicematrix_env_int - { \bool_set_true:N \l_tmpa_bool } - } - \bool_if:NTF \l_tmpa_bool - \prg_return_false: - { - \begin { pgfpicture } - \tl_set:Nx \l_tmpa_tl - { - nm - - \int_use:N \g__nicematrix_env_int - - \int_use:N #1 - - \int_use:N #2 - } - \pgfpointanchor \l_tmpa_tl { east } - \dim_gset:Nn \g_tmpa_dim \pgf@x - \pgfpointanchor \l_tmpa_tl { west } - \dim_gset:Nn \g_tmpb_dim \pgf@x - \end { pgfpicture } - \dim_compare:nNnTF - { \dim_abs:n { \g_tmpb_dim - \g_tmpa_dim } } < { 0.5 pt } - \prg_return_false: - \prg_return_true: - } - } - } - } \cs_new_protected:Npn \__nicematrix_after_array: { \group_begin: - \cs_if_exist:NT \tikz@library@external@loaded - { \tikzset { external / export = false } } + \int_compare:nNnT \l__nicematrix_last_col_int = 0 + { + \bool_if:NT \g__nicematrix_last_col_found_bool + { \dim_set_eq:NN \l__nicematrix_last_col_int \g__nicematrix_col_total_int } + } \bool_if:NT \l__nicematrix_last_row_without_value_bool { + \dim_set_eq:NN \l__nicematrix_last_row_int \g__nicematrix_row_total_int \iow_now:Nn \@mainaux \ExplSyntaxOn \iow_now:Nx \@mainaux { @@ -1265,20 +1263,20 @@ } \bool_if:NT \l__nicematrix_parallelize_diags_bool { - \int_zero_new:N \l__nicematrix_ddots_int - \int_zero_new:N \l__nicematrix_iddots_int - \dim_zero_new:N \l__nicematrix_delta_x_one_dim - \dim_zero_new:N \l__nicematrix_delta_y_one_dim - \dim_zero_new:N \l__nicematrix_delta_x_two_dim - \dim_zero_new:N \l__nicematrix_delta_y_two_dim + \int_gzero_new:N \g__nicematrix_ddots_int + \int_gzero_new:N \g__nicematrix_iddots_int + \dim_gzero_new:N \g__nicematrix_delta_x_one_dim + \dim_gzero_new:N \g__nicematrix_delta_y_one_dim + \dim_gzero_new:N \g__nicematrix_delta_x_two_dim + \dim_gzero_new:N \g__nicematrix_delta_y_two_dim } - \bool_if:nTF \g__nicematrix_medium_nodes_bool + \bool_if:nTF \l__nicematrix_medium_nodes_bool { - \bool_if:NTF \g__nicematrix_large_nodes_bool + \bool_if:NTF \l__nicematrix_large_nodes_bool \__nicematrix_create_medium_and_large_nodes: \__nicematrix_create_medium_nodes: } - { \bool_if:NT \g__nicematrix_large_nodes_bool \__nicematrix_create_large_nodes: } + { \bool_if:NT \l__nicematrix_large_nodes_bool \__nicematrix_create_large_nodes: } \int_zero_new:N \l__nicematrix_initial_i_int \int_zero_new:N \l__nicematrix_initial_j_int \int_zero_new:N \l__nicematrix_final_i_int @@ -1289,59 +1287,50 @@ { \dim_set:Nn \l__nicematrix_radius_dim { 0.37 pt } \dim_set:Nn \l__nicematrix_inter_dots_dim { 0.25 em } + \dim_set:Nn \l__nicematrix_xdots_shorten_dim { 0.6 \l__nicematrix_xdots_shorten_dim } } - \g__nicematrix_Hdotsfor_lines_tl - \g__nicematrix_Vdots_lines_tl - \g__nicematrix_Ddots_lines_tl - \g__nicematrix_Iddots_lines_tl - \g__nicematrix_Cdots_lines_tl - \g__nicematrix_Ldots_lines_tl - \tikzset + \__nicematrix_draw_dotted_lines: + \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines: + \g__nicematrix_internal_code_after_tl + \tl_gclear:N \g__nicematrix_internal_code_after_tl + \bool_if:NT \c__nicematrix_tikz_loaded_bool { - every~picture / .style = + \tikzset { - overlay , - remember~picture , - name~prefix = nm - \int_use:N \g__nicematrix_env_int - + every~picture / .style = + { + overlay , + remember~picture , + name~prefix = \__nicematrix_env: - + } } } - \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines: - \cs_set_eq:NN \line \__nicematrix_line:nn + \cs_set_eq:NN \line \__nicematrix_line \g__nicematrix_code_after_tl \tl_gclear:N \g__nicematrix_code_after_tl \group_end: \str_gclear:N \g__nicematrix_name_env_str \__nicematrix_restore_iRow_jCol: } -\cs_new_protected:Npn \__nicematrix_draw_vlines: +\AtBeginDocument { - \group_begin: - \bool_if:NT \c__nicematrix_colortbl_loaded_bool \CT@arc@ - \begin { tikzpicture } [ line~width = \arrayrulewidth ] - \__nicematrix_extract_coords:w ( row - 1 ) - \dim_set_eq:NN \l_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w ( row - \int_eval:n { \c@iRow + 1 } ) - \dim_set:Nn \l_tmpa_dim { \l_tmpa_dim - \pgf@y } - \dim_zero:N \l_tmpb_dim - \int_compare:nNnT \l__nicematrix_last_row_int > { -1 } - { - \dim_set:Nn \l_tmpb_dim - { \g__nicematrix_dp_last_row_dim + \g__nicematrix_ht_last_row_dim } - \__nicematrix_extract_coords:w ( row - \int_eval:n { \c@iRow + 1 } ) - \dim_add:Nn \l_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w ( row - \int_eval:n { \g__nicematrix_row_total_int + 1 } ) - \dim_sub:Nn \l_tmpa_dim \pgf@y - \dim_sub:Nn \l_tmpa_dim \l_tmpb_dim - } - \int_step_inline:nnn - { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 } - { \bool_if:NTF \l__nicematrix_NiceArray_bool { \c@jCol + 1 } \c@jCol } + \cs_new_protected:Npx \__nicematrix_draw_dotted_lines: { - \draw ( col - ##1 ) ++ ( 0 , \dim_use:N \l_tmpb_dim ) - -- ++ ( 0 , \dim_use:N \l_tmpa_dim ) ; + \c__nicematrix_pgfortikzpicture_tl + \__nicematrix_draw_dotted_lines_i: + \c__nicematrix_endpgfortikzpicture_tl } - \end { tikzpicture } - \group_end: + } +\cs_new_protected:Npn \__nicematrix_draw_dotted_lines_i: + { + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \g__nicematrix_Hdotsfor_lines_tl + \g__nicematrix_Vdots_lines_tl + \g__nicematrix_Ddots_lines_tl + \g__nicematrix_Iddots_lines_tl + \g__nicematrix_Cdots_lines_tl + \g__nicematrix_Ldots_lines_tl } \cs_new_protected:Npn \__nicematrix_restore_iRow_jCol: { @@ -1387,34 +1376,38 @@ \bool_set_true:N \l__nicematrix_stop_loop_bool } { - \__nicematrix_if_not_empty_cell:nnTF \l__nicematrix_final_i_int \l__nicematrix_final_j_int - { \bool_set_true:N \l__nicematrix_stop_loop_bool } + \cs_if_exist:cTF + { + __nicematrix _ dotted _ + \int_use:N \l__nicematrix_final_i_int - + \int_use:N \l__nicematrix_final_j_int + } { - \cs_set:cpn + \int_sub:Nn \l__nicematrix_final_i_int { #3 } + \int_sub:Nn \l__nicematrix_final_j_int { #4 } + \bool_set_true:N \l__nicematrix_final_open_bool + \bool_set_true:N \l__nicematrix_stop_loop_bool + } + { + \cs_if_exist:cTF { - __nicematrix _ dotted _ - \int_use:N \l__nicematrix_final_i_int - - \int_use:N \l__nicematrix_final_j_int + pgf @ sh @ ns @ \__nicematrix_env: + - \int_use:N \l__nicematrix_final_i_int + - \int_use:N \l__nicematrix_final_j_int + } + { \bool_set_true:N \l__nicematrix_stop_loop_bool } + { + \cs_set:cpn + { + __nicematrix _ dotted _ + \int_use:N \l__nicematrix_final_i_int - + \int_use:N \l__nicematrix_final_j_int + } + { } } - { } } } } - \cs_if_free:cT - { - pgf@sh@ns@nm - - \int_use:N \g__nicematrix_env_int - - \int_use:N \l__nicematrix_final_i_int - - \int_use:N \l__nicematrix_final_j_int - } - { - \bool_if:NF \l__nicematrix_final_open_bool - { - \msg_error:nnx { nicematrix } { Impossible~line } - { \int_use:N \l__nicematrix_final_i_int } - \bool_set_true:N \l__nicematrix_impossible_line_bool - } - } \bool_set_false:N \l__nicematrix_stop_loop_bool \bool_do_until:Nn \l__nicematrix_stop_loop_bool { @@ -1447,415 +1440,500 @@ \bool_set_true:N \l__nicematrix_stop_loop_bool } { - \__nicematrix_if_not_empty_cell:nnTF - \l__nicematrix_initial_i_int \l__nicematrix_initial_j_int - { \bool_set_true:N \l__nicematrix_stop_loop_bool } + \cs_if_exist:cTF + { + __nicematrix _ dotted _ + \int_use:N \l__nicematrix_initial_i_int - + \int_use:N \l__nicematrix_initial_j_int + } + { + \int_add:Nn \l__nicematrix_initial_i_int { #3 } + \int_add:Nn \l__nicematrix_initial_j_int { #4 } + \bool_set_true:N \l__nicematrix_initial_open_bool + \bool_set_true:N \l__nicematrix_stop_loop_bool + } { - \cs_set:cpn + \cs_if_exist:cTF + { + pgf @ sh @ ns @ \__nicematrix_env: + - \int_use:N \l__nicematrix_initial_i_int + - \int_use:N \l__nicematrix_initial_j_int + } + { \bool_set_true:N \l__nicematrix_stop_loop_bool } { - __nicematrix _ dotted _ - \int_use:N \l__nicematrix_initial_i_int - - \int_use:N \l__nicematrix_initial_j_int + \cs_set:cpn + { + __nicematrix _ dotted _ + \int_use:N \l__nicematrix_initial_i_int - + \int_use:N \l__nicematrix_initial_j_int + } + { } } - { } } } } - \cs_if_free:cT - { - pgf@sh@ns@nm - - \int_use:N \g__nicematrix_env_int - - \int_use:N \l__nicematrix_initial_i_int - - \int_use:N \l__nicematrix_initial_j_int - } - { - \bool_if:NF \l__nicematrix_initial_open_bool - { - \msg_error:nnx { nicematrix } { Impossible~line } - { \int_use:N \l__nicematrix_initial_i_int } - \bool_set_true:N \l__nicematrix_impossible_line_bool - } - } - \bool_if:NT \l__nicematrix_initial_open_bool \__nicematrix_create_medium_nodes: - \bool_if:NT \l__nicematrix_final_open_bool \__nicematrix_create_medium_nodes: } -\cs_new_protected:Npn \__nicematrix_retrieve_coords:nn #1 #2 +\cs_new:Nn \__nicematrix_initial_cell: + { \__nicematrix_env: - \int_use:N \l__nicematrix_initial_i_int - \int_use:N \l__nicematrix_initial_j_int } +\cs_new:Nn \__nicematrix_final_cell: + { \__nicematrix_env: - \int_use:N \l__nicematrix_final_i_int - \int_use:N \l__nicematrix_final_j_int } +\cs_new_protected:Npn \__nicematrix_set_initial_coords: { - \dim_gzero_new:N \g__nicematrix_x_initial_dim - \dim_gzero_new:N \g__nicematrix_y_initial_dim - \dim_gzero_new:N \g__nicematrix_x_final_dim - \dim_gzero_new:N \g__nicematrix_y_final_dim - \begin { tikzpicture } [ remember~picture ] - \__nicematrix_extract_coords:w - ( nm - \int_use:N \g__nicematrix_env_int - - \int_use:N \l__nicematrix_initial_i_int - - \int_use:N \l__nicematrix_initial_j_int #1 ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_initial_dim \pgf@y - \__nicematrix_extract_coords:w - ( nm - \int_use:N \g__nicematrix_env_int - - \int_use:N \l__nicematrix_final_i_int - - \int_use:N \l__nicematrix_final_j_int #2 ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_final_dim \pgf@y - \end { tikzpicture } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y } -\cs_generate_variant:Nn \__nicematrix_retrieve_coords:nn { x x } -\cs_new_protected:Npn \__nicematrix_adjust_with_col_nodes: +\cs_new_protected:Npn \__nicematrix_set_final_coords: { - \bool_if:NT \l__nicematrix_initial_open_bool - { - \begin { tikzpicture } [ remember~picture ] - \__nicematrix_extract_coords:w ( nm - \int_use:N \g__nicematrix_env_int - col - 1 ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \end { tikzpicture } - } - \bool_if:NT \l__nicematrix_final_open_bool - { - \begin { tikzpicture } [ remember~picture ] - \__nicematrix_extract_coords:w - ( nm - \int_use:N \g__nicematrix_env_int - col - \int_eval:n { \c@jCol + 1 } ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \end { tikzpicture } - } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y } -\cs_new_protected:Npn \__nicematrix_draw_Ldots:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_set_initial_coords_from_anchor:n #1 + { + \pgfpointanchor \__nicematrix_initial_cell: { #1 } + \__nicematrix_set_initial_coords: + } +\cs_new_protected:Npn \__nicematrix_set_final_coords_from_anchor:n #1 + { + \pgfpointanchor \__nicematrix_final_cell: { #1 } + \__nicematrix_set_final_coords: + } +\cs_new_protected:Npn \__nicematrix_draw_Ldots:nnn #1 #2 #3 { \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { - \bool_set_false:N \l__nicematrix_impossible_line_bool \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1 - \bool_if:NF \l__nicematrix_impossible_line_bool \__nicematrix_actually_draw_Ldots: + \group_begin: + \int_compare:nNnTF { #1 } = 0 + { \color { nicematrix-first-row } } + { + \int_compare:nNnT { #1 } = \l__nicematrix_last_row_int + { \color { nicematrix-last-row } } + } + \keys_set:nn { NiceMatrix / xdots } { #3 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \__nicematrix_actually_draw_Ldots: + \group_end: } } \cs_new_protected:Npn \__nicematrix_actually_draw_Ldots: { - \__nicematrix_retrieve_coords:xx + \bool_if:NTF \l__nicematrix_initial_open_bool { - \bool_if:NTF \l__nicematrix_initial_open_bool - { - medium.base~west } - { .base~east } + \__nicematrix_qpoint: { col - \int_use:N \l__nicematrix_initial_j_int } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \dim_add:Nn \l__nicematrix_x_initial_dim \arraycolsep + \__nicematrix_qpoint: { row - \int_use:N \l__nicematrix_initial_i_int - base } + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y } + { \__nicematrix_set_initial_coords_from_anchor:n { base~east } } + \bool_if:NTF \l__nicematrix_final_open_bool { - \bool_if:NTF \l__nicematrix_final_open_bool - { - medium.base~east } - { .base~west } + \__nicematrix_qpoint: { col - \__nicematrix_succ:N \l__nicematrix_final_j_int } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + \dim_sub:Nn \l__nicematrix_x_final_dim \arraycolsep + \__nicematrix_qpoint: { row - \int_use:N \l__nicematrix_final_i_int - base } + \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y } - \__nicematrix_adjust_with_col_nodes: - \bool_if:NT \l__nicematrix_initial_open_bool - { \dim_gset_eq:NN \g__nicematrix_y_initial_dim \g__nicematrix_y_final_dim } - \bool_if:NT \l__nicematrix_final_open_bool - { \dim_gset_eq:NN \g__nicematrix_y_final_dim \g__nicematrix_y_initial_dim } - \dim_gadd:Nn \g__nicematrix_y_initial_dim { 0.53 pt } - \dim_gadd:Nn \g__nicematrix_y_final_dim { 0.53 pt } - \__nicematrix_draw_tikz_line: + { \__nicematrix_set_final_coords_from_anchor:n { base~west } } + \dim_add:Nn \l__nicematrix_y_initial_dim \l__nicematrix_radius_dim + \dim_add:Nn \l__nicematrix_y_final_dim \l__nicematrix_radius_dim + \__nicematrix_draw_line: } -\cs_new_protected:Npn \__nicematrix_draw_Cdots:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_draw_Cdots:nnn #1 #2 #3 { \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { - \bool_set_false:N \l__nicematrix_impossible_line_bool \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1 - \bool_if:NF \l__nicematrix_impossible_line_bool - { - \__nicematrix_retrieve_coords:xx - { - \bool_if:NTF \l__nicematrix_initial_open_bool - { - medium.mid~west } - { .mid~east } - } - { - \bool_if:NTF \l__nicematrix_final_open_bool - { - medium.mid~east } - { .mid~west } - } - \__nicematrix_adjust_with_col_nodes: - \bool_if:NT \l__nicematrix_initial_open_bool - { \dim_gset_eq:NN \g__nicematrix_y_initial_dim \g__nicematrix_y_final_dim } - \bool_if:NT \l__nicematrix_final_open_bool - { \dim_gset_eq:NN \g__nicematrix_y_final_dim \g__nicematrix_y_initial_dim } - \__nicematrix_draw_tikz_line: - } + \group_begin: + \int_compare:nNnTF { #1 } = 0 + { \color { nicematrix-first-row } } + { + \int_compare:nNnT { #1 } = \l__nicematrix_last_row_int + { \color { nicematrix-last-row } } + } + \keys_set:nn { NiceMatrix / xdots } { #3 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \__nicematrix_actually_draw_Cdots: + \group_end: } } -\cs_new_protected:Npn \__nicematrix_draw_Vdots:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_actually_draw_Cdots: { + \bool_if:NTF \l__nicematrix_initial_open_bool + { + \__nicematrix_qpoint: { col - \int_use:N \l__nicematrix_initial_j_int } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \dim_add:Nn \l__nicematrix_x_initial_dim \arraycolsep + } + { \__nicematrix_set_initial_coords_from_anchor:n { mid~east } } + \bool_if:NTF \l__nicematrix_final_open_bool + { + \__nicematrix_qpoint: { col - \__nicematrix_succ:N \l__nicematrix_final_j_int } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + \dim_sub:Nn \l__nicematrix_x_final_dim \arraycolsep + } + { \__nicematrix_set_final_coords_from_anchor:n { mid~west } } + \bool_lazy_and:nnTF + \l__nicematrix_initial_open_bool + \l__nicematrix_final_open_bool + { + \__nicematrix_qpoint: { row - \int_use:N \l__nicematrix_initial_i_int } + \dim_set_eq:NN \l_tmpa_dim \pgf@y + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \l__nicematrix_initial_i_int } + \dim_set:Nn \l__nicematrix_y_initial_dim { ( \l_tmpa_dim + \pgf@y ) / 2 } + \dim_set_eq:NN \l__nicematrix_y_final_dim \l__nicematrix_y_initial_dim + } + { + \bool_if:NT \l__nicematrix_initial_open_bool + { \dim_set_eq:NN \l__nicematrix_y_initial_dim \l__nicematrix_y_final_dim } + \bool_if:NT \l__nicematrix_final_open_bool + { \dim_set_eq:NN \l__nicematrix_y_final_dim \l__nicematrix_y_initial_dim } + } + \__nicematrix_draw_line: + } +\cs_new_protected:Npn \__nicematrix_draw_Vdots:nnn #1 #2 #3 + { + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { - \bool_set_false:N \l__nicematrix_impossible_line_bool \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 0 - \bool_if:NF \l__nicematrix_impossible_line_bool + \group_begin: + \int_compare:nNnTF { #2 } = 0 + { \color { nicematrix-first-col } } + { + \int_compare:nNnT { #2 } = \l__nicematrix_last_col_int + { \color { nicematrix-last-col } } + } + \keys_set:nn { NiceMatrix / xdots } { #3 } + \__nicematrix_actually_draw_Vdots: + \group_end: + } + } +\cs_new_protected:Npn \__nicematrix_actually_draw_Vdots: + { + \bool_set_false:N \l_tmpa_bool + \bool_lazy_or:nnF \l__nicematrix_initial_open_bool \l__nicematrix_final_open_bool + { + \__nicematrix_set_initial_coords_from_anchor:n { south~west } + \__nicematrix_set_final_coords_from_anchor:n { north~west } + \bool_set:Nn \l_tmpa_bool + { \dim_compare_p:nNn \l__nicematrix_x_initial_dim = \l__nicematrix_x_final_dim } + } + \bool_if:NTF \l__nicematrix_initial_open_bool + { + \__nicematrix_qpoint: { row - 1 } + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y + } + { \__nicematrix_set_initial_coords_from_anchor:n { south } } + \bool_if:NTF \l__nicematrix_final_open_bool + { + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \c@iRow } + \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y + } + { \__nicematrix_set_final_coords_from_anchor:n { north } } + \bool_if:NTF \l__nicematrix_initial_open_bool + { + \bool_if:NTF \l__nicematrix_final_open_bool { - \__nicematrix_retrieve_coords:xx - { - \bool_if:NTF \l__nicematrix_initial_open_bool - { - medium.north~west } - { .south~west } - } - { - \bool_if:NTF \l__nicematrix_final_open_bool - { - medium.south~west } - { .north~west } - } - \bool_set:Nn \l_tmpa_bool - { \dim_compare_p:nNn \g__nicematrix_x_initial_dim = \g__nicematrix_x_final_dim } - \__nicematrix_retrieve_coords:xx - { - \bool_if:NTF \l__nicematrix_initial_open_bool - { - medium.north } - { .south } - } - { - \bool_if:NTF \l__nicematrix_final_open_bool - { - medium.south } - { .north } - } - \bool_set:Nn \l_tmpb_bool - { \dim_compare_p:nNn \g__nicematrix_x_initial_dim = \g__nicematrix_x_final_dim } - \bool_if:NF \l_tmpb_bool + \__nicematrix_qpoint: { col - \int_use:N \l__nicematrix_initial_j_int } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \__nicematrix_qpoint: { col - \__nicematrix_succ:N \l__nicematrix_initial_j_int } + \dim_set:Nn \l__nicematrix_x_initial_dim { ( \pgf@x + \l_tmpa_dim ) / 2 } + \dim_set_eq:NN \l__nicematrix_x_final_dim \l__nicematrix_x_initial_dim + } + { \dim_set_eq:NN \l__nicematrix_x_initial_dim \l__nicematrix_x_final_dim } + } + { + \bool_if:NTF \l__nicematrix_final_open_bool + { \dim_set_eq:NN \l__nicematrix_x_final_dim \l__nicematrix_x_initial_dim } + { + \dim_compare:nNnF \l__nicematrix_x_initial_dim = \l__nicematrix_x_final_dim { - \dim_gset:Nn \g__nicematrix_x_initial_dim + \dim_set:Nn \l__nicematrix_x_initial_dim { \bool_if:NTF \l_tmpa_bool \dim_min:nn \dim_max:nn - \g__nicematrix_x_initial_dim \g__nicematrix_x_final_dim + \l__nicematrix_x_initial_dim \l__nicematrix_x_final_dim } - \dim_gset_eq:NN \g__nicematrix_x_final_dim \g__nicematrix_x_initial_dim + \dim_set_eq:NN \l__nicematrix_x_final_dim \l__nicematrix_x_initial_dim } - \__nicematrix_draw_tikz_line: } } + \__nicematrix_draw_line: } -\cs_new_protected:Npn \__nicematrix_draw_Ddots:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_draw_Ddots:nnn #1 #2 #3 { \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { - \bool_set_false:N \l__nicematrix_impossible_line_bool \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 1 - \bool_if:NF \l__nicematrix_impossible_line_bool + \group_begin: + \keys_set:nn { NiceMatrix / xdots } { #3 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \__nicematrix_actually_draw_Ddots: + \group_end: + } + } +\cs_new_protected:Npn \__nicematrix_actually_draw_Ddots: + { + \bool_if:NTF \l__nicematrix_initial_open_bool + { + \__nicematrix_qpoint: { row - \int_use:N \l__nicematrix_initial_i_int } + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y + \__nicematrix_qpoint: { col - \int_use:N \l__nicematrix_initial_j_int } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + } + { \__nicematrix_set_initial_coords_from_anchor:n { south~east } } + \bool_if:NTF \l__nicematrix_final_open_bool + { + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \l__nicematrix_final_i_int } + \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y + \__nicematrix_qpoint: { col - \__nicematrix_succ:N \l__nicematrix_final_j_int } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + } + { \__nicematrix_set_final_coords_from_anchor:n { north~west } } + \bool_if:NT \l__nicematrix_parallelize_diags_bool + { + \int_gincr:N \g__nicematrix_ddots_int + \int_compare:nNnTF \g__nicematrix_ddots_int = 1 { - \__nicematrix_retrieve_coords:xx - { - \bool_if:NTF \l__nicematrix_initial_open_bool - { - medium.north~west } - { .south~east } - } - { - \bool_if:NTF \l__nicematrix_final_open_bool - { - medium.south~east } - { .north~west } - } - \bool_if:NT \l__nicematrix_parallelize_diags_bool + \dim_gset:Nn \g__nicematrix_delta_x_one_dim + { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim } + \dim_gset:Nn \g__nicematrix_delta_y_one_dim + { \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim } + } + { + \dim_set:Nn \l__nicematrix_y_final_dim { - \int_incr:N \l__nicematrix_ddots_int - \int_compare:nNnTF \l__nicematrix_ddots_int = 1 - { - \dim_set:Nn \l__nicematrix_delta_x_one_dim - { \g__nicematrix_x_final_dim - \g__nicematrix_x_initial_dim } - \dim_set:Nn \l__nicematrix_delta_y_one_dim - { \g__nicematrix_y_final_dim - \g__nicematrix_y_initial_dim } - } - { - \dim_gset:Nn \g__nicematrix_y_final_dim - { - \g__nicematrix_y_initial_dim + - ( \g__nicematrix_x_final_dim - \g__nicematrix_x_initial_dim ) * - \dim_ratio:nn \l__nicematrix_delta_y_one_dim \l__nicematrix_delta_x_one_dim - } - } + \l__nicematrix_y_initial_dim + + ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) * + \dim_ratio:nn \g__nicematrix_delta_y_one_dim \g__nicematrix_delta_x_one_dim } - \__nicematrix_draw_tikz_line: } } + \__nicematrix_draw_line: } -\cs_new_protected:Npn \__nicematrix_draw_Iddots:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_draw_Iddots:nnn #1 #2 #3 { \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { - \bool_set_false:N \l__nicematrix_impossible_line_bool \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 { -1 } - \bool_if:NF \l__nicematrix_impossible_line_bool + \group_begin: + \keys_set:nn { NiceMatrix / xdots } { #3 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \__nicematrix_actually_draw_Iddots: + \group_end: + } + } +\cs_new_protected:Npn \__nicematrix_actually_draw_Iddots: + { + \bool_if:NTF \l__nicematrix_initial_open_bool + { + \__nicematrix_qpoint: { row - \int_use:N \l__nicematrix_initial_i_int } + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y + \__nicematrix_qpoint: { col - \__nicematrix_succ:N \l__nicematrix_initial_j_int } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + } + { \__nicematrix_set_initial_coords_from_anchor:n { south~west } } + \bool_if:NTF \l__nicematrix_final_open_bool + { + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \l__nicematrix_final_i_int } + \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y + \__nicematrix_qpoint: { col - \int_use:N \l__nicematrix_final_j_int } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + } + { \__nicematrix_set_final_coords_from_anchor:n { north~east } } + \bool_if:NT \l__nicematrix_parallelize_diags_bool + { + \int_gincr:N \g__nicematrix_iddots_int + \int_compare:nNnTF \g__nicematrix_iddots_int = 1 { - \__nicematrix_retrieve_coords:xx - { - \bool_if:NTF \l__nicematrix_initial_open_bool - { - medium.north~east } - { .south~west } - } - { - \bool_if:NTF \l__nicematrix_final_open_bool - { - medium.south~west } - { .north~east } - } - \bool_if:NT \l__nicematrix_parallelize_diags_bool + \dim_gset:Nn \g__nicematrix_delta_x_two_dim + { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim } + \dim_gset:Nn \g__nicematrix_delta_y_two_dim + { \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim } + } + { + \dim_set:Nn \l__nicematrix_y_final_dim { - \int_incr:N \l__nicematrix_iddots_int - \int_compare:nNnTF \l__nicematrix_iddots_int = 1 - { - \dim_set:Nn \l__nicematrix_delta_x_two_dim - { \g__nicematrix_x_final_dim - \g__nicematrix_x_initial_dim } - \dim_set:Nn \l__nicematrix_delta_y_two_dim - { \g__nicematrix_y_final_dim - \g__nicematrix_y_initial_dim } - } - { - \dim_gset:Nn \g__nicematrix_y_final_dim - { - \g__nicematrix_y_initial_dim + - ( \g__nicematrix_x_final_dim - \g__nicematrix_x_initial_dim ) * - \dim_ratio:nn \l__nicematrix_delta_y_two_dim \l__nicematrix_delta_x_two_dim - } - } + \l__nicematrix_y_initial_dim + + ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) * + \dim_ratio:nn \g__nicematrix_delta_y_two_dim \g__nicematrix_delta_x_two_dim } - \__nicematrix_draw_tikz_line: } } + \__nicematrix_draw_line: } \NewExpandableDocumentCommand \NiceMatrixLastEnv { } { \int_use:N \g__nicematrix_env_int } -\cs_new_protected:Npn \__nicematrix_draw_tikz_line: +\cs_new_protected:Npn \__nicematrix_draw_line: + { + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \tl_if_eq:NNTF \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl + \__nicematrix_draw_standard_dotted_line: + \__nicematrix_draw_non_standard_dotted_line: + } +\cs_new_protected:Npn \__nicematrix_draw_non_standard_dotted_line: + { + \begin { scope } + \exp_args:No \__nicematrix_draw_non_standard_dotted_line:n + { \l__nicematrix_xdots_line_style_tl , \l__nicematrix_xdots_color_tl } + } +\cs_new_protected:Npn \__nicematrix_draw_non_standard_dotted_line:n #1 + { + \draw + [ + #1 , + shorten~> = \l__nicematrix_xdots_shorten_dim , + shorten~< = \l__nicematrix_xdots_shorten_dim , + ] + ( \l__nicematrix_x_initial_dim , \l__nicematrix_y_initial_dim ) + -- ( \l__nicematrix_x_final_dim , \l__nicematrix_y_final_dim ) ; + \end { scope } + } +\cs_new_protected:Npn \__nicematrix_draw_standard_dotted_line: { - \dim_zero_new:N \l__nicematrix_l_dim - \dim_set:Nn \l__nicematrix_l_dim + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \group_begin: + \dim_zero_new:N \l__nicematrix_l_dim + \dim_set:Nn \l__nicematrix_l_dim + { + \fp_to_dim:n + { + sqrt + ( + ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) ^ 2 + + + ( \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ) ^ 2 + ) + } + } + \dim_compare:nNnF \l__nicematrix_l_dim = \c_zero_dim \__nicematrix_actually_draw_line: + \group_end: + } +\cs_new_protected:Npn \__nicematrix_actually_draw_line: + { + \bool_if:NTF \l__nicematrix_initial_open_bool { - \fp_to_dim:n + \bool_if:NTF \l__nicematrix_final_open_bool { - sqrt - ( - ( \dim_use:N \g__nicematrix_x_final_dim - - \dim_use:N \g__nicematrix_x_initial_dim - ) ^ 2 - + - ( \dim_use:N \g__nicematrix_y_final_dim - - \dim_use:N \g__nicematrix_y_initial_dim - ) ^ 2 - ) + \int_set:Nn \l_tmpa_int + { \dim_ratio:nn \l__nicematrix_l_dim \l__nicematrix_inter_dots_dim } } - } - \dim_compare:nNnF \l__nicematrix_l_dim = \c_zero_dim - { - \bool_if:NTF \l__nicematrix_initial_open_bool { - \bool_if:NTF \l__nicematrix_final_open_bool + \int_set:Nn \l_tmpa_int { - \int_set:Nn \l_tmpa_int - { \dim_ratio:nn \l__nicematrix_l_dim \l__nicematrix_inter_dots_dim } - } - { - \int_set:Nn \l_tmpa_int - { - \dim_ratio:nn - { \l__nicematrix_l_dim - \l__nicematrix_dotted_lines_margin_dim } - \l__nicematrix_inter_dots_dim - } + \dim_ratio:nn + { \l__nicematrix_l_dim - \l__nicematrix_xdots_shorten_dim } + \l__nicematrix_inter_dots_dim } } + } + { + \bool_if:NTF \l__nicematrix_final_open_bool { - \bool_if:NTF \l__nicematrix_final_open_bool - { - \int_set:Nn \l_tmpa_int - { - \dim_ratio:nn - { \l__nicematrix_l_dim - \l__nicematrix_dotted_lines_margin_dim } - \l__nicematrix_inter_dots_dim - } - } + \int_set:Nn \l_tmpa_int { - \int_set:Nn \l_tmpa_int - { - \dim_ratio:nn - { \l__nicematrix_l_dim - ( 2 \l__nicematrix_dotted_lines_margin_dim ) } - \l__nicematrix_inter_dots_dim - } + \dim_ratio:nn + { \l__nicematrix_l_dim - \l__nicematrix_xdots_shorten_dim } + \l__nicematrix_inter_dots_dim } } - \dim_set:Nn \l_tmpa_dim - { - ( \g__nicematrix_x_final_dim - \g__nicematrix_x_initial_dim ) * - \dim_ratio:nn \l__nicematrix_inter_dots_dim \l__nicematrix_l_dim - } - \dim_set:Nn \l_tmpb_dim - { - ( \g__nicematrix_y_final_dim - \g__nicematrix_y_initial_dim ) * - \dim_ratio:nn \l__nicematrix_inter_dots_dim \l__nicematrix_l_dim - } - \int_set:Nn \l_tmpb_int - { - \bool_if:NTF \l__nicematrix_initial_open_bool - { \bool_if:NTF \l__nicematrix_final_open_bool 1 0 } - { \bool_if:NTF \l__nicematrix_final_open_bool 2 1 } - } - \dim_gadd:Nn \g__nicematrix_x_initial_dim - { - ( \g__nicematrix_x_final_dim - \g__nicematrix_x_initial_dim ) * - \dim_ratio:nn - { \l__nicematrix_l_dim - \l__nicematrix_inter_dots_dim * \l_tmpa_int } - { 2 \l__nicematrix_l_dim } - * \l_tmpb_int - } - \dim_gadd:Nn \g__nicematrix_y_initial_dim { - ( \g__nicematrix_y_final_dim - \g__nicematrix_y_initial_dim ) * - \dim_ratio:nn - { \l__nicematrix_l_dim - \l__nicematrix_inter_dots_dim * \l_tmpa_int } - { 2 \l__nicematrix_l_dim } - * \l_tmpb_int + \int_set:Nn \l_tmpa_int + { + \dim_ratio:nn + { \l__nicematrix_l_dim - ( 2 \l__nicematrix_xdots_shorten_dim ) } + \l__nicematrix_inter_dots_dim + } } - \begin { tikzpicture } [ overlay ] - \int_step_inline:nnn 0 \l_tmpa_int - { - \pgfpathcircle - { \pgfpoint { \g__nicematrix_x_initial_dim } { \g__nicematrix_y_initial_dim } } - { \l__nicematrix_radius_dim } - \pgfusepath { fill } - \dim_gadd:Nn \g__nicematrix_x_initial_dim \l_tmpa_dim - \dim_gadd:Nn \g__nicematrix_y_initial_dim \l_tmpb_dim - } - \end { tikzpicture } } + \dim_set:Nn \l_tmpa_dim + { + ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) * + \dim_ratio:nn \l__nicematrix_inter_dots_dim \l__nicematrix_l_dim + } + \dim_set:Nn \l_tmpb_dim + { + ( \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ) * + \dim_ratio:nn \l__nicematrix_inter_dots_dim \l__nicematrix_l_dim + } + \int_set:Nn \l_tmpb_int + { + \bool_if:NTF \l__nicematrix_initial_open_bool + { \bool_if:NTF \l__nicematrix_final_open_bool 1 0 } + { \bool_if:NTF \l__nicematrix_final_open_bool 2 1 } + } + \dim_gadd:Nn \l__nicematrix_x_initial_dim + { + ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) * + \dim_ratio:nn + { \l__nicematrix_l_dim - \l__nicematrix_inter_dots_dim * \l_tmpa_int } + { 2 \l__nicematrix_l_dim } + * \l_tmpb_int + } + \dim_gadd:Nn \l__nicematrix_y_initial_dim + { + ( \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ) * + \dim_ratio:nn + { \l__nicematrix_l_dim - \l__nicematrix_inter_dots_dim * \l_tmpa_int } + { 2 \l__nicematrix_l_dim } + * \l_tmpb_int + } + \pgf@relevantforpicturesizefalse + \int_step_inline:nnn 0 \l_tmpa_int + { + \pgfpathcircle + { \pgfpoint \l__nicematrix_x_initial_dim \l__nicematrix_y_initial_dim } + { \l__nicematrix_radius_dim } + \dim_add:Nn \l__nicematrix_x_initial_dim \l_tmpa_dim + \dim_add:Nn \l__nicematrix_y_initial_dim \l_tmpb_dim + } + \pgfusepathqfill } -\cs_set_eq:NN \__nicematrix_ldots \ldots -\cs_set_eq:NN \__nicematrix_cdots \cdots -\cs_set_eq:NN \__nicematrix_vdots \vdots -\cs_set_eq:NN \__nicematrix_ddots \ddots -\cs_set_eq:NN \__nicematrix_iddots \iddots -\cs_new_protected:Npn \__nicematrix_add_to_empty_cells: - { - \cs_gset:cpx - { __nicematrix _ empty _ \int_use:N \c@iRow - \int_use:N \c@jCol } - { \int_use:N \g__nicematrix_env_int } - } -\NewDocumentCommand \__nicematrix_Ldots { s } +\NewDocumentCommand \__nicematrix_Ldots { s O { } } { - \bool_if:nF { #1 } { \__nicematrix_instruction_of_type:n { Ldots } } + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Ldots } { #2 } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_ldots } - \__nicematrix_add_to_empty_cells: + \bool_gset_true:N \g__nicematrix_empty_cell_bool } -\NewDocumentCommand \__nicematrix_Cdots { s } +\NewDocumentCommand \__nicematrix_Cdots { s O { } } { - \bool_if:nF { #1 } { \__nicematrix_instruction_of_type:n { Cdots } } + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Cdots } { #2 } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_cdots } - \__nicematrix_add_to_empty_cells: + \bool_gset_true:N \g__nicematrix_empty_cell_bool } -\NewDocumentCommand \__nicematrix_Vdots { s } +\NewDocumentCommand \__nicematrix_Vdots { s O { } } { - \bool_if:nF { #1 } { \__nicematrix_instruction_of_type:n { Vdots } } + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Vdots } { #2 } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_vdots } - \__nicematrix_add_to_empty_cells: + \bool_gset_true:N \g__nicematrix_empty_cell_bool } -\NewDocumentCommand \__nicematrix_Ddots { s } +\NewDocumentCommand \__nicematrix_Ddots { s O { } } { - \bool_if:nF { #1 } { \__nicematrix_instruction_of_type:n { Ddots } } + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Ddots } { #2 } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_ddots } - \__nicematrix_add_to_empty_cells: + \bool_gset_true:N \g__nicematrix_empty_cell_bool } -\NewDocumentCommand \__nicematrix_Iddots { s } +\NewDocumentCommand \__nicematrix_Iddots { s O { } } { - \bool_if:nF { #1 } { \__nicematrix_instruction_of_type:n { Iddots } } + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Iddots } { #2 } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_iddots } - \__nicematrix_add_to_empty_cells: + \bool_gset_true:N \g__nicematrix_empty_cell_bool } \cs_new_protected:Npn \__nicematrix_Hspace: { - \__nicematrix_add_to_empty_cells: + \bool_gset_true:N \g__nicematrix_empty_cell_bool \hspace } \cs_set_eq:NN \__nicematrix_old_multicolumn \multicolumn @@ -1877,36 +1955,41 @@ } \bool_if:NTF \c__nicematrix_draft_bool { - \NewDocumentCommand \__nicematrix_Hdotsfor_i { O { } m } + \NewDocumentCommand \__nicematrix_Hdotsfor_i { O { } m O { } } { \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } { - \NewDocumentCommand \__nicematrix_Hdotsfor_i { O { } m } + \NewDocumentCommand \__nicematrix_Hdotsfor_i { O { } m O { } } { \tl_gput_right:Nx \g__nicematrix_Hdotsfor_lines_tl { - \__nicematrix_Hdotsfor:nnn + \__nicematrix_Hdotsfor:nnnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { #2 } + { #3 } } \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } -\cs_new_protected:Npn \__nicematrix_Hdotsfor:nnn #1 #2 #3 +\cs_new_protected:Npn \__nicematrix_Hdotsfor:nnnn #1 #2 #3 #4 { \bool_set_false:N \l__nicematrix_initial_open_bool \bool_set_false:N \l__nicematrix_final_open_bool \int_set:Nn \l__nicematrix_initial_i_int { #1 } - \int_set:Nn \l__nicematrix_final_i_int { #1 } + \int_set_eq:NN \l__nicematrix_final_i_int \l__nicematrix_initial_i_int \int_compare:nNnTF #2 = 1 { \int_set:Nn \l__nicematrix_initial_j_int 1 \bool_set_true:N \l__nicematrix_initial_open_bool } { - \int_set:Nn \l_tmpa_int { #2 - 1 } - \__nicematrix_if_not_empty_cell:nnTF \l__nicematrix_initial_i_int \l_tmpa_int + \cs_if_exist:cTF + { + pgf @ sh @ ns @ \__nicematrix_env: + - \int_use:N \l__nicematrix_initial_i_int + - \int_eval:n { #2 - 1 } + } { \int_set:Nn \l__nicematrix_initial_j_int { #2 - 1 } } { \int_set:Nn \l__nicematrix_initial_j_int { #2 } @@ -1919,19 +2002,28 @@ \bool_set_true:N \l__nicematrix_final_open_bool } { - \int_set:Nn \l_tmpa_int { #2 + #3 } - \__nicematrix_if_not_empty_cell:nnTF \l__nicematrix_final_i_int \l_tmpa_int + \cs_if_exist:cTF + { + pgf @ sh @ ns @ \__nicematrix_env: + - \int_use:N \l__nicematrix_final_i_int + - \int_eval:n { #2 + #3 } + } { \int_set:Nn \l__nicematrix_final_j_int { #2 + #3 } } { \int_set:Nn \l__nicematrix_final_j_int { #2 + #3 - 1 } \bool_set_true:N \l__nicematrix_final_open_bool } } - \bool_if:nT { \l__nicematrix_initial_open_bool || \l__nicematrix_final_open_bool } - \__nicematrix_create_medium_nodes: \group_begin: - \cs_set:Npn \__nicematrix_adjust_with_col_nodes: { } - \__nicematrix_actually_draw_Ldots: + \int_compare:nNnTF { #1 } = 0 + { \color { nicematrix-first-row } } + { + \int_compare:nNnT { #1 } = \g__nicematrix_row_total_int + { \color { nicematrix-last-row } } + } + \keys_set:nn { NiceMatrix / xdots } { #4 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \__nicematrix_actually_draw_Ldots: \group_end: \int_step_inline:nnn { #2 } { #2 + #3 - 1 } { \cs_set:cpn { __nicematrix _ dotted _ #1 - ##1 } { } } @@ -1939,52 +2031,73 @@ \cs_new_protected:Npn \__nicematrix_rotate: { \group_insert_after:N \__nicematrix_rotate_i: } \cs_new_protected:Npn \__nicematrix_rotate_i: { \group_insert_after:N \__nicematrix_rotate_ii: } \cs_new_protected:Npn \__nicematrix_rotate_ii: { \group_insert_after:N \__nicematrix_rotate_iii: } -\cs_new_protected:Npn \__nicematrix_rotate_iii: { \box_rotate:Nn \l__nicematrix_cell_box { 90 } } -\cs_new:Npn \__nicematrix_double_int_eval:n #1-#2 \q_stop - { \int_eval:n { #1 } - \int_eval:n { #2 } } -\cs_new_protected:Npn \__nicematrix_line:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_rotate_iii: { - \use:x + \box_rotate:Nn \l__nicematrix_cell_box { 90 } + \int_compare:nNnT \c@iRow = \l__nicematrix_last_row_int { - \__nicematrix_line_i:nn - { \__nicematrix_double_int_eval:n #1 \q_stop } - { \__nicematrix_double_int_eval:n #2 \q_stop } + \vbox_set_top:Nn \l__nicematrix_cell_box + { + \vbox_to_zero:n { } + \skip_vertical:n { - \box_ht:N \@arstrutbox + 0.8 ex } + \box_use:N \l__nicematrix_cell_box + } } } -\cs_new_protected:Npn \__nicematrix_line_i:nn #1 #2 +\cs_new:Npn \__nicematrix_double_int_eval:n #1-#2 \q_stop + { \int_eval:n { #1 } - \int_eval:n { #2 } } +\NewDocumentCommand \__nicematrix_line { O { } m m ! O { } } { - \bool_if:NF \c__nicematrix_draft_bool + \group_begin: + \keys_set:nn { NiceMatrix / xdots } { #1 , #4 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \use:x + { + \__nicematrix_line_i:nn + { \__nicematrix_double_int_eval:n #2 \q_stop } + { \__nicematrix_double_int_eval:n #3 \q_stop } + } + \group_end: + } +\bool_if:NTF \c__nicematrix_draft_bool + { \cs_new_protected:Npn \__nicematrix_line_i:nn #1 #2 { } } + { + \cs_new_protected:Npn \__nicematrix_line_i:nn #1 #2 { - \dim_zero_new:N \g__nicematrix_x_initial_dim - \dim_zero_new:N \g__nicematrix_y_initial_dim - \dim_zero_new:N \g__nicematrix_x_final_dim - \dim_zero_new:N \g__nicematrix_y_final_dim \bool_set_false:N \l__nicematrix_initial_open_bool \bool_set_false:N \l__nicematrix_final_open_bool \bool_if:nTF { - \cs_if_exist_p:c { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - #1 } - && - \cs_if_exist_p:c { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - #2 } - } - { - \begin { tikzpicture } - \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ; - \__nicematrix_extract_coords:w ( i ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_initial_dim \pgf@y - \__nicematrix_extract_coords:w ( f ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_final_dim \pgf@y - \end { tikzpicture } - \__nicematrix_draw_tikz_line: + \cs_if_free_p:c { pgf @ sh @ ns @ \__nicematrix_env: - #1 } + || + \cs_if_free_p:c { pgf @ sh @ ns @ \__nicematrix_env: - #2 } } { - \__nicematrix_error:nnn { unknown~cell~for~line~in~code-after } - { #1 } { #2 } + \__nicematrix_error:nnn { unknown~cell~for~line~in~code-after } { #1 } { #2 } } + { \__nicematrix_draw_line_ii:nn { #1 } { #2 } } } } +\AtBeginDocument + { + \cs_new_protected:Npx \__nicematrix_draw_line_ii:nn #1 #2 + { + \c__nicematrix_pgfortikzpicture_tl + \__nicematrix_draw_line_iii:nn { #1 } { #2 } + \c__nicematrix_endpgfortikzpicture_tl + } + } +\cs_new_protected:Npn \__nicematrix_draw_line_iii:nn #1 #2 + { + \pgfrememberpicturepositiononpagetrue + \pgfpointshapeborder { \__nicematrix_env: - #1 } { \__nicematrix_qpoint: { #2 } } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y + \pgfpointshapeborder { \__nicematrix_env: - #2 } { \__nicematrix_qpoint: { #1 } } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y + \__nicematrix_draw_line: + } \cs_set_eq:NN \OnlyMainNiceMatrix \use:n \cs_new_protected:Npn \__nicematrix_OnlyMainNiceMatrix:n #1 { @@ -2006,62 +2119,154 @@ } \cs_new_protected:Npn \__nicematrix_vline: { \__nicematrix_OnlyMainNiceMatrix:n { \__nicematrix_vline_i: } } \cs_set_eq:NN \__nicematrix_vline_i: \vline -\cs_new:Npn \__nicematrix_hdottedline: +\cs_new_protected:Npn \__nicematrix_draw_vlines: { - \bool_if:NF \c__nicematrix_draft_bool + \group_begin: + \bool_if:NT \c__nicematrix_colortbl_loaded_bool \CT@arc@ + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \__nicematrix_qpoint: {row - 1 } + \dim_set_eq:NN \l_tmpa_dim \pgf@y + \pgfusepathqfill + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \c@iRow } + \dim_sub:Nn \l_tmpa_dim \pgf@y + \pgfusepathqfill + \dim_zero:N \l_tmpb_dim + \int_compare:nNnT \l__nicematrix_last_row_int > { -1 } + { + \dim_set_eq:NN \l_tmpb_dim \g__nicematrix_dp_last_row_dim + \dim_add:Nn \l_tmpb_dim \g__nicematrix_ht_last_row_dim + \__nicematrix_qpoint: { row - \__nicematrix_succ:N\c@iRow } + \dim_add:Nn \l_tmpa_dim \pgf@y + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \g__nicematrix_row_total_int } + \dim_sub:Nn \l_tmpa_dim \pgf@y + \dim_sub:Nn \l_tmpa_dim \l_tmpb_dim + } + \int_step_inline:nnn + { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 } + { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:N \c@jCol } \c@jCol } { - \noalign{ \skip_vertical:n { 2 \l__nicematrix_radius_dim } } + \pgfpathmoveto + { + \pgfpointadd + { \__nicematrix_qpoint: { col - ##1 } } + { + \pgfpoint + { + -0.5 \arrayrulewidth + \int_compare:nNnT { ##1 } = 1 + { + \int_compare:nNnT \l__nicematrix_first_col_int = 1 + { + \arrayrulewidth } + } + } + { \l_tmpb_dim } + } + } + \pgfpathlineto + { + \pgfpointadd + { \__nicematrix_qpoint: { col - ##1 } } + { + \pgfpoint + { + -0.5 \arrayrulewidth + \int_compare:nNnT { ##1 } = 1 + { + \int_compare:nNnT \l__nicematrix_first_col_int = 1 + { + \arrayrulewidth } + } + } + { \l_tmpb_dim + \l_tmpa_dim } + } + } + } + \pgfusepathqstroke + \endpgfpicture + \group_end: + } +\bool_if:NTF \c__nicematrix_draft_bool + { \cs_new:Npn \__nicematrix_hdottedline: { } } + { + \cs_new:Npn \__nicematrix_hdottedline: + { + \noalign { \skip_vertical:N 2\l__nicematrix_radius_dim } \__nicematrix_hdottedline_i: } } \cs_new_protected:Npn \__nicematrix_hdottedline_i: { - \tl_gput_right:Nx \g__nicematrix_code_after_tl + \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl { \__nicematrix_hdottedline:n { \int_use:N \c@iRow } } } -\cs_new_protected:Npn \__nicematrix_hdottedline:n #1 - { - \dim_zero_new:N \g__nicematrix_x_initial_dim - \dim_zero_new:N \g__nicematrix_y_initial_dim - \dim_zero_new:N \g__nicematrix_x_final_dim - \dim_zero_new:N \g__nicematrix_y_final_dim - \bool_set_true:N \l__nicematrix_initial_open_bool - \bool_set_true:N \l__nicematrix_final_open_bool - \begin { tikzpicture } [ remember~picture ] - \__nicematrix_extract_coords:w ( row - #1 ) - \dim_gset:Nn \g__nicematrix_y_initial_dim { \pgf@y - \l__nicematrix_radius_dim } - \dim_gset:Nn \g__nicematrix_y_final_dim { \pgf@y - \l__nicematrix_radius_dim } - \__nicematrix_extract_coords:w ( col - 1 ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \__nicematrix_extract_coords:w ( col - \int_eval:n { \c@jCol + 1 } ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \end { tikzpicture } - \__nicematrix_draw_tikz_line: - } -\cs_new_protected:Npn \__nicematrix_vdottedline:n #1 - { - \int_compare:nNnTF #1 = 0 - { \__nicematrix_error:n { Use~of~:~in~first~position } } - { \bool_if:NF \c__nicematrix_draft_bool { \__nicematrix_vdottedline_i:n { #1 } } } +\AtBeginDocument + { + \cs_new_protected:Npx \__nicematrix_hdottedline:n #1 + { + \bool_set_true:N \exp_not:N \l__nicematrix_initial_open_bool + \bool_set_true:N \exp_not:N \l__nicematrix_final_open_bool + \c__nicematrix_pgfortikzpicture_tl + \__nicematrix_hdottedline_i:n { #1 } + \c__nicematrix_endpgfortikzpicture_tl + } + } +\cs_new_protected:Npn \__nicematrix_hdottedline_i:n #1 + { + \pgfrememberpicturepositiononpagetrue + \__nicematrix_qpoint: { row - #1 } + \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y + \dim_sub:Nn \l__nicematrix_y_initial_dim \l__nicematrix_radius_dim + \dim_set_eq:NN \l__nicematrix_y_final_dim \l__nicematrix_y_initial_dim + \__nicematrix_qpoint: { col - 1 } + \dim_set:Nn \l__nicematrix_x_initial_dim + { \pgf@x + \arraycolsep - \l__nicematrix_left_margin_dim } + \__nicematrix_qpoint: { col - \__nicematrix_succ:N \c@jCol } + \dim_set:Nn \l__nicematrix_x_final_dim + { \pgf@x - \arraycolsep + \l__nicematrix_right_margin_dim } + \tl_set:Nn \l_tmpa_tl { ( } + \tl_if_eq:NNF \l__nicematrix_left_delim_tl \l_tmpa_tl + { \dim_gadd:Nn \l__nicematrix_x_initial_dim { 0.5 \l__nicematrix_inter_dots_dim } } + \tl_set:Nn \l_tmpa_tl { ) } + \tl_if_eq:NNF \l__nicematrix_right_delim_tl \l_tmpa_tl + { \dim_gsub:Nn \l__nicematrix_x_final_dim { 0.5 \l__nicematrix_inter_dots_dim } } + \tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl + \__nicematrix_draw_line: + } +\bool_if:nTF \c__nicematrix_draft_bool + { \cs_new_protected:Npn \__nicematrix_vdottedline:n #1 { } } + { + \cs_new_protected:Npn \__nicematrix_vdottedline:n #1 + { + \bool_set_true:N \l__nicematrix_initial_open_bool + \bool_set_true:N \l__nicematrix_final_open_bool + \bool_if:NTF \c__nicematrix_tikz_loaded_bool + { + \tikzpicture + \__nicematrix_vdottedline_i:n { #1 } + \endtikzpicture + } + { + \pgfpicture + \__nicematrix_vdottedline_i:n { #1 } + \endpgfpicture + } + } } \cs_new_protected:Npn \__nicematrix_vdottedline_i:n #1 { - \dim_zero_new:N \g__nicematrix_x_initial_dim - \dim_zero_new:N \g__nicematrix_y_initial_dim - \dim_zero_new:N \g__nicematrix_x_final_dim - \dim_zero_new:N \g__nicematrix_y_final_dim - \bool_set_true:N \l__nicematrix_initial_open_bool - \bool_set_true:N \l__nicematrix_final_open_bool - \begin { tikzpicture } [ remember~picture ] - \__nicematrix_extract_coords:w ( col - \int_eval:n { #1 + 1 } ) - \dim_gset:Nn \g__nicematrix_x_initial_dim { \pgf@x - \l__nicematrix_radius_dim } - \dim_gset:Nn \g__nicematrix_x_final_dim { \pgf@x - \l__nicematrix_radius_dim } - \__nicematrix_extract_coords:w ( row - 1 ) - \dim_gset:Nn \g__nicematrix_y_initial_dim { \pgf@y - ( \l__nicematrix_inter_dots_dim / 2 ) } - \__nicematrix_extract_coords:w ( row - \int_eval:n { \c@iRow + 1 } ) - \dim_gset:Nn \g__nicematrix_y_final_dim { \pgf@y + ( \l__nicematrix_inter_dots_dim / 2 ) } - \end { tikzpicture } - \__nicematrix_draw_tikz_line: + \bool_if:NT \c__nicematrix_colortbl_loaded_bool \CT@arc@ + \pgfrememberpicturepositiononpagetrue + \__nicematrix_qpoint: { col - \int_eval:n { #1 + 1 } } + \dim_set:Nn \l__nicematrix_x_initial_dim { \pgf@x - \l__nicematrix_radius_dim } + \dim_set:Nn \l__nicematrix_x_final_dim { \pgf@x - \l__nicematrix_radius_dim } + \__nicematrix_qpoint: { row - 1 } + \dim_set:Nn \l__nicematrix_y_initial_dim { \pgf@y - 0.5 \l__nicematrix_inter_dots_dim } + \__nicematrix_qpoint: { row - \__nicematrix_succ:N \c@iRow } + \dim_set:Nn \l__nicematrix_y_final_dim { \pgf@y + 0.5 \l__nicematrix_inter_dots_dim } + \tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl + \__nicematrix_draw_line: } \bool_new:N \l__nicematrix_block_auto_columns_width_bool \keys_define:nn { NiceMatrix / NiceMatrixBlock } @@ -2082,8 +2287,8 @@ { \cs_if_exist:cT { __nicematrix_max_cell_width_ \int_use:N \g__nicematrix_NiceMatrixBlock_int } { - \dim_set:Nx \l__nicematrix_columns_width_dim - { \use:c { __nicematrix_max_cell_width _ \int_use:N \g__nicematrix_NiceMatrixBlock_int } } + \exp_args:NNc \dim_set:Nn \l__nicematrix_columns_width_dim + { __nicematrix_max_cell_width _ \int_use:N \g__nicematrix_NiceMatrixBlock_int } } } } @@ -2095,7 +2300,7 @@ { \cs_gset:cpn { __nicematrix _ max _ cell _ width _ \int_use:N \g__nicematrix_NiceMatrixBlock_int } - { \dim_use:N \g__nicematrix_max_cell_width_dim } + { \dim_eval:n { \g__nicematrix_max_cell_width_dim + \arrayrulewidth } } } \iow_now:Nn \@mainaux \ExplSyntaxOff } @@ -2124,11 +2329,11 @@ \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: { \cs_if_exist:cT - { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: } + { pgf @ sh @ ns @ \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: } { - \__nicematrix_extract_coords:w - ( nm - \int_use:N \g__nicematrix_env_int - - \__nicematrix_i: - \__nicematrix_j: .south~west ) + \pgfpointanchor + { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: } + { south~west } \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _min_dim} { \dim_min:vn { l__nicematrix_row _ \__nicematrix_i: _min_dim } \pgf@y } \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: } @@ -2136,8 +2341,9 @@ \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _min_dim} { \dim_min:vn { l__nicematrix_column _ \__nicematrix_j: _min_dim } \pgf@x } } - \__nicematrix_extract_coords:w - ( nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: .north~east ) + \pgfpointanchor + { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: } + { north~east } \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } { \dim_max:vn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } \pgf@y } \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: } @@ -2151,40 +2357,37 @@ } \cs_new_protected:Npn \__nicematrix_create_medium_nodes: { - \begin { tikzpicture } [ remember~picture , overlay ] + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse \__nicematrix_computations_for_medium_nodes: - \tikzset { name~suffix = -medium } + \tl_set:Nn \l__nicematrix_suffix_tl { -medium } \__nicematrix_create_nodes: - \end { tikzpicture } - \cs_set_protected:Npn \__nicematrix_create_medium_nodes: { } - \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: - { \__nicematrix_create_large_nodes: } + \endpgfpicture } \cs_new_protected:Npn \__nicematrix_create_large_nodes: { - \begin { tikzpicture } [ remember~picture , overlay ] + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse \__nicematrix_computations_for_medium_nodes: \__nicematrix_computations_for_large_nodes: - \tikzset { name~suffix = -large } + \tl_set:Nn \l__nicematrix_suffix_tl { - large } \__nicematrix_create_nodes: - \end { tikzpicture } - \cs_set_protected:Npn \__nicematrix_create_large_nodes: { } - \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: - { \__nicematrix_create_medium_nodes: } + \endpgfpicture } \cs_new_protected:Npn \__nicematrix_create_medium_and_large_nodes: { - \begin { tikzpicture } [ remember~picture , overlay ] + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse \__nicematrix_computations_for_medium_nodes: - \tikzset { name~suffix = -medium } + \tl_set:Nn \l__nicematrix_suffix_tl { - medium } \__nicematrix_create_nodes: \__nicematrix_computations_for_large_nodes: - \tikzset { name~suffix = -large } + \tl_set:Nn \l__nicematrix_suffix_tl { - large } \__nicematrix_create_nodes: - \end { tikzpicture } - \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: { } - \cs_set_protected:Npn \__nicematrix_create_medium_nodes: { } - \cs_set_protected:Npn \__nicematrix_create_large_nodes: { } + \endpgfpicture } \cs_new_protected:Npn \__nicematrix_computations_for_large_nodes: { @@ -2231,23 +2434,18 @@ { \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: { - \coordinate ( __nicematrix~south~west ) - at ( \dim_use:c { l__nicematrix_column_ \__nicematrix_j: _min_dim } , - \dim_use:c { l__nicematrix_row_ \__nicematrix_i: _min_dim } ) ; - \coordinate ( __nicematrix~north~east ) - at ( \dim_use:c { l__nicematrix_column_ \__nicematrix_j: _max_dim } , - \dim_use:c { l__nicematrix_row_ \__nicematrix_i: _max_dim } ) ; - \node - [ - node~contents = { } , - fit = ( __nicematrix~south~west ) ( __nicematrix~north~east ) , - inner~sep = \c_zero_dim , - name = nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: , - alias = - \str_if_empty:NF \l__nicematrix_name_str - { \l__nicematrix_name_str - \__nicematrix_i: - \__nicematrix_j: } - ] - ; + \__nicematrix_pgf_rect_node:nnnnn + { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl } + { \dim_use:c { l__nicematrix_column_ \__nicematrix_j: _min_dim } } + { \dim_use:c { l__nicematrix_row_ \__nicematrix_i: _min_dim } } + { \dim_use:c { l__nicematrix_column_ \__nicematrix_j: _max_dim } } + { \dim_use:c { l__nicematrix_row_ \__nicematrix_i: _max_dim } } + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \l__nicematrix_name_str - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl } + { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl } + } } } \seq_mapthread_function:NNN @@ -2263,34 +2461,25 @@ \cs_new_protected:Npn \__nicematrix_node_for_multicolumn:nn #1 #2 { \__nicematrix_extract_coords_values: #1 \q_stop - \coordinate ( __nicematrix~south~west ) at - ( - \dim_use:c { l__nicematrix_column _ \__nicematrix_j: _ min _ dim } , - \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } - ) ; - \coordinate ( __nicematrix~north~east ) at - ( - \dim_use:c { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: + #2 - 1 } _ max _ dim} , - \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ max _ dim } - ) ; - \node - [ - node~contents = { } , - fit = ( __nicematrix~south~west ) ( __nicematrix~north~east ) , - inner~sep = \c_zero_dim , - name = nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: , - alias = - \str_if_empty:NF \l__nicematrix_name_str - { \l__nicematrix_name_str - \__nicematrix_i: - \__nicematrix_j: } - ] - ; + \__nicematrix_pgf_rect_node:nnnnn + { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl } + { \dim_use:c { l__nicematrix_column _ \__nicematrix_j: _ min _ dim } } + { \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } } + { \dim_use:c { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: +#2-1 } _ max _ dim } } + { \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ max _ dim } } + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \l__nicematrix_name_str - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl } + { \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl} + } } \NewDocumentCommand \__nicematrix_Block: { O { } m D < > { } m } { \__nicematrix_Block_i #2 \q_stop { #1 } { #3 } { #4 } } \cs_new:Npn \__nicematrix_Block_i #1-#2 \q_stop { \__nicematrix_Block_ii:nnnnn { #1 } { #2 } } \cs_new_protected:Npn \__nicematrix_Block_ii:nnnnn #1 #2 #3 #4 #5 { - \tl_gput_left:Nx \g__nicematrix_code_after_tl + \tl_gput_left:Nx \g__nicematrix_internal_code_after_tl { \__nicematrix_Block_iii:nnnnnn { \int_use:N \c@iRow } @@ -2327,58 +2516,59 @@ { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } } { \hbox_set:Nn \l__nicematrix_cell_box { #6 } - \begin { tikzpicture } - \int_set:Nn \l_tmpa_int { #1 } - \int_decr:N \l_tmpa_int - \int_set:Nn \l_tmpb_int { #2 } - \int_decr:N \l_tmpb_int - \__nicematrix_extract_coords:w ( row - \int_eval:n { \l_tmpa_int + 1 } ) - \dim_set_eq:NN \l_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w ( col - \int_eval:n { \l_tmpb_int + 1 } ) - \dim_set_eq:NN \l_tmpb_dim \pgf@x - \coordinate ( one ) at ( \l_tmpb_dim , \l_tmpa_dim ) ; - \__nicematrix_extract_coords:w ( row - \int_eval:n { #3 + 1 } ) + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \__nicematrix_qpoint: { row - #1 } \dim_set_eq:NN \l_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w ( col - \int_eval:n { #4 + 1 } ) + \__nicematrix_qpoint: { col - #2 } \dim_set_eq:NN \l_tmpb_dim \pgf@x - \coordinate ( two ) at ( \l_tmpb_dim , \l_tmpa_dim ) ; + \__nicematrix_qpoint: { row - \__nicematrix_succ:N #3 } + \dim_set_eq:NN \l_tmpc_dim \pgf@y + \__nicematrix_qpoint: { col - \__nicematrix_succ:N #4 } + \dim_set_eq:NN \l_tmpd_dim \pgf@x \bool_if:NT \l__nicematrix_white_bool { - \fill [ white , line~width = 0 pt] - ( [ yshift = -\arrayrulewidth ] one ) - rectangle - ( [ xshift = -\arrayrulewidth ] two ) ; + \begin { pgfscope } + \pgfsetfillcolor { white } + \int_compare:nNnT { #2 } = 1 + { + \int_compare:nNnT \l__nicematrix_first_col_int = 1 + { \dim_add:Nn \l_tmpb_dim \arrayrulewidth } + } + \pgfpathrectanglecorners + { \pgfpoint \l_tmpb_dim { \l_tmpa_dim - \arrayrulewidth } } + { \pgfpoint { \l_tmpd_dim - \arrayrulewidth } \l_tmpc_dim } + \pgfusepathqfill + \end { pgfscope } } - \use:x - { - \exp_not:N \node - [ - fit = ( one ) ( two ) , - inner~sep = 0 pt , - \l__nicematrix_tikz_tl - ] - } - (#1-#2-block) { } ; + \begin { pgfscope } + \exp_args:Nx \pgfset { \l__nicematrix_tikz_tl } + \__nicematrix_pgf_rect_node:nnnnn + { \__nicematrix_env: - #1 - #2 - block } + \l_tmpb_dim \l_tmpa_dim \l_tmpd_dim \l_tmpc_dim + \end { pgfscope } \bool_if:NT \l__nicematrix_medium_nodes_bool { - \node - [ - fit = ( #1 - #2 - medium . north~west ) - ( #3 - #4 - medium . south~east ) , - inner~sep = 0 pt , - ] - (#1-#2-block-medium) { } ; + \__nicematrix_pgf_rect_node:nnn + { \__nicematrix_env: - #1 - #2 - block - medium } + { \pgfpointanchor { \__nicematrix_env: - #1 - #2 - medium } { north~west } } + { \pgfpointanchor { \__nicematrix_env: - #3 - #4 - medium } { south~east } } } \int_compare:nNnTF { #1 } = { #3 } { - \__nicematrix_extract_coords:w (row-#1-base) - \dim_set_eq:NN \l_tmpa_dim \pgf@y - \__nicematrix_extract_coords:w (#1-#2-block) - \path (\pgf@x,\l_tmpa_dim) node [ anchor = base ] - { \box_use_drop:N \l__nicematrix_cell_box } ; + \pgfextracty \l_tmpa_dim { \__nicematrix_qpoint: { row - #1 - base } } + \__nicematrix_qpoint: { #1 - #2 - block } + \pgftransformshift { \pgfpoint \pgf@x \l_tmpa_dim } + \pgfnode { rectangle } { base } + { \box_use_drop:N \l__nicematrix_cell_box } { } { } + } + { + \pgftransformshift { \__nicematrix_qpoint: { #1 - #2 - block } } + \pgfnode { rectangle } { center } + { \box_use_drop:N \l__nicematrix_cell_box } { } { } } - { \node at (#1-#2-block.center) { \box_use_drop:N \l__nicematrix_cell_box } ; } - \end { tikzpicture } + \endpgfpicture } \group_end: } @@ -2454,7 +2644,12 @@ transparent .meta:n = { renew-dots , renew-matrix } , transparent .value_forbidden:n = true, obsolete-environments .code:n = - \__nicematrix_msg_redirect_name:nn { Obsolete~environment } { none } + \__nicematrix_msg_redirect_name:nn { Obsolete~environment } { none } , + obsolete-environments .value_forbidden:n = true, + starred-commands .code:n = + \__nicematrix_msg_redirect_name:nn { starred~commands } { none } , + starred-commands .value_forbidden:n = true , + } \ProcessKeysOptions { NiceMatrix / Package } \cs_new_protected:Npn \__nicematrix_convert_to_str_seq:N #1 @@ -2486,31 +2681,57 @@ } { \__nicematrix_fatal:n { too~much~cols~for~array } } } +\cs_new:Npn \__nicematrix_message_hdotsfor: + { + \tl_if_empty:VF \g__nicematrix_Hdotsfor_lines_tl + { ~Maybe~your~use~of~\token_to_str:N \Hdotsfor\ is~incorrect.} + } \__nicematrix_msg_new:nn { too~much~cols~for~matrix~with~last~col } { You~try~to~use~more~columns~than~allowed~by~your~ - \__nicematrix_full_name_env:.~The~maximal~number~of~columns~is~ - \int_eval:n { \l__nicematrix_last_col_int - 1 }~(plus~the~potential~ + \__nicematrix_full_name_env:.\__nicematrix_message_hdotsfor:\ The~maximal~number~of~ + columns~is~\int_eval:n { \l__nicematrix_last_col_int - 1 }~(plus~the~potential~ exterior~ones).~This~error~is~fatal. } \__nicematrix_msg_new:nn { too~much~cols~for~matrix } { You~try~to~use~more~columns~than~allowed~by~your~ - \__nicematrix_full_name_env:.~ 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. + \__nicematrix_full_name_env:.\__nicematrix_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. } \__nicematrix_msg_new:nn { too~much~cols~for~array } { You~try~to~use~more~columns~than~allowed~by~your~ - \__nicematrix_full_name_env:.~The~maximal~number~of~columns~is~ - \int_use:N \c@jCol\space (plus~the~potential~exterior~ones).~ + \__nicematrix_full_name_env:.\__nicematrix_message_hdotsfor:\ The~maximal~number~of~columns~is~ + \int_eval:n { \c@jCol - 1 }~(plus~the~potential~exterior~ones).~ This~error~is~fatal. } +\__nicematrix_msg_new:nn { bad~option~for~line-style } + { + Since~you~haven't~loaded~Tikz,~the~only~value~you~can~give~to~'line-style'~ + is~'standard'.~If~you~go~on,~this~option~will~be~ignored. + } +\__nicematrix_msg_new:nn { Unknown~option~for~xdots } + { + As~for~now~there~is~only~three~options~available~here:~'color',~'line-style'~ + and~'shorten'~(and~you~try~to~use~'\l_keys_key_str').~If~you~go~on,~ + this~option~will~be~ignored. + } +\__nicematrix_msg_new:nn { starred~commands } + { + The~starred~versions~of~\token_to_str:N \Cdots,~\token_to_str:N \Ldots,~ + \token_to_str:N \Vdots,~\token_to_str:N\Ddots\ and~\token_to_str:N\Iddots\ + are~deprecated.~However,~you~can~go~on~for~this~time.~If~you~don't~want~to~ + see~this~error~we~should~load~'nicematrix'~with~the~option~ + 'starred-commands'. + } \__nicematrix_msg_new:nn { bad~value~for~baseline } { - The~value~you~gave~to~'baseline'~(\int_use:N \l_tmpa_int)~is~not~ - valid.\\ + The~value~given~to~'baseline'~(\int_use:N \l_tmpa_int)~is~not~ + valid.~The~value~must~be~between~\int_use:N \l__nicematrix_first_row_int\ and~ + \int_use:N \g__nicematrix_row_total_int\ or~equal~to~'t',~'c'~or~'b'.\\ If~you~go~on,~a~value~of~1~will~be~used. } \__nicematrix_msg_new:nn { Second~Block } @@ -2523,7 +2744,7 @@ \__nicematrix_msg_new:nn { unknown~cell~for~line~in~code-after } { Your~command~\token_to_str:N\line\{#1\}\{#2\}~in~the~'code-after'~ - can't~be~executed~because~a~Tikz~node~doesn't~exist.\\ + can't~be~executed~because~a~cell~doesn't~exist.\\ If~you~go~on~this~command~will~be~ignored. } \__nicematrix_msg_new:nn { last-col~non~empty~for~NiceArray } @@ -2545,12 +2766,6 @@ too~small~for~that~block. \\ If~you~go~on,~this~command~will~be~ignored. } -\__nicematrix_msg_new:nn { Impossible~line } - { - A~dotted~line~can't~be~drawn~because~you~have~not~put~ - all~the~ampersands~required~on~the~row~#1.\\ - If~you~go~on,~this~dotted~line~will~be~ignored. - } \__nicematrix_msg_new:nn { Wrong~last~row } { You~have~used~'last-row=\int_use:N \l__nicematrix_last_row_int'~but~your~ @@ -2592,7 +2807,6 @@ create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - dotted-lines-margin,~ end-of-row,~ exterior-arraycolsep,~ hlines,~ @@ -2606,8 +2820,11 @@ renew-matrix,~ right-margin,~ small,~ - transparent~ - and~vlines. + transparent,~ + vlines,~ + xdots/color,~ + xdots/shorten~and~ + xdots/line-style. } \__nicematrix_msg_new:nnn { Unknown~option~for~NiceArray } { @@ -2630,7 +2847,6 @@ create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - dotted-lines-margin,~ end-of-row,~ extra-left-margin,~ extra-right-margin,~ @@ -2649,7 +2865,10 @@ right-margin,~ small,~ t,~ - and~vlines. + vlines,~ + xdots/color,~ + xdots/shorten~and~ + xdots/line-style. } \__nicematrix_msg_new:nnn { Unknown~option~for~NiceMatrix } { @@ -2669,7 +2888,6 @@ create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - dotted-lines-margin,~ end-of-row,~ extra-left-margin,~ extra-right-margin,~ @@ -2677,6 +2895,7 @@ first-row,~ hlines,~ hvlines,~ + l~(=L),~ last-col,~ last-row,~ left-margin,~ @@ -2684,10 +2903,14 @@ name,~ nullify-dots,~ parallelize-diags,~ + r~(=R),~ renew-dots,~ right-margin,~ small,~ - and~vlines. + vlines,~ + xdots/color,~ + xdots/shorten~and~ + xdots/line-style. } \__nicematrix_msg_new:nnn { Duplicate~name } { @@ -2713,12 +2936,6 @@ and~R~in~the~preamble~of~your~environment. \\ This~error~is~fatal. } -\__nicematrix_msg_new:nn { Use~of~:~in~first~position } - { - You~can't~use~the~column~specifier~'\l__nicematrix_letter_for_dotted_lines_str'~in~the~ - first~position~of~the~preamble~of~the~\__nicematrix_full_name_env:. \\ - If~you~go~on,~this~dotted~line~will~be~ignored. - } \__nicematrix_msg_new:nn { Obsolete~environment } { The~environment~\{\@currenvir\}~is~obsolete.~You~should~use~#1~instead.~ @@ -2823,6 +3040,55 @@ \NiceArrayWithDelims } { \endNiceArrayWithDelims } +\cs_new_protected:Npn \__nicematrix_pgf_rect_node:nnnnn #1 #2 #3 #4 #5 + { + \begin { pgfscope } + \pgfset + { + outer~sep = \c_zero_dim , + inner~sep = \c_zero_dim , + minimum~size = \c_zero_dim + } + \pgftransformshift { \pgfpoint { 0.5 * ( #2 + #4 ) } { 0.5 * ( #3 + #5 ) } } + \pgfnode + { rectangle } + { center } + { + \vbox_to_ht:nn + { \dim_abs:n { #5 - #3 } } + { + \vfill + \hbox_to_wd:nn { \dim_abs:n { #4 - #2 } } { } + } + } + { #1 } + { } + \end { pgfscope } + } +\cs_new_protected:Npn \__nicematrix_pgf_rect_node:nnn #1 #2 #3 + { + \begin { pgfscope } + \pgfset + { + outer~sep = \c_zero_dim , + inner~sep = \c_zero_dim , + minimum~size = \c_zero_dim + } + \pgftransformshift { \pgfpointscale { 0.5 } { \pgfpointadd { #2 } { #3 } } } + \pgfpointdiff { #3 } { #2 } + \pgfgetlastxy \l_tmpa_dim \l_tmpb_dim + \pgfnode + { rectangle } + { center } + { + \vbox_to_ht:nn + { \dim_abs:n { \l_tmpb_dim } } + { \vfill \hbox_to_wd:nn { \dim_abs:n { \l_tmpa_dim } } { } } + } + { #1 } + { } + \end { pgfscope } + } \endinput %% -- cgit v1.2.3