From e2c2e92594542226ff8816e672ef05dc43a41217 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 15 Aug 2019 20:22:51 +0000 Subject: nicematrix (15aug19) git-svn-id: svn://tug.org/texlive/trunk@51885 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 1391 +++++++++++++------- 1 file changed, 932 insertions(+), 459 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index a1e3830d1cf..a8c8baaf489 100644 --- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty +++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty @@ -18,8 +18,8 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{2.3} -\def\myfiledate{2019/07/18} +\def\myfileversion{3.0} +\def\myfiledate{2019/08/15} \RequirePackage{tikz} \usetikzlibrary{fit} \RequirePackage{expl3}[2019/02/15] @@ -36,8 +36,10 @@ \RequirePackage { array } \RequirePackage { amsmath } \RequirePackage { xparse } [ 2018-10-17 ] -\cs_new_protected:Nn \__nm_error:n { \msg_error:nn { nicematrix } { #1 } } -\cs_new_protected:Nn \__nm_error:nn { \msg_error:nn { nicematrix } { #1 } { #2 } } +\cs_new_protected:Npn \__nm_error:n { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \__nm_error:nn { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \__nm_fatal:n { \msg_fatal:nn { nicematrix } } +\cs_new_protected:Npn \__nm_fatal:nn { \msg_fatal:nn { nicematrix } } \cs_new_protected:Npn \__nm_msg_new:nn { \msg_new:nnn { nicematrix } } \cs_new_protected:Npn \__nm_msg_new:nnn { \msg_new:nnnn { nicematrix } } \cs_new_protected:Npn \__nm_msg_redirect_name:nn @@ -53,19 +55,6 @@ { The~compilation~is~in~draft~mode:~the~dotted~lines~won't~be~drawn. } \bool_if:NT \c__nm_draft_bool { \msg_warning:nn { nicematrix } { Draft~mode } } -\AtBeginDocument - { - \clist_map_inline:nn - { - siunitx - } - { - \bool_new:c { c__nm_#1_loaded_bool } - \@ifpackageloaded { #1 } - { \bool_set_true:c { c__nm_#1_loaded_bool } } - { } - } - } \ProvideDocumentCommand \iddots { } { \mathinner @@ -81,28 +70,72 @@ \int_new:N \g__nm_env_int \dim_new:N \l__nm_columns_width_dim \seq_new:N \g__nm_names_seq -\int_new:N \l__nm_nb_first_row_int -\int_set:Nn \l__nm_nb_first_row_int 1 -\bool_new:N \l__nm_exterior_column_bool -\bool_new:N \g__nm_exterior_column_found_bool -\bool_new:N \l__nm_in_NiceArray_bool + +\bool_new:N \l__nm_in_env_bool +\bool_new:N \l__nm_NiceArray_bool +\bool_new:N \g__nm_NiceArray_bool +\cs_new_protected:Npn \__nm_test_if_math_mode: + { + \if_mode_math: \else: + \__nm_fatal:n { Outside~math~mode } + \fi: + } +\__nm_msg_new:nn { Yet~in~env } + { + Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ + nested.\\ + This~error~is~fatal. + } +\__nm_msg_new:nn { Outside~math~mode } + { + The~environment~\{\@currenvir\}~can~be~used~only~in~math~mode~ + (and~not~in~\token_to_str:N \vcenter).\\ + This~error~is~fatal. + } +\bool_new:N \c__nm_colortbl_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { colortbl } + { \bool_set_true:N \c__nm_colortbl_loaded_bool } + { } + } +\int_new:N \l__nm_first_row_int +\int_set:Nn \l__nm_first_row_int 1 +\int_new:N \g__nm_first_row_int +\int_new:N \l__nm_first_col_int +\int_set:Nn \l__nm_first_col_int 1 +\int_new:N \g__nm_first_col_int +\int_new:N \l__nm_last_row_int +\int_set:Nn \l__nm_last_row_int { -2 } +\int_new:N \g__nm_last_row_int +\bool_new:N \l__nm_last_row_without_value_bool +\bool_new:N \g__nm_last_row_without_value_bool +\bool_new:N \l__nm_last_col_bool +\bool_new:N \g__nm_last_col_found_bool +\bool_new:N \c__nm_siunitx_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { siunitx } + { \bool_set_true:N \c__nm_siunitx_loaded_bool } + { } + } \cs_set_protected:Npn \__nm_adapt_S_column: { \bool_if:NT \c__nm_siunitx_loaded_bool { \group_begin: - \@temptokena = { } - \cs_set_eq:NN \NC@find \prg_do_nothing: - \NC@rewrite@S { } - \exp_args:NNo \tl_gset:Nn \g_tmpa_tl { \tex_the:D \@temptokena } + \@temptokena = { } + \cs_set_eq:NN \NC@find \prg_do_nothing: + \NC@rewrite@S { } + \tl_gset:NV \g_tmpa_tl \@temptokena \group_end: \tl_new:N \c__nm_table_collect_begin_tl \tl_set:Nx \l_tmpa_tl { \tl_item:Nn \g_tmpa_tl 2 } \tl_gset:Nx \c__nm_table_collect_begin_tl { \tl_item:Nn \l_tmpa_tl 1 } \tl_new:N \c__nm_table_print_tl \tl_gset:Nx \c__nm_table_print_tl { \tl_item:Nn \g_tmpa_tl { -1 } } + \cs_gset_eq:NN \__nm_adapt_S_column: \prg_do_nothing: } - \cs_gset_eq:NN \__nm_adapt_S_column: \prg_do_nothing: } \cs_new_protected:Npn \__nm_renew_NC@rewrite@S: { @@ -125,7 +158,7 @@ } \__nm_msg_new:nn { Option~RenewMatrix~suppressed } { - The~option~'RenewMatrix~has~been~renamed~'renew-matrix'.\\ + The~option~'RenewMatrix'~has~been~renamed~'renew-matrix'.\\ However,~you~can~go~on~for~this~time. } \str_new:N \l__nm_pos_env_str @@ -136,15 +169,16 @@ \bool_new:N \l__nm_hlines_bool \bool_new:N \l__nm_nullify_dots_bool \bool_new:N \l__nm_auto_columns_width_bool -\tl_new:N \l__nm_code_for_last_col_tl -\str_new:N \g__nm_name_str \str_new:N \l__nm_name_str +\str_new:N \g__nm_name_str \bool_new:N \l__nm_extra_nodes_bool \bool_new:N \g__nm_extra_nodes_bool \dim_new:N \l__nm_left_margin_dim \dim_new:N \l__nm_right_margin_dim \dim_new:N \g__nm_left_margin_dim \dim_new:N \g__nm_right_margin_dim +\dim_new:N \g__nm_width_last_col_dim +\dim_new:N \g__nm_width_first_col_dim \dim_new:N \l__nm_extra_left_margin_dim \dim_new:N \l__nm_extra_right_margin_dim \dim_new:N \g__nm_extra_right_margin_dim @@ -163,8 +197,23 @@ left-margin .default:n = \arraycolsep , right-margin .dim_set:N = \l__nm_right_margin_dim , right-margin .default:n = \arraycolsep , + margin .meta:n = { left-margin = #1 , right-margin = #1 } , + margin .default:n = \arraycolsep , extra-left-margin .dim_set:N = \l__nm_extra_left_margin_dim , - extra-right-margin .dim_set:N = \l__nm_extra_right_margin_dim + extra-right-margin .dim_set:N = \l__nm_extra_right_margin_dim , + extra-margin .meta:n = + { extra-left-margin = #1 , extra-right-margin = #1 } , + } +\keys_define:nn { NiceMatrix / Code } + { + code-for-first-col .tl_set:N = \l__nm_code_for_first_col_tl , + code-for-first-col .value_required:n = true , + code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , + code-for-last-col .value_required:n = true , + code-for-first-row .tl_set:N = \l__nm_code_for_first_row_tl , + code-for-first-row .value_required:n = true , + code-for-last-row .tl_set:N = \l__nm_code_for_last_row_tl , + code-for-last-row .value_required:n = true , } \keys_define:nn { NiceMatrix / Env } { @@ -174,10 +223,11 @@ { \dim_set:Nn \l__nm_columns_width_dim { #1 } } , columns-width .value_required:n = true , name .code:n = - \seq_if_in:NnTF \g__nm_names_seq { #1 } + \str_set:Nn \l_tmpa_str { #1 } + \seq_if_in:NVTF \g__nm_names_seq \l_tmpa_str { \__nm_error:nn { Duplicate~name } { #1 } } - { \seq_gput_left:Nn \g__nm_names_seq { #1 } } - \str_set:Nn \l__nm_name_str { #1 } , + { \seq_gput_left:NV \g__nm_names_seq \l_tmpa_str } + \str_set_eq:NN \l__nm_name_str \l_tmpa_str , name .value_required:n = true , code-after .tl_gset:N = \g__nm_code_after_tl , code-after .initial:n = \c_empty_tl , @@ -185,26 +235,27 @@ } \keys_define:nn { NiceMatrix } { - NiceMatrixOptions .inherit:n = NiceMatrix / Global , - NiceMatrix .inherit:n = + NiceMatrixOptions .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Code } , - NiceArray .inherit:n = + NiceMatrix .inherit:n = { NiceMatrix / Global , NiceMatrix / Env } , - NiceArrayC .inherit:n = + NiceArray .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env - } , - NiceArrayRC .inherit:n = + NiceMatrix / Env , + NiceMatrix / Code + } , + pNiceArray .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Env , + NiceMatrix / Code } } \keys_define:nn { NiceMatrix / NiceMatrixOptions } @@ -218,10 +269,6 @@ Transparent .code:n = \__nm_error:n { Option~Transparent~suppressed } \__nm_renew_matrix: \bool_set_true:N \l__nm_renew_dots_bool , - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - code-for-first-row .tl_set:N = \l__nm_code_for_first_row_tl , - code-for-first-row .value_required:n = true , exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool , exterior-arraycolsep .default:n = true , columns-width .code:n = @@ -231,10 +278,20 @@ allow-duplicate-names .code:n = \__nm_msg_redirect_name:nn { Duplicate~name } { none } , allow-duplicate-names .value_forbidden:n = true , - letter-for-dotted-lines .tl_set:N = \l__nm_letter_for_dotted_lines_str , + letter-for-dotted-lines .code:n = + { + \int_compare:nTF { \tl_count:n { #1 } = \c_one_int } + { \tl_set:Nx \l__nm_letter_for_dotted_lines_str { #1 } } + { \__nm_error:n { Bad~value~for~letter~for~dotted~lines } } + } , letter-for-dotted-lines .value_required:n = true , letter-for-dotted-lines .initial:n = \c_colon_str , unknown .code:n = \__nm_error:n { Unknown~key~for~NiceMatrixOptions } } +\__nm_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.\\ + If~you~go~on,~it~will~be~ignored. + } \__nm_msg_new:nnn { Unknown~key~for~NiceMatrixOptions } { The~key~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~command~ @@ -245,7 +302,10 @@ { The~available~keys~are~(in~alphabetic~order):~ allow-duplicate-names,~ + code-for-first-col,~ + code-for-first-row,~ code-for-last-col,~ + code-for-last-row,~ exterior-arraycolsep,~ hlines,~ left-margin,~ @@ -307,6 +367,11 @@ c .code:n = \str_set:Nn \l__nm_pos_env_str c , t .code:n = \str_set:Nn \l__nm_pos_env_str t , b .code:n = \str_set:Nn \l__nm_pos_env_str b , + first-col .code:n = \int_zero:N \l__nm_first_col_int , + last-col .bool_set:N = \l__nm_last_col_bool , + first-row .code:n = \int_zero:N \l__nm_first_row_int , + last-row .int_set:N = \l__nm_last_row_int , + last-row .default:n = -1 , unknown .code:n = \__nm_error:n { Unknown~option~for~NiceArray } } \__nm_msg_new:nnn { Unknown~option~for~NiceArray } @@ -321,8 +386,12 @@ b,~ c,~ code-after,~ - create-extra-nodes,~ + code-for-first-col,~ + code-for-first-row,~ + code-for-last-col,~ + code-for-last-row,~ columns-width,~ + create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ hlines,~ @@ -334,35 +403,97 @@ right-margin,~ and~t. } +\keys_define:nn { NiceMatrix / pNiceArray } + { + first-col .code:n = \int_zero:N \l__nm_first_col_int , + last-col .bool_set:N = \l__nm_last_col_bool , + first-row .code:n = \int_zero:N \l__nm_first_row_int , + last-row .int_set:N = \l__nm_last_row_int , + last-row .default:n = -1 , + unknown .code:n = \__nm_error:n { Unknown~option~for~pNiceArray } + } +\__nm_msg_new:nnn { Unknown~option~for~pNiceArray } + { + The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ + \{\@currenvir\}. \\ + If~you~go~on,~it~will~be~ignored. \\ + For~a~list~of~the~available~options,~type~H~. + } + { + The~available~options~are~(in~alphabetic~order):~ + code-after,~ + code-for-first-col,~ + code-for-first-row,~ + code-for-last-col,~ + code-for-last-row,~ + columns-width,~ + create-extra-nodes,~ + extra-left-margin,~ + extra-right-margin,~ + first-col,~ + first-row,~ + last-col,~ + last-row,~ + hlines,~ + left-margin,~ + name,~ + nullify-dots,~ + parallelize-diags,~ + renew-dots,~ + and~right-margin. + } \cs_new_protected:Nn \__nm_Cell: { - \int_gincr:N \g__nm_column_int - \int_compare:nNnT \g__nm_column_int = 1 { \int_gincr:N \g__nm_row_int } - \int_gset:Nn \g__nm_column_total_int - { \int_max:nn \g__nm_column_total_int \g__nm_column_int } + \int_gincr:N \g__nm_col_int + \int_compare:nNnT \g__nm_col_int = \c_one_int + { + \int_compare:nNnT \l__nm_first_col_int = \c_one_int + \__nm_begin_of_row: + } + \int_gset:Nn \g__nm_col_total_int + { \int_max:nn \g__nm_col_total_int \g__nm_col_int } \hbox_set:Nw \l_tmpa_box \c_math_toggle_token - \int_compare:nNnT \g__nm_row_int = \c_zero_int + \int_compare:nNnTF \g__nm_row_int = \c_zero_int \l__nm_code_for_first_row_tl + { + \int_compare:nNnT \g__nm_row_int = \l__nm_last_row_int + \l__nm_code_for_last_row_tl + } } -\cs_new_protected:Nn \__nm_end_Cell: +\cs_new_protected:Nn \__nm_begin_of_row: + { + \int_gincr:N \g__nm_row_int + \dim_gset_eq:NN \g__nm_dp_ante_last_row_dim \g__nm_dp_last_row_dim + \dim_gzero:N \g__nm_dp_last_row_dim + \dim_gzero:N \g__nm_ht_last_row_dim + } +\cs_new_protected:Npn \__nm_actualization_for_first_and_last_row: { - \c_math_toggle_token - \hbox_set_end: - \dim_gset:Nn \g__nm_max_cell_width_dim - { \dim_max:nn \g__nm_max_cell_width_dim { \box_wd:N \l_tmpa_box } } \int_compare:nNnT \g__nm_row_int = \c_zero_int { - \dim_gset:Nn \g__nm_max_dp_row_zero_dim - { \dim_max:nn \g__nm_max_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } - \dim_gset:Nn \g__nm_max_ht_row_zero_dim - { \dim_max:nn \g__nm_max_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_dp_row_zero_dim + { \dim_max:nn \g__nm_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_ht_row_zero_dim + { \dim_max:nn \g__nm_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } } \int_compare:nNnT \g__nm_row_int = \c_one_int { - \dim_gset:Nn \g__nm_max_ht_row_one_dim - { \dim_max:nn \g__nm_max_ht_row_one_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_ht_row_one_dim + { \dim_max:nn \g__nm_ht_row_one_dim { \box_ht:N \l_tmpa_box } } } + \dim_gset:Nn \g__nm_ht_last_row_dim + { \dim_max:nn \g__nm_ht_last_row_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_dp_last_row_dim + { \dim_max:nn \g__nm_dp_last_row_dim { \box_dp:N \l_tmpa_box } } + } +\cs_new_protected:Nn \__nm_end_Cell: + { + \c_math_toggle_token + \hbox_set_end: + \dim_gset:Nn \g__nm_max_cell_width_dim + { \dim_max:nn \g__nm_max_cell_width_dim { \box_wd:N \l_tmpa_box } } + \__nm_actualization_for_first_and_last_row: \tikz [ remember~picture , @@ -375,44 +506,20 @@ anchor = base , name = nm - \int_use:N \g__nm_env_int - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int , + \int_use:N \g__nm_col_int , alias = \str_if_empty:NF \l__nm_name_str { \l__nm_name_str - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int + \int_use:N \g__nm_col_int } ] \bgroup \box_use:N \l_tmpa_box \egroup ; } -\NewDocumentEnvironment { NiceMatrix } { ! O { } } - { - \keys_set:nn { NiceMatrix / NiceMatrix } { #1 } - \str_set:Nn \l__nm_pos_env_str c - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \NiceArray { * \c@MaxMatrixCols C } - } - { - \endarray - \skip_horizontal:n - { \g__nm_right_margin_dim + \g__nm_extra_right_margin_dim - \arraycolsep } - } \cs_generate_variant:Nn \dim_set:Nn { N x } -\__nm_msg_new:nn { Yet~in~NiceArray } - { - Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ - nested.~You~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~ - result. - } -\__nm_msg_new:nn { Outside~math~mode } - { - The~environment~\{\@currenvir\}~can~be~used~only~in~math~mode~ - (and~not~in~\token_to_str:N \vcenter).\_ - If~you~go~on,~you~will~have~other~errors. - } \cs_new_protected:Nn \__nm_renewcolumntype:nn { \newcolumntype #1 [ 2 ] @@ -453,13 +560,13 @@ node~contents = { } , name = nm - \int_use:N \g__nm_env_int - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int - w, + \int_use:N \g__nm_col_int - w, alias = \str_if_empty:NF \l__nm_name_str { \l__nm_name_str - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int - w + \int_use:N \g__nm_col_int - w } , inner~sep = \c_zero_dim , fit = (__nm~south~west) (__nm~north~east) @@ -468,30 +575,51 @@ } } } -\cs_new_protected:Npn \__nm_test_if_math_mode: +\bool_if:NTF \c__nm_draft_bool + { \cs_set_protected:Npn \__nm_instruction_of_type:n #1 { } } { - \ifmmode \else - \__nm_error:n { Outside~math~mode } - \fi + \cs_new_protected:Npn \__nm_instruction_of_type:n #1 + { + \tl_gput_right:Nx \g__nm_lines_to_draw_tl + { + \use:c { __nm _ draw _ #1 : nn } + { \int_use:N \g__nm_row_int } + { \int_use:N \g__nm_col_int } + } + } } -\NewDocumentEnvironment { NiceArray } { O { } m ! O { } } +\cs_new_protected:Npn \__nm_array: + { + \bool_if:NTF \c__nm_revtex_bool + { + \cs_set_eq:NN \@acoll \@arrayacol + \cs_set_eq:NN \@acolr \@arrayacol + \cs_set_eq:NN \@acol \@arrayacol + \cs_set:Npn \@halignto { } + \@array@array + } + \array + [ \l__nm_pos_env_str ] + } +\cs_new:Npn \__nm_everycr: + { \noalign { \__nm_everycr_i: } } +\cs_new_protected:Npn \__nm_everycr_i: + { + \int_gzero:N \g__nm_col_int + \bool_if:NT \l__nm_hlines_bool + { + \int_compare:nNnT \g__nm_row_int > { -1 } + { + \int_compare:nNnF \g__nm_row_int = \g__nm_last_row_int + { + \hrule \@height \arrayrulewidth + \skip_vertical:n { - \arrayrulewidth } + } + } + } + } +\cs_new_protected:Npn \__nm_pre_array: { - \__nm_adapt_S_column: - \__nm_test_if_math_mode: - \bool_if:NT \l__nm_in_NiceArray_bool - { \__nm_error:n { Yet~in~NiceArray } } - \bool_set_true:N \l__nm_in_NiceArray_bool - \cs_if_exist:NT \tikz@library@external@loaded - { \tikzset { external / export = false } } - \group_insert_after:N \__nm_after_array: - \tl_gclear_new:N \g__nm_lines_to_draw_tl - \int_gincr:N \g__nm_env_int - \bool_if:NF \l__nm_block_auto_columns_width_bool - { \dim_gzero_new:N \g__nm_max_cell_width_dim } - \dim_gzero_new:N \g__nm_max_dp_row_zero_dim - \dim_gzero_new:N \g__nm_max_ht_row_zero_dim - \dim_gzero_new:N \g__nm_max_ht_row_one_dim - \keys_set:nn { NiceMatrix / NiceArray } { #1 , #3 } \bool_if:NT \l__nm_auto_columns_width_bool { \group_insert_after:N \__nm_write_max_cell_width: @@ -514,24 +642,24 @@ \dim_gset_eq:NN \g__nm_left_margin_dim \l__nm_left_margin_dim \dim_gset_eq:NN \g__nm_right_margin_dim \l__nm_right_margin_dim \dim_gset_eq:NN \g__nm_extra_right_margin_dim \l__nm_extra_right_margin_dim + \int_gset_eq:NN \g__nm_last_row_int \l__nm_last_row_int \tl_gset_eq:NN \g__nm_name_str \l__nm_name_str + \int_gset_eq:NN \g__nm_first_row_int \l__nm_first_row_int + \int_gset_eq:NN \g__nm_first_col_int \l__nm_first_col_int + \bool_gset_eq:NN \g__nm_NiceArray_bool \l__nm_NiceArray_bool + \bool_gset_eq:NN \g__nm_last_row_without_value_bool + \l__nm_last_row_without_value_bool \cs_set:Npn \ialign { - \everycr + \bool_if:NTF \c__nm_colortbl_loaded_bool { - \noalign + \CT@everycr { - \int_gzero:N \g__nm_column_int - \bool_if:NT \l__nm_hlines_bool - { - \int_compare:nNnT \g__nm_row_int > { -1 } - { - \hrule \@height \arrayrulewidth - \skip_vertical:n { - \arrayrulewidth } - } - } + \noalign { \global\let\CT@row@color\relax } + \__nm_everycr: } } + { \everycr { \__nm_everycr: } } \tabskip = \c_zero_skip \cs_set:Npn \ialign { @@ -552,24 +680,6 @@ \newcolumntype C { w c { \dim_use:N \l__nm_columns_width_dim } } \newcolumntype R { w r { \dim_use:N \l__nm_columns_width_dim } } } - \cs_set_eq:NN \NC@find@w \relax - \cs_set_eq:NN \NC@find@W \relax - \__nm_renewcolumntype:nn w { } - \__nm_renewcolumntype:nn W { \cs_set_eq:NN \hss \hfil } - \exp_args:Nx \newcolumntype \l__nm_letter_for_dotted_lines_str - { - ! - { - \skip_horizontal:n { 0.53 pt } - \bool_gset_true:N \g__nm_extra_nodes_bool - \int_compare:nNnT \g__nm_column_int > \g__nm_last_vdotted_col_int - { - \int_gset_eq:NN \g__nm_last_vdotted_col_int \g__nm_column_int - \tl_gput_right:Nx \g__nm_code_after_tl - { \__nm_vdottedline:n { \int_use:N \g__nm_column_int } } - } - } - } \cs_set_eq:NN \Ldots \__nm_Ldots \cs_set_eq:NN \Cdots \__nm_Cdots \cs_set_eq:NN \Vdots \__nm_Vdots @@ -577,7 +687,7 @@ \cs_set_eq:NN \Iddots \__nm_Iddots \cs_set_eq:NN \hdottedline \__nm_hdottedline: \cs_set_eq:NN \Hspace \__nm_Hspace: - \cs_set_eq:NN \Hdotsfor \__nm_Hdotsfor + \cs_set_eq:NN \Hdotsfor \__nm_Hdotsfor: \cs_set_eq:NN \multicolumn \__nm_multicolumn:nnn \bool_if:NT \l__nm_renew_dots_bool { @@ -587,39 +697,424 @@ \cs_set_eq:NN \ddots \__nm_Ddots \cs_set_eq:NN \iddots \__nm_Iddots \cs_set_eq:NN \dots \__nm_Ldots - \cs_set_eq:NN \hdotsfor \__nm_Hdotsfor + \cs_set_eq:NN \hdotsfor \__nm_Hdotsfor: } - \bool_if:NT \c__nm_siunitx_loaded_bool \__nm_renew_NC@rewrite@S: \seq_gclear_new:N \g__nm_empty_cells_seq \seq_gclear_new:N \g__nm_multicolumn_cells_seq \seq_gclear_new:N \g__nm_multicolumn_sizes_seq \int_gzero_new:N \g__nm_row_int - \int_gset:Nn \g__nm_row_int { \l__nm_nb_first_row_int - 1 } - \int_gzero_new:N \g__nm_column_int - \int_gzero_new:N \g__nm_column_total_int + \int_gset:Nn \g__nm_row_int { \l__nm_first_row_int - 1 } + \int_gzero_new:N \g__nm_row_total_int + \int_gzero_new:N \g__nm_col_int + \int_gzero_new:N \g__nm_col_total_int + \cs_set_eq:NN \@ifnextchar \new@ifnextchar + \cs_set_eq:NN \NC@find@w \relax + \cs_set_eq:NN \NC@find@W \relax + \__nm_renewcolumntype:nn w { } + \__nm_renewcolumntype:nn W { \cs_set_eq:NN \hss \hfil } + \dim_gzero_new:N \g__nm_dp_row_zero_dim + \dim_gzero_new:N \g__nm_ht_row_zero_dim + \dim_gzero_new:N \g__nm_ht_row_one_dim + \dim_gzero_new:N \g__nm_dp_ante_last_row_dim + \dim_gzero_new:N \g__nm_ht_last_row_dim + \dim_gzero_new:N \g__nm_dp_last_row_dim + \exp_args:Nx \newcolumntype \l__nm_letter_for_dotted_lines_str + { + ! + { + \skip_horizontal:n { 0.53 pt } + \bool_gset_true:N \g__nm_extra_nodes_bool + \int_compare:nNnT \g__nm_col_int > \g__nm_last_vdotted_col_int + { + \int_gset_eq:NN \g__nm_last_vdotted_col_int \g__nm_col_int + \tl_gput_right:Nx \g__nm_code_after_tl + { \__nm_vdottedline:n { \int_use:N \g__nm_col_int } } + } + } + } \int_gzero_new:N \g__nm_last_vdotted_col_int + \bool_if:NT \c__nm_siunitx_loaded_bool \__nm_renew_NC@rewrite@S: \int_gset:Nn \g__nm_last_vdotted_col_int { -1 } - \cs_set_eq:NN \@ifnextchar \new@ifnextchar - \bool_if:NF \l__nm_exterior_arraycolsep_bool - { \skip_horizontal:n { - \arraycolsep } } + \bool_gset_false:N \g__nm_last_col_found_bool + } +\NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } } + { + \__nm_adapt_S_column: + \__nm_test_if_math_mode: + \bool_if:NT \l__nm_in_env_bool { \__nm_fatal:n { Yet~in~env } } + \bool_set_true:N \l__nm_in_env_bool + \cs_if_exist:NT \tikz@library@external@loaded + { \tikzset { external / export = false } } + \group_insert_after:N \__nm_after_array: + \tl_gclear_new:N \g__nm_lines_to_draw_tl + \int_gincr:N \g__nm_env_int + \bool_if:NF \l__nm_block_auto_columns_width_bool + { \dim_gzero_new:N \g__nm_max_cell_width_dim } + \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nm_vline: } + \bool_if:NTF \l__nm_NiceArray_bool + { \keys_set:nn { NiceMatrix / NiceArray } } + { \keys_set:nn { NiceMatrix / pNiceArray } } + { #3 , #5 } + \int_compare:nNnT \l__nm_last_row_int = { -1 } + { + \bool_set_true:N \l__nm_last_row_without_value_bool + \str_if_empty:NTF \g__nm_name_str + { + \cs_if_exist:cT { __nm_last_row_ \int_use:N \g__nm_env_int } + { + \int_set:Nn \l__nm_last_row_int + { \use:c { __nm_last_row_ \int_use:N \g__nm_env_int } } + } + } + { + \cs_if_exist:cT { __nm_last_row_ \g__nm_name_str } + { + \int_set:Nn \l__nm_last_row_int + { \use:c { __nm_last_row_ \g__nm_name_str } } + } + } + } + \__nm_pre_array: + \dim_zero_new:N \g__nm_left_delim_dim + \dim_zero_new:N \g__nm_right_delim_dim + \bool_if:NTF \l__nm_NiceArray_bool + { + \dim_gset:Nn \g__nm_left_delim_dim { 2 \arraycolsep } + \dim_gset:Nn \g__nm_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 1 cm { } \right. + \c_math_toggle_token + + } + \dim_gset:Nn \g__nm_left_delim_dim { \box_wd:N \l_tmpa_box } + \hbox_set:Nn \l_tmpa_box + { + \dim_set_eq:NN \nulldelimiterspace \c_zero_dim + \c_math_toggle_token + \left. \vcenter to 1 cm { } \right #2 + \c_math_toggle_token + } + \dim_gset:Nn \g__nm_right_delim_dim { \box_wd:N \l_tmpa_box } + \group_end: + } + \box_clear_new:N \l__nm_the_array_box + \tl_set:Nn \l_tmpa_tl { #4 } + \int_compare:nNnTF \l__nm_first_col_int = \c_zero_int + { \tl_put_left:NV \l_tmpa_tl \c__nm_preamble_first_col_tl } + { + \bool_if:NT \l__nm_NiceArray_bool + { + \bool_if:NF \l__nm_exterior_arraycolsep_bool + { \tl_put_left:Nn \l_tmpa_tl { @ { } } } + } + } + \bool_if:NTF \l__nm_last_col_bool + { \tl_put_right:NV \l_tmpa_tl \c__nm_preamble_last_col_tl } + { + \bool_if:NT \l__nm_NiceArray_bool + { + \bool_if:NF \l__nm_exterior_arraycolsep_bool + { \tl_put_right:Nn \l_tmpa_tl { @ { } } } + } + } + \hbox_set:Nw \l__nm_the_array_box + \skip_horizontal:n \l__nm_left_margin_dim + \skip_horizontal:n \l__nm_extra_left_margin_dim + \c_math_toggle_token + \exp_args:NV \__nm_array: \l_tmpa_tl + } + { + \endarray + \c_math_toggle_token + \skip_horizontal:n \g__nm_right_margin_dim + \skip_horizontal:n \g__nm_extra_right_margin_dim + \hbox_set_end: + \int_compare:nNnTF \l__nm_first_row_int = \c_zero_int + { + \dim_compare:nNnTF + { \g__nm_ht_row_one_dim + \g__nm_dp_row_zero_dim + \lineskiplimit } + > \baselineskip + { + \dim_set:Nn \l_tmpa_dim + { + \g__nm_ht_row_one_dim + \g__nm_dp_row_zero_dim + \lineskip + + \g__nm_ht_row_zero_dim - \g__nm_ht_row_one_dim + } + } + { + \dim_set:Nn \l_tmpa_dim + { \baselineskip + \g__nm_ht_row_zero_dim - \g__nm_ht_row_one_dim } + } + } + { \dim_zero:N \l_tmpa_dim } + \int_compare:nNnTF \l__nm_last_row_int > { -2 } + { + \dim_compare:nNnTF + { + \g__nm_ht_last_row_dim + \g__nm_dp_ante_last_row_dim + \lineskiplimit + } + > + \baselineskip + { + \dim_set:Nn \l_tmpb_dim + { + \g__nm_ht_last_row_dim + \g__nm_dp_ante_last_row_dim + \lineskip + + \g__nm_dp_last_row_dim - \g__nm_dp_ante_last_row_dim + } + } + { + \dim_set:Nn \l_tmpb_dim + { + \baselineskip + + \g__nm_dp_last_row_dim - \g__nm_dp_ante_last_row_dim + } + } + } + { \dim_zero:N \l_tmpb_dim } + \int_compare:nNnT \g__nm_first_col_int = \c_zero_int + { + \skip_horizontal:n \arraycolsep + \skip_horizontal:n \g__nm_width_first_col_dim + } + \bool_if:NTF \g__nm_NiceArray_bool + { + \int_compare:nNnT \g__nm_first_row_int = \c_zero_int + { + \str_if_eq:VnTF \l__nm_pos_env_str { t } + { + \box_move_up:nn + { \l_tmpa_dim - \g__nm_ht_row_zero_dim + \g__nm_ht_row_one_dim } + } + } + { + \bool_if:NT \g__nm_last_row_int + { + \str_if_eq:VnT \l__nm_pos_env_str { b } + { + \box_move_down:nn + { + \l_tmpb_dim + - \g__nm_dp_last_row_dim + \g__nm_dp_ante_last_row_dim + } + } + } + } + { \box_use_drop:N \l__nm_the_array_box } + } + { + \hbox_set:Nn \l_tmpa_box + { + \c_math_toggle_token + \left #1 + \vcenter + { + \skip_vertical:n { - \l_tmpa_dim } + \hbox:n + { + \skip_horizontal:n { - \arraycolsep } + \box_use_drop:N \l__nm_the_array_box + \skip_horizontal:n { - \arraycolsep } + } + \skip_vertical:n { - \l_tmpb_dim } + } + \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:NT \g__nm_last_col_found_bool + { + \skip_horizontal:n \g__nm_width_last_col_dim + \skip_horizontal:n \arraycolsep + } + } +\tl_const:Nn \c__nm_preamble_first_col_tl + { + > + { + \__nm_begin_of_row: + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token + \l__nm_code_for_first_col_tl + } + l + < + { + \c_math_toggle_token + \hbox_set_end: + \__nm_actualization_for_first_and_last_row: + \dim_gset:Nn \g__nm_width_first_col_dim + { + \dim_max:nn + \g__nm_width_first_col_dim + { \box_wd:N \l_tmpa_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__nm_env_int - + \int_use:N \g__nm_row_int - + 0 , + alias = + \str_if_empty:NF \l__nm_name_str + { + \l__nm_name_str - + \int_use:N \g__nm_row_int - + 0 + } + ] + { \box_use:N \l_tmpa_box } ; + \skip_horizontal:n + { + \g__nm_left_delim_dim + + \l__nm_left_margin_dim + + \l__nm_extra_left_margin_dim + } + } + \skip_horizontal:n { - 2 \arraycolsep } + } + } +\tl_const:Nn \c__nm_preamble_last_col_tl + { + > + { + \bool_gset_true:N \g__nm_last_col_found_bool + \int_gincr:N \g__nm_col_int + \int_gset:Nn \g__nm_col_total_int + { \int_max:nn \g__nm_col_total_int \g__nm_col_int } + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token + \l__nm_code_for_last_col_tl + } + l + < + { + \c_math_toggle_token + \hbox_set_end: + \__nm_actualization_for_first_and_last_row: + \dim_gset:Nn \g__nm_width_last_col_dim + { + \dim_max:nn + \g__nm_width_last_col_dim + { \box_wd:N \l_tmpa_box } + } + \skip_horizontal:n { - 2 \arraycolsep } + \hbox_overlap_right:n + { + \skip_horizontal:n + { + \g__nm_right_delim_dim + + \l__nm_right_margin_dim + + \l__nm_extra_right_margin_dim + } + \tikz + [ + remember~picture , + inner~sep = \c_zero_dim , + minimum~width = \c_zero_dim , + baseline + ] + \node + [ + anchor = base , + name = + nm - + \int_use:N \g__nm_env_int - + \int_use:N \g__nm_row_int - + \int_use:N \g__nm_col_int , + alias = + \str_if_empty:NF \l__nm_name_str + { + \l__nm_name_str - + \int_use:N \g__nm_row_int - + \int_use:N \g__nm_col_int + } + ] + { \box_use:N \l_tmpa_box } ; + } + } + } +\NewDocumentEnvironment { NiceArray } { } + { + \bool_set_true:N \l__nm_NiceArray_bool + \NiceArrayWithDelims . . + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { pNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims ( ) + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { bNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims [ ] + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { BNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims \{ \} + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { vNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims | | + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { VNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims \| \| + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { NiceMatrix } { ! O { } } + { + \__nm_test_if_math_mode: + \bool_if:NT \l__nm_in_env_bool { \__nm_fatal:n { Yet~in~env } } + \bool_set_true:N \l__nm_in_env_bool + \cs_if_exist:NT \tikz@library@external@loaded + { \tikzset { external / export = false } } + \group_insert_after:N \__nm_after_array: + \tl_gclear_new:N \g__nm_lines_to_draw_tl + \int_gincr:N \g__nm_env_int + \bool_if:NF \l__nm_block_auto_columns_width_bool + { \dim_gzero_new:N \g__nm_max_cell_width_dim } + \keys_set:nn { NiceMatrix / NiceMatrix } { #1 } + \__nm_pre_array: + \skip_horizontal:n { - \arraycolsep } \skip_horizontal:n \l__nm_left_margin_dim \skip_horizontal:n \l__nm_extra_left_margin_dim - \bool_if:NTF \c__nm_revtex_bool - { - \cs_set_eq:NN \@acoll \@arrayacol - \cs_set_eq:NN \@acolr \@arrayacol - \cs_set_eq:NN \@acol \@arrayacol - \cs_set:Npn \@halignto { } - \@array@array - } - \array - [ \l__nm_pos_env_str ] { #2 } + \str_set:Nn \l__nm_pos_env_str c + \bool_set_false:N \l__nm_exterior_arraycolsep_bool + \__nm_array: { * \c@MaxMatrixCols C } } - { \endarray - \bool_if:NF \l__nm_exterior_arraycolsep_bool - { \skip_horizontal:n { - \arraycolsep } } - \skip_horizontal:n \g__nm_right_margin_dim - \skip_horizontal:n \g__nm_extra_right_margin_dim + { + \endarray + \skip_horizontal:n { - \arraycolsep } + \skip_horizontal:n \g__nm_right_margin_dim + \skip_horizontal:n \g__nm_extra_right_margin_dim } \NewDocumentEnvironment { pNiceMatrix } { } { @@ -645,7 +1140,7 @@ \left\lvert \begin{NiceMatrix} } { \end{NiceMatrix} \right\rvert } -\NewDocumentEnvironment { VNiceMatrix } {} +\NewDocumentEnvironment { VNiceMatrix } { } { \__nm_test_if_math_mode: \left\lVert \begin{NiceMatrix} @@ -696,19 +1191,6 @@ } } } -\bool_if:NTF \c__nm_draft_bool - { \cs_set_protected:Npn \__nm_instruction_of_type:n #1 { } } - { - \cs_new_protected:Npn \__nm_instruction_of_type:n #1 - { - \tl_gput_right:Nx \g__nm_lines_to_draw_tl - { - \exp_not:c { __nm _ draw _ #1 : nn } - { \int_use:N \g__nm_row_int } - { \int_use:N \g__nm_column_int } - } - } - } \cs_new_protected:Nn \__nm_after_array: { \int_compare:nNnTF \g__nm_row_int > \c_zero_int @@ -718,7 +1200,7 @@ \__nm_msg_new:nn { Zero~row } { There~is~a~problem.~Maybe~your~environment~\{\@currenvir\}~is~empty.~ - Maybe~you~have~used~L,~C~and~R~instead~of~l,~c~and~r~in~the~preamble~ + 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. } @@ -727,9 +1209,29 @@ \group_begin: \cs_if_exist:NT \tikz@library@external@loaded { \tikzset { external / export = false } } - \int_gset_eq:NN \g__nm_column_int \g__nm_column_total_int - \bool_if:nT { \l__nm_exterior_column_bool && \g__nm_exterior_column_found_bool } - { \int_gdecr:N \g__nm_column_int } + \int_gset_eq:NN \g__nm_col_int \g__nm_col_total_int + \bool_if:nT \g__nm_last_col_found_bool { \int_gdecr:N \g__nm_col_int } + \int_gset_eq:NN \g__nm_row_total_int \g__nm_row_int + \int_compare:nNnT \g__nm_last_row_int > { -1 } + { \int_gsub:Nn \g__nm_row_int \c_one_int } + \bool_if:NT \g__nm_last_row_without_value_bool + { + \iow_now:Nn \@mainaux \ExplSyntaxOn + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { __nm_last_row_ \int_use:N \g__nm_env_int } + { \int_use:N \g__nm_row_total_int } + } + \str_if_empty:NF \g__nm_name_str + { + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { __nm_last_row_ \g__nm_name_str } + { \int_use:N \g__nm_row_total_int } + } + } + \iow_now:Nn \@mainaux \ExplSyntaxOff + } \seq_gclear_new:N \g__nm_yet_drawn_seq \bool_if:NT \l__nm_parallelize_diags_bool { @@ -772,25 +1274,33 @@ \int_set:Nn \l__nm_initial_j_int { #2 } \int_set:Nn \l__nm_final_i_int { #1 } \int_set:Nn \l__nm_final_j_int { #2 } - \bool_set_false:N \l__nm_initial_open_bool - \bool_set_false:N \l__nm_final_open_bool \bool_set_false:N \l__nm_stop_loop_bool \bool_do_until:Nn \l__nm_stop_loop_bool { \int_add:Nn \l__nm_final_i_int { #3 } \int_add:Nn \l__nm_final_j_int { #4 } - \bool_if:nTF + \bool_set_false:N \l__nm_final_open_bool + \int_compare:nNnTF \l__nm_final_i_int > \g__nm_row_int { - \int_compare_p:nNn - \l__nm_final_i_int < { \l__nm_nb_first_row_int - 1 } - || \int_compare_p:nNn \l__nm_final_i_int > \g__nm_row_int - || \int_compare_p:nNn \l__nm_final_j_int < \c_one_int - || \int_compare_p:nNn \l__nm_final_j_int > \g__nm_column_total_int - || \int_compare_p:nNn \l__nm_final_j_int > \g__nm_column_int - && \int_compare_p:nNn { #4 } > \c_zero_int + \int_compare:nNnT { #3 } = 1 + { \bool_set_true:N \l__nm_final_open_bool } } { - \bool_set_true:N \l__nm_final_open_bool + \int_compare:nNnTF \l__nm_final_j_int < 1 + { + \int_compare:nNnT { #4 } = { -1 } + { \bool_set_true:N \l__nm_final_open_bool } + } + { + \int_compare:nNnT \l__nm_final_j_int > \g__nm_col_int + { + \int_compare:nNnT { #4 } = 1 + { \bool_set_true:N \l__nm_final_open_bool } + } + } + } + \bool_if:NTF \l__nm_final_open_bool + { \int_sub:Nn \l__nm_final_i_int { #3 } \int_sub:Nn \l__nm_final_j_int { #4 } \bool_set_true:N \l__nm_stop_loop_bool @@ -805,18 +1315,28 @@ { \int_sub:Nn \l__nm_initial_i_int { #3 } \int_sub:Nn \l__nm_initial_j_int { #4 } - \bool_if:nTF + \bool_set_false:N \l__nm_initial_open_bool + \int_compare:nNnTF \l__nm_initial_i_int < 1 { - \int_compare_p:nNn \l__nm_initial_i_int < \l__nm_nb_first_row_int - || - \int_compare_p:nNn \l__nm_initial_i_int > \g__nm_row_int - || - \int_compare_p:nNn \l__nm_initial_j_int < 1 - || - \int_compare_p:nNn \l__nm_initial_j_int > \g__nm_column_total_int + \int_compare:nNnT { #3 } = 1 + { \bool_set_true:N \l__nm_initial_open_bool } } { - \bool_set_true:N \l__nm_initial_open_bool + \int_compare:nNnTF \l__nm_initial_j_int < 1 + { + \int_compare:nNnT { #4 } = 1 + { \bool_set_true:N \l__nm_initial_open_bool } + } + { + \int_compare:nNnT \l__nm_initial_j_int > \g__nm_col_int + { + \int_compare:nNnT { #4 } = { -1 } + { \bool_set_true:N \l__nm_initial_open_bool } + } + } + } + \bool_if:NTF \l__nm_initial_open_bool + { \int_add:Nn \l__nm_initial_i_int { #3 } \int_add:Nn \l__nm_initial_j_int { #4 } \bool_set_true:N \l__nm_stop_loop_bool @@ -875,17 +1395,37 @@ } \cs_new_protected:Nn \__nm_actually_draw_Ldots: { - \__nm_retrieve_coords:xx - { - \bool_if:NTF \l__nm_initial_open_bool - { - medium.base~west } - { .base~east } - } - { - \bool_if:NTF \l__nm_final_open_bool - { - medium.base~east } - { . base~west } - } + \__nm_retrieve_coords:xx + { + \bool_if:NTF \l__nm_initial_open_bool + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_initial_i_int + - \int_use:N \l__nm_initial_j_int - w + } + { - w.base~west } + { - medium.base~west } + } + { .base~east } + } + { + \bool_if:NTF \l__nm_final_open_bool + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_final_i_int + - \int_use:N \l__nm_final_j_int - w + } + { - w.base~east } + { - medium.base~east } + } + { .base~west } + } \bool_if:NT \l__nm_initial_open_bool { \dim_gset_eq:NN \g__nm_y_initial_dim \g__nm_y_final_dim } \bool_if:NT \l__nm_final_open_bool @@ -902,13 +1442,33 @@ \__nm_retrieve_coords:xx { \bool_if:NTF \l__nm_initial_open_bool - { - medium.mid~west } + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_initial_i_int + - \int_use:N \l__nm_initial_j_int - w + } + { - w.mid~west } + { - medium.mid~west } + } { .mid~east } } { \bool_if:NTF \l__nm_final_open_bool - { - medium.mid~east } - { .mid~west } + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_final_i_int + - \int_use:N \l__nm_final_j_int - w + } + { - w.mid~east } + { - medium.mid~east } + } + { .mid~west } } \bool_if:NT \l__nm_initial_open_bool { \dim_gset_eq:NN \g__nm_y_initial_dim \g__nm_y_final_dim } @@ -1042,7 +1602,8 @@ \fp_to_dim:n { sqrt - ( ( \dim_use:N \g__nm_x_final_dim + ( + ( \dim_use:N \g__nm_x_final_dim - \dim_use:N \g__nm_x_initial_dim ) ^ 2 + @@ -1129,7 +1690,7 @@ \cs_new_protected:Nn \__nm_add_to_empty_cells: { \seq_gput_right:Nx \g__nm_empty_cells_seq - { \int_use:N \g__nm_row_int - \int_use:N \g__nm_column_int } + { \int_use:N \g__nm_row_int - \int_use:N \g__nm_col_int } } \NewDocumentCommand \__nm_Ldots { s } { @@ -1173,27 +1734,34 @@ \int_compare:nNnT #1 > 1 { \seq_gput_left:Nx \g__nm_multicolumn_cells_seq - { \int_eval:n \g__nm_row_int - \int_use:N \g__nm_column_int } + { \int_eval:n \g__nm_row_int - \int_use:N \g__nm_col_int } \seq_gput_left:Nn \g__nm_multicolumn_sizes_seq { #1 } } - \int_gadd:Nn \g__nm_column_int { #1 - 1 } + \int_gadd:Nn \g__nm_col_int { #1 - 1 } + } +\cs_new:Npn \__nm_Hdotsfor: + { + \multicolumn { 1 } { C } { } + \__nm_Hdotsfor_i } \bool_if:NTF \c__nm_draft_bool { - \NewDocumentCommand \__nm_Hdotsfor { O { } m } - { \prg_replicate:nn { #2 - 1 } { & } } + \NewDocumentCommand \__nm_Hdotsfor_i { O { } m } + { + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } + } } { - \NewDocumentCommand \__nm_Hdotsfor { O { } m } + \NewDocumentCommand \__nm_Hdotsfor_i { O { } m } { \tl_gput_right:Nx \g__nm_lines_to_draw_tl { \__nm_draw_Hdotsfor:nnn { \int_use:N \g__nm_row_int } - { \int_use:N \g__nm_column_int } + { \int_use:N \g__nm_col_int } { #2 } } - \prg_replicate:nn { #2 - 1 } { & } + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } \cs_new_protected:Nn \__nm_draw_Hdotsfor:nnn @@ -1216,7 +1784,7 @@ \bool_set_true:N \l__nm_initial_open_bool } } - \int_compare:nNnTF { #2 + #3 -1 } = \g__nm_column_int + \int_compare:nNnTF { #2 + #3 -1 } = \g__nm_col_int { \int_set:Nn \l__nm_final_j_int { #2 + #3 - 1 } \bool_set_true:N \l__nm_final_open_bool @@ -1259,7 +1827,7 @@ { \cs_set:Npn \__nm_dotfill: { - \cleaders \hbox_to_wd:nn { .44 em } { \hss .\hss } \hfill + \cleaders \hbox_to_wd:nn { .44 em } { \hss . \hss } \hfill \skip_horizontal:n \c_zero_dim } } @@ -1272,7 +1840,8 @@ { \dim_set:Nv \l_tmpa_dim { __nm_width_ \int_use:N \g__nm_env_int } } { \dim_set:Nn \l_tmpa_dim { 5 mm } } \hbox_overlap_right:n - { \hbox_to_wd:nn + { + \hbox_to_wd:nn { \l_tmpa_dim + 2 \arraycolsep - \l__nm_left_margin_dim - \g__nm_right_margin_dim @@ -1329,6 +1898,46 @@ first~position~of~the~preamble~of~the~environment~\{\@currenvir\}. \\ If~you~go~on,~this~dotted~line~will~be~ignored. } +\cs_new_protected:Npn \__nm_vline: + { + \int_compare:nNnTF \l__nm_first_col_int = \c_zero_int + { + \int_compare:nNnTF \g__nm_col_int = \c_zero_int + { + \int_compare:nNnTF \l__nm_first_row_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline + } + } + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline + } + } + } + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline } + } + } + { + \int_compare:nNnTF \g__nm_col_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = { -1 } + { + \int_compare:nNnF \g__nm_row_int = { \l__nm_last_row_int - 1 } + \vline + } + } + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline } + } + } + } \bool_new:N \l__nm_block_auto_columns_width_bool \keys_define:nn { NiceMatrix / NiceMatrixBlock } { @@ -1360,244 +1969,29 @@ \iow_now:Nn \@mainaux \ExplSyntaxOff } } -\keys_define:nn { NiceMatrix / NiceArrayC } - { - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - unknown .code:n = \__nm_error:n { Unknown~option~for~NiceArrayC } - } -\__nm_msg_new:nnn { Unknown~option~for~NiceArrayC } - { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ - \{\@currenvir\}. \\ - If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. - } - { - The~available~options~are~(in~alphabetic~order):~ - code-after,~ - code-for-last-col,~ - columns-width,~ - create-extra-nodes,~ - extra-left-margin,~ - extra-right-margin,~ - hlines,~ - left-margin,~ - name,~ - nullify-dots,~ - parallelize-diags~ - renew-dots~ - and~right-margin. - } -\cs_new_protected:Nn \__nm_NiceArrayC:n - { - \bool_set_true:N \l__nm_exterior_column_bool - \bool_gset_false:N \g__nm_exterior_column_found_bool - \begin { NiceArray } - { #1 - > - { - \bool_gset_true:N \g__nm_exterior_column_found_bool - \int_gincr:N \g__nm_column_int - \int_gset:Nn \g__nm_column_total_int - { \int_max:nn \g__nm_column_total_int \g__nm_column_int } - \hbox_set:Nw \l_tmpa_box \c_math_toggle_token - \l__nm_code_for_last_col_tl - } - l - < { \c_math_toggle_token - \hbox_set_end: - \dim_gset:Nn \g__nm_width_last_col_dim - { - \dim_max:nn - \g__nm_width_last_col_dim - { \box_wd:N \l_tmpa_box } - } - \skip_horizontal:n { - 2 \arraycolsep } - \hbox_overlap_right:n - { - \skip_horizontal:n - { - 2 \arraycolsep + - \l__nm_right_margin_dim + - \l__nm_extra_right_margin_dim - } - \tikz - [ - remember~picture , - inner~sep = \c_zero_dim , - minimum~width = \c_zero_dim , - baseline - ] - \node - [ - anchor = base , - name = - nm - - \int_use:N \g__nm_env_int - - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int , - alias = - \str_if_empty:NF \l__nm_name_str - { - \l__nm_name_str - - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int - } - ] - { \box_use:N \l_tmpa_box } ; - } - } - } - } -\NewDocumentEnvironment { NiceArrayCwithDelims } { m m O { } m ! O { } } - { - \__nm_test_if_math_mode: - \dim_gzero_new:N \g__nm_width_last_col_dim - \keys_set:nn { NiceMatrix / NiceArrayC } { #3 , #5 } - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \str_set:Nn \l__nm_pos_env_str c - \left #1 - \__nm_NiceArrayC:n { #4 } - } - { - \end { NiceArray } - \right #2 - \skip_horizontal:n \g__nm_width_last_col_dim - } -\NewDocumentEnvironment { pNiceArrayC } { } - { \NiceArrayCwithDelims ( ) } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { vNiceArrayC } { } - { \NiceArrayCwithDelims | | } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { VNiceArrayC } { } - { \NiceArrayCwithDelims \| \| } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { bNiceArrayC } { } - { \NiceArrayCwithDelims [ ] } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { BNiceArrayC } { } - { \NiceArrayCwithDelims \{ \} } - { \endNiceArrayCwithDelims } -\keys_define:nn { NiceMatrix / NiceArrayRC } - { - code-for-first-row .tl_set:N = \l__nm_code_for_first_row_tl , - code-for-first-row .value_required:n = true , - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - unknown .code:n = \__nm_error:n { Unknown~option~for~NiceArrayRC } - } -\__nm_msg_new:nnn { Unknown~option~for~NiceArrayRC } - { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ - \{ \@currenvir \}. \\ - If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. - } - { - The~available~options~are~(in~alphabetic~order):~ - code-after,~ - code-for-last-col,~ - code-for-first-row,~ - columns-width,~ - create-extra-nodes,~ - extra-left-margin,~ - extra-right-margin,~ - hlines,~ - left-margin,~ - name,~ - nullify-dots,~ - parallelize-diags,~ - renew-dots~ - and~right-margin. - } -\cs_new_protected:Npn \__nm_vline: - { - \int_compare:nNnTF \g__nm_column_int = \c_zero_int - { \int_compare:nNnF \g__nm_row_int < \c_zero_int \vline } - { \int_compare:nNnF \g__nm_row_int < \c_one_int \vline } - } -\NewDocumentEnvironment { NiceArrayRCwithDelims } { m m O { } m ! O { } } - { - \__nm_test_if_math_mode: - \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nm_vline: } - \int_zero:N \l__nm_nb_first_row_int - \dim_gzero_new:N \g__nm_width_last_col_dim - \keys_set:nn { NiceMatrix / NiceArrayRC } { #3 , #5 } - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \str_set:Nn \l__nm_pos_env_str c - \box_clear_new:N \l__nm_the_array_box - \hbox_set:Nw \l__nm_the_array_box - \c_math_toggle_token - \__nm_NiceArrayC:n { #4 } - } - { - \end { NiceArray } - \c_math_toggle_token - \hbox_set_end: - \dim_set:Nn \l_tmpa_dim - { - ( - \dim_max:nn - { 12 pt } - { \g__nm_max_ht_row_one_dim + \g__nm_max_dp_row_zero_dim } - ) - + \g__nm_max_ht_row_zero_dim - \g__nm_max_ht_row_one_dim - } - \hbox_set:Nn \l_tmpa_box - { - \c_math_toggle_token - \left #1 - \vcenter - { - \skip_vertical:n { - \l_tmpa_dim } - \box_use_drop:N \l__nm_the_array_box - } - \right #2 - \c_math_toggle_token - \skip_horizontal:n \g__nm_width_last_col_dim - } - \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } - \box_use_drop:N \l_tmpa_box - } -\NewDocumentEnvironment { pNiceArrayRC } { } - { \NiceArrayRCwithDelims ( ) } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { bNiceArrayRC } { } - { \NiceArrayRCwithDelims [ ] } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { vNiceArrayRC } { } - { \NiceArrayRCwithDelims | | } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { VNiceArrayRC } { } - { \NiceArrayRCwithDelims \| \| } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { BNiceArrayRC } { } - { \NiceArrayRCwithDelims \{ \} } - { \endNiceArrayRCwithDelims } \cs_generate_variant:Nn \dim_min:nn { v n } \cs_generate_variant:Nn \dim_max:nn { v n } \cs_new_protected:Nn \__nm_create_extra_nodes: { \begin { tikzpicture } [ remember~picture , overlay ] - \int_step_variable:nnnNn \l__nm_nb_first_row_int 1 \g__nm_row_int \__nm_i: + \int_step_variable:nnNn \g__nm_first_row_int \g__nm_row_total_int \__nm_i: { \dim_zero_new:c { l__nm_row_\__nm_i: _min_dim } \dim_set_eq:cN { l__nm_row_\__nm_i: _min_dim } \c_max_dim \dim_zero_new:c { l__nm_row_\__nm_i: _max_dim } \dim_set:cn { l__nm_row_\__nm_i: _max_dim } { - \c_max_dim } } - \int_step_variable:nNn \g__nm_column_total_int \__nm_j: + \int_step_variable:nnNn \g__nm_first_col_int \g__nm_col_total_int \__nm_j: { \dim_zero_new:c { l__nm_column_\__nm_j: _min_dim } \dim_set_eq:cN { l__nm_column_\__nm_j: _min_dim } \c_max_dim \dim_zero_new:c { l__nm_column_\__nm_j: _max_dim } \dim_set:cn { l__nm_column_\__nm_j: _max_dim } { - \c_max_dim } } - \int_step_variable:nnNn \l__nm_nb_first_row_int \g__nm_row_int \__nm_i: + \int_step_variable:nnNn \g__nm_first_row_int \g__nm_row_total_int \__nm_i: { - \int_step_variable:nNn \g__nm_column_total_int \__nm_j: + \int_step_variable:nnNn + \g__nm_first_col_int \g__nm_col_total_int \__nm_j: { \cs_if_exist:cT { pgf@sh@ns@nm - \int_use:N \g__nm_env_int - \__nm_i: - \__nm_j: } { @@ -1625,7 +2019,8 @@ } \tikzset { name~suffix = -medium } \__nm_create_nodes: - \int_set:Nn \l__nm_nb_first_row_int 1 + \int_set:Nn \g__nm_first_row_int 1 + \int_set:Nn \g__nm_first_col_int 1 \int_step_variable:nNn { \g__nm_row_int - 1 } \__nm_i: { \dim_set:cn { l__nm_row _ \__nm_i: _ min _ dim } @@ -1639,7 +2034,7 @@ \dim_set_eq:cc { l__nm_row _ \int_eval:n { \__nm_i: + 1 } _ max _ dim } { l__nm_row_\__nm_i: _min_dim } } - \int_step_variable:nNn { \g__nm_column_int - 1 } \__nm_j: + \int_step_variable:nNn { \g__nm_col_int - 1 } \__nm_j: { \dim_set:cn { l__nm_column _ \__nm_j: _ max _ dim } { @@ -1658,7 +2053,7 @@ { l__nm_column _ 1 _ min _ dim } \g__nm_left_margin_dim \dim_add:cn - { l__nm_column _ \int_use:N \g__nm_column_int _ max _ dim } + { l__nm_column _ \int_use:N \g__nm_col_int _ max _ dim } \g__nm_right_margin_dim \tikzset { name~suffix = -large } \__nm_create_nodes: @@ -1670,9 +2065,9 @@ \dim_gset:Nn \g_tmpa_dim \pgf@x \tikz@parse@node \pgfutil@firstofone ( nm - \int_use:N \g__nm_env_int - 1 - - \int_use:N \g__nm_column_int - large .north~east ) + \int_use:N \g__nm_col_int - large .north~east ) \dim_gset:Nn \g_tmpb_dim \pgf@x - \end { tikzpicture } + \end { tikzpicture } \iow_now:Nn \@mainaux \ExplSyntaxOn \iow_now:Nx \@mainaux { @@ -1683,15 +2078,15 @@ } \cs_new_protected:Nn \__nm_create_nodes: { - \int_step_variable:nnNn \l__nm_nb_first_row_int \g__nm_row_int \__nm_i: + \int_step_variable:nnNn \g__nm_first_row_int \g__nm_row_total_int \__nm_i: { - \int_step_variable:nNn \g__nm_column_total_int \__nm_j: + \int_step_variable:nnNn \g__nm_first_col_int \g__nm_col_total_int \__nm_j: { \coordinate ( __nm~south~west ) at ( \dim_use:c { l__nm_column_ \__nm_j: _min_dim } , \dim_use:c { l__nm_row_ \__nm_i: _min_dim } ) ; \coordinate ( __nm~north~east ) - at ( \dim_use:c { l__nm_column_ \__nm_j: _max_dim }, + at ( \dim_use:c { l__nm_column_ \__nm_j: _max_dim } , \dim_use:c { l__nm_row_ \__nm_i: _max_dim } ) ; \node [ @@ -1770,6 +2165,84 @@ { \BNiceMatrix } { \endBNiceMatrix } } +\NewDocumentEnvironment { pNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \pNiceArray + } + { \endpNiceArray } +\NewDocumentEnvironment { bNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \bNiceArray + } + { \endbNiceArray } +\NewDocumentEnvironment { BNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \BNiceArray + } + { \endBNiceArray } +\NewDocumentEnvironment { vNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \vNiceArray + } + { \endvNiceArray } +\NewDocumentEnvironment { VNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \VNiceArray + } + { \endVNiceArray } +\NewDocumentEnvironment { pNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \pNiceArray + } + { \endpNiceArray } +\NewDocumentEnvironment { bNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \bNiceArray + } + { \endbNiceArray } +\NewDocumentEnvironment { BNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \BNiceArray + } + { \endBNiceArray } +\NewDocumentEnvironment { vNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \vNiceArray + } + { \endvNiceArray } +\NewDocumentEnvironment { VNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \VNiceArray + } + { \endVNiceArray } +\NewDocumentEnvironment { NiceArrayCwithDelims } { } + { + \bool_set_true:N \l__nm_last_col_bool + \NiceArrayWithDelims + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { NiceArrayRCwithDelims } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \NiceArrayWithDelims + } + { \endNiceArrayWithDelims } \endinput %% %% End of file `nicematrix.sty'. -- cgit v1.2.3