diff options
author | Karl Berry <karl@freefriends.org> | 2021-03-10 22:21:00 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-03-10 22:21:00 +0000 |
commit | 12076ff67b851c936ad4f5d47a8d054a497cb7fb (patch) | |
tree | e81792162c68f09d9adef5d981f96398f1194d03 /Master/texmf-dist/tex/latex | |
parent | 3137a052691d37f1ec87f00109adcceedb6db0b6 (diff) |
nicematrix (10mar21)
git-svn-id: svn://tug.org/texlive/trunk@58257 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty | 636 |
1 files changed, 447 insertions, 189 deletions
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index 3a1076b1831..671bc44ef0c 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{5.11} -\def\myfiledate{2021/02/22} +\def\myfileversion{5.12} +\def\myfiledate{2021/03/10} \RequirePackage{pgfcore} \usepgfmodule{shapes} \RequirePackage{l3keys2e} @@ -182,6 +182,7 @@ { \cs_set:Npn \CT@arc@ { \color [ #1 ] { #2 } } } \cs_new_protected:Npn \__nicematrix_set_CT@arc@_ii: #1 \q_stop { \cs_set:Npn \CT@arc@ { \color { #1 } } } +\cs_set_eq:NN \__nicematrix_old_pgfpointanchor \pgfpointanchor \bool_new:N \c__nicematrix_siunitx_loaded_bool \AtBeginDocument { @@ -286,6 +287,7 @@ { environment \space \{ \g__nicematrix_name_env_str \} } } \tl_new:N \g_nicematrix_code_after_tl +\tl_new:N \l__nicematrix_code_tl \tl_new:N \g__nicematrix_internal_code_after_tl \int_new:N \l__nicematrix_old_iRow_int \int_new:N \l__nicematrix_old_jCol_int @@ -309,9 +311,15 @@ \seq_new:N \g__nicematrix_pos_of_xdots_seq \seq_new:N \g__nicematrix_pos_of_stroken_blocks_seq \seq_new:N \g__nicematrix_submatrix_names_seq +\int_new:N \l__nicematrix_row_min_int +\int_new:N \l__nicematrix_row_max_int +\int_new:N \l__nicematrix_col_min_int +\int_new:N \l__nicematrix_col_max_int +\seq_new:N \g__nicematrix_submatrix_seq \int_new:N \g__nicematrix_static_num_of_col_int \tl_new:N \l__nicematrix_fill_tl \tl_new:N \l__nicematrix_draw_tl +\dim_new:N \l__nicematrix_rounded_corners_dim \tl_new:N \l__nicematrix_color_tl \dim_new:N \l__nicematrix_line_width_dim \tl_new:N \l__nicematrix_pos_of_block_tl @@ -321,8 +329,8 @@ \dim_new:N \l__nicematrix_submatrix_extra_height_dim \dim_new:N \l__nicematrix_submatrix_left_xshift_dim \dim_new:N \l__nicematrix_submatrix_right_xshift_dim -\clist_new:N \l__nicematrix_submatrix_hlines_clist -\clist_new:N \l__nicematrix_submatrix_vlines_clist +\clist_new:N \l__nicematrix_hlines_clist +\clist_new:N \l__nicematrix_vlines_clist \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 @@ -470,8 +478,6 @@ \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_vlines_bool -\bool_new:N \l__nicematrix_hlines_bool \clist_new:N \l__nicematrix_except_corners_clist \dim_new:N \l__nicematrix_notes_above_space_dim \AtBeginDocument { \dim_set:Nn \l__nicematrix_notes_above_space_dim { 1 mm } } @@ -488,7 +494,7 @@ \tl_set:Nn \l__nicematrix_end_of_row_tl { ; } \tl_new:N \l__nicematrix_xdots_color_tl \tl_new:N \l__nicematrix_delimiters_color_tl -\bool_new:N \l__nicematrix_max_delimiter_width_bool +\bool_new:N \l__nicematrix_delimiters_max_width_bool \keys_define:nn { NiceMatrix / xdots } { line-style .code:n = @@ -531,9 +537,8 @@ cell-space-top-limit = #1 , cell-space-bottom-limit = #1 , } , - cell-spaces-limits .value_required:n = true , + cell-space-limits .value_required:n = true , xdots .code:n = \keys_set:nn { NiceMatrix / xdots } { #1 } , - max-delimiter-width .bool_set:N = \l__nicematrix_max_delimiter_width_bool , light-syntax .bool_set:N = \l__nicematrix_light_syntax_bool , light-syntax .default:n = true , end-of-row .tl_set:N = \l__nicematrix_end_of_row_tl , @@ -550,8 +555,10 @@ code-for-first-row .value_required:n = true , code-for-last-row .tl_set:N = \l__nicematrix_code_for_last_row_tl , code-for-last-row .value_required:n = true , - hlines .bool_set:N = \l__nicematrix_hlines_bool , - vlines .bool_set:N = \l__nicematrix_vlines_bool , + hlines .clist_set:N = \l__nicematrix_hlines_clist , + vlines .clist_set:N = \l__nicematrix_vlines_clist , + hlines .default:n = all , + vlines .default:n = all , vlines-in-sub-matrix .code:n = { \tl_if_single_token:nTF { #1 } @@ -561,8 +568,8 @@ vlines-in-sub-matrix .value_required:n = true , hvlines .code:n = { - \bool_set_true:N \l__nicematrix_vlines_bool - \bool_set_true:N \l__nicematrix_hlines_bool + \clist_set:Nn \l__nicematrix_vlines_clist { all } + \clist_set:Nn \l__nicematrix_hlines_clist { all } } , parallelize-diags .bool_set:N = \l__nicematrix_parallelize_diags_bool , renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool , @@ -586,13 +593,14 @@ } \keys_define:nn { NiceMatrix / Env } { + delimiters/max-width .bool_set:N = \l__nicematrix_delimiters_max_width_bool , except-corners .clist_set:N = \l__nicematrix_except_corners_clist , except-corners .default:n = { NW , SW , NE , SE } , hvlines-except-corners .code:n = { \clist_set:Nn \l__nicematrix_except_corners_clist { #1 } - \bool_set_true:N \l__nicematrix_vlines_bool - \bool_set_true:N \l__nicematrix_hlines_bool + \clist_set:Nn \l__nicematrix_vlines_clist { all } + \clist_set:Nn \l__nicematrix_hlines_clist { all } } , hvlines-except-corners .default:n = { NW , SW , NE , SE } , code-before .code:n = @@ -723,6 +731,7 @@ } \keys_define:nn { NiceMatrix / NiceMatrixOptions } { + delimiters / max-width .bool_set:N = \l__nicematrix_delimiters_max_width_bool , delimiters / color .tl_set:N = \l__nicematrix_delimiters_color_tl , delimiters / color .value_required:n = true , delimiters-color .tl_set:N = \l__nicematrix_delimiters_color_tl , @@ -802,6 +811,8 @@ delimiters-color .value_required:n = true , delimiters / color .tl_set:N = \l__nicematrix_delimiters_color_tl , delimiters / color .value_required:n = true , + r .code:n = \__nicematrix_error:n { r~or~l~with~preamble } , + l .code:n = \__nicematrix_error:n { r~or~l~with~preamble } , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceArray } } \keys_define:nn { NiceMatrix / pNiceArray } @@ -813,6 +824,8 @@ first-row .code:n = \int_zero:N \l__nicematrix_first_row_int , small .bool_set:N = \l__nicematrix_small_bool , small .value_forbidden:n = true , + r .code:n = \__nicematrix_error:n { r~or~l~with~preamble } , + l .code:n = \__nicematrix_error:n { r~or~l~with~preamble } , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceMatrix } } \keys_define:nn { NiceMatrix / NiceTabular } @@ -826,6 +839,8 @@ 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 , + r .code:n = \__nicematrix_error:n { r~or~l~with~preamble } , + l .code:n = \__nicematrix_error:n { r~or~l~with~preamble } , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceTabular } } \cs_new_protected:Npn \__nicematrix_Cell: @@ -1046,12 +1061,21 @@ \bool_if:NF \g__nicematrix_row_of_col_done_bool { \__nicematrix_create_row_node: - \bool_if:NT \l__nicematrix_hlines_bool + \tl_if_empty:NF \l__nicematrix_hlines_clist { - \int_compare:nNnT \c@iRow > { -1 } + \tl_if_eq:NnF \l__nicematrix_hlines_clist { all } { - \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - { \hrule height \arrayrulewidth width \c_zero_dim } + \exp_args:NNx + \clist_if_in:NnT + \l__nicematrix_hlines_clist + { \__nicematrix_succ:n \c@iRow } + } + { + \int_compare:nNnT \c@iRow > { -1 } + { + \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int + { \hrule height \arrayrulewidth width \c_zero_dim } + } } } } @@ -1079,7 +1103,7 @@ \cs_set_eq:NN \rowcolor \__nicematrix_rowcolor_tabular \cs_set_eq:NN \columncolor \__nicematrix_columncolor_preamble } -\cs_new_protected:Npn \__nicematrix_pre_array: +\cs_new_protected:Npn \__nicematrix_pre_array_ii: { \bool_if:NT \c__nicematrix_booktabs_loaded_bool { \tl_put_left:Nn \@BTnormal \__nicematrix_create_row_node: } @@ -1166,52 +1190,9 @@ \tl_gclear_new:N \g__nicematrix_HVdotsfor_lines_tl \tl_gclear_new:N \g_nicematrix_code_before_tl } -\NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } } +\cs_new_protected:Npn \__nicematrix_pre_array: { - \__nicematrix_provide_pgfsyspdfmark: - \bool_if:NT \c__nicematrix_footnote_bool \savenotes - \bgroup - \tl_set:Nn \l__nicematrix_left_delim_tl { #1 } - \tl_set:Nn \l__nicematrix_right_delim_tl { #2 } - \tl_gset:Nn \g__nicematrix_preamble_tl { #4 } - \int_gzero:N \g__nicematrix_block_box_int - \dim_zero:N \g__nicematrix_width_last_col_dim - \dim_zero:N \g__nicematrix_width_first_col_dim - \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: - \bool_if:NTF \l__nicematrix_NiceTabular_bool - \mode_leave_vertical: - \__nicematrix_test_if_math_mode: - \bool_if:NT \l__nicematrix_in_env_bool { \__nicematrix_fatal:n { Yet~in~env } } - \bool_set_true:N \l__nicematrix_in_env_bool - \cs_gset_eq:NN \__nicematrix_old_CT@arc@ \CT@arc@ - \cs_if_exist:NT \tikz@library@external@loaded - { - \tikzexternaldisable - \cs_if_exist:NT \ifstandalone - { \tikzset { external / optimize = false } } - } - \int_gincr:N \g__nicematrix_env_int - \bool_if:NF \l__nicematrix_block_auto_columns_width_bool - { \dim_gzero_new:N \g__nicematrix_max_cell_width_dim } - \seq_gclear:N \g__nicematrix_blocks_seq - \seq_gclear:N \g__nicematrix_pos_of_blocks_seq - \seq_gclear:N \g__nicematrix_pos_of_stroken_blocks_seq - \seq_gclear:N \g__nicematrix_pos_of_xdots_seq - \tl_if_exist:cT { g__nicematrix_code_before_ \int_use:N \g__nicematrix_env_int _ tl } - { - \bool_set_true:N \l__nicematrix_code_before_bool - \exp_args:NNv \tl_put_right:Nn \l__nicematrix_code_before_tl - { g__nicematrix_code_before_ \int_use:N \g__nicematrix_env_int _ tl } - } - \bool_if:NTF \l__nicematrix_NiceArray_bool - { \keys_set:nn { NiceMatrix / NiceArray } } - { \keys_set:nn { NiceMatrix / pNiceArray } } - { #3 , #5 } - \tl_if_empty:NF \l__nicematrix_rules_color_tl - { \exp_after:wN \__nicematrix_set_CT@arc@: \l__nicematrix_rules_color_tl \q_stop } + \seq_gclear:N \g__nicematrix_submatrix_seq \bool_if:NT \l__nicematrix_code_before_bool { \seq_if_exist:cT { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } @@ -1258,13 +1239,15 @@ } \cs_set_eq:NN \cellcolor \__nicematrix_cellcolor \cs_set_eq:NN \rectanglecolor \__nicematrix_rectanglecolor + \cs_set_eq:NN \roundedrectanglecolor \__nicematrix_roundedrectanglecolor \cs_set_eq:NN \rowcolor \__nicematrix_rowcolor \cs_set_eq:NN \rowcolors \__nicematrix_rowcolors \cs_set_eq:NN \columncolor \__nicematrix_columncolor \cs_set_eq:NN \chessboardcolors \__nicematrix_chessboardcolors + \cs_set_eq:NN \SubMatrix \__nicematrix_SubMatrix_in_code_before \bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token \seq_clear_new:N \l__nicematrix_colors_seq - \l__nicematrix_code_before_tl + \exp_last_unbraced:NV \__nicematrix_CodeAfter_keys: \l__nicematrix_code_before_tl \__nicematrix_actually_color: \bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token \group_end: @@ -1317,7 +1300,7 @@ } } } - \__nicematrix_pre_array: + \__nicematrix_pre_array_ii: \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 @@ -1342,6 +1325,61 @@ { \use:c { __nicematrix-light-syntax } } { \use:c { __nicematrix-normal-syntax } } } +\cs_new_protected:Npn \__nicematrix_pre_array_i:w #1 \Body + { + \tl_put_right:Nn \l__nicematrix_code_before_tl { #1 } + \bool_set_true:N \l__nicematrix_code_before_bool + \__nicematrix_pre_array: + } +\NewDocumentEnvironment { NiceArrayWithDelims } + { m m O { } m ! O { } t \CodeBefore } + { + \__nicematrix_provide_pgfsyspdfmark: + \bool_if:NT \c__nicematrix_footnote_bool \savenotes + \bgroup + \tl_set:Nn \l__nicematrix_left_delim_tl { #1 } + \tl_set:Nn \l__nicematrix_right_delim_tl { #2 } + \tl_gset:Nn \g__nicematrix_preamble_tl { #4 } + \int_gzero:N \g__nicematrix_block_box_int + \dim_zero:N \g__nicematrix_width_last_col_dim + \dim_zero:N \g__nicematrix_width_first_col_dim + \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: + \bool_if:NTF \l__nicematrix_NiceTabular_bool + \mode_leave_vertical: + \__nicematrix_test_if_math_mode: + \bool_if:NT \l__nicematrix_in_env_bool { \__nicematrix_fatal:n { Yet~in~env } } + \bool_set_true:N \l__nicematrix_in_env_bool + \cs_gset_eq:NN \__nicematrix_old_CT@arc@ \CT@arc@ + \cs_if_exist:NT \tikz@library@external@loaded + { + \tikzexternaldisable + \cs_if_exist:NT \ifstandalone + { \tikzset { external / optimize = false } } + } + \int_gincr:N \g__nicematrix_env_int + \bool_if:NF \l__nicematrix_block_auto_columns_width_bool + { \dim_gzero_new:N \g__nicematrix_max_cell_width_dim } + \seq_gclear:N \g__nicematrix_blocks_seq + \seq_gclear:N \g__nicematrix_pos_of_blocks_seq + \seq_gclear:N \g__nicematrix_pos_of_stroken_blocks_seq + \seq_gclear:N \g__nicematrix_pos_of_xdots_seq + \tl_if_exist:cT { g__nicematrix_code_before_ \int_use:N \g__nicematrix_env_int _ tl } + { + \bool_set_true:N \l__nicematrix_code_before_bool + \exp_args:NNv \tl_put_right:Nn \l__nicematrix_code_before_tl + { g__nicematrix_code_before_ \int_use:N \g__nicematrix_env_int _ tl } + } + \bool_if:NTF \l__nicematrix_NiceArray_bool + { \keys_set:nn { NiceMatrix / NiceArray } } + { \keys_set:nn { NiceMatrix / pNiceArray } } + { #3 , #5 } + \tl_if_empty:NF \l__nicematrix_rules_color_tl + { \exp_after:wN \__nicematrix_set_CT@arc@: \l__nicematrix_rules_color_tl \q_stop } + \IfBooleanTF { #6 } \__nicematrix_pre_array_i:w \__nicematrix_pre_array: + } { \bool_if:NTF \l__nicematrix_light_syntax_bool { \use:c { end __nicematrix-light-syntax } } @@ -1418,10 +1456,12 @@ } \skip_vertical:N -\l_tmpb_dim } + \tl_if_empty:NF \l__nicematrix_delimiters_color_tl + { \color { \l__nicematrix_delimiters_color_tl } } \exp_after:wN \right \l__nicematrix_right_delim_tl \c_math_toggle_token } - \bool_if:NTF \l__nicematrix_max_delimiter_width_bool + \bool_if:NTF \l__nicematrix_delimiters_max_width_bool { \__nicematrix_put_box_in_flow_bis:nn { #1 } { #2 } } \__nicematrix_put_box_in_flow: } @@ -1454,12 +1494,19 @@ \@tempswatrue \@whilesw \if@tempswa \fi { \@tempswafalse \the \NC@list } \int_gzero_new:N \c@jCol - \bool_if:NTF \l__nicematrix_vlines_bool + \tl_gclear:N \g__nicematrix_preamble_tl + \tl_if_eq:NnTF \l__nicematrix_vlines_clist { all } { \tl_gset:Nn \g__nicematrix_preamble_tl { ! { \skip_horizontal:N \arrayrulewidth } } } - { \tl_gclear:N \g__nicematrix_preamble_tl } + { + \clist_if_in:NnT \l__nicematrix_vlines_clist 1 + { + \tl_gset:Nn \g__nicematrix_preamble_tl + { ! { \skip_horizontal:N \arrayrulewidth } } + } + } \seq_clear:N \g__nicematrix_cols_vlism_seq \int_zero:N \l_tmpa_int \exp_after:wN \__nicematrix_patch_preamble:n \the \@temptokena \q_stop @@ -1479,7 +1526,7 @@ { \l__nicematrix_NiceArray_bool { \bool_not_p:n \l__nicematrix_NiceTabular_bool } - { \bool_not_p:n \l__nicematrix_vlines_bool } + { \tl_if_empty_p:N \l__nicematrix_vlines_clist } { \bool_not_p:n \l__nicematrix_exterior_arraycolsep_bool } } { \tl_gput_left:Nn \g__nicematrix_preamble_tl { @ { } } } @@ -1491,7 +1538,7 @@ { \l__nicematrix_NiceArray_bool { \bool_not_p:n \l__nicematrix_NiceTabular_bool } - { \bool_not_p:n \l__nicematrix_vlines_bool } + { \tl_if_empty_p:N \l__nicematrix_vlines_clist } { \bool_not_p:n \l__nicematrix_exterior_arraycolsep_bool } } { \tl_gput_right:Nn \g__nicematrix_preamble_tl { @ { } } } @@ -1694,11 +1741,19 @@ \str_if_eq:nnTF { #1 } { < } \__nicematrix_patch_preamble_ix:n { - \bool_if:NT \l__nicematrix_vlines_bool + \tl_if_eq:NnTF \l__nicematrix_vlines_clist { all } { \tl_gput_right:Nn \g__nicematrix_preamble_tl { ! { \skip_horizontal:N \arrayrulewidth } } } + { + \exp_args:NNx + \clist_if_in:NnT \l__nicematrix_vlines_clist { \__nicematrix_succ:n \c@jCol } + { + \tl_gput_right:Nn \g__nicematrix_preamble_tl + { ! { \skip_horizontal:N \arrayrulewidth } } + } + } \__nicematrix_patch_preamble:n { #1 } } } @@ -2368,10 +2423,9 @@ \cs_set_eq:NN \__nicematrix_vline_i:nn \__nicematrix_vline_i_complete:nn \cs_set_eq:NN \__nicematrix_hline_i:nn \__nicematrix_hline_i_complete:nn } - \bool_if:NT \l__nicematrix_hlines_bool \__nicematrix_draw_hlines: - \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines: - \g__nicematrix_internal_code_after_tl - \tl_gclear:N \g__nicematrix_internal_code_after_tl + \tl_if_empty:NF \l__nicematrix_hlines_clist \__nicematrix_draw_hlines: + \tl_if_empty:NF \l__nicematrix_vlines_clist \__nicematrix_draw_vlines: + \cs_set_eq:NN \SubMatrix \__nicematrix_SubMatrix \bool_if:NT \c__nicematrix_tikz_loaded_bool { \tikzset @@ -2385,7 +2439,8 @@ } } \cs_set_eq:NN \line \__nicematrix_line - \cs_set_eq:NN \SubMatrix \__nicematrix_SubMatrix + \g__nicematrix_internal_code_after_tl + \tl_gclear:N \g__nicematrix_internal_code_after_tl \cs_set_eq:NN \CodeAfter \prg_do_nothing: \seq_gclear:N \g__nicematrix_submatrix_names_seq \exp_last_unbraced:NV \__nicematrix_CodeAfter_keys: \g_nicematrix_code_after_tl @@ -2483,23 +2538,23 @@ \int_add:Nn \l__nicematrix_final_i_int { #3 } \int_add:Nn \l__nicematrix_final_j_int { #4 } \bool_set_false:N \l__nicematrix_final_open_bool - \int_compare:nNnTF \l__nicematrix_final_i_int > \c@iRow + \int_compare:nNnTF \l__nicematrix_final_i_int > \l__nicematrix_row_max_int { \int_compare:nNnTF { #3 } = 1 { \bool_set_true:N \l__nicematrix_final_open_bool } { - \int_compare:nNnT \l__nicematrix_final_j_int > \c@jCol + \int_compare:nNnT \l__nicematrix_final_j_int > \l__nicematrix_col_max_int { \bool_set_true:N \l__nicematrix_final_open_bool } } } { - \int_compare:nNnTF \l__nicematrix_final_j_int < 1 + \int_compare:nNnTF \l__nicematrix_final_j_int < \l__nicematrix_col_min_int { \int_compare:nNnT { #4 } = { -1 } { \bool_set_true:N \l__nicematrix_final_open_bool } } { - \int_compare:nNnT \l__nicematrix_final_j_int > \c@jCol + \int_compare:nNnT \l__nicematrix_final_j_int > \l__nicematrix_col_max_int { \int_compare:nNnT { #4 } = 1 { \bool_set_true:N \l__nicematrix_final_open_bool } @@ -2551,23 +2606,23 @@ \int_sub:Nn \l__nicematrix_initial_i_int { #3 } \int_sub:Nn \l__nicematrix_initial_j_int { #4 } \bool_set_false:N \l__nicematrix_initial_open_bool - \int_compare:nNnTF \l__nicematrix_initial_i_int < 1 + \int_compare:nNnTF \l__nicematrix_initial_i_int < \l__nicematrix_row_min_int { \int_compare:nNnTF { #3 } = 1 { \bool_set_true:N \l__nicematrix_initial_open_bool } { - \int_compare:nNnT \l__nicematrix_initial_j_int = 0 + \int_compare:nNnT \l__nicematrix_initial_j_int = { \l__nicematrix_col_min_int -1 } { \bool_set_true:N \l__nicematrix_initial_open_bool } } } { - \int_compare:nNnTF \l__nicematrix_initial_j_int < 1 + \int_compare:nNnTF \l__nicematrix_initial_j_int < \l__nicematrix_col_min_int { \int_compare:nNnT { #4 } = 1 { \bool_set_true:N \l__nicematrix_initial_open_bool } } { - \int_compare:nNnT \l__nicematrix_initial_j_int > \c@jCol + \int_compare:nNnT \l__nicematrix_initial_j_int > \l__nicematrix_col_max_int { \int_compare:nNnT { #4 } = { -1 } { \bool_set_true:N \l__nicematrix_initial_open_bool } @@ -2621,6 +2676,31 @@ { \int_use:N \l__nicematrix_final_j_int } } } +\cs_new_protected:Npn \__nicematrix_adjust_to_submatrix:nn #1 #2 + { + \int_set:Nn \l__nicematrix_row_min_int 1 + \int_set:Nn \l__nicematrix_col_min_int 1 + \int_set_eq:NN \l__nicematrix_row_max_int \c@iRow + \int_set_eq:NN \l__nicematrix_col_max_int \c@jCol + \seq_map_inline:Nn \g__nicematrix_submatrix_seq + { \__nicematrix_adjust_to_submatrix:nnnnnn { #1 } { #2 } ##1 } + } +\cs_set_protected:Npn \__nicematrix_adjust_to_submatrix:nnnnnn #1 #2 #3 #4 #5 #6 + { + \bool_if:nT + { + \int_compare_p:n { #3 <= #1 } + && \int_compare_p:n { #1 <= #5 } + && \int_compare_p:n { #4 <= #2 } + && \int_compare_p:n { #2 <= #6 } + } + { + \int_set:Nn \l__nicematrix_row_min_int { \int_max:nn \l__nicematrix_row_min_int { #3 } } + \int_set:Nn \l__nicematrix_col_min_int { \int_max:nn \l__nicematrix_col_min_int { #4 } } + \int_set:Nn \l__nicematrix_row_max_int { \int_min:nn \l__nicematrix_row_max_int { #5 } } + \int_set:Nn \l__nicematrix_col_max_int { \int_min:nn \l__nicematrix_col_max_int { #6 } } + } + } \cs_new_protected:Npn \__nicematrix_set_initial_coords: { \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x @@ -2653,8 +2733,53 @@ { #1 } \__nicematrix_set_final_coords: } +\cs_new_protected:Npn \__nicematrix_open_x_initial_dim: + { + \dim_set_eq:NN \l__nicematrix_x_initial_dim \c_max_dim + \int_step_inline:nnn \l__nicematrix_first_row_int \g__nicematrix_row_total_int + { + \cs_if_exist:cT + { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \int_use:N \l__nicematrix_initial_j_int } + { + \pgfpointanchor + { \__nicematrix_env: - ##1 - \int_use:N \l__nicematrix_initial_j_int } + { west } + \dim_set:Nn \l__nicematrix_x_initial_dim + { \dim_min:nn \l__nicematrix_x_initial_dim \pgf@x } + } + } + \dim_compare:nNnT \l__nicematrix_x_initial_dim = \c_max_dim + { + \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int } + \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \dim_add:Nn \l__nicematrix_x_initial_dim \col@sep + } + } +\cs_new_protected:Npn \__nicematrix_open_x_final_dim: + { + \dim_set:Nn \l__nicematrix_x_final_dim { - \c_max_dim } + \int_step_inline:nnn \l__nicematrix_first_row_int \g__nicematrix_row_total_int + { + \cs_if_exist:cT + { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \int_use:N \l__nicematrix_final_j_int } + { + \pgfpointanchor + { \__nicematrix_env: - ##1 - \int_use:N \l__nicematrix_final_j_int } + { east } + \dim_set:Nn \l__nicematrix_x_final_dim + { \dim_max:nn \l__nicematrix_x_final_dim \pgf@x } + } + } + \dim_compare:nNnT \l__nicematrix_x_final_dim = { - \c_max_dim } + { + \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int } + \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + \dim_sub:Nn \l__nicematrix_x_final_dim \col@sep + } + } \cs_new_protected:Npn \__nicematrix_draw_Ldots:nnn #1 #2 #3 { + \__nicematrix_adjust_to_submatrix:nn { #1 } { #2 } \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1 @@ -2675,18 +2800,14 @@ { \bool_if:NTF \l__nicematrix_initial_open_bool { - \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int } - \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x - \dim_add:Nn \l__nicematrix_x_initial_dim \col@sep + \__nicematrix_open_x_initial_dim: \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int - base } \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y } { \__nicematrix_set_initial_coords_from_anchor:n { base~east } } \bool_if:NTF \l__nicematrix_final_open_bool { - \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int } - \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x - \dim_sub:Nn \l__nicematrix_x_final_dim \col@sep + \__nicematrix_open_x_final_dim: \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_final_i_int - base } \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y } @@ -2697,6 +2818,7 @@ } \cs_new_protected:Npn \__nicematrix_draw_Cdots:nnn #1 #2 #3 { + \__nicematrix_adjust_to_submatrix:nn { #1 } { #2 } \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1 @@ -2716,18 +2838,10 @@ \cs_new_protected:Npn \__nicematrix_actually_draw_Cdots: { \bool_if:NTF \l__nicematrix_initial_open_bool - { - \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int } - \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x - \dim_add:Nn \l__nicematrix_x_initial_dim \col@sep - } + { \__nicematrix_open_x_initial_dim: } { \__nicematrix_set_initial_coords_from_anchor:n { mid~east } } \bool_if:NTF \l__nicematrix_final_open_bool - { - \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int } - \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x - \dim_sub:Nn \l__nicematrix_x_final_dim \col@sep - } + { \__nicematrix_open_x_final_dim: } { \__nicematrix_set_final_coords_from_anchor:n { mid~west } } \bool_lazy_and:nnTF \l__nicematrix_initial_open_bool @@ -2747,8 +2861,45 @@ } \__nicematrix_draw_line: } +\cs_new_protected:Npn \__nicematrix_open_y_initial_dim: + { + \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int - base } + \dim_set:Nn \l__nicematrix_y_initial_dim + { \pgf@y + ( \box_ht:N \strutbox + \extrarowheight ) * \arraystretch } + \int_step_inline:nnn \l__nicematrix_first_col_int \g__nicematrix_col_total_int + { + \cs_if_exist:cT + { pgf @ sh @ ns @ \__nicematrix_env: - \int_use:N \l__nicematrix_initial_i_int - ##1 } + { + \pgfpointanchor + { \__nicematrix_env: - \int_use:N \l__nicematrix_initial_i_int - ##1 } + { north } + \dim_set:Nn \l__nicematrix_y_initial_dim + { \dim_max:nn \l__nicematrix_y_initial_dim \pgf@y } + } + } + } +\cs_new_protected:Npn \__nicematrix_open_y_final_dim: + { + \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_final_i_int - base } + \dim_set:Nn \l__nicematrix_y_final_dim + { \pgf@y - ( \box_dp:N \strutbox ) * \arraystretch } + \int_step_inline:nnn \l__nicematrix_first_col_int \g__nicematrix_col_total_int + { + \cs_if_exist:cT + { pgf @ sh @ ns @ \__nicematrix_env: - \int_use:N \l__nicematrix_final_i_int - ##1 } + { + \pgfpointanchor + { \__nicematrix_env: - \int_use:N \l__nicematrix_final_i_int - ##1 } + { south } + \dim_set:Nn \l__nicematrix_y_final_dim + { \dim_min:nn \l__nicematrix_y_final_dim \pgf@y } + } + } + } \cs_new_protected:Npn \__nicematrix_draw_Vdots:nnn #1 #2 #3 { + \__nicematrix_adjust_to_submatrix:nn { #1 } { #2 } \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 0 @@ -2777,16 +2928,10 @@ { \dim_compare_p:nNn \l__nicematrix_x_initial_dim = \l__nicematrix_x_final_dim } } \bool_if:NTF \l__nicematrix_initial_open_bool - { - \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int } - \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y - } + \__nicematrix_open_y_initial_dim: { \__nicematrix_set_initial_coords_from_anchor:n { south } } \bool_if:NTF \l__nicematrix_final_open_bool - { - \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int } - \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y - } + \__nicematrix_open_y_final_dim: { \__nicematrix_set_final_coords_from_anchor:n { north } } \bool_if:NTF \l__nicematrix_initial_open_bool { @@ -2829,6 +2974,7 @@ } \cs_new_protected:Npn \__nicematrix_draw_Ddots:nnn #1 #2 #3 { + \__nicematrix_adjust_to_submatrix:nn { #1 } { #2 } \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 1 @@ -2843,17 +2989,17 @@ { \bool_if:NTF \l__nicematrix_initial_open_bool { - \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int } - \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y - \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int } - \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \__nicematrix_open_y_initial_dim: + % \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int } + % \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \__nicematrix_open_x_initial_dim: } { \__nicematrix_set_initial_coords_from_anchor:n { south~east } } \bool_if:NTF \l__nicematrix_final_open_bool { - \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int } - \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y - \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int } + % \__nicematrix_open_y_final_dim: + % \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int } + \__nicematrix_open_x_final_dim: \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x } { \__nicematrix_set_final_coords_from_anchor:n { north~west } } @@ -2880,6 +3026,7 @@ } \cs_new_protected:Npn \__nicematrix_draw_Iddots:nnn #1 #2 #3 { + \__nicematrix_adjust_to_submatrix:nn { #1 } { #2 } \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 } { \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 { -1 } @@ -2894,18 +3041,22 @@ { \bool_if:NTF \l__nicematrix_initial_open_bool { - \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int } - \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y - \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_initial_j_int } - \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + % \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int } + % \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y + \__nicematrix_open_y_initial_dim: + % \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_initial_j_int } + % \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x + \__nicematrix_open_x_initial_dim: } { \__nicematrix_set_initial_coords_from_anchor:n { south~west } } \bool_if:NTF \l__nicematrix_final_open_bool { - \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int } - \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y - \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_final_j_int } - \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + % \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int } + % \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y + \__nicematrix_open_y_final_dim: + % \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_final_j_int } + % \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x + \__nicematrix_open_x_final_dim: } { \__nicematrix_set_final_coords_from_anchor:n { north~east } } \bool_if:NT \l__nicematrix_parallelize_diags_bool @@ -3288,7 +3439,7 @@ \AtBeginDocument { \tl_set:Nn \l__nicematrix_argspec_tl { O { } m O { } E { _ ^ } { { } { } } } - \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl + \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl \exp_args:NNV \NewDocumentCommand \__nicematrix_Hdotsfor_i \l__nicematrix_argspec_tl { \tl_gput_right:Nx \g__nicematrix_HVdotsfor_lines_tl @@ -3513,7 +3664,7 @@ { \color ##2 \use:c { l__nicematrix_color _ ##1 _tl } - \pgfusepathqfill + \pgfusepath { fill } } \endpgfpicture } @@ -3558,10 +3709,19 @@ { \__nicematrix_add_to_colors_seq:xn { \tl_if_blank:nF { #1 } { [ #1 ] } { #2 } } - { \__nicematrix_rectanglecolor:nn { #3 } { #4 } } + { \__nicematrix_rectanglecolor:nnn { #3 } { #4 } { 0 pt }} } } -\cs_new_protected:Npn \__nicematrix_rectanglecolor:nn #1 #2 +\NewDocumentCommand \__nicematrix_roundedrectanglecolor { O { } m m m m } + { + \tl_if_blank:nF { #2 } + { + \__nicematrix_add_to_colors_seq:xn + { \tl_if_blank:nF { #1 } { [ #1 ] } { #2 } } + { \__nicematrix_rectanglecolor:nnn { #3 } { #4 } { #5 } } + } + } +\cs_new_protected:Npn \__nicematrix_rectanglecolor:nnn #1 #2 #3 { \__nicematrix_cut_on_hyphen:w #1 \q_stop \tl_clear_new:N \l_tmpc_tl @@ -3571,7 +3731,7 @@ \__nicematrix_cut_on_hyphen:w #2 \q_stop \tl_set:Nx \l__nicematrix_rows_tl { \l_tmpc_tl - \l_tmpa_tl } \tl_set:Nx \l__nicematrix_cols_tl { \l_tmpd_tl - \l_tmpb_tl } - \__nicematrix_cartesian_path: + \__nicematrix_cartesian_path:n { #3 } } \NewDocumentCommand \__nicematrix_cellcolor { O { } m m } { @@ -3657,7 +3817,7 @@ { \color [ #1 ] } { #3 } \__nicematrix_cartesian_path: - \pgfusepathqfill + \pgfusepath { fill } } \bool_set_false:N \l_tmpa_bool } @@ -3669,7 +3829,7 @@ { \color [ #1 ] } { #4 } \__nicematrix_cartesian_path: - \pgfusepathqfill + \pgfusepath { fill } } \bool_set_true:N \l_tmpa_bool } @@ -3703,7 +3863,8 @@ \prg_return_true: \prg_return_false: } -\cs_new_protected:Npn \__nicematrix_cartesian_path: +\cs_new:Npn \__nicematrix_cartesian_path: { \__nicematrix_cartesian_path:n { 0 pt } } +\cs_new_protected:Npn \__nicematrix_cartesian_path:n #1 { \clist_map_inline:Nn \l__nicematrix_cols_tl { @@ -3737,6 +3898,7 @@ \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } \__nicematrix_qpoint:n { row - \l_tmpa_tl } \dim_set:Nn \l_tmpd_dim { \pgf@y + 0.5 \arrayrulewidth } + \pgfsetcornersarced { \pgfpoint { #1 } { #1 } } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpd_dim } { \pgfpoint \l_tmpa_dim \l_tmpb_dim } @@ -3746,13 +3908,16 @@ \NewDocumentCommand \__nicematrix_cellcolor_tabular { O { } m } { \tl_gput_right:Nx \g_nicematrix_code_before_tl - { \cellcolor [ #1 ] { #2 } { \int_use:N \c@iRow - \int_use:N \c@jCol } } + { + \cellcolor [ #1 ] { \exp_not:n { #2 } } + { \int_use:N \c@iRow - \int_use:N \c@jCol } + } } \NewDocumentCommand \__nicematrix_rowcolor_tabular { O { } m } { \tl_gput_right:Nx \g_nicematrix_code_before_tl { - \exp_not:N \rectanglecolor [ #1 ] { #2 } + \exp_not:N \rectanglecolor [ #1 ] { \exp_not:n { #2 } } { \int_use:N \c@iRow - \int_use:N \c@jCol } { \int_use:N \c@iRow - \exp_not:n { \int_use:N \c@jCol } } } @@ -3762,7 +3927,10 @@ \int_compare:nNnT \c@iRow = 1 { \tl_gput_left:Nx \g_nicematrix_code_before_tl - { \exp_not:N \columncolor [ #1 ] { #2 } { \int_use:N \c@jCol } } + { + \exp_not:N \columncolor [ #1 ] + { \exp_not:n { #2 } } { \int_use:N \c@jCol } + } } } \cs_set_eq:NN \OnlyMainNiceMatrix \use:n @@ -3883,7 +4051,7 @@ \pgfpathrectanglecorners { \pgfpoint \l_tmpb_dim \l_tmpa_dim } { \pgfpoint \l_tmpd_dim \l_tmpc_dim } - \pgfusepathqfill + \pgfusepath { fill } \group_end: } \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim } @@ -3907,7 +4075,11 @@ \int_step_inline:nnn { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 } { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c@jCol } \c@jCol } - { \__nicematrix_vline:nn { ##1 } 1 } + { + \tl_if_eq:NnF \l__nicematrix_vlines_clist { all } + { \clist_if_in:NnT \l__nicematrix_vlines_clist { ##1 } } + { \__nicematrix_vline:nn { ##1 } 1 } + } } \cs_new_protected:Npn \__nicematrix_hline:nn #1 #2 { @@ -4026,7 +4198,11 @@ \int_step_inline:nnn { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 } { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c@iRow } \c@iRow } - { \__nicematrix_hline:nn { ##1 } 1 } + { + \tl_if_eq:NnF \l__nicematrix_hlines_clist { all } + { \clist_if_in:NnT \l__nicematrix_hlines_clist { ##1 } } + { \__nicematrix_hline:nn { ##1 } 1 } + } } \cs_set:Npn \__nicematrix_Hline: { \noalign { \ifnum 0 = `} \fi \__nicematrix_Hline_i:n { 1 } } \cs_set:Npn \__nicematrix_Hline_i:n #1 @@ -4513,8 +4689,8 @@ r .value_forbidden:n = true , c .code:n = \tl_set:Nn \l__nicematrix_pos_of_block_tl c , c .value_forbidden:n = true , - % color .tl_set:N = \l__nicematrix_color_tl , - % color .value_required:n = true , + color .tl_set:N = \l__nicematrix_color_tl , + color .value_required:n = true , } \NewExpandableDocumentCommand \__nicematrix_Block: { O { } m D < > { } m } { @@ -4697,10 +4873,9 @@ fill .value_required:n = true , draw .tl_set:N = \l__nicematrix_draw_tl , draw .default:n = default , - color .code:n = - \__nicematrix_fatal:n { Key~color~for~Block } - \tl_set:Nn \l__nicematrix_fill_tl { #1 } , - % color .code:n = \color { #1 } \tl_set:Nn \l__nicematrix_draw_tl { #1 } , + rounded-corners .dim_set:N = \l__nicematrix_rounded_corners_dim , + rounded-corners .default:n = 4 pt , + color .code:n = \color { #1 } \tl_set:Nn \l__nicematrix_draw_tl { #1 } , color .value_required:n = true , line-width .dim_set:N = \l__nicematrix_line_width_dim , line-width .value_required:n = true , @@ -4770,10 +4945,11 @@ { \tl_gput_right:Nx \g_nicematrix_code_before_tl { - \exp_not:N \rectanglecolor + \exp_not:N \roundedrectanglecolor { \exp_not:V \l__nicematrix_fill_tl } { #1 - #2 } { \int_use:N \l__nicematrix_last_row_int - \int_use:N \l__nicematrix_last_col_int } + { \dim_use:N \l__nicematrix_rounded_corners_dim } } } \cs_set_protected_nopar:Npn \diagbox ##1 ##2 @@ -4788,7 +4964,7 @@ { \exp_not:n { ##1 } } { \exp_not:n { ##2 } } } } - \hbox_set:Nn \l__nicematrix_cell_box { #6 } + \hbox_set:Nn \l__nicematrix_cell_box { \set@color #6 } \bool_if:NT \g__nicematrix_rotate_bool \__nicematrix_rotate_cell_box: \pgfpicture \pgfrememberpicturepositiononpagetrue @@ -4944,7 +5120,13 @@ { \str_if_eq:VnTF \l__nicematrix_draw_tl { default } { \CT@arc@ } - { \pgfsetstrokecolor { \l__nicematrix_draw_tl } } + { \exp_args:NV \pgfsetstrokecolor \l__nicematrix_draw_tl } + } + \pgfsetcornersarced + { + \pgfpoint + { \dim_use:N \l__nicematrix_rounded_corners_dim } + { \dim_use:N \l__nicematrix_rounded_corners_dim } } \__nicematrix_cut_on_hyphen:w #2 \q_stop \bool_lazy_and:nnT @@ -4968,17 +5150,19 @@ { \pgfpoint \l_tmpc_dim \l_tmpb_dim } { \pgfpoint \l_tmpd_dim \l_tmpa_dim } \pgfsetlinewidth { 1.1 \l__nicematrix_line_width_dim } - \pgfusepathqstroke + \pgfusepath { stroke } } \endpgfpicture \group_end: } \keys_define:nn { NiceMatrix / BlockStroke } { - % color .tl_set:N = \l__nicematrix_draw_tl , + color .tl_set:N = \l__nicematrix_draw_tl , draw .tl_set:N = \l__nicematrix_draw_tl , draw .default:n = default , line-width .dim_set:N = \l__nicematrix_line_width_dim , + rounded-corners .dim_set:N = \l__nicematrix_rounded_corners_dim , + rounded-corners .default:n = 4 pt } \cs_set_protected:Npn \__nicematrix_renew_matrix: { @@ -5217,10 +5401,12 @@ } \keys_define:nn { NiceMatrix / SubMatrix } { - hlines .clist_set:N = \l__nicematrix_submatrix_hlines_clist , + hlines .clist_set:N = \l__nicematrix_hlines_clist , hlines .default:n = all , - vlines .clist_set:N = \l__nicematrix_submatrix_vlines_clist , + vlines .clist_set:N = \l__nicematrix_vlines_clist , vlines .default:n = all , + hvlines .meta:n = { hlines, vlines } , + hvlines .value_forbidden:n = true , name .code:n = \tl_if_empty:nTF { #1 } { \__nicematrix_error:n { Invalid~name~format } } @@ -5238,24 +5424,45 @@ } , rules .code:n = \keys_set:nn { NiceMatrix / rules } { #1 } , rules .value_required:n = true , + code .tl_set:N = \l__nicematrix_code_tl , + code .value_required:n = true , name .value_required:n = true , unknown .code:n = \__nicematrix_error:n { Unknown~key~for~SubMatrix } } -\NewDocumentCommand \__nicematrix_SubMatrix { m m m m ! O { } } +\NewDocumentCommand \__nicematrix_SubMatrix_in_code_before { m m m m ! O { } } { - \group_begin: \__nicematrix_cut_on_hyphen:w #3 \q_stop \tl_clear_new:N \l_tmpc_tl \tl_clear_new:N \l_tmpd_tl \tl_set_eq:NN \l_tmpc_tl \l_tmpa_tl \tl_set_eq:NN \l_tmpd_tl \l_tmpb_tl \__nicematrix_cut_on_hyphen:w #2 \q_stop + \seq_gput_right:Nx \g__nicematrix_submatrix_seq + { { \l_tmpa_tl } { \l_tmpb_tl } { \l_tmpc_tl } { \l_tmpd_tl } } + \tl_gput_right:Nn \g__nicematrix_internal_code_after_tl + { \SubMatrix { #1 } { #2 } { #3 } { #4 } [ #5 ] } + } +\NewDocumentCommand \__nicematrix_SubMatrix { m m m m O { } } + { + \group_begin: + \tl_clear_new:N \l__nicematrix_first_i_tl + \tl_clear_new:N \l__nicematrix_first_j_tl + \tl_clear_new:N \l__nicematrix_last_i_tl + \tl_clear_new:N \l__nicematrix_last_j_tl + \__nicematrix_cut_on_hyphen:w #2 \q_stop + \tl_set_eq:NN \l__nicematrix_first_i_tl \l_tmpa_tl + \tl_set_eq:NN \l__nicematrix_first_j_tl \l_tmpb_tl + \__nicematrix_cut_on_hyphen:w #3 \q_stop + \tl_set_eq:NN \l__nicematrix_last_i_tl \l_tmpa_tl + \tl_set_eq:NN \l__nicematrix_last_j_tl \l_tmpb_tl \bool_lazy_or:nnTF - { \int_compare_p:nNn \l_tmpc_tl > \g__nicematrix_row_total_int } - { \int_compare_p:nNn \l_tmpd_tl > \g__nicematrix_col_total_int } + { \int_compare_p:nNn \l__nicematrix_last_i_tl > \g__nicematrix_row_total_int } + { \int_compare_p:nNn \l__nicematrix_last_j_tl > \g__nicematrix_col_total_int } { \__nicematrix_error:n { SubMatrix~too~large } } { \str_clear_new:N \l__nicematrix_submatrix_name_str + \clist_clear:N \l__nicematrix_hlines_clist + \clist_clear:N \l__nicematrix_vlines_clist \keys_set:nn { NiceMatrix / SubMatrix } { #5 } \pgfpicture \pgfrememberpicturepositiononpagetrue @@ -5264,43 +5471,43 @@ \dim_set_eq:NN \l__nicematrix_x_initial_dim \c_max_dim \dim_set:Nn \l__nicematrix_x_final_dim { - \c_max_dim } \bool_if:NTF \l__nicematrix_submatrix_slim_bool - { \int_step_inline:nnn \l_tmpa_tl \l_tmpc_tl } + { \int_step_inline:nnn \l__nicematrix_first_i_tl \l__nicematrix_last_i_tl } { \int_step_inline:nnn \l__nicematrix_first_row_int \g__nicematrix_row_total_int } { \cs_if_exist:cT - { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \l_tmpb_tl } + { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \l__nicematrix_first_j_tl } { - \pgfpointanchor { \__nicematrix_env: - ##1 - \l_tmpb_tl } { west } + \pgfpointanchor { \__nicematrix_env: - ##1 - \l__nicematrix_first_j_tl } { west } \dim_set:Nn \l__nicematrix_x_initial_dim { \dim_min:nn \l__nicematrix_x_initial_dim \pgf@x } } \cs_if_exist:cT - { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \l_tmpd_tl } + { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \l__nicematrix_last_j_tl } { - \pgfpointanchor { \__nicematrix_env: - ##1 - \l_tmpd_tl } { east } + \pgfpointanchor { \__nicematrix_env: - ##1 - \l__nicematrix_last_j_tl } { east } \dim_set:Nn \l__nicematrix_x_final_dim { \dim_max:nn \l__nicematrix_x_final_dim \pgf@x } } } - \__nicematrix_qpoint:n { row - \l_tmpa_tl - base } + \__nicematrix_qpoint:n { row - \l__nicematrix_first_i_tl - base } \dim_set:Nn \l__nicematrix_y_initial_dim { \pgf@y + ( \box_ht:N \strutbox + \extrarowheight ) * \arraystretch } - \__nicematrix_qpoint:n { row - \l_tmpc_tl - base } + \__nicematrix_qpoint:n { row - \l__nicematrix_last_i_tl - base } \dim_set:Nn \l__nicematrix_y_final_dim { \pgf@y - ( \box_dp:N \strutbox ) * \arraystretch } \int_step_inline:nnn \l__nicematrix_first_col_int \g__nicematrix_col_total_int { \cs_if_exist:cT - { pgf @ sh @ ns @ \__nicematrix_env: - \l_tmpa_tl - ##1 } + { pgf @ sh @ ns @ \__nicematrix_env: - \l__nicematrix_first_i_tl - ##1 } { - \pgfpointanchor { \__nicematrix_env: - \l_tmpa_tl - ##1 } { north } + \pgfpointanchor { \__nicematrix_env: - \l__nicematrix_first_i_tl - ##1 } { north } \dim_set:Nn \l__nicematrix_y_initial_dim { \dim_max:nn \l__nicematrix_y_initial_dim \pgf@y } } \cs_if_exist:cT - { pgf @ sh @ ns @ \__nicematrix_env: - \l_tmpc_tl - ##1 } + { pgf @ sh @ ns @ \__nicematrix_env: - \l__nicematrix_last_i_tl - ##1 } { - \pgfpointanchor { \__nicematrix_env: - \l_tmpc_tl - ##1 } { south } + \pgfpointanchor { \__nicematrix_env: - \l__nicematrix_last_i_tl - ##1 } { south } \dim_set:Nn \l__nicematrix_y_final_dim { \dim_min:nn \l__nicematrix_y_final_dim \pgf@y } } @@ -5318,9 +5525,10 @@ \CT@arc@ \seq_map_inline:Nn \g__nicematrix_cols_vlism_seq { - \int_compare:nNnT \l_tmpb_tl < { ##1 } + \int_compare:nNnT \l__nicematrix_first_j_tl < { ##1 } { - \int_compare:nNnT { ##1 } < { \int_eval:n { \l_tmpd_tl + 1 } } + \int_compare:nNnT + { ##1 } < { \int_eval:n { \l__nicematrix_last_j_tl + 1 } } { \__nicematrix_qpoint:n { col - ##1 } \pgfpathmoveto { \pgfpoint \pgf@x \l__nicematrix_y_initial_dim } @@ -5329,30 +5537,34 @@ } } } - \tl_if_eq:NnTF \l__nicematrix_submatrix_vlines_clist { all } - { \int_step_inline:nn { \l_tmpd_tl - \l_tmpb_tl } } - { \clist_map_inline:Nn \l__nicematrix_submatrix_vlines_clist } + \tl_if_eq:NnTF \l__nicematrix_vlines_clist { all } + { \int_step_inline:nn { \l__nicematrix_last_j_tl - \l__nicematrix_first_j_tl } } + { \clist_map_inline:Nn \l__nicematrix_vlines_clist } { \bool_lazy_and:nnTF { \int_compare_p:nNn { ##1 } > 0 } - { \int_compare_p:nNn { ##1 } < { \l_tmpd_tl - \l_tmpb_tl + 1 } } { - \__nicematrix_qpoint:n { col - \int_eval:n { ##1 + \l_tmpb_tl } } + \int_compare_p:nNn + { ##1 } < { \l__nicematrix_last_j_tl - \l__nicematrix_first_j_tl + 1 } } + { + \__nicematrix_qpoint:n { col - \int_eval:n { ##1 + \l__nicematrix_first_j_tl } } \pgfpathmoveto { \pgfpoint \pgf@x \l__nicematrix_y_initial_dim } \pgfpathlineto { \pgfpoint \pgf@x \l__nicematrix_y_final_dim } \pgfusepathqstroke } { \__nicematrix_error:nnn { Wrong~line~in~SubMatrix } { vertical } { ##1 } } } - \tl_if_eq:NnTF \l__nicematrix_submatrix_hlines_clist { all } - { \int_step_inline:nn { \l_tmpc_tl - \l_tmpa_tl } } - { \clist_map_inline:Nn \l__nicematrix_submatrix_hlines_clist } + \tl_if_eq:NnTF \l__nicematrix_hlines_clist { all } + { \int_step_inline:nn { \l__nicematrix_last_i_tl - \l__nicematrix_first_i_tl } } + { \clist_map_inline:Nn \l__nicematrix_hlines_clist } { \bool_lazy_and:nnTF { \int_compare_p:nNn { ##1 } > 0 } - { \int_compare_p:nNn { ##1 } < { \l_tmpc_tl - \l_tmpa_tl + 1 } } { - \__nicematrix_qpoint:n { row - \int_eval:n { ##1 + \l_tmpa_tl } } + \int_compare_p:nNn + { ##1 } < { \l__nicematrix_last_i_tl - \l__nicematrix_first_i_tl + 1 } } + { + \__nicematrix_qpoint:n { row - \int_eval:n { ##1 + \l__nicematrix_first_i_tl } } \group_begin: \dim_set:Nn \l_tmpa_dim { \l__nicematrix_x_initial_dim - \l__nicematrix_submatrix_left_xshift_dim } @@ -5407,9 +5619,54 @@ \__nicematrix_node_right:nn #4 { \__nicematrix_env: - \l__nicematrix_submatrix_name_str - right } } \endpgfpicture + \cs_set_eq:NN \pgfpointanchor \__nicematrix_pgfpointanchor:n + \flag_clear_new:n { nicematrix } + \l__nicematrix_code_tl } \group_end: } +\cs_set_eq:NN \__nicematrix_old_pgfpointanchor \pgfpointanchor +\cs_new_protected:Npn \__nicematrix_pgfpointanchor:n #1 + { + \use:e + { \exp_not:N \__nicematrix_old_pgfpointanchor { \__nicematrix_pgfpointanchor_i:nn #1 } } + } +\cs_new:Npn \__nicematrix_pgfpointanchor_i:nn #1 #2 + { #1 { \__nicematrix_pgfpointanchor_ii:w #2 - \q_stop } } +\tl_const:Nn \c__nicematrix_integers_alist_tl + { + { 1 } { } { 2 } { } { 3 } { } { 4 } { } { 5 } { } + { 6 } { } { 7 } { } { 8 } { } { 9 } { } { 10 } { } + { 11 } { } { 12 } { } { 13 } { } { 14 } { } { 15 } { } + { 16 } { } { 17 } { } { 18 } { } { 19 } { } { 20 } { } + } +\cs_new:Npn \__nicematrix_pgfpointanchor_ii:w #1-#2\q_stop + { + \tl_if_empty:nTF { #2 } + { + \str_case:nVTF { #1 } \c__nicematrix_integers_alist_tl + { + \flag_raise:n { nicematrix } + \int_if_even:nTF { \flag_height:n { nicematrix } } + { \int_eval:n { #1 + \l__nicematrix_first_i_tl - 1 } } + { \int_eval:n { #1 + \l__nicematrix_first_j_tl - 1 } } + } + { #1 } + } + { \__nicematrix_pgfpointanchor_iii:w { #1 } #2 } + } +\cs_new:Npn \__nicematrix_pgfpointanchor_iii:w #1 #2 - + { + \str_case:nnF { #1 } + { + { row } { row - \int_eval:n { #2 + \l__nicematrix_first_i_tl - 1 } } + { col } { col - \int_eval:n { #2 + \l__nicematrix_first_j_tl - 1 } } + } + { + \int_eval:n { #1 + \l__nicematrix_first_i_tl - 1 } + - \int_eval:n { #2 + \l__nicematrix_first_j_tl - 1 } + } + } \cs_new_protected:Npn \__nicematrix_node_left:nn #1 #2 { \pgfnode @@ -5636,13 +5893,6 @@ (and~you~try~to~use~'\l_keys_key_str').~If~you~go~on,~ this~key~will~be~ignored. } -\__nicematrix_msg_new:nn { Key~color~for~Block } - { - The~key~'color'~for~the~command~\token_to_str:N \Block\ - is~deprecated:~you~should~use~'fill'~instead.\\ - This~error~is~fatal. - - } \__nicematrix_msg_new:nn { ampersand~in~light-syntax } { You~can't~use~an~ampersand~(\token_to_str:N &)~to~separate~columns~because~ @@ -5717,6 +5967,13 @@ The~names~already~defined~in~this~\__nicematrix_full_name_env:\ are:~ \seq_use:Nnnn \g__nicematrix_submatrix_names_seq { ~and~ } { ,~ } { ~and~ }. } +\__nicematrix_msg_new:nn { r~or~l~with~preamble } + { + You~can't~use~the~key~'\l_keys_key_str'~in~your~\__nicematrix_full_name_env:.~ + You~must~specify~the~alignment~of~your~columns~with~the~preamble~of~ + your~\__nicematrix_full_name_env:.\\ + If~you~go~on,~this~key~will~be~ignored. + } \__nicematrix_msg_new:nn { Hdotsfor~in~col~0 } { You~can't~use~\token_to_str:N \Hdotsfor\ in~an~exterior~column~of~ @@ -5811,8 +6068,8 @@ For~a~list~of~the~available~keys,~type~H~<return>. } { - The~available~keys~are~(in~alphabetic~order):~-,~c,~draw,~fill,~l,~ - line-width~and~r. + The~available~keys~are~(in~alphabetic~order):~c,~draw,~fill,~l,~ + line-width,~rounded-corners~and~r. } \__nicematrix_msg_new:nnn { Unknown~key~for~CodeAfter } { @@ -5841,12 +6098,13 @@ 'delimiters/color',~ 'extra-height',~ 'hlines',~ + 'hvlines',~ 'left-xshift',~ 'name',~ 'right-xshift',~ 'rules'~(with~the~subkeys~'color'~and~'width'),~ 'slim',~ - 'vlines'~and~'xshift'~(which~set~both~'left-xshift'~ + 'vlines'~and~'xshift'~(which~sets~both~'left-xshift'~ and~'right-xshift').\\ } \__nicematrix_msg_new:nnn { Unknown~key~for~notes } |