diff options
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty | 1201 |
1 files changed, 633 insertions, 568 deletions
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index 5e13b4e6c12..bfa03a3231f 100644 --- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty +++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty @@ -18,17 +18,25 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{3.11} -\def\myfiledate{2020/02/07} +\def\myfileversion{3.12} +\def\myfiledate{2020/02/28} \RequirePackage{tikz} \usetikzlibrary{fit} -\RequirePackage{expl3}[2019/07/01] +\RequirePackage{expl3}[2020/02/08] \RequirePackage{l3keys2e} \ProvidesExplPackage {nicematrix} {\myfiledate} {\myfileversion} {Mathematical matrices with TikZ} +\msg_new:nnn { nicematrix } { expl3~too~old } + { + Your~version~of~LaTeX~(especially~expl3)~is~too~old.~ + You~can~go~on~but~you~will~probably~have~other~errors~ + if~you~use~the~functionalities~of~nicematrix. + } +\cs_if_exist:NF \l_keys_key_str + { \msg_error:nn { nicematrix } { expl3~too~old } } \bool_new:N \c__nicematrix_draft_bool \DeclareOption { draft } { \bool_set_true:N \c__nicematrix_draft_bool } \DeclareOption* { } @@ -40,7 +48,7 @@ \cs_new_protected:Npn \__nicematrix_error:nn { \msg_error:nnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_error:nnn { \msg_error:nnnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_fatal:n { \msg_fatal:nn { nicematrix } } -\cs_new_protected:Npn \__nicematrix_fatal:nn { \msg_fatal:nn { nicematrix } } +\cs_new_protected:Npn \__nicematrix_fatal:nn { \msg_fatal:nnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_msg_new:nn { \msg_new:nnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_msg_new:nnn { \msg_new:nnnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_msg_redirect_name:nn @@ -60,12 +68,14 @@ { \mathinner { - \mkern 1 mu - \raise \p@ \hbox:n { . } - \mkern 2 mu - \raise 4 \p@ \hbox:n { . } - \mkern 2 mu - \raise 7 \p@ \vbox { \kern 7 pt \hbox:n { . } } \mkern 1 mu + \tex_mkern:D 1 mu + \box_move_up:nn { 1 pt } { \hbox:n { . } } + \tex_mkern:D 2 mu + \box_move_up:nn { 4 pt } { \hbox:n { . } } + \tex_mkern:D 2 mu + \box_move_up:nn { 7 pt } + { \vbox:n { \kern 7 pt \hbox:n { . } } } + \tex_mkern:D 1 mu } } \int_new:N \g__nicematrix_env_int @@ -92,16 +102,27 @@ } { } } +\cs_set_protected:Npn \__nicematrix_extract_coords:w + { \tikz@parse@node \pgfutil@firstofone } \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_radius_dim \dim_set:Nn \l__nicematrix_radius_dim { 0.53 pt } -\str_new:N \g__nicematrix_type_env_str +\str_new:N \g__nicematrix_name_env_str +\str_new:N \g__nicematrix_com_or_env_str +\str_set:Nn \g__nicematrix_com_or_env_str { environment } +\cs_new:Npn \__nicematrix_full_name_env: + { + \str_if_eq:VnTF \g__nicematrix_com_or_env_str { command } + { command \space \c_backslash_str \g__nicematrix_name_env_str } + { environment \space \{ \g__nicematrix_name_env_str \} } + } \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 \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 @@ -152,12 +173,13 @@ } } \bool_new:N \l__nicematrix_light_syntax_bool -\str_new:N \l__nicematrix_pos_env_str -\str_set:Nn \l__nicematrix_pos_env_str c +\str_new:N \l__nicematrix_baseline_str +\str_set:Nn \l__nicematrix_baseline_str c \bool_new:N \l__nicematrix_exterior_arraycolsep_bool \bool_new:N \l__nicematrix_parallelize_diags_bool \bool_set_true:N \l__nicematrix_parallelize_diags_bool \bool_new:N \l__nicematrix_hlines_bool +\bool_new:N \l__nicematrix_vlines_bool \bool_new:N \l__nicematrix_nullify_dots_bool \bool_new:N \l__nicematrix_auto_columns_width_bool \str_new:N \l__nicematrix_name_str @@ -173,8 +195,10 @@ \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 { ; } +\bool_new:N \l__nicematrix_max_delimiter_width_bool \keys_define:nn { NiceMatrix / Global } { + 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 , @@ -191,6 +215,8 @@ code-for-last-row .value_required:n = true , small .bool_set:N = \l__nicematrix_small_bool , hlines .bool_set:N = \l__nicematrix_hlines_bool , + vlines .bool_set:N = \l__nicematrix_vlines_bool , + hvlines .meta:n = { hlines , vlines } , parallelize-diags .bool_set:N = \l__nicematrix_parallelize_diags_bool , renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool , renew-dots .value_forbidden:n = true , @@ -218,13 +244,14 @@ { \dim_set:Nn \l__nicematrix_columns_width_dim { #1 } } , columns-width .value_required:n = true , name .code:n = - \unless \ifmeasuring@ - \str_set:Nn \l_tmpa_str { #1 } - \seq_if_in:NVTF \g__nicematrix_names_seq \l_tmpa_str - { \__nicematrix_error:nn { Duplicate~name } { #1 } } - { \seq_gput_left:NV \g__nicematrix_names_seq \l_tmpa_str } - \str_set_eq:NN \l__nicematrix_name_str \l_tmpa_str - \fi , + \legacy_if:nF { measuring@ } + { + \str_set:Nn \l_tmpa_str { #1 } + \seq_if_in:NVTF \g__nicematrix_names_seq \l_tmpa_str + { \__nicematrix_error:nn { Duplicate~name } { #1 } } + { \seq_gput_left:NV \g__nicematrix_names_seq \l_tmpa_str } + \str_set_eq:NN \l__nicematrix_name_str \l_tmpa_str + } , name .value_required:n = true , code-after .tl_gset:N = \g__nicematrix_code_after_tl , code-after .value_required:n = true , @@ -259,10 +286,8 @@ { renew-matrix .code:n = \__nicematrix_renew_matrix: , renew-matrix .value_forbidden:n = true , - RenewMatrix .code:n = \__nicematrix_error:n { Option~RenewMatrix~suppressed } , transparent .meta:n = { renew-dots , renew-matrix } , transparent .value_forbidden:n = true, - Transparent .code:n = \__nicematrix_error:n { Option~Transparent~suppressed } , exterior-arraycolsep .bool_set:N = \l__nicematrix_exterior_arraycolsep_bool , columns-width .code:n = \str_if_eq:nnTF { #1 } { auto } @@ -273,7 +298,7 @@ allow-duplicate-names .value_forbidden:n = true , letter-for-dotted-lines .code:n = { - \int_compare:nTF { \tl_count:n { #1 } = \c_one_int } + \int_compare:nTF { \tl_count:n { #1 } = 1 } { \str_set:Nx \l__nicematrix_letter_for_dotted_lines_str { #1 } } { \__nicematrix_error:n { Bad~value~for~letter~for~dotted~lines } } } , @@ -293,9 +318,11 @@ } \keys_define:nn { NiceMatrix / NiceArray } { - c .code:n = \str_set:Nn \l__nicematrix_pos_env_str c , - t .code:n = \str_set:Nn \l__nicematrix_pos_env_str t , - b .code:n = \str_set:Nn \l__nicematrix_pos_env_str b , + c .code:n = \str_set:Nn \l__nicematrix_baseline_str c , + t .code:n = \str_set:Nn \l__nicematrix_baseline_str t , + b .code:n = \str_set:Nn \l__nicematrix_baseline_str b , + baseline .tl_set:N = \l__nicematrix_baseline_str , + baseline .value_required:n = true , last-col .code:n = \tl_if_empty:nF { #1 } { \__nicematrix_error:n { last-col~non~empty~for~NiceArray } } \int_zero:N \l__nicematrix_last_col_int , @@ -312,17 +339,17 @@ last-row .default:n = -1 , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceMatrix } } -\cs_new_protected:Nn \__nicematrix_Cell: +\cs_new_protected:Npn \__nicematrix_Cell: { \int_gincr:N \c@jCol - \int_compare:nNnT \c@jCol = \c_one_int + \int_compare:nNnT \c@jCol = 1 { - \int_compare:nNnT \l__nicematrix_first_col_int = \c_one_int + \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_tmpa_box + \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 @@ -332,39 +359,39 @@ \l__nicematrix_code_for_last_row_tl } } -\cs_new_protected:Nn \__nicematrix_begin_of_row: +\cs_new_protected:Npn \__nicematrix_begin_of_row: { \int_gincr:N \c@iRow \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 ) ; } -\cs_new_protected:Npn \__nicematrix_actualization_for_first_and_last_row: +\cs_new_protected:Npn \__nicematrix_update_for_first_and_last_row: { - \int_compare:nNnT \c@iRow = 0 + \int_compare:nNnTF \c@iRow = 0 { \dim_gset:Nn \g__nicematrix_dp_row_zero_dim - { \dim_max:nn \g__nicematrix_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } + { \dim_max:nn \g__nicematrix_dp_row_zero_dim { \box_dp:N \l__nicematrix_cell_box } } \dim_gset:Nn \g__nicematrix_ht_row_zero_dim - { \dim_max:nn \g__nicematrix_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } + { \dim_max:nn \g__nicematrix_ht_row_zero_dim { \box_ht:N \l__nicematrix_cell_box } } } - \int_compare:nNnT \c@iRow = \c_one_int { - \dim_gset:Nn \g__nicematrix_ht_row_one_dim - { \dim_max:nn \g__nicematrix_ht_row_one_dim { \box_ht:N \l_tmpa_box } } + \int_compare:nNnT \c@iRow = 1 + { + \dim_gset:Nn \g__nicematrix_ht_row_one_dim + { \dim_max:nn \g__nicematrix_ht_row_one_dim { \box_ht:N \l__nicematrix_cell_box } } + } } - \dim_gset:Nn \g__nicematrix_ht_last_row_dim - { \dim_max:nn \g__nicematrix_ht_last_row_dim { \box_ht:N \l_tmpa_box } } - \dim_gset:Nn \g__nicematrix_dp_last_row_dim - { \dim_max:nn \g__nicematrix_dp_last_row_dim { \box_dp:N \l_tmpa_box } } } -\cs_new_protected:Nn \__nicematrix_end_Cell: +\cs_new_protected:Npn \__nicematrix_end_Cell: { \c_math_toggle_token \hbox_set_end: \dim_gset:Nn \g__nicematrix_max_cell_width_dim - { \dim_max:nn \g__nicematrix_max_cell_width_dim { \box_wd:N \l_tmpa_box } } - \__nicematrix_actualization_for_first_and_last_row: + { \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 , @@ -386,17 +413,15 @@ \int_use:N \c@jCol } ] - \bgroup - \box_use:N \l_tmpa_box - \egroup ; + { \box_use_drop:N \l__nicematrix_cell_box } ; } \cs_generate_variant:Nn \dim_set:Nn { N x } -\cs_new_protected:Nn \__nicematrix_renewcolumntype:nn +\cs_new_protected:Npn \__nicematrix_renewcolumntype:nn #1 #2 { \newcolumntype #1 [ 2 ] { > { - \hbox_set:Nw \l_tmpa_box + \hbox_set:Nw \l__nicematrix_cell_box \__nicematrix_Cell: } c @@ -404,23 +429,7 @@ \__nicematrix_end_Cell: \hbox_set_end: #2 - \tikz [ remember~picture ] - \node - [ - name = nm - \int_use:N \g__nicematrix_env_int - - \int_use:N \c@iRow - - \int_use:N \c@jCol - w, - alias = - \str_if_empty:NF \l__nicematrix_name_str - { - \l__nicematrix_name_str - - \int_use:N \c@iRow - - \int_use:N \c@jCol - w - } , - inner~sep = \c_zero_dim , - ] - { \makebox [ ##2 ] [ ##1 ] { \box_use:N \l_tmpa_box } } - ; + \makebox [ ##2 ] [ ##1 ] { \box_use_drop:N \l__nicematrix_cell_box } } } } @@ -449,27 +458,38 @@ \@array@array } \array - [ \l__nicematrix_pos_env_str ] + [ \str_if_eq:VnTF \l__nicematrix_baseline_str c c t ] } -\cs_new:Npn \__nicematrix_everycr: - { \noalign { \__nicematrix_everycr_i: } } +\cs_set_eq:NN \__nicematrix_standard_ialign: \ialign +\cs_new:Npn \__nicematrix_everycr: { \noalign { \__nicematrix_everycr_i: } } \cs_new_protected:Npn \__nicematrix_everycr_i: { \int_gzero:N \c@jCol + \hbox:n + { + \tikz [ remember~picture ] + \coordinate + ( nm - \int_use:N \g__nicematrix_env_int - row - \int_eval:n { \c@iRow + 1 } ) ; + } \bool_if:NT \l__nicematrix_hlines_bool { \int_compare:nNnT \c@iRow > { -1 } { - \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int + \bool_if:NF \g__nicematrix_row_of_col_done_bool { - \hrule \@height \arrayrulewidth - \skip_vertical:n { - \arrayrulewidth } + \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int + { + \bool_if:NTF \c__nicematrix_colortbl_loaded_bool + { { \CT@arc@ \hrule height \arrayrulewidth } } + { \hrule height \arrayrulewidth } + } } } } } \cs_new_protected:Npn \__nicematrix_pre_array: { + \box_clear_new:N \l__nicematrix_cell_box \cs_if_exist:NT \theiRow { \int_set_eq:NN \l__nicematrix_save_iRow_int \c@iRow } \int_gzero_new:N \c@iRow @@ -507,17 +527,14 @@ \dim_gset:Nn \g__nicematrix_ht_last_row_dim { \box_ht:N \@arstrutbox } \dim_gzero_new:N \g__nicematrix_dp_last_row_dim \dim_gset:Nn \g__nicematrix_dp_last_row_dim { \box_dp:N \@arstrutbox } - \cs_set:Npn \ialign - { - \everycr { } - \tabskip = \c_zero_skip - \halign - } + \cs_set_eq:NN \ialign \__nicematrix_standard_ialign: \halign } \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 \firsthline \hline + \cs_set_eq:NN \lasthline \hline \cs_set_eq:NN \Ldots \__nicematrix_Ldots \cs_set_eq:NN \Cdots \__nicematrix_Cdots \cs_set_eq:NN \Vdots \__nicematrix_Vdots @@ -528,6 +545,7 @@ \cs_set_eq:NN \Hdotsfor \__nicematrix_Hdotsfor: \cs_set_eq:NN \multicolumn \__nicematrix_multicolumn:nnn \cs_set_eq:NN \Block \__nicematrix_Block: + \cs_set_eq:NN \rotate \__nicematrix_rotate: \cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n \bool_if:NT \l__nicematrix_renew_dots_bool { @@ -555,13 +573,11 @@ { ! { - \skip_horizontal:n { 0.53 pt } - \bool_if:nF + \int_compare:nNnF \c@iRow = 0 { - \l__nicematrix_auto_columns_width_bool - || \dim_compare_p:nNn \l__nicematrix_columns_width_dim > \c_zero_dim + \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int + { \skip_horizontal:n { 2 \l__nicematrix_radius_dim } } } - { \bool_gset_true:N \g__nicematrix_large_nodes_bool } \int_compare:nNnT \c@jCol > \g__nicematrix_last_vdotted_col_int { \int_gset_eq:NN \g__nicematrix_last_vdotted_col_int \c@jCol @@ -583,11 +599,9 @@ } \NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } } { - \str_if_empty:NT \g__nicematrix_type_env_str - { - \str_gset:Nn \g__nicematrix_type_env_str - { environment ~ { NiceArrayWithDelims } } - } + \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 } } \__nicematrix_adapt_S_column: \__nicematrix_test_if_math_mode: \bool_if:NT \l__nicematrix_in_env_bool { \__nicematrix_fatal:n { Yet~in~env } } @@ -606,6 +620,16 @@ { \keys_set:nn { NiceMatrix / NiceArray } } { \keys_set:nn { NiceMatrix / pNiceArray } } { #3 , #5 } + \int_compare:nNnT \l__nicematrix_last_row_int > { -2 } + { + \tl_put_right:Nn \__nicematrix_update_for_first_and_last_row: + { + \dim_gset:Nn \g__nicematrix_ht_last_row_dim + { \dim_max:nn \g__nicematrix_ht_last_row_dim { \box_ht:N \l__nicematrix_cell_box } } + \dim_gset:Nn \g__nicematrix_dp_last_row_dim + { \dim_max:nn \g__nicematrix_dp_last_row_dim { \box_dp:N \l__nicematrix_cell_box } } + } + } \int_compare:nNnT \l__nicematrix_last_row_int = { -1 } { \bool_set_true:N \l__nicematrix_last_row_without_value_bool @@ -626,54 +650,62 @@ } } \__nicematrix_pre_array: - \dim_gzero_new:N \g__nicematrix_left_delim_dim - \dim_gzero_new:N \g__nicematrix_right_delim_dim + \dim_zero_new:N \l__nicematrix_left_delim_dim + \dim_zero_new:N \l__nicematrix_right_delim_dim \bool_if:NTF \l__nicematrix_NiceArray_bool { - \dim_gset:Nn \g__nicematrix_left_delim_dim { 2 \arraycolsep } - \dim_gset:Nn \g__nicematrix_right_delim_dim { 2 \arraycolsep } + \dim_gset:Nn \l__nicematrix_left_delim_dim { 2 \arraycolsep } + \dim_gset:Nn \l__nicematrix_right_delim_dim { 2 \arraycolsep } } { - \group_begin: - \dim_set_eq:NN \nulldelimiterspace \c_zero_dim \hbox_set:Nn \l_tmpa_box { \c_math_toggle_token \left #1 \vcenter to 3 cm { } \right. \c_math_toggle_token } - \dim_gset:Nn \g__nicematrix_left_delim_dim { \box_wd:N \l_tmpa_box } + \dim_set:Nn \l__nicematrix_left_delim_dim + { \box_wd:N \l_tmpa_box - \nulldelimiterspace } \hbox_set:Nn \l_tmpa_box { - \dim_set_eq:NN \nulldelimiterspace \c_zero_dim \c_math_toggle_token \left. \vcenter to 3 cm { } \right #2 \c_math_toggle_token } - \dim_gset:Nn \g__nicematrix_right_delim_dim { \box_wd:N \l_tmpa_box } - \group_end: + \dim_set:Nn \l__nicematrix_right_delim_dim + { \box_wd:N \l_tmpa_box - \nulldelimiterspace } } \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 \l__nicematrix_NiceArray_bool + \bool_if:nT { - \bool_if:NF \l__nicematrix_exterior_arraycolsep_bool - { \tl_put_left:Nn \l_tmpa_tl { @ { } } } + \l__nicematrix_NiceArray_bool + && ! \l__nicematrix_vlines_bool + && ! \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 \l__nicematrix_NiceArray_bool + \bool_if:nT { - \bool_if:NF \l__nicematrix_exterior_arraycolsep_bool - { \tl_put_right:Nn \l_tmpa_tl { @ { } } } + \l__nicematrix_NiceArray_bool + && ! \l__nicematrix_vlines_bool + && ! \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 + { + \dim_add:Nn \arraycolsep { 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 \c_math_toggle_token @@ -688,6 +720,7 @@ \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 } } \hbox_set_end: \int_compare:nNnT \l__nicematrix_last_row_int > { -2 } { @@ -700,6 +733,10 @@ } } } + \int_gset_eq:NN \c@jCol \g__nicematrix_col_total_int + \bool_if:nT \g__nicematrix_last_col_found_bool { \int_gdecr:N \c@jCol } + \int_gset_eq:NN \g__nicematrix_row_total_int \c@iRow + \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 @@ -707,24 +744,61 @@ } \bool_if:NTF \l__nicematrix_NiceArray_bool { - \int_compare:nNnTF \l__nicematrix_first_row_int = 0 - { - \str_if_eq:VnT \l__nicematrix_pos_env_str { t } - { - \box_move_up:nn { \g__nicematrix_dp_row_zero_dim + \g__nicematrix_ht_row_one_dim } - } + \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 ) + \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 + ) + \dim_gsub:Nn \g_tmpa_dim \pgf@y + \end { tikzpicture } + \int_compare:nNnT \l__nicematrix_first_row_int = 0 + { + \dim_gadd:Nn \g_tmpa_dim + { \g__nicematrix_ht_row_zero_dim + \g__nicematrix_dp_row_zero_dim } + } + \box_move_up:nn \g_tmpa_dim { \box_use_drop:N \l__nicematrix_the_array_box } } { - \int_compare:nNnT \l__nicematrix_last_row_int > 0 + \str_if_eq:VnTF \l__nicematrix_baseline_str { c } + { \box_use_drop:N \l__nicematrix_the_array_box } { - \str_if_eq:VnT \l__nicematrix_pos_env_str { b } + \str_if_eq:VnT \l__nicematrix_baseline_str { t } + { \str_set:Nn \l__nicematrix_baseline_str { 1 } } + \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 > \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 ) + \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 + ) + \dim_gsub:Nn \g_tmpa_dim \pgf@y + \end { tikzpicture } + \int_compare:nNnT \l__nicematrix_first_row_int = 0 { - \box_move_down:nn - { \g__nicematrix_ht_last_row_dim + \g__nicematrix_dp_ante_last_row_dim } + \dim_gadd:Nn \g_tmpa_dim + { \g__nicematrix_ht_row_zero_dim + \g__nicematrix_dp_row_zero_dim } } + \box_move_up:nn \g_tmpa_dim + { \box_use_drop:N \l__nicematrix_the_array_box } } } - { \box_use_drop:N \l__nicematrix_the_array_box } } { \int_compare:nNnTF \l__nicematrix_first_row_int = 0 @@ -757,25 +831,68 @@ \right #2 \c_math_toggle_token } - \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } - \box_set_dp:Nn \l_tmpa_box { \box_dp:N \l_tmpa_box + \l_tmpb_dim } - \box_use_drop:N \l_tmpa_box + \bool_if:NTF \l__nicematrix_max_delimiter_width_bool + { \__nicematrix_put_box_in_flow_bis:nn { #1 } { #2 } } + \__nicematrix_put_box_in_flow: } \bool_if:NT \g__nicematrix_last_col_found_bool + { \skip_horizontal:n { \g__nicematrix_width_last_col_dim + \arraycolsep } } + \__nicematrix_after_array: + } +\cs_new_protected:Npn \__nicematrix_put_box_in_flow: + { + \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } + \box_set_dp:Nn \l_tmpa_box { \box_dp:N \l_tmpa_box + \l_tmpb_dim } + \box_use_drop:N \l_tmpa_box + } +\cs_new_protected:Npn \__nicematrix_put_box_in_flow_bis:nn #1 #2 + { + \dim_zero_new:N \l__nicematrix_real_left_delim_dim + \dim_zero_new:N \l__nicematrix_real_right_delim_dim + \hbox_set:Nn \l_tmpb_box { - \skip_horizontal:n \g__nicematrix_width_last_col_dim - \skip_horizontal:n \arraycolsep + \c_math_toggle_token + \left #1 + \vcenter + { + \vbox_to_ht:nn + { \box_ht:N \l_tmpa_box + \box_dp:N \l_tmpa_box } + { } + } + \right . + \c_math_toggle_token } - \__nicematrix_after_array: + \dim_set:Nn \l__nicematrix_real_left_delim_dim + { \box_wd:N \l_tmpb_box - \nulldelimiterspace } + \hbox_set:Nn \l_tmpb_box + { + \c_math_toggle_token + \left . + \vbox_to_ht:nn + { \box_ht:N \l_tmpa_box + \box_dp:N \l_tmpa_box } + { } + \right #2 + \c_math_toggle_token + } + \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 } + \__nicematrix_put_box_in_flow: + \skip_horizontal:n { \l__nicematrix_right_delim_dim - \l__nicematrix_real_right_delim_dim } } \NewDocumentEnvironment { __nicematrix-normal-syntax } { } - { \exp_args:NV \__nicematrix_array: \l_tmpa_tl } { - \__nicematrix_create_row_of_col_nodes: + \peek_meaning_ignore_spaces:NTF \end + { \__nicematrix_analyze_end:Nn } + { \exp_args:NV \__nicematrix_array: \l_tmpa_tl } + } + { + \__nicematrix_create_col_nodes: \endarray } \NewDocumentEnvironment { __nicematrix-light-syntax } { b } { + \tl_if_empty:nT { #1 } { \__nicematrix_fatal:n { empty~environment } } \exp_args:NV \__nicematrix_array: \l_tmpa_tl \seq_gclear_new:N \g__nicematrix_rows_seq \tl_set_rescan:Nno \l__nicematrix_end_of_row_tl { } \l__nicematrix_end_of_row_tl @@ -783,7 +900,7 @@ \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 - \__nicematrix_create_row_of_col_nodes: + \__nicematrix_create_col_nodes: \endarray } { } @@ -801,72 +918,72 @@ { \\ \__nicematrix_line_with_light_syntax_i:n { #1 } } } \cs_new_protected:Npn \__nicematrix_cell_with_light_syntax:n #1 { & #1 } -\cs_new:Npn \__nicematrix_create_row_of_col_nodes: +\cs_new_protected:Npn \__nicematrix_analyze_end:Nn #1 #2 + { + \str_if_eq:VnT \g__nicematrix_name_env_str { #2 } + { \__nicematrix_fatal:n { empty~environment } } + \end { #2 } + } +\cs_new:Npn \__nicematrix_create_col_nodes: { - \bool_if:nT + \crcr + \int_compare:nNnT \c@iRow = 0 { \__nicematrix_fatal:n { Zero~row } } + \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 } { - \crcr - \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & } - \omit - \skip_horizontal:N \arraycolsep - \tikz [ remember~picture , overlay ] - \coordinate [ name = nm - \int_use:N \g__nicematrix_env_int - col - 0 ] ; - \skip_horizontal:n { - \arraycolsep } \bool_if:nTF { \l__nicematrix_auto_columns_width_bool && ! \l__nicematrix_block_auto_columns_width_bool } { - \dim_gset:Nn \g_tmpa_dim + \skip_gset:Nn \g_tmpa_skip { \g__nicematrix_max_cell_width_dim + 2 \arraycolsep } } { - \dim_gset:Nn \g_tmpa_dim + \skip_gset:Nn \g_tmpa_skip { \l__nicematrix_columns_width_dim + 2 \arraycolsep } } - \skip_horizontal:N \g_tmpa_dim - \tikz [ remember~picture , overlay ] - \coordinate [ name = nm - \int_use:N \g__nicematrix_env_int - col - 1 ] ; - \int_gset:Nn \g_tmpa_int 1 - \bool_if:nTF \g__nicematrix_last_col_found_bool - { \prg_replicate:nn { \g__nicematrix_col_total_int - 3 } } - { \prg_replicate:nn { \g__nicematrix_col_total_int - 2 } } - { - & - \omit - \int_gincr:N \g_tmpa_int - \skip_horizontal:N \g_tmpa_dim - \__nicematrix_create_col_node: - } - & - \omit - \int_gincr:N \g_tmpa_int - \skip_horizontal:N \g_tmpa_dim - \skip_horizontal:n { - \arraycolsep } - \__nicematrix_create_col_node: - \skip_horizontal:N \arraycolsep - } - } -\cs_new_protected:Npn \__nicematrix_create_col_node: - { - \tikz [ remember~picture , overlay ] - \coordinate - [ - name = nm - \int_use:N \g__nicematrix_env_int - - col - \int_use:N \g_tmpa_int - ] ; + } + { \skip_gset:Nn \g_tmpa_skip { 0 pt~plus 1 fill } } + \skip_horizontal:N \g_tmpa_skip + \hbox:n + { + \tikz [ remember~picture ] + \coordinate ( nm - \int_use:N \g__nicematrix_env_int - col - 2 ) ; + } + \int_gset:Nn \g_tmpa_int 1 + \bool_if:NTF \g__nicematrix_last_col_found_bool + { \prg_replicate:nn { \g__nicematrix_col_total_int - 2 } } + { \prg_replicate:nn { \g__nicematrix_col_total_int - 1 } } + { + & + \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 } + ) ; + } + \cr } \tl_const:Nn \c__nicematrix_preamble_first_col_tl { > { \__nicematrix_begin_of_row: - \hbox_set:Nw \l_tmpa_box + \hbox_set:Nw \l__nicematrix_cell_box \c_math_toggle_token \bool_if:NT \l__nicematrix_small_bool \scriptstyle \bool_if:nT @@ -886,12 +1003,12 @@ { \c_math_toggle_token \hbox_set_end: - \__nicematrix_actualization_for_first_and_last_row: + \__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_tmpa_box } + { \box_wd:N \l__nicematrix_cell_box } } \hbox_overlap_left:n { @@ -918,10 +1035,10 @@ 0 } ] - { \box_use:N \l_tmpa_box } ; + { \box_use_drop:N \l__nicematrix_cell_box } ; \skip_horizontal:n { - \g__nicematrix_left_delim_dim + + \l__nicematrix_left_delim_dim + \l__nicematrix_left_margin_dim + \l__nicematrix_extra_left_margin_dim } @@ -937,7 +1054,7 @@ \int_gincr:N \c@jCol \int_gset:Nn \g__nicematrix_col_total_int { \int_max:nn \g__nicematrix_col_total_int \c@jCol } - \hbox_set:Nw \l_tmpa_box + \hbox_set:Nw \l__nicematrix_cell_box \c_math_toggle_token \bool_if:NT \l__nicematrix_small_bool \scriptstyle \bool_if:nT @@ -957,19 +1074,19 @@ { \c_math_toggle_token \hbox_set_end: - \__nicematrix_actualization_for_first_and_last_row: + \__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_tmpa_box } + { \box_wd:N \l__nicematrix_cell_box } } \skip_horizontal:n { - 2 \arraycolsep } \hbox_overlap_right:n { \skip_horizontal:n { - \g__nicematrix_right_delim_dim + + \l__nicematrix_right_delim_dim + \l__nicematrix_right_margin_dim + \l__nicematrix_extra_right_margin_dim } @@ -996,54 +1113,54 @@ \int_use:N \c@jCol } ] - { \box_use:N \l_tmpa_box } ; + { \box_use_drop:N \l__nicematrix_cell_box } ; } } } \NewDocumentEnvironment { NiceArray } { } { \bool_set_true:N \l__nicematrix_NiceArray_bool - \str_if_empty:NT \g__nicematrix_type_env_str - { \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { NiceArray } } } + \str_if_empty:NT \g__nicematrix_name_env_str + { \str_gset:Nn \g__nicematrix_name_env_str { NiceArray } } \NiceArrayWithDelims . . } { \endNiceArrayWithDelims } \NewDocumentEnvironment { pNiceArray } { } { - \str_if_empty:NT \g__nicematrix_type_env_str - { \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { pNiceArray } } } + \str_if_empty:NT \g__nicematrix_name_env_str + { \str_gset:Nn \g__nicematrix_name_env_str { pNiceArray } } \__nicematrix_test_if_math_mode: \NiceArrayWithDelims ( ) } { \endNiceArrayWithDelims } \NewDocumentEnvironment { bNiceArray } { } { - \str_if_empty:NT \g__nicematrix_type_env_str - { \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { bNiceArray } } } + \str_if_empty:NT \g__nicematrix_name_env_str + { \str_gset:Nn \g__nicematrix_name_env_str { bNiceArray } } \__nicematrix_test_if_math_mode: \NiceArrayWithDelims [ ] } { \endNiceArrayWithDelims } \NewDocumentEnvironment { BNiceArray } { } { - \str_if_empty:NT \g__nicematrix_type_env_str - { \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { BNiceArray } } } + \str_if_empty:NT \g__nicematrix_name_env_str + { \str_gset:Nn \g__nicematrix_name_env_str { BNiceArray } } \__nicematrix_test_if_math_mode: \NiceArrayWithDelims \{ \} } { \endNiceArrayWithDelims } \NewDocumentEnvironment { vNiceArray } { } { - \str_if_empty:NT \g__nicematrix_type_env_str - { \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { vNiceArray } } } + \str_if_empty:NT \g__nicematrix_name_env_str + { \str_gset:Nn \g__nicematrix_name_env_str { vNiceArray } } \__nicematrix_test_if_math_mode: \NiceArrayWithDelims | | } { \endNiceArrayWithDelims } \NewDocumentEnvironment { VNiceArray } { } { - \str_if_empty:NT \g__nicematrix_type_env_str - { \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { VNiceArray } } } + \str_if_empty:NT \g__nicematrix_name_env_str + { \str_gset:Nn \g__nicematrix_name_env_str { VNiceArray } } \__nicematrix_test_if_math_mode: \NiceArrayWithDelims \| \| } @@ -1052,7 +1169,7 @@ { \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } } { - \str_gset:Nn \g__nicematrix_type_env_str { environment ~ { #1 NiceMatrix } } + \str_gset:Nn \g__nicematrix_name_env_str { #1 NiceMatrix } \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 } \begin { #1 NiceArray } { @@ -1123,25 +1240,11 @@ } } } -\cs_new_protected:Nn \__nicematrix_after_array: - { - \int_compare:nNnTF \c@iRow > 0 - \__nicematrix_after_array_i: - { - \__nicematrix_error:n { Zero~row } - \__nicematrix_restore_iRow_jCol: - } - } -\cs_new_protected:Nn \__nicematrix_after_array_i: +\cs_new_protected:Npn \__nicematrix_after_array: { \group_begin: \cs_if_exist:NT \tikz@library@external@loaded { \tikzset { external / export = false } } - \int_gset_eq:NN \c@jCol \g__nicematrix_col_total_int - \bool_if:nT \g__nicematrix_last_col_found_bool { \int_gdecr:N \c@jCol } - \int_gset_eq:NN \g__nicematrix_row_total_int \c@iRow - \int_compare:nNnT \l__nicematrix_last_row_int > { -1 } - { \int_gsub:Nn \c@iRow \c_one_int } \bool_if:NT \l__nicematrix_last_row_without_value_bool { \iow_now:Nn \@mainaux \ExplSyntaxOn @@ -1202,19 +1305,50 @@ name~prefix = nm - \int_use:N \g__nicematrix_env_int - } } + \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines: \cs_set_eq:NN \line \__nicematrix_line:nn \g__nicematrix_code_after_tl \tl_gclear:N \g__nicematrix_code_after_tl \group_end: - \str_gclear:N \g__nicematrix_type_env_str + \str_gclear:N \g__nicematrix_name_env_str \__nicematrix_restore_iRow_jCol: } -\cs_new_protected:Nn \__nicematrix_restore_iRow_jCol: +\cs_new_protected:Npn \__nicematrix_draw_vlines: + { + \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 } + { + \draw ( col - ##1 ) ++ ( 0 , \dim_use:N \l_tmpb_dim ) + -- ++ ( 0 , \dim_use:N \l_tmpa_dim ) ; + } + \end { tikzpicture } + \group_end: + } +\cs_new_protected:Npn \__nicematrix_restore_iRow_jCol: { \cs_if_exist:NT \theiRow { \int_gset_eq:NN \c@iRow \l__nicematrix_save_iRow_int } \cs_if_exist:NT \thejCol { \int_gset_eq:NN \c@jCol \l__nicematrix_save_jCol_int } } -\cs_new_protected:Nn \__nicematrix_find_extremities_of_line:nnnn +\cs_new_protected:Npn \__nicematrix_find_extremities_of_line:nnnn #1 #2 #3 #4 { \cs_set:cpn { __nicematrix _ dotted _ #1 - #2 } { } \int_set:Nn \l__nicematrix_initial_i_int { #1 } @@ -1342,23 +1476,23 @@ \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_initial_open_bool \__nicematrix_create_medium_nodes: \bool_if:NT \l__nicematrix_final_open_bool \__nicematrix_create_medium_nodes: } -\cs_new_protected:Nn \__nicematrix_retrieve_coords:nn +\cs_new_protected:Npn \__nicematrix_retrieve_coords:nn #1 #2 { \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 ] - \tikz@parse@node \pgfutil@firstofone + \__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 - \tikz@parse@node \pgfutil@firstofone + \__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 ) @@ -1367,76 +1501,44 @@ \end { tikzpicture } } \cs_generate_variant:Nn \__nicematrix_retrieve_coords:nn { x x } -\cs_new_protected:Nn \__nicematrix_adjust_with_col_nodes: +\cs_new_protected:Npn \__nicematrix_adjust_with_col_nodes: { \bool_if:NT \l__nicematrix_initial_open_bool { - \cs_if_exist:cT - { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - col - 0 } - { - \begin { tikzpicture } [ remember~picture ] - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - col - 0 ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \end { tikzpicture } - } + \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 { - \cs_if_exist:cT - { - pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - col - - \int_use:N \c@jCol - } - { - \begin { tikzpicture } [ remember~picture ] - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - col - \int_use:N \c@jCol ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \end { tikzpicture } - } + \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 } } } -\cs_new_protected:Nn \__nicematrix_draw_Ldots:nn +\cs_new_protected:Npn \__nicematrix_draw_Ldots:nn #1 #2 { \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 \c_one_int + \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1 \bool_if:NF \l__nicematrix_impossible_line_bool \__nicematrix_actually_draw_Ldots: } } -\cs_new_protected:Nn \__nicematrix_actually_draw_Ldots: +\cs_new_protected:Npn \__nicematrix_actually_draw_Ldots: { \__nicematrix_retrieve_coords:xx { \bool_if:NTF \l__nicematrix_initial_open_bool - { - \cs_if_exist:cTF - { - 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 - w - } - { - w.base~west } - { - medium.base~west } - } - { .base~east } + { - medium.base~west } + { .base~east } } { \bool_if:NTF \l__nicematrix_final_open_bool - { - \cs_if_exist:cTF - { - 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 - w - } - { - w.base~east } - { - medium.base~east } - } + { - medium.base~east } { .base~west } } \__nicematrix_adjust_with_col_nodes: @@ -1448,43 +1550,23 @@ \dim_gadd:Nn \g__nicematrix_y_final_dim { 0.53 pt } \__nicematrix_draw_tikz_line: } -\cs_new_protected:Nn \__nicematrix_draw_Cdots:nn +\cs_new_protected:Npn \__nicematrix_draw_Cdots:nn #1 #2 { \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 \c_one_int + \__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 - { - \cs_if_exist:cTF - { - 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 - w - } - { - w.mid~west } - { - medium.mid~west } - } + { - medium.mid~west } { .mid~east } } { \bool_if:NTF \l__nicematrix_final_open_bool - { - \cs_if_exist:cTF - { - 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 - w - } - { - w.mid~east } - { - medium.mid~east } - } + { - medium.mid~east } { .mid~west } } \__nicematrix_adjust_with_col_nodes: @@ -1496,12 +1578,12 @@ } } } -\cs_new_protected:Nn \__nicematrix_draw_Vdots:nn +\cs_new_protected:Npn \__nicematrix_draw_Vdots:nn #1 #2 { \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 } \c_one_int 0 + \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 0 \bool_if:NF \l__nicematrix_impossible_line_bool { \__nicematrix_retrieve_coords:xx @@ -1543,12 +1625,12 @@ } } } -\cs_new_protected:Nn \__nicematrix_draw_Ddots:nn +\cs_new_protected:Npn \__nicematrix_draw_Ddots:nn #1 #2 { \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 } \c_one_int \c_one_int + \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 1 \bool_if:NF \l__nicematrix_impossible_line_bool { \__nicematrix_retrieve_coords:xx @@ -1565,7 +1647,7 @@ \bool_if:NT \l__nicematrix_parallelize_diags_bool { \int_incr:N \l__nicematrix_ddots_int - \int_compare:nNnTF \l__nicematrix_ddots_int = \c_one_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 } @@ -1585,7 +1667,7 @@ } } } -\cs_new_protected:Nn \__nicematrix_draw_Iddots:nn +\cs_new_protected:Npn \__nicematrix_draw_Iddots:nn #1 #2 { \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { @@ -1607,7 +1689,7 @@ \bool_if:NT \l__nicematrix_parallelize_diags_bool { \int_incr:N \l__nicematrix_iddots_int - \int_compare:nNnTF \l__nicematrix_iddots_int = \c_one_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 } @@ -1629,7 +1711,7 @@ } \NewExpandableDocumentCommand \NiceMatrixLastEnv { } { \int_use:N \g__nicematrix_env_int } -\cs_new_protected:Nn \__nicematrix_draw_tikz_line: +\cs_new_protected:Npn \__nicematrix_draw_tikz_line: { \dim_zero_new:N \l__nicematrix_l_dim \dim_set:Nn \l__nicematrix_l_dim @@ -1680,7 +1762,7 @@ \int_set:Nn \l_tmpa_int { \dim_ratio:nn - { \l__nicematrix_l_dim - ( \l__nicematrix_dotted_lines_margin_dim * 2 ) } + { \l__nicematrix_l_dim - ( 2 \l__nicematrix_dotted_lines_margin_dim ) } \l__nicematrix_inter_dots_dim } } @@ -1706,7 +1788,7 @@ ( \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 } - { \l__nicematrix_l_dim * 2 } + { 2 \l__nicematrix_l_dim } * \l_tmpb_int } \dim_gadd:Nn \g__nicematrix_y_initial_dim @@ -1714,8 +1796,8 @@ ( \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 } - { \l__nicematrix_l_dim * 2 } * - \l_tmpb_int + { 2 \l__nicematrix_l_dim } + * \l_tmpb_int } \begin { tikzpicture } [ overlay ] \int_step_inline:nnn 0 \l_tmpa_int @@ -1735,7 +1817,7 @@ \cs_set_eq:NN \__nicematrix_vdots \vdots \cs_set_eq:NN \__nicematrix_ddots \ddots \cs_set_eq:NN \__nicematrix_iddots \iddots -\cs_new_protected:Nn \__nicematrix_add_to_empty_cells: +\cs_new_protected:Npn \__nicematrix_add_to_empty_cells: { \cs_gset:cpx { __nicematrix _ empty _ \int_use:N \c@iRow - \int_use:N \c@jCol } @@ -1771,7 +1853,7 @@ \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_iddots } \__nicematrix_add_to_empty_cells: } -\cs_new_protected:Nn \__nicematrix_Hspace: +\cs_new_protected:Npn \__nicematrix_Hspace: { \__nicematrix_add_to_empty_cells: \hspace @@ -1803,7 +1885,7 @@ { \tl_gput_right:Nx \g__nicematrix_Hdotsfor_lines_tl { - \__nicematrix_draw_Hdotsfor:nnn + \__nicematrix_Hdotsfor:nnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { #2 } @@ -1811,7 +1893,7 @@ \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } -\cs_new_protected:Nn \__nicematrix_draw_Hdotsfor:nnn +\cs_new_protected:Npn \__nicematrix_Hdotsfor:nnn #1 #2 #3 { \bool_set_false:N \l__nicematrix_initial_open_bool \bool_set_false:N \l__nicematrix_final_open_bool @@ -1827,7 +1909,7 @@ \__nicematrix_if_not_empty_cell:nnTF \l__nicematrix_initial_i_int \l_tmpa_int { \int_set:Nn \l__nicematrix_initial_j_int { #2 - 1 } } { - \int_set:Nn \l__nicematrix_initial_j_int {#2} + \int_set:Nn \l__nicematrix_initial_j_int { #2 } \bool_set_true:N \l__nicematrix_initial_open_bool } } @@ -1847,10 +1929,17 @@ } \bool_if:nT { \l__nicematrix_initial_open_bool || \l__nicematrix_final_open_bool } \__nicematrix_create_medium_nodes: - \__nicematrix_actually_draw_Ldots: + \group_begin: + \cs_set:Npn \__nicematrix_adjust_with_col_nodes: { } + \__nicematrix_actually_draw_Ldots: + \group_end: \int_step_inline:nnn { #2 } { #2 + #3 - 1 } { \cs_set:cpn { __nicematrix _ dotted _ #1 - ##1 } { } } } +\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 @@ -1862,7 +1951,7 @@ { \__nicematrix_double_int_eval:n #2 \q_stop } } } -\cs_new_protected:Nn \__nicematrix_line_i:nn +\cs_new_protected:Npn \__nicematrix_line_i:nn #1 #2 { \bool_if:NF \c__nicematrix_draft_bool { @@ -1881,10 +1970,10 @@ { \begin { tikzpicture } \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ; - \tikz@parse@node \pgfutil@firstofone ( i ) + \__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 - \tikz@parse@node \pgfutil@firstofone ( f ) + \__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 } @@ -1896,171 +1985,83 @@ } } } -\bool_if:NTF \c__nicematrix_draft_bool - { \cs_set_eq:NN \__nicematrix_dotfill: \prg_do_nothing: } +\cs_set_eq:NN \OnlyMainNiceMatrix \use:n +\cs_new_protected:Npn \__nicematrix_OnlyMainNiceMatrix:n #1 { - \cs_set:Npn \__nicematrix_dotfill: + \int_compare:nNnTF \l__nicematrix_first_col_int = 0 + { \__nicematrix_OnlyMainNiceMatrix_i:n { #1 } } { - \bool_if:NT \l__nicematrix_small_bool - { \dim_set:Nn \l__nicematrix_inter_dots_dim { 0.25 em } } - \cleaders - \hbox_to_wd:nn - { \l__nicematrix_inter_dots_dim } + \int_compare:nNnTF \c@jCol = 0 { - \c_math_toggle_token - \bool_if:NT \l__nicematrix_small_bool \scriptstyle - \hss . \hss - \c_math_toggle_token + \int_compare:nNnF \c@iRow = { -1 } + { \int_compare:nNnF \c@iRow = { \l__nicematrix_last_row_int - 1 } { #1 } } } - \hfill + { \__nicematrix_OnlyMainNiceMatrix_i:n { #1 } } } } +\cs_new_protected:Npn \__nicematrix_OnlyMainNiceMatrix_i:n #1 + { + \int_compare:nNnF \c@iRow = 0 + { \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int { #1 } } + } +\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: { - \noalign + \bool_if:NF \c__nicematrix_draft_bool { - \bool_gset_true:N \g__nicematrix_large_nodes_bool - \cs_if_exist:cTF { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } - { \dim_set_eq:Nc \l_tmpa_dim { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } } - { \dim_set:Nn \l_tmpa_dim { 5 mm } } - \hbox_overlap_right:n - { - \bool_if:nT - { - \l__nicematrix_NiceArray_bool - && - ! \l__nicematrix_exterior_arraycolsep_bool - && - \int_compare_p:nNn \l__nicematrix_first_col_int > 0 - } - { \skip_horizontal:n { - \arraycolsep } } - \hbox_to_wd:nn - { - \l_tmpa_dim + 2 \arraycolsep - - \l__nicematrix_left_margin_dim - \l__nicematrix_right_margin_dim - } - \__nicematrix_dotfill: - } + \noalign{ \skip_vertical:n { 2 \l__nicematrix_radius_dim } } + \__nicematrix_hdottedline_i: } } -\cs_new_protected:Nn \__nicematrix_vdottedline:n +\cs_new_protected:Npn \__nicematrix_hdottedline_i: { - \int_compare:nNnTF #1 = 0 - { \__nicematrix_error:n { Use~of~:~in~first~position } } - { - \bool_if:NF \c__nicematrix_draft_bool - { - \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 - \cs_if_exist:cTF - { pgf@sh@ns@nm -\int_use:N \g__nicematrix_env_int - col - #1 } - { - \begin { tikzpicture } [ remember~picture ] - \tikz@parse@node\pgfutil@firstofone - ( col - #1 ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_final_dim \pgf@y - \end { tikzpicture } - \dim_gset:Nn \g__nicematrix_y_initial_dim { - \c_max_dim } - \int_step_inline:nn \c@jCol - { - \begin { tikzpicture } [ remember~picture ] - \tikz@parse@node\pgfutil@firstofone - ( 1 - ##1 . north~east ) - \dim_gset:Nn \g__nicematrix_y_initial_dim - { \dim_max:nn \g__nicematrix_y_initial_dim \pgf@y } - \end { tikzpicture } - } - } - { - \begin { tikzpicture } [ remember~picture ] - \tikz@parse@node\pgfutil@firstofone - ( 1 - #1 - large .north~east ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_initial_dim \pgf@y - \tikz@parse@node\pgfutil@firstofone - ( \int_use:N \c@iRow - #1 - large .south~east ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \dim_gset:Nn \g__nicematrix_y_final_dim \pgf@y - \end { tikzpicture } - \cs_if_exist:cT - { pgf@sh@ns@nm -\int_use:N \g__nicematrix_env_int - 1 - #1 - w } - { - \begin { tikzpicture } [ remember~picture ] - \tikz@parse@node\pgfutil@firstofone - ( 1 - #1 - w .north~east ) - \dim_gset:Nn \g__nicematrix_x_initial_dim \pgf@x - \tikz@parse@node\pgfutil@firstofone - ( \int_use:N \c@iRow - #1 - w .south~east ) - \dim_gset:Nn \g__nicematrix_x_final_dim \pgf@x - \end { tikzpicture } - \dim_gadd:Nn \g__nicematrix_x_initial_dim \arraycolsep - \dim_gadd:Nn \g__nicematrix_x_final_dim \arraycolsep - } - } - \__nicematrix_draw_tikz_line: - } - } + \tl_gput_right:Nx \g__nicematrix_code_after_tl + { \__nicematrix_hdottedline:n { \int_use:N \c@iRow } } } -\cs_new_protected:Npn \__nicematrix_vline: +\cs_new_protected:Npn \__nicematrix_hdottedline:n #1 { - \int_compare:nNnTF \l__nicematrix_first_col_int = 0 - { - \int_compare:nNnTF \c@jCol = 0 - { - \int_compare:nNnTF \l__nicematrix_first_row_int = 0 - { - \int_compare:nNnF \c@iRow = 0 - { - \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - \__nicematrix_vline_i: - } - } - { - \int_compare:nNnF \c@iRow = 0 - { - \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - \__nicematrix_vline_i: - } - } - } - { - \int_compare:nNnF \c@iRow = 0 - { - \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - \__nicematrix_vline_i: - } - } - } - { - \int_compare:nNnTF \c@jCol = 0 - { - \int_compare:nNnF \c@iRow = { -1 } - { - \int_compare:nNnF \c@iRow = { \l__nicematrix_last_row_int - 1 } - \__nicematrix_vline_i: - } - } - { - \int_compare:nNnF \c@iRow = 0 - { - \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - \__nicematrix_vline_i: - } - } - } + \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_set_eq:NN \__nicematrix_vline_i: \vline -\cs_set_eq:NN \OnlyMainNiceMatrix \use:n -\cs_new:Npn \__nicematrix_OnlyMainNiceMatrix:n #1 +\cs_new_protected:Npn \__nicematrix_vdottedline:n #1 { - \int_compare:nNnF \c@iRow = 0 - { \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int { #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 } } } + } +\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_new:N \l__nicematrix_block_auto_columns_width_bool \keys_define:nn { NiceMatrix / NiceMatrixBlock } @@ -2121,10 +2122,11 @@ { \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: - { \cs_if_exist:cT + { + \cs_if_exist:cT { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: } { - \tikz@parse@node \pgfutil@firstofone + \__nicematrix_extract_coords:w ( nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: .south~west ) \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _min_dim} @@ -2134,7 +2136,7 @@ \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _min_dim} { \dim_min:vn { l__nicematrix_column _ \__nicematrix_j: _min_dim } \pgf@x } } - \tikz@parse@node \pgfutil@firstofone + \__nicematrix_extract_coords:w ( nm - \int_use:N \g__nicematrix_env_int - \__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 } @@ -2166,7 +2168,6 @@ \tikzset { name~suffix = -large } \__nicematrix_create_nodes: \end { tikzpicture } - \__nicematrix_compute_width_of_array: \cs_set_protected:Npn \__nicematrix_create_large_nodes: { } \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: { \__nicematrix_create_medium_nodes: } @@ -2180,9 +2181,7 @@ \__nicematrix_computations_for_large_nodes: \tikzset { name~suffix = -large } \__nicematrix_create_nodes: - \__nicematrix_compute_width_of_array: \end { tikzpicture } - \__nicematrix_compute_width_of_array: \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: { } @@ -2256,33 +2255,14 @@ \g__nicematrix_multicolumn_sizes_seq \__nicematrix_node_for_multicolumn:nn } -\cs_new_protected:Npn \__nicematrix_compute_width_of_array: - { - \begin { tikzpicture } [ remember~picture , overlay ] - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - 1 - 1 - large .north~west ) - \dim_gset:Nn \g_tmpa_dim \pgf@x - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - 1 - - \int_use:N \c@jCol - large .north~east ) - \dim_gset:Nn \g_tmpb_dim \pgf@x - \end { tikzpicture } - \iow_now:Nn \@mainaux \ExplSyntaxOn - \iow_now:Nx \@mainaux - { - \cs_gset:cpn { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } - { \dim_eval:n { \g_tmpb_dim - \g_tmpa_dim } } - } - \iow_now:Nn \@mainaux \ExplSyntaxOff - } -\cs_new_protected:Npn \__nicematrix_extract_coords: #1 - #2 \q_stop +\cs_new_protected:Npn \__nicematrix_extract_coords_values: #1 - #2 \q_stop { \cs_set:Npn \__nicematrix_i: { #1 } \cs_set:Npn \__nicematrix_j: { #2 } } -\cs_new_protected:Nn \__nicematrix_node_for_multicolumn:nn +\cs_new_protected:Npn \__nicematrix_node_for_multicolumn:nn #1 #2 { - \__nicematrix_extract_coords: #1 \q_stop + \__nicematrix_extract_coords_values: #1 \q_stop \coordinate ( __nicematrix~south~west ) at ( \dim_use:c { l__nicematrix_column _ \__nicematrix_j: _ min _ dim } , @@ -2305,34 +2285,40 @@ ] ; } -\NewDocumentCommand \__nicematrix_Block: { m D < > { } m } - { \__nicematrix_Block_i #1 \q_stop { #2 } { #3 } } -\cs_new:Npn \__nicematrix_Block_i #1-#2 \q_stop { \__nicematrix_Block_ii:nnnn { #1 } { #2 } } -\cs_new:Npn \__nicematrix_Block_ii:nnnn #1 #2 #3 #4 +\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 { - \int_compare:nNnT { #1 } = 1 - { - \begin { tikzpicture } [ remember~picture , baseline ] - \coordinate - ( nm - \int_use:N \g__nicematrix_env_int - - Block - - \int_use:N \c@iRow - - \int_use:N \c@jCol ) ; - \end { tikzpicture } - } - \bool_gset_true:N \g__nicematrix_medium_nodes_bool \tl_gput_left:Nx \g__nicematrix_code_after_tl { - \__nicematrix_Block_iii:nnnnn + \__nicematrix_Block_iii:nnnnnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { \int_eval:n { \c@iRow + #1 - 1 } } { \int_eval:n { \c@jCol + #2 - 1 } } - \exp_not:n { { #3 $ #4 $ } } + { #3 } + \exp_not:n { { #4 $ #5 $ } } } + \cs_set_eq:NN \Block \__nicematrix_Block_error:nn + } +\cs_new:Npn \__nicematrix_Block_error:nn #1 #2 + { + \__nicematrix_error:n { Second~Block } + \cs_set_eq:NN \Block \use:nn + } +\keys_define:nn { NiceMatrix / Block } + { + tikz .tl_set:N = \l__nicematrix_tikz_tl , + tikz .value_required:n = true , + white .bool_set:N = \l__nicematrix_white_bool , + white .default:n = true , + white .value_forbidden:n = true , } -\cs_new_protected:Npn \__nicematrix_Block_iii:nnnnn #1 #2 #3 #4 #5 +\cs_new_protected:Npn \__nicematrix_Block_iii:nnnnnn #1 #2 #3 #4 #5 #6 { + \group_begin: + \keys_set:nn { NiceMatrix / Block } { #5 } \bool_if:nTF { \int_compare_p:nNn { #3 } > \c@iRow @@ -2340,35 +2326,61 @@ } { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } } { - \int_compare:nNnTF { #1 } = { #3 } - { - \begin { tikzpicture } - \tikz@parse@node \pgfutil@firstofone (Block-#1-#2) - \dim_set:Nn \l_tmpa_dim \pgf@y - \node + \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 } ) + \dim_set_eq:NN \l_tmpa_dim \pgf@y + \__nicematrix_extract_coords:w ( col - \int_eval:n { #4 + 1 } ) + \dim_set_eq:NN \l_tmpb_dim \pgf@x + \coordinate ( two ) at ( \l_tmpb_dim , \l_tmpa_dim ) ; + \bool_if:NT \l__nicematrix_white_bool + { + \fill [ white , line~width = 0 pt] + ( [ yshift = -\arrayrulewidth ] one ) + rectangle + ( [ xshift = -\arrayrulewidth ] two ) ; + } + \use:x + { + \exp_not:N \node [ - fit = ( #1 - #2 - medium . north~west ) - ( #3 - #4 - medium . south~east ) , + fit = ( one ) ( two ) , inner~sep = 0 pt , + \l__nicematrix_tikz_tl ] - (#1-#2) { } ; - \tikz@parse@node \pgfutil@firstofone (#1-#2) - \path (\pgf@x,\l_tmpa_dim) node [ anchor = base ] { #5 } ; - \end { tikzpicture } - } + } + (#1-#2-block) { } ; + \bool_if:NT \l__nicematrix_medium_nodes_bool { - \begin { tikzpicture } \node [ fit = ( #1 - #2 - medium . north~west ) ( #3 - #4 - medium . south~east ) , inner~sep = 0 pt , ] - (#1-#2) { } ; - \node at (#1-#2.center) { #5 } ; - \end { tikzpicture } + (#1-#2-block-medium) { } ; + } + \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 } ; } + { \node at (#1-#2-block.center) { \box_use_drop:N \l__nicematrix_cell_box } ; } + \end { tikzpicture } } + \group_end: } \cs_set_protected:Npn \__nicematrix_renew_matrix: { @@ -2424,8 +2436,7 @@ { \cs_set_protected:cpn { #1 AutoNiceMatrix } { - \str_gset:Nx \g__nicematrix_type_env_str - { command ~ \c_backslash_str #1 AutoNiceMatrix } + \str_gset:Nx \g__nicematrix_name_env_str { #1 AutoNiceMatrix } \AutoNiceMatrixWithDelims { #2 } { #3 } } } @@ -2446,6 +2457,69 @@ \__nicematrix_msg_redirect_name:nn { Obsolete~environment } { none } } \ProcessKeysOptions { NiceMatrix / Package } +\cs_new_protected:Npn \__nicematrix_convert_to_str_seq:N #1 + { + \seq_clear:N \l_tmpa_seq + \seq_map_inline:Nn #1 + { + \seq_put_left:Nx \l_tmpa_seq { \tl_to_str:n { ##1 } } + } + \seq_set_eq:NN #1 \l_tmpa_seq + } +\cs_new_protected:Npn \__nicematrix_set_seq_of_str_from_clist:Nn #1 #2 + { + \seq_set_from_clist:Nn #1 { #2 } + \__nicematrix_convert_to_str_seq:N #1 + } +\__nicematrix_set_seq_of_str_from_clist:Nn \c__nicematrix_types_of_matrix_seq + { + NiceMatrix , + pNiceMatrix , bNiceMatrix , vNiceMatrix, BNiceMatrix, VNiceMatrix + } +\cs_new_protected:Npn \__nicematrix_error_too_much_cols: + { + \seq_if_in:NVTF \c__nicematrix_types_of_matrix_seq \g__nicematrix_name_env_str + { + \int_compare:nNnTF \l__nicematrix_last_col_int = { -1 } + { \__nicematrix_fatal:n { too~much~cols~for~matrix } } + { \__nicematrix_fatal:n { too~much~cols~for~matrix~with~last~col } } + } + { \__nicematrix_fatal:n { too~much~cols~for~array } } + } +\__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~ + 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_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).~ + This~error~is~fatal. + } +\__nicematrix_msg_new:nn { bad~value~for~baseline } + { + The~value~you~gave~to~'baseline'~(\int_use:N \l_tmpa_int)~is~not~ + valid.\\ + If~you~go~on,~a~value~of~1~will~be~used. + } +\__nicematrix_msg_new:nn { Second~Block } + { + You~can't~use~\token_to_str:N \Block\ twice~in~the~same~cell~of~the~array.\\ + If~you~go~on,~this~command~(and~the~other)~will~be~ignored. + } +\__nicematrix_msg_new:nn { empty~environment } + { Your~\__nicematrix_full_name_env:\ is~empty.~This~error~is~fatal. } \__nicematrix_msg_new:nn { unknown~cell~for~line~in~code-after } { Your~command~\token_to_str:N\line\{#1\}\{#2\}~in~the~'code-after'~ @@ -2454,21 +2528,21 @@ } \__nicematrix_msg_new:nn { last-col~non~empty~for~NiceArray } { - In~the~\g__nicematrix_type_env_str,~you~must~use~the~option~ + In~the~\__nicematrix_full_name_env:,~you~must~use~the~option~ 'last-col'~without~value.\\ However,~you~can~go~on~for~this~time~ (the~value~'\l_keys_value_tl'~will~be~ignored). } \__nicematrix_msg_new:nn { last-col~empty~for~NiceMatrix } { - In~the~\g__nicematrix_type_env_str, you~can't~use~the~option~ + In~the~\__nicematrix_full_name_env:, you~can't~use~the~option~ 'last-col'~without~value.~You~must~give~the~number~of~that~last~column.\\ If~you~go~on~this~option~will~be~ignored. } \__nicematrix_msg_new:nn { Block~too~large } { You~try~to~draw~a~block~in~the~cell~#1-#2~of~your~matrix~but~the~matrix~is~ - too~small~for~that~block.\\ + too~small~for~that~block. \\ If~you~go~on,~this~command~will~be~ignored. } \__nicematrix_msg_new:nn { Impossible~line } @@ -2480,7 +2554,7 @@ \__nicematrix_msg_new:nn { Wrong~last~row } { You~have~used~'last-row=\int_use:N \l__nicematrix_last_row_int'~but~your~ - \g__nicematrix_type_env_str\ seems~to~have~\int_use:N \c@iRow \ rows.~ + \__nicematrix_full_name_env:\ seems~to~have~\int_use:N \c@iRow \ rows.~ If~you~go~on,~the~value~of~\int_use:N \c@iRow \ will~be~used~for~ last~row.~You~can~avoid~this~problem~by~using~'last-row'~ without~value~(more~compilations~might~be~necessary). @@ -2492,28 +2566,18 @@ } \__nicematrix_msg_new:nn { Outside~math~mode } { - The~\g__nicematrix_type_env_str\ can~be~used~only~in~math~mode~ + The~\__nicematrix_full_name_env:\ can~be~used~only~in~math~mode~ (and~not~in~\token_to_str:N \vcenter).\\ This~error~is~fatal. } -\__nicematrix_msg_new:nn { Option~Transparent~suppressed } - { - The~option~'Transparent'~has~been~renamed~'transparent'.\\ - If~you~go~on~this~command~will~be~ignored. - } -\__nicematrix_msg_new:nn { Option~RenewMatrix~suppressed } - { - The~option~'RenewMatrix'~has~been~renamed~'renew-matrix'.\\ - If~you~go~on~this~command~will~be~ignored. - } \__nicematrix_msg_new:nn { Bad~value~for~letter~for~dotted~lines } { - The~value~of~key~'\tl_use:N\l_keys_key_tl'~must~be~of~length~1.\\ + The~value~of~key~'\tl_use:N\l_keys_key_str'~must~be~of~length~1.\\ If~you~go~on,~it~will~be~ignored. } \__nicematrix_msg_new:nnn { Unknown~key~for~NiceMatrixOptions } { - The~key~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~command~ + The~key~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~command~ \token_to_str:N \NiceMatrixOptions. \\ If~you~go~on,~it~will~be~ignored. \\ For~a~list~of~the~available~keys,~type~H~<return>. @@ -2532,6 +2596,7 @@ end-of-row,~ exterior-arraycolsep,~ hlines,~ + hvlines,~ left-margin,~ letter-for-dotted-lines,~ light-syntax,~ @@ -2541,11 +2606,12 @@ renew-matrix,~ right-margin,~ small,~ - and~transparent + transparent~ + and~vlines. } \__nicematrix_msg_new:nnn { Unknown~option~for~NiceArray } { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ + The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~ \{NiceArray\}. \\ If~you~go~on,~it~will~be~ignored. \\ For~a~list~of~the~available~options,~type~H~<return>. @@ -2553,6 +2619,7 @@ { The~available~options~are~(in~alphabetic~order):~ b,~ + baseline,~ c,~ code-after,~ code-for-first-col,~ @@ -2570,6 +2637,7 @@ first-col,~ first-row,~ hlines,~ + hvlines,~ last-col,~ last-row,~ left-margin,~ @@ -2580,12 +2648,13 @@ renew-dots,~ right-margin,~ small,~ - and~t. + t,~ + and~vlines. } \__nicematrix_msg_new:nnn { Unknown~option~for~NiceMatrix } { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~ - \g__nicematrix_type_env_str. \\ + The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~ + \__nicematrix_full_name_env:. \\ If~you~go~on,~it~will~be~ignored. \\ For~a~list~of~the~available~options,~type~H~<return>. } @@ -2607,6 +2676,7 @@ first-col,~ first-row,~ hlines,~ + hvlines,~ last-col,~ last-row,~ left-margin,~ @@ -2616,7 +2686,8 @@ parallelize-diags,~ renew-dots,~ right-margin,~ - and~small. + small,~ + and~vlines. } \__nicematrix_msg_new:nnn { Duplicate~name } { @@ -2638,67 +2709,61 @@ } \__nicematrix_msg_new:nn { Zero~row } { - There~is~a~problem.~Maybe~your~\g__nicematrix_type_env_str\ is~empty.~ - Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~and~R~in~the~preamble~ - of~your~environment. \\ - If~you~go~on,~the~result~may~be~incorrect. + There~is~a~problem.~Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~ + 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~\g__nicematrix_type_env_str. \\ + 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.~We~should~use~#1~instead.~ - However,~you~can~go~on~for~this~time.~ - If~you~don't~want~to~see~this~error~again,~you~should~load~'nicematrix'~ - with~the~option~'obsolete-environments'. + The~environment~\{\@currenvir\}~is~obsolete.~You~should~use~#1~instead.~ + However,~it's~still~possible~to~use~the~environment~\{\@currenvir\}~(for~ + a~few~months)~by~loading~'nicematrix'~with~the~option~ + 'obsolete-environments'. } \NewDocumentEnvironment { pNiceArrayC } { } { - \__nicematrix_error:nn { Obsolete~environment } - { the~option~'last-col' } + \__nicematrix_fatal:nn { Obsolete~environment } { the~option~'last-col' } \int_zero:N \l__nicematrix_last_col_int \pNiceArray } { \endpNiceArray } \NewDocumentEnvironment { bNiceArrayC } { } { - \__nicematrix_error:nn { Obsolete~environment } - { the~option~'last-col' } + \__nicematrix_fatal:nn { Obsolete~environment } { the~option~'last-col' } \int_zero:N \l__nicematrix_last_col_int \bNiceArray } { \endbNiceArray } \NewDocumentEnvironment { BNiceArrayC } { } { - \__nicematrix_error:nn { Obsolete~environment } - { the~option~'last-col' } + \__nicematrix_fatal:nn { Obsolete~environment } { the~option~'last-col' } \int_zero:N \l__nicematrix_last_col_int \BNiceArray } { \endBNiceArray } \NewDocumentEnvironment { vNiceArrayC } { } { - \__nicematrix_error:nn { Obsolete~environment } - { the~option~'last-col' } + \__nicematrix_fatal:nn { Obsolete~environment } { the~option~'last-col' } \int_zero:N \l__nicematrix_last_col_int \vNiceArray } { \endvNiceArray } \NewDocumentEnvironment { VNiceArrayC } { } { - \__nicematrix_error:nn { Obsolete~environment } - { the~option~'last-col' } + \__nicematrix_fatal:nn { Obsolete~environment } { the~option~'last-col' } \int_zero:N \l__nicematrix_last_col_int \VNiceArray } { \endVNiceArray } \NewDocumentEnvironment { pNiceArrayRC } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~options~'last-col'~and~'first-row' } \int_zero:N \l__nicematrix_last_col_int \int_zero:N \l__nicematrix_first_row_int @@ -2707,7 +2772,7 @@ { \endpNiceArray } \NewDocumentEnvironment { bNiceArrayRC } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~options~'last-col'~and~'first-row' } \int_zero:N \l__nicematrix_last_col_int \int_zero:N \l__nicematrix_first_row_int @@ -2716,7 +2781,7 @@ { \endbNiceArray } \NewDocumentEnvironment { BNiceArrayRC } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~options~'last-col'~and~'first-row' } \int_zero:N \l__nicematrix_last_col_int \int_zero:N \l__nicematrix_first_row_int @@ -2725,7 +2790,7 @@ { \endBNiceArray } \NewDocumentEnvironment { vNiceArrayRC } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~options~'last-col'~and~'first-row' } \int_zero:N \l__nicematrix_last_col_int \int_zero:N \l__nicematrix_first_row_int @@ -2734,7 +2799,7 @@ { \endvNiceArray } \NewDocumentEnvironment { VNiceArrayRC } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~options~'last-col'~and~'first-row' } \int_zero:N \l__nicematrix_last_col_int \int_zero:N \l__nicematrix_first_row_int @@ -2743,7 +2808,7 @@ { \endVNiceArray } \NewDocumentEnvironment { NiceArrayCwithDelims } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~option~'last-col' } \int_zero:N \l__nicematrix_last_col_int \NiceArrayWithDelims @@ -2751,7 +2816,7 @@ { \endNiceArrayWithDelims } \NewDocumentEnvironment { NiceArrayRCwithDelims } { } { - \__nicematrix_error:nn { Obsolete~environment } + \__nicematrix_fatal:nn { Obsolete~environment } { the~options~'last-col'~and~'first-row' } \int_zero:N \l__nicematrix_last_col_int \int_zero:N \l__nicematrix_first_row_int |