summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty')
-rw-r--r--Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty434
1 files changed, 266 insertions, 168 deletions
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
index c9122db838d..b0fa2412209 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.19}
-\def\myfiledate{2021/07/23}
+\def\myfileversion{6.0}
+\def\myfiledate{2021/08/10}
\RequirePackage{pgfcore}
\usepgfmodule{shapes}
\RequirePackage{l3keys2e}
@@ -123,9 +123,7 @@
\AtBeginDocument
{
\@ifpackageloaded { colortbl }
- {
- \bool_set_true:N \c__nicematrix_colortbl_loaded_bool
- }
+ { \bool_set_true:N \c__nicematrix_colortbl_loaded_bool }
{
\cs_set_protected:Npn \CT@arc@ { }
\cs_set:Npn \arrayrulecolor #1 # { \CT@arc { #1 } }
@@ -152,6 +150,7 @@
}
}
}
+\cs_if_exist:NF \AtBeginEnvironment { \RequirePackage { etoolbox } }
\cs_set:Npn \__nicematrix_standard_cline #1 { \__nicematrix_standard_cline:w #1 \q_stop }
\cs_set:Npn \__nicematrix_standard_cline:w #1-#2 \q_stop
{
@@ -271,13 +270,6 @@
}
}
}
-\bool_new:N \c__nicematrix_define_L_C_R_bool
-\cs_new_protected:Npn \__nicematrix_define_L_C_R:
- {
- \newcolumntype L l
- \newcolumntype C c
- \newcolumntype R r
- }
\int_new:N \g__nicematrix_env_int
\cs_new:Npn \__nicematrix_env: { nm - \int_use:N \g__nicematrix_env_int }
\NewExpandableDocumentCommand \NiceMatrixLastEnv { }
@@ -286,10 +278,12 @@
{ \pgfpointanchor { \__nicematrix_env: - #1 } { center } }
\int_new:N \g__nicematrix_NiceMatrixBlock_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 }
\int_new:N \g__nicematrix_row_total_int
\int_new:N \g__nicematrix_col_total_int
-\tl_new:N \l__nicematrix_cell_type_tl
-\tl_set:Nn \l__nicematrix_cell_type_tl { c }
+\str_new:N \l__nicematrix_hpos_cell_str
+\str_set:Nn \l__nicematrix_hpos_cell_str { c }
\dim_new:N \g__nicematrix_blocks_wd_dim
\dim_new:N \g__nicematrix_blocks_ht_dim
\dim_new:N \g__nicematrix_blocks_dp_dim
@@ -300,6 +294,7 @@
\dim_new:N \l__nicematrix_tabular_width_dim
\bool_new:N \l__nicematrix_Matrix_bool
\bool_new:N \g__nicematrix_rotate_bool
+\bool_new:N \l__nicematrix_X_column_bool
\tl_new:N \g__nicematrix_aux_tl
\cs_new_protected:Npn \__nicematrix_test_if_math_mode:
{
@@ -325,7 +320,7 @@
\int_new:N \l__nicematrix_old_iRow_int
\int_new:N \l__nicematrix_old_jCol_int
\tl_new:N \l__nicematrix_rules_color_tl
-\int_new:N \g__nicematrix_nb_of_X_int
+\int_new:N \g__nicematrix_total_X_weight_int
\bool_new:N \l__nicematrix_X_columns_aux_bool
\dim_new:N \l__nicematrix_X_columns_dim
\bool_new:N \g__nicematrix_after_col_zero_bool
@@ -349,6 +344,7 @@
\seq_new:N \g__nicematrix_pos_of_stroken_blocks_seq
\seq_new:N \l__nicematrix_corners_cells_seq
\seq_new:N \g__nicematrix_submatrix_names_seq
+\bool_new:N \l__nicematrix_width_used_bool
\seq_new:N \g__nicematrix_multicolumn_cells_seq
\seq_new:N \g__nicematrix_multicolumn_sizes_seq
\int_new:N \l__nicematrix_row_min_int
@@ -364,8 +360,8 @@
\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_hpos_of_block_tl
-\tl_set:Nn \l__nicematrix_hpos_of_block_tl { c }
+\str_new:N \l__nicematrix_hpos_block_str
+\str_set:Nn \l__nicematrix_hpos_block_str { c }
\bool_new:N \l__nicematrix_hpos_of_block_cap_bool
\tl_new:N \l__nicematrix_vpos_of_block_tl
\tl_set:Nn \l__nicematrix_vpos_of_block_tl { c }
@@ -652,7 +648,6 @@
}
\keys_define:nn { NiceMatrix / Env }
{
-
hvlines-except-corners .code:n =
{
\clist_set:Nn \l__nicematrix_corners_clist { #1 }
@@ -888,6 +883,9 @@
}
\keys_define:nn { NiceMatrix / NiceTabular }
{
+ width .code:n = \dim_set:Nn \l__nicematrix_width_dim { #1 }
+ \bool_set_true:N \l__nicematrix_width_used_bool ,
+ width .value_required:n = true ,
notes / para .bool_set:N = \l__nicematrix_notes_para_bool ,
notes / para .default:n = true ,
notes / bottomrule .bool_set:N = \l__nicematrix_notes_bottomrule_bool ,
@@ -903,7 +901,7 @@
}
\cs_new_protected:Npn \__nicematrix_Cell:
{
- \tl_gclear:N \g__nicematrix_post_treatment_cell_tl
+ \tl_gclear:N \g__nicematrix_post_action_cell_tl
\cs_set_eq:NN \CodeAfter \__nicematrix_CodeAfter_i:n
\int_gincr:N \c@jCol
\int_compare:nNnT \c@jCol = 1
@@ -1007,7 +1005,7 @@
{
\__nicematrix_math_toggle_token:
\hbox_set_end:
- \g__nicematrix_post_treatment_cell_tl
+ \g__nicematrix_post_action_cell_tl
\bool_if:NT \g__nicematrix_rotate_bool \__nicematrix_rotate_cell_box:
\__nicematrix_adjust_size_box:
\box_set_ht:Nn \l__nicematrix_cell_box
@@ -1258,7 +1256,6 @@
\cs_set_eq:NN \Hspace \__nicematrix_Hspace:
\cs_set_eq:NN \Hdotsfor \__nicematrix_Hdotsfor:
\cs_set_eq:NN \Vdotsfor \__nicematrix_Vdotsfor:
- \cs_set_eq:NN \multicolumn \__nicematrix_multicolumn:nnn
\cs_set_eq:NN \Block \__nicematrix_Block:
\cs_set_eq:NN \rotate \__nicematrix_rotate:
\cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n
@@ -1269,6 +1266,9 @@
\cs_set_eq:NN \RowStyle \__nicematrix_RowStyle:n
\bool_if:NT \l__nicematrix_colortbl_like_bool \__nicematrix_colortbl_like:
\bool_if:NT \l__nicematrix_renew_dots_bool \__nicematrix_renew_dots:
+ \cs_set_eq:NN \multicolumn \__nicematrix_multicolumn:nnn
+ \AtBeginEnvironment { tabular }
+ { \cs_set_eq:NN \multicolumn \__nicematrix_old_multicolumn }
\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 }
@@ -1319,7 +1319,6 @@
\seq_gclear_new:N \g__nicematrix_multicolumn_sizes_seq
\__nicematrix_pre_array_ii:
\box_clear_new:N \l__nicematrix_the_array_box
- \bool_if:NT \c__nicematrix_define_L_C_R_bool \__nicematrix_define_L_C_R:
\__nicematrix_construct_preamble:
\dim_zero_new:N \l__nicematrix_left_delim_dim
\dim_zero_new:N \l__nicematrix_right_delim_dim
@@ -1354,7 +1353,7 @@
{
\tl_gput_right:Nn \g__nicematrix_row_style_tl
{
- \tl_gput_right:Nn \g__nicematrix_post_treatment_cell_tl
+ \tl_gput_right:Nn \g__nicematrix_post_action_cell_tl
{ \dim_set:Nn \l__nicematrix_cell_space_top_limit_dim { #1 } }
}
} ,
@@ -1363,7 +1362,7 @@
{
\tl_gput_right:Nn \g__nicematrix_row_style_tl
{
- \tl_gput_right:Nn \g__nicematrix_post_treatment_cell_tl
+ \tl_gput_right:Nn \g__nicematrix_post_action_cell_tl
{ \dim_set:Nn \l__nicematrix_cell_space_bottom_limit_dim { #1 } }
}
} ,
@@ -1420,6 +1419,7 @@
\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 \rowlistcolors \__nicematrix_rowlistcolors
\cs_set_eq:NN \arraycolor \__nicematrix_arraycolor
\cs_set_eq:NN \columncolor \__nicematrix_columncolor
\cs_set_eq:NN \chessboardcolors \__nicematrix_chessboardcolors
@@ -1553,15 +1553,20 @@
\skip_horizontal:N \l__nicematrix_right_margin_dim
\skip_horizontal:N \l__nicematrix_extra_right_margin_dim
\hbox_set_end:
- \int_compare:nNnT \g__nicematrix_nb_of_X_int > 0
+ \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 } }
+ }
+ \int_compare:nNnT \g__nicematrix_total_X_weight_int > 0
{
\bool_if:NTF \l__nicematrix_X_columns_aux_bool
{ \dim_set_eq:NN \l_tmpa_dim \l__nicematrix_X_columns_dim }
{
\dim_set:Nn \l_tmpa_dim
{
- ( \textwidth - \box_wd:N \l__nicematrix_the_array_box )
- / \int_use:N \g__nicematrix_nb_of_X_int
+ ( \l__nicematrix_width_dim - \box_wd:N \l__nicematrix_the_array_box )
+ / \int_use:N \g__nicematrix_total_X_weight_int
}
}
\tl_gput_right:Nx \g__nicematrix_aux_tl
@@ -1701,7 +1706,7 @@
{ ! { \skip_horizontal:N \arrayrulewidth } }
}
}
- \int_gzero:N \g__nicematrix_nb_of_X_int
+ \int_gzero:N \g__nicematrix_total_X_weight_int
\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
@@ -1761,9 +1766,9 @@
! { \__nicematrix_patch_preamble_ii:nn #1 }
@ { \__nicematrix_patch_preamble_ii:nn #1 }
| { \__nicematrix_patch_preamble_iii:n #1 }
- p { \__nicematrix_patch_preamble_iv:nnn t #1 }
- b { \__nicematrix_patch_preamble_iv:nnn b #1 }
- m { \__nicematrix_patch_preamble_iv:nnn b #1 }
+ p { \__nicematrix_patch_preamble_iv:n #1 }
+ b { \__nicematrix_patch_preamble_iv:n #1 }
+ m { \__nicematrix_patch_preamble_iv:n #1 }
\__nicematrix_w: { \__nicematrix_patch_preamble_v:nnnn { } #1 }
\__nicematrix_W: { \__nicematrix_patch_preamble_v:nnnn { \cs_set_eq:NN \hss \hfil } #1 }
\__nicematrix_true_c: { \__nicematrix_patch_preamble_vi:n #1 }
@@ -1773,10 +1778,7 @@
) { \__nicematrix_patch_preamble_viii:nn #1 }
] { \__nicematrix_patch_preamble_viii:nn #1 }
\} { \__nicematrix_patch_preamble_viii:nn #1 }
- X { \__nicematrix_patch_preamble_xii: }
- C { \__nicematrix_error:nn { old~column~type } #1 }
- L { \__nicematrix_error:nn { old~column~type } #1 }
- R { \__nicematrix_error:nn { old~column~type } #1 }
+ X { \__nicematrix_patch_preamble_ix:n }
\q_stop { }
}
{
@@ -1808,7 +1810,7 @@
{
\tl_gput_right:Nn \g__nicematrix_preamble_tl
{
- > { \__nicematrix_Cell: \tl_set:Nn \l__nicematrix_cell_type_tl { #1 } }
+ > { \__nicematrix_Cell: \str_set:Nn \l__nicematrix_hpos_cell_str { #1 } }
#1
< \__nicematrix_end_Cell:
}
@@ -1853,35 +1855,93 @@
}
}
\bool_new:N \l__nicematrix_bar_at_end_of_pream_bool
-\cs_new_protected:Npn \__nicematrix_patch_preamble_iv:nnn #1 #2 #3
+\keys_define:nn { WithArrows / p-column }
+ {
+ r .code:n = \str_set:Nn \l__nicematrix_hpos_col_str { r } ,
+ r .value_forbidden:n = true ,
+ c .code:n = \str_set:Nn \l__nicematrix_hpos_col_str { c } ,
+ c .value_forbidden:n = true ,
+ l .code:n = \str_set:Nn \l__nicematrix_hpos_col_str { l } ,
+ l .value_forbidden:n = true ,
+ p .code:n = \str_set:Nn \l__nicematrix_vpos_col_str { p } ,
+ p .value_forbidden:n = true ,
+ t .meta:n = p ,
+ m .code:n = \str_set:Nn \l__nicematrix_vpos_col_str { m } ,
+ m .value_forbidden:n = true ,
+ b .code:n = \str_set:Nn \l__nicematrix_vpos_col_str { b } ,
+ b .value_forbidden:n = true
+ }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_iv:n #1
+ {
+ \str_set:Nn \l__nicematrix_vpos_col_str { #1 }
+ \__nicematrix_patch_preamble_iv_i:n
+ }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_iv_i:n #1
+ {
+ \str_if_eq:nnTF { #1 } { [ }
+ { \__nicematrix_patch_preamble_iv_ii:w [ }
+ { \__nicematrix_patch_preamble_iv_ii:w [ ] { #1 } }
+ }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_iv_ii:w [ #1 ]
+ { \__nicematrix_patch_preamble_iv_iii:nn { #1 } }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_iv_iii:nn #1 #2
+ {
+ \str_set:Nn \l__nicematrix_hpos_col_str { j }
+ \keys_set:nn { WithArrows / p-column } { #1 }
+ \__nicematrix_patch_preamble_iv_iv:n { #2 }
+ }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_iv_iv:n #1
+ {
+ \use:x
+ {
+ \__nicematrix_patch_preamble_iv_v:nnnn
+ { \str_if_eq:VnTF \l__nicematrix_vpos_col_str { p } { t } { b } }
+ { \dim_eval:n { #1 } }
+ {
+ \str_if_eq:VnTF \l__nicematrix_hpos_col_str j
+ { \str_set:Nn \exp_not:N \l__nicematrix_hpos_cell_str { c } }
+ { \str_set:Nn \exp_not:N \l__nicematrix_hpos_cell_str \l__nicematrix_hpos_col_str }
+ \str_case:Vn \l__nicematrix_hpos_col_str
+ {
+ c { \exp_not:N \centering }
+ l { \exp_not:N \raggedright }
+ r { \exp_not:N \raggedleft }
+ }
+ }
+ { \str_if_eq:VnT \l__nicematrix_vpos_col_str { m } \__nicematrix_center_cell_box: }
+ }
+ \int_gincr:N \c@jCol
+ \__nicematrix_patch_preamble_x:n
+ }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_iv_v:nnnn #1 #2 #3 #4
{
\tl_gput_right:Nn \g__nicematrix_preamble_tl
{
> {
+ \dim_set:Nn \l__nicematrix_col_width_dim { #2 }
\__nicematrix_Cell:
- \begin { minipage } [ #1 ] { \dim_eval:n { #3 } }
+ \begin { minipage } [ #1 ] { #2 }
\everypar
{
\vrule height \box_ht:N \@arstrutbox width \c_zero_dim
\everypar { }
}
- \g__nicematrix_row_style_tl % added the 2021-07-17
+ #3
+ \g__nicematrix_row_style_tl
\arraybackslash
}
c
< {
\@finalstrut \@arstrutbox
\end { minipage }
- \str_if_eq:nnT { #2 } m \__nicematrix_center_cell_box:
+ #4
\__nicematrix_end_Cell:
}
}
- \int_gincr:N \c@jCol
- \__nicematrix_patch_preamble_x:n
}
\cs_new_protected:Npn \__nicematrix_center_cell_box:
{
- \tl_gput_right:Nn \g__nicematrix_post_treatment_cell_tl
+ \tl_gput_right:Nn \g__nicematrix_post_action_cell_tl
{
\int_compare:nNnT
{ \box_ht:N \l__nicematrix_cell_box }
@@ -1905,9 +1965,10 @@
\tl_gput_right:Nn \g__nicematrix_preamble_tl
{
> {
+ \dim_set:Nn \l__nicematrix_col_width_dim { #4 }
\hbox_set:Nw \l__nicematrix_cell_box
\__nicematrix_Cell:
- \tl_set:Nn \l__nicematrix_cell_type_tl { #3 }
+ \str_set:Nn \l__nicematrix_hpos_cell_str { #3 }
}
c
< {
@@ -2008,6 +2069,47 @@
\__nicematrix_patch_preamble:n #3
}
}
+\cs_new_protected:Npn \__nicematrix_patch_preamble_ix:n #1
+ {
+ \str_if_eq:nnTF { #1 } { [ }
+ { \__nicematrix_patch_preamble_ix_i:w [ }
+ { \__nicematrix_patch_preamble_ix_i:w [ ] #1 }
+ }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_ix_i:w [ #1 ]
+ { \__nicematrix_patch_preamble_ix_ii:n { #1 } }
+\keys_define:nn { WithArrows / X-column }
+ { unknown .code:n = \int_set:Nn \l__nicematrix_weight_int { \l_keys_key_str } }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_ix_ii:n #1
+ {
+ \str_set:Nn \l__nicematrix_hpos_col_str { j }
+ \tl_set:Nn \l__nicematrix_vpos_col_str { p }
+ \int_zero_new:N \l__nicematrix_weight_int
+ \int_set:Nn \l__nicematrix_weight_int { 1 }
+ \keys_set_known:nnN { WithArrows / p-column } { #1 } \l_tmpa_tl
+ \keys_set:nV { WithArrows / X-column } \l_tmpa_tl
+ \int_gadd:Nn \g__nicematrix_total_X_weight_int \l__nicematrix_weight_int
+ \bool_if:NTF \l__nicematrix_X_columns_aux_bool
+ { \__nicematrix_patch_preamble_iv_iv:n { \l__nicematrix_weight_int \l__nicematrix_X_columns_dim } }
+ {
+ \tl_gput_right:Nn \g__nicematrix_preamble_tl
+ {
+ > {
+ \__nicematrix_Cell:
+ \bool_set_true:N \l__nicematrix_X_column_bool
+ \tl_gput_right:Nn \g__nicematrix_post_action_cell_tl
+ { \hbox_set:Nn \l__nicematrix_cell_box { } }
+ \begin { minipage } { 5 cm } \arraybackslash
+ }
+ c
+ < {
+ \end { minipage }
+ \__nicematrix_end_Cell:
+ }
+ }
+ \int_gincr:N \c@jCol
+ \__nicematrix_patch_preamble_x:n
+ }
+ }
\cs_new_protected:Npn \__nicematrix_patch_preamble_xi:n #1
{
\tl_gput_right:Nn \g__nicematrix_preamble_tl
@@ -2019,7 +2121,7 @@
\cs_new_protected:Npn \__nicematrix_patch_preamble_x:n #1
{
\str_if_eq:nnTF { #1 } { < }
- \__nicematrix_patch_preamble_ix:n
+ \__nicematrix_patch_preamble_xii:n
{
\tl_if_eq:NnTF \l__nicematrix_vlines_clist { all }
{
@@ -2037,32 +2139,11 @@
\__nicematrix_patch_preamble:n { #1 }
}
}
-\cs_new_protected:Npn \__nicematrix_patch_preamble_ix:n #1
+\cs_new_protected:Npn \__nicematrix_patch_preamble_xii:n #1
{
\tl_gput_right:Nn \g__nicematrix_preamble_tl { < { #1 } }
\__nicematrix_patch_preamble_x:n
}
-\cs_new_protected:Npn \__nicematrix_patch_preamble_xii:
- {
- \int_gincr:N \g__nicematrix_nb_of_X_int
- \bool_if:NTF \l__nicematrix_X_columns_aux_bool
- { \exp_args:NNNV \__nicematrix_patch_preamble_iv:nnn t p \l__nicematrix_X_columns_dim }
- {
- \tl_gput_right:Nn \g__nicematrix_preamble_tl
- {
- > {
- \__nicematrix_Cell:
- \tl_set:Nn \l__nicematrix_cell_type_tl { c }
- \tl_gput_right:Nn \g__nicematrix_post_treatment_cell_tl
- { \hbox_set:Nn \l__nicematrix_cell_box { } }
- }
- c
- < { \__nicematrix_end_Cell: }
- }
- \int_gincr:N \c@jCol
- \__nicematrix_patch_preamble_x:n
- }
- }
\cs_new:Npn \__nicematrix_multicolumn:nnn #1 #2 #3
{
\multispan { #1 }
@@ -2115,9 +2196,6 @@
\__nicematrix_w: { \__nicematrix_patch_m_preamble_v:nnnn { } #1 }
\__nicematrix_W: { \__nicematrix_patch_m_preamble_v:nnnn { \cs_set_eq:NN \hss \hfil } #1 }
\__nicematrix_true_c: { \__nicematrix_patch_m_preamble_vi:n #1 }
- C { \__nicematrix_error:nn { old~column~type } #1 }
- L { \__nicematrix_error:nn { old~column~type } #1 }
- R { \__nicematrix_error:nn { old~column~type } #1 }
\q_stop { }
}
{ \__nicematrix_fatal:nn { unknown~column~type } { #1 } }
@@ -2126,7 +2204,7 @@
{
\tl_gput_right:Nn \g__nicematrix_preamble_tl
{
- > { \__nicematrix_Cell: \tl_set:Nn \l__nicematrix_cell_type_tl { #1 } }
+ > { \__nicematrix_Cell: \str_set:Nn \l__nicematrix_hpos_cell_str { #1 } }
#1
< \__nicematrix_end_Cell:
}
@@ -2169,7 +2247,7 @@
> {
\hbox_set:Nw \l__nicematrix_cell_box
\__nicematrix_Cell:
- \tl_set:Nn \l__nicematrix_cell_type_tl { #3 }
+ \str_set:Nn \l__nicematrix_hpos_cell_str { #3 }
}
c
< {
@@ -2799,12 +2877,24 @@
{ \bool_gset_true:N \g__nicematrix_not_empty_cell_bool }
\NewDocumentEnvironment { NiceTabular } { O { } m ! O { } }
{
+ \dim_zero_new:N \l__nicematrix_width_dim
+ \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 }
\bool_set_true:N \l__nicematrix_NiceTabular_bool
\NiceArray { #2 }
}
{ \endNiceArray }
+\NewDocumentEnvironment { NiceTabularX } { m O { } m ! O { } }
+ {
+ \str_gset:Nn \g__nicematrix_name_env_str { NiceTabularX }
+ \dim_zero_new:N \l__nicematrix_width_dim
+ \dim_set:Nn \l__nicematrix_width_dim { #1 }
+ \keys_set:nn { NiceMatrix / NiceTabular } { #2 , #4 }
+ \bool_set_true:N \l__nicematrix_NiceTabular_bool
+ \NiceArray { #3 }
+ }
+ { \endNiceArray }
\NewDocumentEnvironment { NiceTabular* } { m O { } m ! O { } }
{
\str_gset:Nn \g__nicematrix_name_env_str { NiceTabular* }
@@ -4152,6 +4242,7 @@
{ \tl_gput_right:cx { g__nicematrix_color _ \int_use:N \l_tmpa_int _tl } { #2 } }
}
\cs_generate_variant:Nn \__nicematrix_add_to_colors_seq:nn { x n }
+\cs_generate_variant:Nn \__nicematrix_add_to_colors_seq:nn { x x }
\cs_new_protected:Npn \__nicematrix_actually_color:
{
\pgfpicture
@@ -4170,36 +4261,30 @@
\tl_set:Nn \l_tmpa_tl { #1 }
\tl_set:Nn \l_tmpb_tl { #2 }
}
+\cs_new_protected:Npn \__nicematrix_cartesian_color:nn #1 #2
+ {
+ \tl_set:Nn \l__nicematrix_rows_tl { #1 }
+ \tl_set:Nn \l__nicematrix_cols_tl { #2 }
+ \__nicematrix_cartesian_path:
+ }
\NewDocumentCommand \__nicematrix_rowcolor { O { } m m }
{
\tl_if_blank:nF { #2 }
{
\__nicematrix_add_to_colors_seq:xn
{ \tl_if_blank:nF { #1 } { [ #1 ] } { #2 } }
- { \__nicematrix_rowcolor:n { #3 } }
+ { \__nicematrix_cartesian_color:nn { #3 } { - } }
}
}
-\cs_new_protected:Npn \__nicematrix_rowcolor:n #1
- {
- \tl_set:Nn \l__nicematrix_rows_tl { #1 }
- \tl_set:Nn \l__nicematrix_cols_tl { - }
- \__nicematrix_cartesian_path:
- }
\NewDocumentCommand \__nicematrix_columncolor { O { } m m }
{
\tl_if_blank:nF { #2 }
{
\__nicematrix_add_to_colors_seq:xn
{ \tl_if_blank:nF { #1 } { [ #1 ] } { #2 } }
- { \__nicematrix_columncolor:n { #3 } }
+ { \__nicematrix_cartesian_color:nn { - } { #3 } }
}
}
-\cs_new_protected:Npn \__nicematrix_columncolor:n #1
- {
- \tl_set:Nn \l__nicematrix_rows_tl { - }
- \tl_set:Nn \l__nicematrix_cols_tl { #1 }
- \__nicematrix_cartesian_path:
- }
\NewDocumentCommand \__nicematrix_rectanglecolor { O { } m m m }
{
\tl_if_blank:nF { #2 }
@@ -4266,13 +4351,16 @@
restart .default:n = true ,
unknown .code:n = \__nicematrix_error:n { Unknown~key~for~rowcolors }
}
-\NewDocumentCommand \__nicematrix_rowcolors { O { } m m m O { } }
+\NewDocumentCommand \__nicematrix_rowlistcolors { O { } m m O { } }
{
\group_begin:
+ \seq_clear_new:N \l__nicematrix_colors_seq
+ \seq_set_split:Nnn \l__nicematrix_colors_seq { , } { #3 }
\tl_clear_new:N \l__nicematrix_cols_tl
\tl_set:Nn \l__nicematrix_cols_tl { - }
- \keys_set:nn { NiceMatrix / rowcolors } { #5 }
- \bool_set_true:N \l_tmpa_bool
+ \keys_set:nn { NiceMatrix / rowcolors } { #4 }
+ \int_zero_new:N \l__nicematrix_color_int
+ \int_set:Nn \l__nicematrix_color_int 1
\bool_if:NT \l__nicematrix_respect_blocks_bool
{
\seq_set_eq:NN \l_tmpb_seq \g__nicematrix_pos_of_blocks_seq
@@ -4289,8 +4377,8 @@
{ \tl_set:Nx \l_tmpb_tl { \int_use:N \c@iRow } }
\int_set:Nn \l_tmpa_int \l_tmpa_tl
\bool_if:NTF \l__nicematrix_rowcolors_restart_bool
- { \bool_set_true:N \l_tmpa_bool }
- { \bool_set:Nn \l_tmpa_bool { \int_if_odd_p:n { \l_tmpa_tl } } }
+ { \int_set:Nn \l__nicematrix_color_int 1 }
+ { \int_set:Nn \l__nicematrix_color_int \l_tmpa_tl }
\int_zero_new:N \l_tmpc_int
\int_set:Nn \l_tmpc_int \l_tmpb_tl
\int_do_until:nNnn \l_tmpa_int > \l_tmpc_int
@@ -4304,37 +4392,38 @@
}
\tl_set:Nx \l__nicematrix_rows_tl
{ \int_use:N \l_tmpa_int - \int_use:N \l_tmpb_int }
- \bool_if:NTF \l_tmpa_bool
+ \tl_clear_new:N \l__nicematrix_color_tl
+ \tl_set:Nx \l__nicematrix_color_tl
{
- \tl_if_blank:nF { #3 }
+ \__nicematrix_color_index:n
{
- \tl_if_empty:nTF { #1 }
- \color
- { \color [ #1 ] }
- { #3 }
- \__nicematrix_cartesian_path:
- \pgfusepath { fill }
+ \int_mod:nn
+ { \l__nicematrix_color_int - 1 }
+ { \seq_count:N \l__nicematrix_colors_seq }
+ + 1
}
- \bool_set_false:N \l_tmpa_bool
}
+ \tl_if_empty:NF \l__nicematrix_color_tl
{
- \tl_if_blank:nF { #4 }
- {
- \tl_if_empty:nTF { #1 }
- \color
- { \color [ #1 ] }
- { #4 }
- \__nicematrix_cartesian_path:
- \pgfusepath { fill }
- }
- \bool_set_true:N \l_tmpa_bool
+ \__nicematrix_add_to_colors_seq:xx
+ { \tl_if_blank:nF { #1 } { [ #1 ] } { \l__nicematrix_color_tl } }
+ { \__nicematrix_cartesian_color:nn { \l__nicematrix_rows_tl } { \l__nicematrix_cols_tl } }
}
+ \int_incr:N \l__nicematrix_color_int
\int_set:Nn \l_tmpa_int { \l_tmpb_int + 1 }
}
}
\endpgfpicture
\group_end:
}
+\cs_new:Npn \__nicematrix_color_index:n #1
+ {
+ \str_if_eq:eeTF { \seq_item:Nn \l__nicematrix_colors_seq { #1 } } { = }
+ { \__nicematrix_color_index:n { #1 - 1 } }
+ { \seq_item:Nn \l__nicematrix_colors_seq { #1 } }
+ }
+\NewDocumentCommand \__nicematrix_rowcolors { O { } m m m O { } }
+ { \__nicematrix_rowlistcolors [ #1 ] { #2 } { { #3 } , { #4 } } [ #5 ] }
\cs_new_protected:Npn \__nicematrix_rowcolors_i:nnnn #1 #2 #3 #4
{
\int_compare:nNnT { #3 } > \l_tmpb_int
@@ -4716,9 +4805,12 @@
\dim_set_eq:NN \l_tmpb_dim \pgf@y
\__nicematrix_qpoint:n { col - \__nicematrix_succ:n { #4 } }
\dim_set_eq:NN \l_tmpc_dim \pgf@x
- \bool_lazy_and:nnT
- { \int_compare_p:nNn { #2 } > 1 }
- { ! \tl_if_blank_p:V \CT@drsc@ }
+ \bool_lazy_all:nT
+ {
+ { \int_compare_p:nNn { #2 } > 1 }
+ { \cs_if_exist_p:N \CT@drsc@ } % condition added in version 6.0
+ { ! \tl_if_blank_p:V \CT@drsc@ }
+ }
{
\group_begin:
\CT@drsc@
@@ -5251,21 +5343,21 @@
}
\keys_define:nn { NiceMatrix / Block / FirstPass }
{
- l .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl l ,
+ l .code:n = \str_set:Nn \l__nicematrix_hpos_block_str l ,
l .value_forbidden:n = true ,
- r .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl r ,
+ r .code:n = \str_set:Nn \l__nicematrix_hpos_block_str r ,
r .value_forbidden:n = true ,
- c .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl c ,
+ c .code:n = \str_set:Nn \l__nicematrix_hpos_block_str c ,
c .value_forbidden:n = true ,
- L .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl l ,
+ L .code:n = \str_set:Nn \l__nicematrix_hpos_block_str l ,
L .value_forbidden:n = true ,
- R .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl r ,
+ R .code:n = \str_set:Nn \l__nicematrix_hpos_block_str r ,
R .value_forbidden:n = true ,
- C .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl c ,
+ C .code:n = \str_set:Nn \l__nicematrix_hpos_block_str c ,
C .value_forbidden:n = true ,
- t .code:n = \tl_set:Nn \l__nicematrix_vpos_of_block_tl t ,
+ t .code:n = \str_set:Nn \l__nicematrix_vpos_of_block_tl t ,
t .value_forbidden:n = true ,
- b .code:n = \tl_set:Nn \l__nicematrix_vpos_of_block_tl b ,
+ b .code:n = \str_set:Nn \l__nicematrix_vpos_of_block_tl b ,
b .value_forbidden:n = true ,
color .tl_set:N = \l__nicematrix_color_tl ,
color .value_required:n = true ,
@@ -5295,11 +5387,11 @@
{ \int_set:Nn \l_tmpb_int { #2 } }
\int_compare:nNnTF \l_tmpb_int = 1
{
- \tl_if_empty:NTF \l__nicematrix_cell_type_tl
- { \tl_set:Nn \l__nicematrix_hpos_of_block_tl c }
- { \tl_set_eq:NN \l__nicematrix_hpos_of_block_tl \l__nicematrix_cell_type_tl }
+ \str_if_empty:NTF \l__nicematrix_hpos_cell_str
+ { \str_set:Nn \l__nicematrix_hpos_block_str c }
+ { \str_set_eq:NN \l__nicematrix_hpos_block_str \l__nicematrix_hpos_cell_str }
}
- { \tl_set:Nn \l__nicematrix_hpos_of_block_tl c }
+ { \str_set:Nn \l__nicematrix_hpos_block_str c }
\keys_set_known:nn { NiceMatrix / Block / FirstPass } { #3 }
\tl_set:Nx \l_tmpa_tl
{
@@ -5316,6 +5408,7 @@
\int_compare_p:nNn { \l_tmpb_int } = 1
)
&& ! \tl_if_empty_p:n { #5 }
+ && ! \l__nicematrix_X_column_bool
}
{ \exp_args:Nxx \__nicematrix_Block_iv:nnnnn }
{ \exp_args:Nxx \__nicematrix_Block_v:nnnnn }
@@ -5349,23 +5442,40 @@
\cs_set:Npn \arraystretch { 1 }
\dim_set_eq:NN \extrarowheight \c_zero_dim
#4
- \bool_if:NT \g__nicematrix_rotate_bool { \tl_set:Nn \l__nicematrix_hpos_of_block_tl c }
+ \bool_if:NT \g__nicematrix_rotate_bool { \str_set:Nn \l__nicematrix_hpos_block_str c }
\bool_if:NTF \l__nicematrix_NiceTabular_bool
{
- \use:x
+ \bool_lazy_and:nnTF
+ { \int_compare_p:nNn { #2 } = 1 }
+ { \dim_compare_p:n { \l__nicematrix_col_width_dim >= \c_zero_dim } }
{
- \exp_not:N \begin { tabular } [ \l__nicematrix_vpos_of_block_tl ]
- { @ { } \l__nicematrix_hpos_of_block_tl @ { } }
+ \begin { minipage } [ l__nicematrix_vpos_of_block_tl ]
+ { \l__nicematrix_col_width_dim }
+ \str_case:Vn \l__nicematrix_hpos_block_str
+ {
+ c \centering
+ r \raggedleft
+ l \raggedright
+ }
+ #5
+ \end { minipage }
+ }
+ {
+ \use:x
+ {
+ \exp_not:N \begin { tabular } [ \l__nicematrix_vpos_of_block_tl ]
+ { @ { } \l__nicematrix_hpos_block_str @ { } }
+ }
+ #5
+ \end { tabular }
}
- #5
- \end { tabular }
}
{
\c_math_toggle_token
\use:x
{
\exp_not:N \begin { array } [ \l__nicematrix_vpos_of_block_tl ]
- { @ { } \l__nicematrix_hpos_of_block_tl @ { } }
+ { @ { } \l__nicematrix_hpos_block_str @ { } }
}
#5
\end { array }
@@ -5416,7 +5526,7 @@
\seq_gput_right:Nx \g__nicematrix_blocks_seq
{
\l_tmpa_tl
- { \exp_not:n { #3 } , \l__nicematrix_hpos_of_block_tl }
+ { \exp_not:n { #3 } , \l__nicematrix_hpos_block_str }
{
\box_use_drop:c
{ g__nicematrix_ block _ box _ \int_use:N \g__nicematrix_block_box_int _ box }
@@ -5439,11 +5549,11 @@
\dim_set_eq:NN \extrarowheight \c_zero_dim
#4
\bool_if:NT \g__nicematrix_rotate_bool
- { \tl_set:Nn \l__nicematrix_hpos_of_block_tl c }
+ { \str_set:Nn \l__nicematrix_hpos_block_str c }
\use:x
{
\exp_not:N \begin { tabular } [ \l__nicematrix_vpos_of_block_tl ]
- { @ { } \l__nicematrix_hpos_of_block_tl @ { } }
+ { @ { } \l__nicematrix_hpos_block_str @ { } }
}
#5
\end { tabular }
@@ -5455,12 +5565,12 @@
\dim_set_eq:NN \extrarowheight \c_zero_dim
#4
\bool_if:NT \g__nicematrix_rotate_bool
- { \tl_set:Nn \l__nicematrix_hpos_of_block_tl c }
+ { \str_set:Nn \l__nicematrix_hpos_block_str c }
\c_math_toggle_token
\use:x
{
\exp_not:N \begin { array } [ \l__nicematrix_vpos_of_block_tl ]
- { @ { } \l__nicematrix_hpos_of_block_tl @ { } }
+ { @ { } \l__nicematrix_hpos_block_str @ { } }
}
#5
\end { array }
@@ -5492,24 +5602,24 @@
hvlines .default:n = true ,
line-width .dim_set:N = \l__nicematrix_line_width_dim ,
line-width .value_required:n = true ,
- l .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl l ,
+ l .code:n = \str_set:Nn \l__nicematrix_hpos_block_str l ,
l .value_forbidden:n = true ,
- r .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl r ,
+ r .code:n = \str_set:Nn \l__nicematrix_hpos_block_str r ,
r .value_forbidden:n = true ,
- c .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl c ,
+ c .code:n = \str_set:Nn \l__nicematrix_hpos_block_str c ,
c .value_forbidden:n = true ,
- L .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl l
+ L .code:n = \str_set:Nn \l__nicematrix_hpos_block_str l
\bool_set_true:N \l__nicematrix_hpos_of_block_cap_bool ,
L .value_forbidden:n = true ,
- R .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl r
+ R .code:n = \str_set:Nn \l__nicematrix_hpos_block_str r
\bool_set_true:N \l__nicematrix_hpos_of_block_cap_bool ,
R .value_forbidden:n = true ,
- C .code:n = \tl_set:Nn \l__nicematrix_hpos_of_block_tl c
+ C .code:n = \str_set:Nn \l__nicematrix_hpos_block_str c
\bool_set_true:N \l__nicematrix_hpos_of_block_cap_bool ,
C .value_forbidden:n = true ,
- t .code:n = \tl_set:Nn \l__nicematrix_vpos_of_block_tl t ,
+ t .code:n = \str_set:Nn \l__nicematrix_vpos_of_block_tl t ,
t .value_forbidden:n = true ,
- b .code:n = \tl_set:Nn \l__nicematrix_vpos_of_block_tl b ,
+ b .code:n = \str_set:Nn \l__nicematrix_vpos_of_block_tl b ,
b .value_forbidden:n = true ,
unknown .code:n = \__nicematrix_error:n { Unknown~key~for~Block }
}
@@ -5713,7 +5823,7 @@
\bool_if:NF \l__nicematrix_hpos_of_block_cap_bool { - short }
}
{
- \str_case:Vn \l__nicematrix_hpos_of_block_tl
+ \str_case:Vn \l__nicematrix_hpos_block_str
{
c { center }
l { west }
@@ -5725,7 +5835,7 @@
\pgfnode
{ rectangle }
{
- \str_case:Vn \l__nicematrix_hpos_of_block_tl
+ \str_case:Vn \l__nicematrix_hpos_block_str
{
c { base }
l { base~west }
@@ -5736,11 +5846,11 @@
}
{
\int_compare:nNnT { #2 } = 0
- { \tl_set:Nn \l__nicematrix_hpos_of_block_tl r }
+ { \str_set:Nn \l__nicematrix_hpos_block_str r }
\bool_if:nT \g__nicematrix_last_col_found_bool
{
\int_compare:nNnT { #2 } = \g__nicematrix_col_total_int
- { \tl_set:Nn \l__nicematrix_hpos_of_block_tl l }
+ { \str_set:Nn \l__nicematrix_hpos_block_str l }
}
\pgftransformshift
{
@@ -5750,7 +5860,7 @@
\bool_if:NF \l__nicematrix_hpos_of_block_cap_bool { - short }
}
{
- \str_case:Vn \l__nicematrix_hpos_of_block_tl
+ \str_case:Vn \l__nicematrix_hpos_block_str
{
c { center }
l { west }
@@ -5762,7 +5872,7 @@
\pgfnode
{ rectangle }
{
- \str_case:Vn \l__nicematrix_hpos_of_block_tl
+ \str_case:Vn \l__nicematrix_hpos_block_str
{
c { center }
l { west }
@@ -6566,7 +6676,6 @@
}
{
The~available~keys~are~(in~alphabetic~order):~
- define-L-C-R,~
footnote,~
footnotehyper,~
renew-dots,~and
@@ -6578,17 +6687,8 @@
is~not~clear).~You~should~use~the~conjonction~of~'renew-dots'~
and~'renew-matrix'.~However,~you~can~go~on.
}
-\__nicematrix_msg_new:nn { define-L-C-R }
- {
- You~have~used~the~key~'define-L-C-R'.~Please~note~that~this~key~
- will~probably~be~deleted~in~a~future~version~of~'nicematrix'.\\
- However,~you~can~go~on.
- }
\keys_define:nn { NiceMatrix / Package }
{
- define-L-C-R .code:n =
- \__nicematrix_error:n { define-L-C-R }
- \bool_set_true:N \c__nicematrix_define_L_C_R_bool ,
renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool ,
renew-dots .value_forbidden:n = true ,
renew-matrix .code:n = \__nicematrix_renew_matrix: ,
@@ -6786,13 +6886,6 @@
The~key~'standard-cline'~is~available~only~in~the~preamble.\\
If~you~go~on~this~command~will~be~ignored.
}
-\__nicematrix_msg_new:nn { old~column~type }
- {
- The~column~type~'#1'~is~no~longer~defined~in~'nicematrix'.~
- Since~version~5.0,~you~have~to~use~'l',~'c'~and~'r'~instead~of~'L',~
- 'C'~and~'R'.~You~can~also~use~the~key~'define-L-C-R'.\\
- This~error~is~fatal.
- }
\__nicematrix_msg_new:nn { bad~value~for~baseline }
{
The~value~given~to~'baseline'~(\int_use:N \l_tmpa_int)~is~not~
@@ -6822,6 +6915,11 @@
{ ~Maybe~you~should~try~without~the~key~'slim'. } \\
If~you~go~on,~this~\token_to_str:N \SubMatrix\ will~be~ignored.
}
+\__nicematrix_msg_new:nn { width~without~X~columns }
+ {
+ You~have~used~the~key~'width'~but~you~have~put~no~'X'~column. \\
+ If~you~go~on,~that~key~will~be~ignored.
+ }
\__nicematrix_msg_new:nn { empty~environment }
{ Your~\__nicematrix_full_name_env:\ is~empty.~This~error~is~fatal. }
\__nicematrix_msg_new:nn { Delimiter~with~small }