From c150dcc3b7c55cbf06fcd5a557660f533471aa1a Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 28 Jul 2022 20:06:07 +0000 Subject: nicematrix (28jul22) git-svn-id: svn://tug.org/texlive/trunk@63993 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 510 +++++++++++++++------ 1 file changed, 379 insertions(+), 131 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 3034746e98c..1e58c04393c 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{6.11} -\def\myfiledate{2022/07/16} +\def\myfileversion{6.12} +\def\myfiledate{2022/07/28} \RequirePackage{pgfcore} \usepgfmodule{shapes} \RequirePackage{l3keys2e} @@ -31,6 +31,7 @@ \RequirePackage { array } \RequirePackage { amsmath } \cs_new_protected:Npn \__nicematrix_error:n { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \__nicematrix_warning:n { \msg_warning:nn { nicematrix } } \cs_new_protected:Npn \__nicematrix_error:nn { \msg_error:nnn { nicematrix } } \cs_generate_variant:Nn \__nicematrix_error:nn { n x } \cs_new_protected:Npn \__nicematrix_error:nnn { \msg_error:nnnn { nicematrix } } @@ -43,10 +44,29 @@ { \msg_new:nnn { nicematrix } { #1 } { #2 \\ #3 } } { \msg_new:nnnn { nicematrix } { #1 } { #2 } { #3 } } } +\cs_new_protected:Npn \__nicematrix_error_or_warning:n + { \bool_if:NTF \c__nicematrix_messages_for_Overleaf_bool \__nicematrix_warning:n \__nicematrix_error:n } \str_if_eq:VnT \c_sys_jobname_str { output } { \bool_set_true:N \c__nicematrix_messages_for_Overleaf_bool } \cs_new_protected:Npn \__nicematrix_msg_redirect_name:nn { \msg_redirect_name:nnn { nicematrix } } +\cs_new_protected:Npn \__nicematrix_gredirect_none:n #1 + { + \group_begin: + \globaldefs = 1 + \__nicematrix_msg_redirect_name:nn { #1 } { none } + \group_end: + } +\cs_new_protected:Npn \__nicematrix_err_gredirect_none:n #1 + { + \__nicematrix_error:n { #1 } + \__nicematrix_gredirect_none:n { #1 } + } +\cs_new_protected:Npn \__nicematrix_warning_gredirect_none:n #1 + { + \__nicematrix_warning:n { #1 } + \__nicematrix_gredirect_none:n { #1 } + } \tl_new:N \l__nicematrix_argspec_tl \cs_generate_variant:Nn \seq_set_split:Nnn { N V n } \cs_generate_variant:Nn \keys_define:nn { n x } @@ -55,9 +75,6 @@ \@ifpackageloaded { varwidth } { \bool_const:Nn \c__nicematrix_varwidth_loaded_bool { \c_true_bool } } { \bool_const:Nn \c__nicematrix_varwidth_loaded_bool { \c_false_bool } } - \@ifpackageloaded { arydshln } - { \bool_const:Nn \c__nicematrix_arydshln_loaded_bool { \c_true_bool } } - { \bool_const:Nn \c__nicematrix_arydshln_loaded_bool { \c_false_bool } } \@ifpackageloaded { booktabs } { \bool_const:Nn \c__nicematrix_booktabs_loaded_bool { \c_true_bool } } { \bool_const:Nn \c__nicematrix_booktabs_loaded_bool { \c_false_bool } } @@ -67,7 +84,9 @@ \@ifpackageloaded { tabularx } { \bool_const:Nn \c__nicematrix_tabularx_loaded_bool { \c_true_bool } } { \bool_const:Nn \c__nicematrix_tabularx_loaded_bool { \c_false_bool } } - { } + \@ifpackageloaded { floatrow } + { \bool_const:Nn \c__nicematrix_floatrow_loaded_bool { \c_true_bool } } + { \bool_const:Nn \c__nicematrix_floatrow_loaded_bool { \c_false_bool } } \@ifpackageloaded { tikz } { \bool_const:Nn \c__nicematrix_tikz_loaded_bool \c_true_bool @@ -268,6 +287,7 @@ \cs_new_protected:Npn \__nicematrix_qpoint:n #1 { \pgfpointanchor { \__nicematrix_env: - #1 } { center } } \int_new:N \g__nicematrix_NiceMatrixBlock_int +\int_new:N \l__nicematrix_note_in_caption_int \dim_new:N \l__nicematrix_columns_width_dim \dim_new:N \l__nicematrix_col_width_dim \dim_set:Nn \l__nicematrix_col_width_dim { -1 cm } @@ -292,6 +312,7 @@ \bool_new:N \l__nicematrix_Matrix_bool \bool_new:N \g__nicematrix_rotate_bool \bool_new:N \l__nicematrix_X_column_bool +\bool_new:N \g__nicematrix_caption_finished_bool \tl_new:N \g__nicematrix_aux_tl \tl_new:N \l__nicematrix_columns_type_tl \hook_gput_code:nnn { begindocument } { . } @@ -338,6 +359,7 @@ \dim_zero_new:N \l__nicematrix_tmpc_dim \dim_zero_new:N \l__nicematrix_tmpd_dim \bool_new:N \g__nicematrix_empty_cell_bool +\bool_new:N \g__nicematrix_second_composition_bool \dim_new:N \g__nicematrix_width_last_col_dim \dim_new:N \g__nicematrix_width_first_col_dim \seq_new:N \g__nicematrix_blocks_seq @@ -379,6 +401,7 @@ \clist_new:N \l__nicematrix_submatrix_hlines_clist \clist_new:N \l__nicematrix_submatrix_vlines_clist \bool_new:N \l__nicematrix_dotted_bool +\bool_new:N \l__nicematrix_in_caption_bool \int_new:N \l__nicematrix_first_row_int \int_set:Nn \l__nicematrix_first_row_int 1 \int_new:N \l__nicematrix_first_col_int @@ -415,7 +438,8 @@ } } \newcounter { tabularnote } -\seq_new:N \g__nicematrix_tabularnotes_seq +\seq_new:N \g__nicematrix_notes_seq +\seq_new:N \g__nicematrix_notes_in_caption_seq \tl_new:N \l__nicematrix_tabularnote_tl \seq_new:N \l__nicematrix_notes_labels_seq \newcounter{nicematrix_draft} @@ -433,7 +457,10 @@ \bool_if:nTF { ! \c__nicematrix_enumitem_loaded_bool } { \NewDocumentCommand \tabularnote { m } - { \__nicematrix_error:n { enumitem~not~loaded } } + { + \__nicematrix_error_or_warning:n { enumitem~not~loaded } + \__nicematrix_gredirect_none:n { enumitem~not~loaded } + } } { \newlist { tabularnotes } { enumerate } { 1 } @@ -457,45 +484,95 @@ } \NewDocumentCommand \tabularnote { m } { - \bool_if:nTF { ! \g__nicematrix_NiceArray_bool && \l__nicematrix_in_env_bool } - { \__nicematrix_error:n { tabularnote~forbidden } } + \bool_if:nT { \cs_if_exist_p:N \@captype || \l__nicematrix_in_env_bool } { - \int_zero:N \l_tmpa_int - \bool_if:NT \l__nicematrix_notes_detect_duplicates_bool + \bool_if:nTF { ! \g__nicematrix_NiceArray_bool && \l__nicematrix_in_env_bool } + { \__nicematrix_error:n { tabularnote~forbidden } } { - \seq_map_indexed_inline:Nn \g__nicematrix_tabularnotes_seq - { - \tl_if_eq:nnT { #1 } { ##2 } - { \int_set:Nn \l_tmpa_int { ##1 } \seq_map_break: } - } + \bool_if:NTF \l__nicematrix_in_caption_bool + { \__nicematrix_tabularnote_ii:n { #1 } } + { \__nicematrix_tabularnote_i:n { #1 } } } - \int_compare:nNnTF \l_tmpa_int = 0 + } + } + \cs_new_protected:Npn \__nicematrix_tabularnote_i:n #1 + { + \int_zero:N \l_tmpa_int + \bool_if:NT \l__nicematrix_notes_detect_duplicates_bool + { + \seq_map_indexed_inline:Nn \g__nicematrix_notes_seq { - \stepcounter { tabularnote } - \seq_put_right:Nx \l__nicematrix_notes_labels_seq - { \__nicematrix_notes_format:n { \int_use:c { c @ tabularnote } } } - \seq_gput_right:Nn \g__nicematrix_tabularnotes_seq { #1 } + \tl_if_eq:nnT { #1 } { ##2 } + { \int_set:Nn \l_tmpa_int { ##1 } \seq_map_break: } } + \int_compare:nNnF \l_tmpa_int = 0 + { \int_add:Nn \l_tmpa_int \l__nicematrix_note_in_caption_int } + } + \int_compare:nNnTF \l_tmpa_int = 0 + { + \int_gincr:N \c@tabularnote + \seq_put_right:Nx \l__nicematrix_notes_labels_seq + { \__nicematrix_notes_format:n { \int_use:c { c @ tabularnote } } } + \seq_gput_right:Nn \g__nicematrix_notes_seq { #1 } + } + { + \seq_put_right:Nx \l__nicematrix_notes_labels_seq + { \__nicematrix_notes_format:n { \int_use:N \l_tmpa_int } } + } + \peek_meaning:NF \tabularnote + { + \hbox_set:Nn \l_tmpa_box { - \seq_put_right:Nx \l__nicematrix_notes_labels_seq - { \__nicematrix_notes_format:n { \int_use:N \l_tmpa_int } } + \__nicematrix_notes_label_in_tabular:n + { + \seq_use:Nnnn + \l__nicematrix_notes_labels_seq { , } { , } { , } + } } - \peek_meaning:NF \tabularnote + \int_gsub:Nn \c@tabularnote { 1 } + \int_set_eq:NN \l_tmpa_int \c@tabularnote + \refstepcounter { tabularnote } + \int_compare:nNnT \l_tmpa_int = \c@tabularnote + { \int_gincr:N \c@tabularnote } + \seq_clear:N \l__nicematrix_notes_labels_seq + \hbox_overlap_right:n { \box_use:N \l_tmpa_box } + \skip_horizontal:n { \box_wd:N \l_tmpa_box } + } + } + \cs_new_protected:Npn \__nicematrix_tabularnote_ii:n #1 + { + \int_gincr:N \c@tabularnote + \bool_if:NTF \g__nicematrix_caption_finished_bool + { + \int_compare:nNnTF + \c@tabularnote > { \tl_count:N \g__nicematrix_notes_in_caption_seq } + { \int_gset:Nn \c@tabularnote { 1 } } + \seq_if_in:NnF \g__nicematrix_notes_in_caption_seq { #1 } + { \__nicematrix_fatal:n { Identical~notes~in~caption } } + } + { + \seq_if_in:NnTF \g__nicematrix_notes_in_caption_seq { #1 } + { + \bool_gset_true:N \g__nicematrix_caption_finished_bool + \int_gset:Nn \c@tabularnote { 1 } + } + { \seq_gput_right:Nn \g__nicematrix_notes_in_caption_seq { #1 } } + } + \seq_put_right:Nx \l__nicematrix_notes_labels_seq + { \__nicematrix_notes_format:n { \int_use:N \c@tabularnote } } + \peek_meaning:NF \tabularnote + { + \hbox_set:Nn \l_tmpa_box { - \hbox_set:Nn \l_tmpa_box + \__nicematrix_notes_label_in_tabular:n { - \__nicematrix_notes_label_in_tabular:n - { - \seq_use:Nnnn - \l__nicematrix_notes_labels_seq { , } { , } { , } - } + \seq_use:Nnnn + \l__nicematrix_notes_labels_seq { , } { , } { , } } - \addtocounter { tabularnote } { -1 } - \refstepcounter { tabularnote } - \seq_clear:N \l__nicematrix_notes_labels_seq - \hbox_overlap_right:n { \box_use:N \l_tmpa_box } - \skip_horizontal:n { \box_wd:N \l_tmpa_box } } + \seq_clear:N \l__nicematrix_notes_labels_seq + \hbox_overlap_right:n { \box_use:N \l_tmpa_box } + \skip_horizontal:n { \box_wd:N \l_tmpa_box } } } } @@ -549,6 +626,10 @@ { } \end { pgfscope } } +\tl_new:N \l__nicematrix_caption_tl +\tl_new:N \l__nicematrix_short_caption_tl +\tl_new:N \l__nicematrix_label_tl +\bool_new:N \l__nicematrix_caption_above_bool \bool_new:N \l__nicematrix_colortbl_like_bool \bool_new:N \l__nicematrix_standard_cline_bool \dim_new:N \l__nicematrix_cell_space_top_limit_dim @@ -727,8 +808,6 @@ } \keys_define:nn { NiceMatrix / Env } { - hvlines-except-corners .code:n = \__nicematrix_fatal:n { hvlines-except-corners } , - hvlines-except-corners .default:n = { NW , SW , NE , SE } , corners .clist_set:N = \l__nicematrix_corners_clist , corners .default:n = { NW , SW , NE , SE } , code-before .code:n = @@ -861,9 +940,10 @@ { width .code:n = \dim_set:Nn \l__nicematrix_width_dim { #1 } , width .value_required:n = true , - last-col .code:n = \tl_if_empty:nF { #1 } - { \__nicematrix_error:n { last-col~non~empty~for~NiceMatrixOptions } } - \int_zero:N \l__nicematrix_last_col_int , + last-col .code:n = + \tl_if_empty:nF { #1 } + { \__nicematrix_error:n { last-col~non~empty~for~NiceMatrixOptions } } + \int_zero:N \l__nicematrix_last_col_int , small .bool_set:N = \l__nicematrix_small_bool , small .value_forbidden:n = true , renew-matrix .code:n = \__nicematrix_renew_matrix: , @@ -883,6 +963,8 @@ matrix / columns-type .code:n = \__nicematrix_set_preamble:Nn \l__nicematrix_columns_type_tl { #1 }, matrix / columns-type .value_required:n = true , + caption-above .bool_set:N = \l__nicematrix_caption_above_bool , + caption-above .default:n = true , unknown .code:n = \__nicematrix_error:n { Unknown~key~for~NiceMatrixOptions } } \NewDocumentCommand \NiceMatrixOptions { m } @@ -944,6 +1026,12 @@ notes / bottomrule .default:n = true , tabularnote .tl_set:N = \l__nicematrix_tabularnote_tl , tabularnote .value_required:n = true , + caption .tl_set:N = \l__nicematrix_caption_tl , + caption .value_required:n = true , + short-caption .tl_set:N = \l__nicematrix_short_caption_tl , + short-caption .value_required:n = true , + label .tl_set:N = \l__nicematrix_label_tl , + label .value_required:n = true , last-col .code:n = \tl_if_empty:nF {#1} { \__nicematrix_error:n { last-col~non~empty~for~NiceArray } } \int_zero:N \l__nicematrix_last_col_int , @@ -953,7 +1041,7 @@ } \cs_new_protected:Npn \__nicematrix_cell_begin:w { - \tl_gclear:N \g__nicematrix_post_action_cell_tl + \tl_gclear:N \g__nicematrix_cell_after_hook_tl \cs_set_eq:NN \CodeAfter \__nicematrix_CodeAfter_i: \int_gincr:N \c@jCol \int_compare:nNnT \c@jCol = 1 @@ -1057,7 +1145,7 @@ { \__nicematrix_math_toggle_token: \hbox_set_end: - \g__nicematrix_post_action_cell_tl + \g__nicematrix_cell_after_hook_tl \bool_if:NT \g__nicematrix_rotate_bool \__nicematrix_rotate_cell_box: \__nicematrix_adjust_size_box: \box_set_ht:Nn \l__nicematrix_cell_box @@ -1324,6 +1412,15 @@ \cs_set_eq:NN \multicolumn \__nicematrix_multicolumn:nnn \hook_gput_code:nnn { env / tabular / begin } { . } { \cs_set_eq:NN \multicolumn \__nicematrix_old_multicolumn } + \tl_if_exist:NT \l__nicematrix_note_in_caption_tl + { + \tl_if_empty:NF \l__nicematrix_note_in_caption_tl + { + \int_set_eq:NN \l__nicematrix_note_in_caption_int + { \l__nicematrix_note_in_caption_tl } + \int_gset:Nn \c@tabularnote { \l__nicematrix_note_in_caption_tl } + } + } \seq_gclear:N \g__nicematrix_multicolumn_cells_seq \seq_gclear:N \g__nicematrix_multicolumn_sizes_seq \int_gset:Nn \c@iRow { \l__nicematrix_first_row_int - 1 } @@ -1636,7 +1733,7 @@ \bool_if:NT \l__nicematrix_width_used_bool { \int_compare:nNnT \g__nicematrix_total_X_weight_int = 0 - { \__nicematrix_error:n { width~without~X~columns } } + { \__nicematrix_error_or_warning:n { width~without~X~columns } } } \int_compare:nNnT \g__nicematrix_total_X_weight_int > 0 { @@ -1750,13 +1847,7 @@ \bool_if:NF \l__nicematrix_Matrix_bool { \int_compare:nNnT \c@jCol < \g__nicematrix_static_num_of_col_int - { - \__nicematrix_error:n { columns~not~used } - \group_begin: - \globaldefs = 1 - \__nicematrix_msg_redirect_name:nn { columns~not~used } { none } - \group_end: - } + { \__nicematrix_warning_gredirect_none:n { columns~not~used } } } \__nicematrix_after_array: \egroup @@ -2051,7 +2142,7 @@ } \cs_new_protected:Npn \__nicematrix_center_cell_box: { - \tl_gput_right:Nn \g__nicematrix_post_action_cell_tl + \tl_gput_right:Nn \g__nicematrix_cell_after_hook_tl { \int_compare:nNnT { \box_ht:N \l__nicematrix_cell_box } @@ -2086,7 +2177,7 @@ \bool_if:NTF \c__nicematrix_varwidth_loaded_bool { \__nicematrix_patch_preamble_iv_iv:nn { #2 } { varwidth } } { - \__nicematrix_error:n { varwidth~not~loaded } + \__nicematrix_error_or_warning:n { varwidth~not~loaded } \__nicematrix_patch_preamble_iv_iv:nn { #2 } { minipage } } } @@ -2240,7 +2331,7 @@ \keys_set:nV { WithArrows / X-column } \l_tmpa_tl \int_compare:nNnT \l__nicematrix_weight_int < 0 { - \__nicematrix_error:nx { negative~weight } { \int_use:N \l__nicematrix_weight_int } + \__nicematrix_error_or_warning:n { negative~weight } \int_set:Nn \l__nicematrix_weight_int { - \l__nicematrix_weight_int } } \int_gadd:Nn \g__nicematrix_total_X_weight_int \l__nicematrix_weight_int @@ -2256,7 +2347,7 @@ > { \__nicematrix_cell_begin:w \bool_set_true:N \l__nicematrix_X_column_bool - \tl_gput_right:Nn \g__nicematrix_post_action_cell_tl + \tl_gput_right:Nn \g__nicematrix_cell_after_hook_tl { \hbox_set:Nn \l__nicematrix_cell_box { } } \begin { minipage } { 5 cm } \arraybackslash } @@ -2498,20 +2589,72 @@ { \box_wd:N \l__nicematrix_the_array_box - \arraycolsep } } \begin { minipage } [ t ] { \box_wd:N \l__nicematrix_the_array_box } + \bool_if:NT \l__nicematrix_caption_above_bool + { + \tl_if_empty:NF \l__nicematrix_caption_tl + { + \bool_set_false:N \g__nicematrix_caption_finished_bool + \int_gzero:N \c@tabularnote + \__nicematrix_insert_caption: + \int_gset:Nn \c@tabularnote + { \seq_count:N \g__nicematrix_notes_in_caption_seq } + \int_compare:nNnF \c@tabularnote = 0 + { + \tl_gput_right:Nx \g__nicematrix_aux_tl + { + \tl_set:Nn \exp_not:N \l__nicematrix_note_in_caption_tl + { \int_eval:n { \c@tabularnote } } + } + } + } + } \hbox { \box_use_drop:N \l__nicematrix_the_array_box \__nicematrix_create_extra_nodes: \seq_if_empty:NF \g__nicematrix_blocks_seq \__nicematrix_draw_blocks: } - \bool_lazy_or:nnT - { ! \seq_if_empty_p:N \g__nicematrix_tabularnotes_seq } - { ! \tl_if_empty_p:V \l__nicematrix_tabularnote_tl } + \bool_lazy_any:nT + { + { ! \seq_if_empty_p:N \g__nicematrix_notes_seq } + { ! \seq_if_empty_p:N \g__nicematrix_notes_in_caption_seq } + { ! \tl_if_empty_p:V \l__nicematrix_tabularnote_tl } + } \__nicematrix_insert_tabularnotes: + \cs_set_eq:NN \tabularnote \__nicematrix_tabularnote_error:n + \bool_if:NF \l__nicematrix_caption_above_bool \__nicematrix_insert_caption: \end { minipage } } +\cs_new_protected:Npn \__nicematrix_insert_caption: + { + \tl_if_empty:NF \l__nicematrix_caption_tl + { + \cs_if_exist:NTF \@captype + { \__nicematrix_insert_caption_i: } + { \__nicematrix_error:n { caption~outside~float } } + } + } +\cs_new_protected:Npn \__nicematrix_insert_caption_i: + { + \group_begin: + \bool_set_true:N \l__nicematrix_in_caption_bool + \bool_if:NT \c__nicematrix_floatrow_loaded_bool + { \cs_set_eq:NN \@makecaption \FR@makecaption } + \tl_if_empty:NTF \l__nicematrix_short_caption_tl + { \caption { \l__nicematrix_caption_tl } } + { \caption [ \l__nicematrix_short_caption_tl ] { \l__nicematrix_caption_tl } } + \tl_if_empty:NF \l__nicematrix_label_tl { \label { \l__nicematrix_label_tl } } + \group_end: + } +\cs_new_protected:Npn \__nicematrix_tabularnote_error:n #1 + { + \__nicematrix_error_or_warning:n { tabularnote~below~the~tabular } + \__nicematrix_gredirect_none:n { tabularnote~below~the~tabular } + } \cs_new_protected:Npn \__nicematrix_insert_tabularnotes: { + \seq_gconcat:NNN \g__nicematrix_notes_seq \g__nicematrix_notes_in_caption_seq \g__nicematrix_notes_seq + \int_set:Nn \c@tabularnote { \seq_count:N \g__nicematrix_notes_seq } \skip_vertical:N 0.65ex \group_begin: \l__nicematrix_notes_code_before_tl @@ -2521,13 +2664,13 @@ \bool_if:NTF \l__nicematrix_notes_para_bool { \begin { tabularnotes* } - \seq_map_inline:Nn \g__nicematrix_tabularnotes_seq { \item ##1 } \strut + \seq_map_inline:Nn \g__nicematrix_notes_seq { \item ##1 } \strut \end { tabularnotes* } \par } { \tabularnotes - \seq_map_inline:Nn \g__nicematrix_tabularnotes_seq { \item ##1 } \strut + \seq_map_inline:Nn \g__nicematrix_notes_seq { \item ##1 } \strut \endtabularnotes } } @@ -2540,10 +2683,11 @@ \skip_vertical:N \aboverulesep { \CT@arc@ \hrule height \heavyrulewidth } } - { \__nicematrix_error:n { bottomrule~without~booktabs } } + { \__nicematrix_error_or_warning:n { bottomrule~without~booktabs } } } \l__nicematrix_notes_code_after_tl - \seq_gclear:N \g__nicematrix_tabularnotes_seq + \seq_gclear:N \g__nicematrix_notes_seq + \seq_gclear:N \g__nicematrix_notes_in_caption_seq \int_gzero:N \c@tabularnote } \cs_new_protected:Npn \__nicematrix_use_arraybox_with_notes_b: @@ -3078,6 +3222,19 @@ { \dim_set_eq:NN \l__nicematrix_width_dim \linewidth } \str_gset:Nn \g__nicematrix_name_env_str { NiceTabular } \keys_set:nn { NiceMatrix / NiceTabular } { #1 , #3 } + \tl_if_empty:NF \l__nicematrix_short_caption_tl + { + \tl_if_empty:NT \l__nicematrix_caption_tl + { + \__nicematrix_error_or_warning:n { short-caption~without~caption } + \tl_set_eq:NN \l__nicematrix_caption_tl \l__nicematrix_short_caption_tl + } + } + \tl_if_empty:NF \l__nicematrix_label_tl + { + \tl_if_empty:NT \l__nicematrix_caption_tl + { \__nicematrix_error_or_warning:n { label~without~caption } } + } \bool_set_true:N \l__nicematrix_NiceTabular_bool \NiceArray { #2 } } @@ -4486,7 +4643,7 @@ { \tl_gput_right:Nx \g__nicematrix_row_style_tl { - \tl_gput_right:Nn \exp_not:N \g__nicematrix_post_action_cell_tl + \tl_gput_right:Nn \exp_not:N \g__nicematrix_cell_after_hook_tl { \dim_set:Nn \l__nicematrix_cell_space_top_limit_dim { \dim_use:N \l_tmpa_dim } @@ -4497,7 +4654,7 @@ { \tl_gput_right:Nx \g__nicematrix_row_style_tl { - \tl_gput_right:Nn \exp_not:N \g__nicematrix_post_action_cell_tl + \tl_gput_right:Nn \exp_not:N \g__nicematrix_cell_after_hook_tl { \dim_set:Nn \l__nicematrix_cell_space_bottom_limit_dim { \dim_use:N \l_tmpb_dim } @@ -4906,7 +5063,8 @@ tikz .initial:n = , total-width .dim_set:N = \l__nicematrix_rule_width_dim , total-width .value_required:n = true , - width .meta:n = { total-width = #1 } + width .meta:n = { total-width = #1 } , + unknown .code:n = \__nicematrix_error:n { Unknow~key~for~RulesBis } } \cs_new_protected:Npn \__nicematrix_vline:n #1 { @@ -4981,7 +5139,6 @@ } \cs_new_protected:Npn \__nicematrix_vline_ii: { - \bool_set_false:N \l__nicematrix_dotted_bool \keys_set:nV { NiceMatrix / RulesBis } \l__nicematrix_other_keys_tl \bool_if:NTF \l__nicematrix_dotted_bool \__nicematrix_vline_iv: @@ -5169,7 +5326,7 @@ } \cs_new_protected:Npn \__nicematrix_hline_ii: { - \bool_set_false:N \l__nicematrix_dotted_bool + % \bool_set_false:N \l__nicematrix_dotted_bool \keys_set:nV { NiceMatrix / RulesBis } \l__nicematrix_other_keys_tl \bool_if:NTF \l__nicematrix_dotted_bool \__nicematrix_hline_iv: @@ -5299,33 +5456,38 @@ { \__nicematrix_hline:n { position = ##1 , total-width = \arrayrulewidth } } } } -\cs_set:Npn \__nicematrix_Hline: { \noalign { \ifnum 0 = `} \fi \__nicematrix_Hline_i:n { 1 } } +\cs_set:Npn \__nicematrix_Hline: { \noalign \bgroup \__nicematrix_Hline_i:n { 1 } } \cs_set:Npn \__nicematrix_Hline_i:n #1 { \peek_remove_spaces:n - { - \peek_meaning:NTF \Hline - { \__nicematrix_Hline_ii:nn { #1 + 1 } } - { \__nicematrix_Hline_iii:n { #1 } } - } + { + \peek_meaning:NTF \Hline + { \__nicematrix_Hline_ii:nn { #1 + 1 } } + { \__nicematrix_Hline_iii:n { #1 } } + } } \cs_set:Npn \__nicematrix_Hline_ii:nn #1 #2 { \__nicematrix_Hline_i:n { #1 } } \cs_set:Npn \__nicematrix_Hline_iii:n #1 { - \skip_vertical:n - { - \arrayrulewidth * ( #1 ) - + \doublerulesep * ( \int_max:nn 0 { #1 - 1 } ) - } + \peek_meaning:NTF [ + { \__nicematrix_Hline_iv:nw { #1 } } + { \__nicematrix_Hline_iv:nw { #1 } [ ] } + } +\cs_set:Npn \__nicematrix_Hline_iv:nw #1 [ #2 ] + { + \__nicematrix_compute_rule_width:n { multiplicity = #1 , #2 } + \skip_vertical:n { \l__nicematrix_rule_width_dim } \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl { \__nicematrix_hline:n { + multiplicity = #1 , position = \int_eval:n { \c@iRow + 1 } , - multiplicity = #1 + total-width = \dim_use:N \l__nicematrix_rule_width_dim , + #2 } } - \ifnum 0 = `{ \fi } + \egroup } \keys_define:nn { NiceMatrix / ColumnTypes } { } \cs_new_protected:Npn \__nicematrix_custom_line:n #1 @@ -6235,10 +6397,7 @@ { \msg_error:nnnn { nicematrix } { Block~too~large~2 } { #1 } { #2 } \__nicematrix_msg_redirect_name:nn { Block~too~large~2 } { none } - \group_begin: - \globaldefs = 1 \__nicematrix_msg_redirect_name:nn { columns~not~used } { none } - \group_end: } { \msg_error:nnnn { nicematrix } { Block~too~large~1 } { #1 } { #2 } } } @@ -6286,6 +6445,10 @@ \seq_gput_left:Nx \g__nicematrix_pos_of_blocks_seq { { #1 } { #2 } { #3 } { #4 } { \l__nicematrix_block_name_str } } } + \bool_lazy_and:nnT + { ! (\tl_if_empty_p:N \l__nicematrix_draw_tl) } + { \l__nicematrix_hlines_block_bool || \l__nicematrix_vlines_block_bool } + { \__nicematrix_error:n { hlines~with~color } } \tl_if_empty:NF \l__nicematrix_draw_tl { \tl_gput_right:Nx \g_nicematrix_code_after_tl @@ -6296,7 +6459,7 @@ { \int_use:N \l__nicematrix_last_row_int - \int_use:N \l__nicematrix_last_col_int } } \seq_gput_right:Nn \g__nicematrix_pos_of_stroken_blocks_seq - { { #1 } { #2 } { #3 } { #4 } } + { { #1 } { #2 } { #3 } { #4 } } } \clist_if_empty:NF \l__nicematrix_borders_clist { @@ -6744,11 +6907,6 @@ { \BNiceMatrix } { \endBNiceMatrix } } -\cs_new_protected:Npn \__nicematrix_set_size:n #1-#2 \q_stop - { - \int_set:Nn \l__nicematrix_nb_rows_int { #1 } - \int_set:Nn \l__nicematrix_nb_cols_int { #2 } - } \keys_define:nn { NiceMatrix / Auto } { columns-type .code:n = \__nicematrix_set_preamble:Nn \l__nicematrix_columns_type_tl { #1 } , @@ -6757,40 +6915,37 @@ r .meta:n = { columns-type = r } , c .meta:n = { columns-type = c } } -\NewDocumentCommand \AutoNiceMatrixWithDelims { m m O { } m O { } m ! O { } } +\NewDocumentCommand \AutoNiceMatrixWithDelims + { m m O { } > { \SplitArgument { 1 } { - } } m O { } m ! O { } } + { \__nicematrix_auto_nice_matrix:nnnnnn { #1 } { #2 } #4 { #6 } { #3 , #5 , #7 } } +\cs_new_protected:Npn \__nicematrix_auto_nice_matrix:nnnnnn #1 #2 #3 #4 #5 #6 { - \int_zero_new:N \l__nicematrix_nb_rows_int - \int_zero_new:N \l__nicematrix_nb_cols_int - \__nicematrix_set_size:n #4 \q_stop \group_begin: \bool_set_true:N \l__nicematrix_Matrix_bool - \keys_set_known:nnN { NiceMatrix / Auto } { #3, #5, #7 } \l_tmpa_tl + \keys_set_known:nnN { NiceMatrix / Auto } { #6 } \l_tmpa_tl \cs_set_eq:NN \__nicematrix_transform_preamble: \prg_do_nothing: \use:x { \exp_not:N \begin { NiceArrayWithDelims } { #1 } { #2 } - { - * { \int_use:N \l__nicematrix_nb_cols_int } - { \exp_not:V \l__nicematrix_columns_type_tl } - } + { * { #4 } { \exp_not:V \l__nicematrix_columns_type_tl } } [ \exp_not:V \l_tmpa_tl ] } \int_compare:nNnT \l__nicematrix_first_row_int = 0 { \int_compare:nNnT \l__nicematrix_first_col_int = 0 { & } - \prg_replicate:nn { \l__nicematrix_nb_cols_int - 1 } { & } + \prg_replicate:nn { #4 - 1 } { & } \int_compare:nNnT \l__nicematrix_last_col_int > { -1 } { & } \\ } - \prg_replicate:nn \l__nicematrix_nb_rows_int + \prg_replicate:nn { #3 } { \int_compare:nNnT \l__nicematrix_first_col_int = 0 { & } - \prg_replicate:nn { \l__nicematrix_nb_cols_int - 1 } { { } #6 & } #6 + \prg_replicate:nn { #4 - 1 } { { } #5 & } #5 \int_compare:nNnT \l__nicematrix_last_col_int > { -1 } { & } \\ } \int_compare:nNnT \l__nicematrix_last_row_int > { -2 } { \int_compare:nNnT \l__nicematrix_first_col_int = 0 { & } - \prg_replicate:nn { \l__nicematrix_nb_cols_int - 1 } { & } + \prg_replicate:nn { #4 - 1 } { & } \int_compare:nNnT \l__nicematrix_last_col_int > { -1 } { & } \\ } \end { NiceArrayWithDelims } @@ -6918,7 +7073,8 @@ } \cs_new_protected:Npn \__nicematrix_CodeAfter_iv:n #1 { - \str_if_eq:eeTF \@currenvir { #1 } { \end { #1 } } + \str_if_eq:eeTF \@currenvir { #1 } + { \end { #1 } } { \tl_gput_right:Nn \g_nicematrix_code_after_tl { \end { #1 } } \__nicematrix_CodeAfter_ii:n @@ -7466,7 +7622,7 @@ { \pgfpoint { ( \l__nicematrix_x_initial_dim + \l__nicematrix_x_final_dim) / 2 } - { \pgf@y + \l__nicematrix_brace_yshift_dim } + { \pgf@y + \l__nicematrix_brace_yshift_dim - 3 pt} } \pgfnode { rectangle } @@ -7480,10 +7636,16 @@ { \hfil ## \hfil \crcr \__nicematrix_math_toggle_token: #1 \__nicematrix_math_toggle_token: \cr - \noalign { \skip_vertical:n { 4.5 pt } \nointerlineskip } - \hbox_to_wd:nn - { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim } - { \downbracefill } \cr + \noalign { \skip_vertical:n { 3 pt } \nointerlineskip } + \c_math_toggle_token + \overbrace + { + \hbox_to_wd:nn + { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim } + { } + } + \c_math_toggle_token + \cr } \group_end: } @@ -7498,7 +7660,7 @@ { \pgfpoint { ( \l__nicematrix_x_initial_dim + \l__nicematrix_x_final_dim) / 2 } - { \pgf@y - \l__nicematrix_brace_yshift_dim } + { \pgf@y - \l__nicematrix_brace_yshift_dim + 3 pt } } \pgfnode { rectangle } @@ -7511,10 +7673,16 @@ \halign { \hfil ## \hfil \crcr - \hbox_to_wd:nn - { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim } - { \upbracefill } \cr - \noalign { \skip_vertical:n { 4.5 pt } \nointerlineskip } + \c_math_toggle_token + \underbrace + { + \hbox_to_wd:nn + { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim } + { } + } + \c_math_toggle_token + \cr + \noalign { \skip_vertical:n { 3 pt } \nointerlineskip } \__nicematrix_math_toggle_token: #1 \__nicematrix_math_toggle_token: \cr } } @@ -7645,6 +7813,18 @@ } \bool_set_true:N \c__nicematrix_footnote_bool } +\bool_new:N \l__nicematrix_underscore_loaded_bool +\@ifpackageloaded { underscore } + { \bool_set_true:N \l__nicematrix_underscore_loaded_bool } + { } +\hook_gput_code:nnn { begindocument } { . } + { + \bool_if:NF \l__nicematrix_underscore_loaded_bool + { + \@ifpackageloaded { underscore } + { \__nicematrix_error:n { underscore~after~nicematrix } } + } + } \bool_if:NTF \c__nicematrix_messages_for_Overleaf_bool { \str_const:Nn \c__nicematrix_available_keys_str { } } { @@ -7681,7 +7861,7 @@ { Negative~weight.\\ The~weight~of~the~'X'~columns~must~be~positive~and~you~have~used~ - the~value~'#1'.\\ + the~value~'\int_use:N \l__nicematrix_weight_int'.\\ The~absolute~value~will~be~used. } \__nicematrix_msg_new:nn { last~col~not~used } @@ -7719,13 +7899,7 @@ ~(plus~the~potential~exterior~ones).~ This~error~is~fatal. } -\__nicematrix_msg_new:nn { hvlines-except-corners } - { - Obsolete~key.\\ - The~key~'hvlines-except-corners'~is~now~obsolete.~You~should~instead~use~the~ - keys~'hvlines'~and~'corners'.\\ - This~error~is~fatal. - } + \__nicematrix_msg_new:nn { columns~not~used } { Columns~not~used.\\ @@ -7757,6 +7931,17 @@ You~can't~use~the~command~#1 in~the~last~row~(exterior)~of~the~array.\\ That~command~will~be~ignored. } +\__nicematrix_msg_new:nn { caption~outside~float } + { + Key~caption~forbidden.\\ + You~can't~use~the~key~'caption'~because~you~are~not~in~a~floating~ + environment.~This~key~will~be~ignored. + } +\__nicematrix_msg_new:nn { short-caption~without~caption } + { + You~should~not~use~the~key~'short-caption'~without~'caption'.~ + However,~your~'short-caption'~will~be~used~as~'caption'. + } \__nicematrix_msg_new:nn { double~closing~delimiter } { Double~delimiter.\\ @@ -7775,6 +7960,23 @@ Since~you~haven't~loaded~Tikz,~the~only~value~you~can~give~to~'line-style'~ is~'standard'.~That~key~will~be~ignored. } +\__nicematrix_msg_new:nn { Identical~notes~in~caption } + { + Identical~tabular~notes.\\ + You~can't~put~several~notes~with~the~same~content~in~ + \token_to_str:N \caption\ (but~you~can~in~the~main~tabular).\\ + If~you~go~on,~the~output~will~probably~be~erroneous. + } +\__nicematrix_msg_new:nn { tabularnote~below~the~tabular } + { + \token_to_str:N \tabularnote\ forbidden\\ + You~can't~use~\token_to_str:N \tabularnote\ in~the~caption~ + of~your~tabular~because~the~caption~will~be~composed~below~ + the~tabular.~If~you~want~the~caption~above~the~tabular~use~the~ + key~'caption-above'~in~\token_to_str:N \NiceMatrixOptions.\\ + Your~\token_to_str:N \tabularnote\ will~be~discarded~and~ + no~similar~error~will~raised~in~this~document. + } \__nicematrix_msg_new:nn { Unknown~key~for~rules } { Unknown~key.\\ @@ -7785,26 +7987,34 @@ { Unknown~key.\\ The~key~'\l_keys_key_str'~is~unknown~in~a~'custom-line'.~ - It~will~be~ignored. \\ + It~you~go~on,~you~will~probably~have~other~errors. \\ \c__nicematrix_available_keys_str } { The~available~keys~are~(in~alphabetic~order):~ + ccommand,~ color,~ command,~ dotted,~ letter,~ multiplicity,~ sep-color,~ - tikz,~and~tota-width. + tikz,~and~total-width. } -\__nicematrix_msg_new:nn { Unknown~key~for~xdots } +\__nicematrix_msg_new:nnn { Unknown~key~for~xdots } { Unknown~key.\\ - As~for~now,~there~is~only~five~keys~available~here:~'color',~'inter',~ - 'line-style',~'radius',~ - and~'shorten'~(and~you~try~to~use~'\l_keys_key_str').~ - That~key~will~be~ignored. + The~key~'\l_keys_key_str'~is~unknown~for~a~command~for~drawing~dotted~rules.\\ + \c__nicematrix_available_keys_str + } + { + The~available~keys~are~(in~alphabetic~order):~ + 'color',~ + 'inter',~ + 'line-style',~ + 'radius',~ + 'shorten',~ + 'shorten-end'~and~'shorten-start'. } \__nicematrix_msg_new:nn { Unknown~key~for~rowcolors } { @@ -7813,6 +8023,11 @@ (and~you~try~to~use~'\l_keys_key_str')\\ That~key~will~be~ignored. } +\__nicematrix_msg_new:nn { label~without~caption } + { + You~can't~use~the~key~'label'~in~your~'{NiceTabular}'~because~ + you~have~not~used~the~key~'caption'.~The~key~'label'~will~be~ignored. + } \__nicematrix_msg_new:nn { Construct~too~large } { Construct~too~large.\\ @@ -7820,6 +8035,13 @@ can't~be~drawn~because~your~matrix~is~too~small.\\ That~command~will~be~ignored. } +\__nicematrix_msg_new:nn { underscore~after~nicematrix } + { + Problem~with~'underscore'.\\ + The~package~'underscore'~should~be~loaded~before~'nicematrix'.~ + You~can~go~on~but~you~won't~be~able~to~write~something~such~as:\\ + '\token_to_str:N \Cdots\token_to_str:N _{n~\token_to_str:N \text{~times}}'. + } \__nicematrix_msg_new:nn { ampersand~in~light-syntax } { Ampersand~forbidden.\\ @@ -7834,6 +8056,13 @@ is~in~force.~You~must~use~the~character~'\l__nicematrix_end_of_row_tl'~ (set~by~the~key~'end-of-row').~This~error~is~fatal. } +\__nicematrix_msg_new:nn { hlines~with~color } + { + Incompatible~keys.\\ + You~can't~use~the~keys~'hlines',~'vlines'~or~'hvlines'~for~a~ + '\token_to_str:N \Block'~when~the~key~'color'~or~'draw'~is~used.\\ + Your~key~will~be~discarded. + } \__nicematrix_msg_new:nn { bad~value~for~baseline } { Bad~value~for~baseline.\\ @@ -7870,8 +8099,7 @@ } \__nicematrix_msg_new:nn { width~without~X~columns } { - No~X~column.\\ - You~have~used~the~key~'width'~but~you~have~put~no~'X'~column. \\ + You~have~used~the~key~'width'~but~you~have~put~no~'X'~column.~ That~key~will~be~ignored. } \__nicematrix_msg_new:nn { key~multiplicity~with~dotted } @@ -8048,7 +8276,8 @@ enumitem~not~loaded.\\ You~can't~use~the~command~\token_to_str:N\tabularnote\ ~because~you~haven't~loaded~'enumitem'.\\ - This~command~will~be~ignored. + All~the~commands~\token_to_str:N\tabularnote\ will~be~ + ignored~in~the~document. } \__nicematrix_msg_new:nn { tikz~in~custom-line~without~tikz } { @@ -8107,6 +8336,21 @@ loaded.\\ Your~column~will~behave~like~'p'. } +\__nicematrix_msg_new:nnn { Unknow~key~for~RulesBis } + { + Unkown~key.\\ + Your~key~'\l_keys_key_str'~is~unknown~for~a~rule.\\ + \c__nicematrix_available_keys_str + } + { + The~available~keys~are~(in~alphabetic~order):~ + color,~ + dotted,~ + multiplicity,~ + sep-color,~ + tikz,~and~total-width. + } + \__nicematrix_msg_new:nnn { Unknown~key~for~Block } { Unknown~key.\\ @@ -8225,6 +8469,7 @@ { The~available~keys~are~(in~alphabetic~order):~ allow-duplicate-names,~ + caption-above,~ cell-space-bottom-limit,~ cell-space-limits,~ cell-space-top-limit,~ @@ -8385,6 +8630,7 @@ b,~ baseline,~ c,~ + caption,~ cell-space-bottom-limit,~ cell-space-limits,~ cell-space-top-limit,~ @@ -8406,6 +8652,7 @@ first-row,~ hlines,~ hvlines,~ + label,~ last-col,~ last-row,~ left-margin,~ @@ -8418,6 +8665,7 @@ respect-arraystretch,~ right-margin,~ rules~(with~the~subkeys~'color'~and~'width'),~ + short-caption,~ t,~ tabularnote,~ vlines,~ -- cgit v1.2.3