From 6e40e8d9ab2cae35317a09775a62ec82f295d368 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 10 Jan 2020 21:41:22 +0000 Subject: nicematrix (10jan20) git-svn-id: svn://tug.org/texlive/trunk@53363 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 292 +++++++++++++-------- 1 file changed, 179 insertions(+), 113 deletions(-) (limited to 'Master/texmf-dist/tex/latex/nicematrix') diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index fd41a0cf057..ce81093ceaa 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{3.8} -\def\myfiledate{2020/01/02} +\def\myfileversion{3.9} +\def\myfiledate{2020/01/10} \RequirePackage{tikz} \usetikzlibrary{fit} \RequirePackage{expl3}[2019/07/01] @@ -158,8 +158,10 @@ \bool_new:N \l__nicematrix_nullify_dots_bool \bool_new:N \l__nicematrix_auto_columns_width_bool \str_new:N \l__nicematrix_name_str -\bool_new:N \l__nicematrix_extra_nodes_bool -\bool_new:N \g__nicematrix_extra_nodes_bool +\bool_new:N \l__nicematrix_medium_nodes_bool +\bool_new:N \g__nicematrix_medium_nodes_bool +\bool_new:N \l__nicematrix_large_nodes_bool +\bool_new:N \g__nicematrix_large_nodes_bool \dim_new:N \l__nicematrix_left_margin_dim \dim_new:N \l__nicematrix_right_margin_dim \dim_new:N \g__nicematrix_width_last_col_dim @@ -176,9 +178,11 @@ hlines .bool_set:N = \l__nicematrix_hlines_bool , parallelize-diags .bool_set:N = \l__nicematrix_parallelize_diags_bool , renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool , - nullify-dots .bool_set:N = \l__nicematrix_nullify_dots_bool , - create-extra-nodes .bool_set:N = \l__nicematrix_extra_nodes_bool , + create-medium-nodes .bool_set:N = \l__nicematrix_medium_nodes_bool , + create-large-nodes .bool_set:N = \l__nicematrix_large_nodes_bool , + create-extra-nodes .meta:n = + { create-medium-nodes , create-large-nodes } , left-margin .dim_set:N = \l__nicematrix_left_margin_dim , left-margin .default:n = \arraycolsep , right-margin .dim_set:N = \l__nicematrix_right_margin_dim , @@ -484,7 +488,8 @@ \cs_set:Npn \arraystretch { 0.47 } \dim_set:Nn \arraycolsep { 1.45 pt } } - \bool_gset_eq:NN \g__nicematrix_extra_nodes_bool \l__nicematrix_extra_nodes_bool + \bool_gset_eq:NN \g__nicematrix_medium_nodes_bool \l__nicematrix_medium_nodes_bool + \bool_gset_eq:NN \g__nicematrix_large_nodes_bool \l__nicematrix_large_nodes_bool \cs_set:Npn \ialign { \bool_if:NTF \c__nicematrix_colortbl_loaded_bool @@ -530,6 +535,7 @@ \cs_set_eq:NN \Hdotsfor \__nicematrix_Hdotsfor: \cs_set_eq:NN \multicolumn \__nicematrix_multicolumn:nnn \cs_set_eq:NN \Block \__nicematrix_Block: + \cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n \bool_if:NT \l__nicematrix_renew_dots_bool { \cs_set_eq:NN \ldots \__nicematrix_Ldots @@ -562,7 +568,7 @@ \l__nicematrix_auto_columns_width_bool || \dim_compare_p:nNn \l__nicematrix_columns_width_dim > \c_zero_dim } - { \bool_gset_true:N \g__nicematrix_extra_nodes_bool } + { \bool_gset_true:N \g__nicematrix_large_nodes_bool } \int_compare:nNnT \c@jCol > \g__nicematrix_last_vdotted_col_int { \int_gset_eq:NN \g__nicematrix_last_vdotted_col_int \c@jCol @@ -1136,7 +1142,13 @@ \dim_zero_new:N \l__nicematrix_delta_x_two_dim \dim_zero_new:N \l__nicematrix_delta_y_two_dim } - \bool_if:NT \g__nicematrix_extra_nodes_bool \__nicematrix_create_extra_nodes: + \bool_if:nTF \g__nicematrix_medium_nodes_bool + { + \bool_if:NTF \g__nicematrix_large_nodes_bool + \__nicematrix_create_medium_and_large_nodes: + \__nicematrix_create_medium_nodes: + } + { \bool_if:NT \g__nicematrix_large_nodes_bool \__nicematrix_create_large_nodes: } \int_zero_new:N \l__nicematrix_initial_i_int \int_zero_new:N \l__nicematrix_initial_j_int \int_zero_new:N \l__nicematrix_final_i_int @@ -1303,8 +1315,8 @@ \bool_set_true:N \l__nicematrix_impossible_line_bool } } - \bool_if:nT \l__nicematrix_initial_open_bool \__nicematrix_create_extra_nodes: - \bool_if:NT \l__nicematrix_final_open_bool \__nicematrix_create_extra_nodes: + \bool_if:nT \l__nicematrix_initial_open_bool \__nicematrix_create_medium_nodes: + \bool_if:NT \l__nicematrix_final_open_bool \__nicematrix_create_medium_nodes: } \cs_new_protected:Nn \__nicematrix_retrieve_coords:nn { @@ -1588,6 +1600,8 @@ } } } +\NewExpandableDocumentCommand \NiceMatrixLastEnv { } + { \int_use:N \g__nicematrix_env_int } \cs_new_protected:Nn \__nicematrix_draw_tikz_line: { \dim_zero_new:N \l__nicematrix_l_dim @@ -1793,7 +1807,7 @@ } } \bool_if:nT { \l__nicematrix_initial_open_bool || \l__nicematrix_final_open_bool } - \__nicematrix_create_extra_nodes: + \__nicematrix_create_medium_nodes: \__nicematrix_actually_draw_Ldots: \int_step_inline:nnn { #2 } { #2 + #3 - 1 } { \cs_set:cpn { __nicematrix _ dotted _ #1 - ##1 } { } } @@ -1866,7 +1880,7 @@ { \noalign { - \bool_gset_true:N \g__nicematrix_extra_nodes_bool + \bool_gset_true:N \g__nicematrix_large_nodes_bool \cs_if_exist:cTF { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } { \dim_set_eq:Nc \l_tmpa_dim { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } } { \dim_set:Nn \l_tmpa_dim { 5 mm } } @@ -2003,6 +2017,12 @@ } } \cs_set_eq:NN \__nicematrix_vline_i: \vline +\cs_set_eq:NN \OnlyMainNiceMatrix \use:n +\cs_new:Npn \__nicematrix_OnlyMainNiceMatrix:n #1 + { + \int_compare:nNnF \c@iRow = \c_zero_int + { \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int { #1 } } + } \bool_new:N \l__nicematrix_block_auto_columns_width_bool \keys_define:nn { NiceMatrix / NiceMatrixBlock } { @@ -2042,112 +2062,132 @@ } \cs_generate_variant:Nn \dim_min:nn { v n } \cs_generate_variant:Nn \dim_max:nn { v n } -\cs_new_protected:Nn \__nicematrix_create_extra_nodes: +\cs_new_protected:Npn \__nicematrix_computations_for_medium_nodes: + { + \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i: + { + \dim_zero_new:c { l__nicematrix_row_\__nicematrix_i: _min_dim } + \dim_set_eq:cN { l__nicematrix_row_\__nicematrix_i: _min_dim } \c_max_dim + \dim_zero_new:c { l__nicematrix_row_\__nicematrix_i: _max_dim } + \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _max_dim } { - \c_max_dim } + } + \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: + { + \dim_zero_new:c { l__nicematrix_column_\__nicematrix_j: _min_dim } + \dim_set_eq:cN { l__nicematrix_column_\__nicematrix_j: _min_dim } \c_max_dim + \dim_zero_new:c { l__nicematrix_column_\__nicematrix_j: _max_dim } + \dim_set:cn { l__nicematrix_column_\__nicematrix_j: _max_dim } { - \c_max_dim } + } + \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i: + { + \int_step_variable:nnNn + \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: + { \cs_if_exist:cT + { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: } + { + \tikz@parse@node \pgfutil@firstofone + ( nm - \int_use:N \g__nicematrix_env_int + - \__nicematrix_i: - \__nicematrix_j: .south~west ) + \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _min_dim} + { \dim_min:vn { l__nicematrix_row _ \__nicematrix_i: _min_dim } \pgf@y } + \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: } + { + \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _min_dim} + { \dim_min:vn { l__nicematrix_column _ \__nicematrix_j: _min_dim } \pgf@x } + } + \tikz@parse@node \pgfutil@firstofone + ( nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: .north~east ) + \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } + { \dim_max:vn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } \pgf@y } + \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: } + { + \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max_dim } + { \dim_max:vn { l__nicematrix_column _ \__nicematrix_j: _max_dim } \pgf@x } + } + } + } + } + } +\cs_new_protected:Npn \__nicematrix_create_medium_nodes: { \begin { tikzpicture } [ remember~picture , overlay ] - \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i: - { - \dim_zero_new:c { l__nicematrix_row_\__nicematrix_i: _min_dim } - \dim_set_eq:cN { l__nicematrix_row_\__nicematrix_i: _min_dim } \c_max_dim - \dim_zero_new:c { l__nicematrix_row_\__nicematrix_i: _max_dim } - \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _max_dim } { - \c_max_dim } - } - \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: - { - \dim_zero_new:c { l__nicematrix_column_\__nicematrix_j: _min_dim } - \dim_set_eq:cN { l__nicematrix_column_\__nicematrix_j: _min_dim } \c_max_dim - \dim_zero_new:c { l__nicematrix_column_\__nicematrix_j: _max_dim } - \dim_set:cn { l__nicematrix_column_\__nicematrix_j: _max_dim } { - \c_max_dim } - } - \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i: - { - \int_step_variable:nnNn - \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j: - { \cs_if_exist:cT - { pgf@sh@ns@nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: } - { - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - - \__nicematrix_i: - \__nicematrix_j: .south~west ) - \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _min_dim} - { \dim_min:vn { l__nicematrix_row _ \__nicematrix_i: _min_dim } \pgf@y } - \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: } - { - \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _min_dim} - { \dim_min:vn { l__nicematrix_column _ \__nicematrix_j: _min_dim } \pgf@x } - } - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: .north~east ) - \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } - { \dim_max:vn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } \pgf@y } - \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: } - { - \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max_dim } - { \dim_max:vn { l__nicematrix_column _ \__nicematrix_j: _max_dim } \pgf@x } - } - } - } - } + \__nicematrix_computations_for_medium_nodes: \tikzset { name~suffix = -medium } \__nicematrix_create_nodes: - \int_set:Nn \l__nicematrix_first_row_int 1 - \int_set:Nn \l__nicematrix_first_col_int 1 - \int_step_variable:nNn { \c@iRow - 1 } \__nicematrix_i: - { - \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } - { - ( - \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } + - \dim_use:c { l__nicematrix_row _ \int_eval:n { \__nicematrix_i: + 1 } _ max _ dim } - ) - / 2 - } - \dim_set_eq:cc { l__nicematrix_row _ \int_eval:n { \__nicematrix_i: + 1 } _ max _ dim } - { l__nicematrix_row_\__nicematrix_i: _min_dim } - } - \int_step_variable:nNn { \c@jCol - 1 } \__nicematrix_j: - { - \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } - { - ( - \dim_use:c - { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } + - \dim_use:c - { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: + 1 } _ min _ dim } - ) - / 2 - } - \dim_set_eq:cc { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: + 1 } _ min _ dim } - { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } - } - \dim_sub:cn - { l__nicematrix_column _ 1 _ min _ dim } - \l__nicematrix_left_margin_dim - \dim_add:cn - { l__nicematrix_column _ \int_use:N \c@jCol _ max _ dim } - \l__nicematrix_right_margin_dim + \end { tikzpicture } + \cs_set_protected:Npn \__nicematrix_create_medium_nodes: { } + \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: + { \__nicematrix_create_large_nodes: } + } +\cs_new_protected:Npn \__nicematrix_create_large_nodes: + { + \begin { tikzpicture } [ remember~picture , overlay ] + \__nicematrix_computations_for_medium_nodes: + \__nicematrix_computations_for_large_nodes: \tikzset { name~suffix = -large } \__nicematrix_create_nodes: - \end{tikzpicture} - \cs_set:Npn \__nicematrix_create_extra_nodes: { } - \begin { tikzpicture } [ remember~picture , overlay ] - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - 1 - 1 - large .north~west ) - \dim_gset:Nn \g_tmpa_dim \pgf@x - \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nicematrix_env_int - 1 - - \int_use:N \c@jCol - large .north~east ) - \dim_gset:Nn \g_tmpb_dim \pgf@x - \end { tikzpicture } - \iow_now:Nn \@mainaux \ExplSyntaxOn - \iow_now:Nx \@mainaux - { - \cs_gset:cpn { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } - { \dim_eval:n { \g_tmpb_dim - \g_tmpa_dim } } - } - \iow_now:Nn \@mainaux \ExplSyntaxOff + \end { tikzpicture } + \__nicematrix_compute_width_of_array: + \cs_set_protected:Npn \__nicematrix_create_large_nodes: { } + \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: + { \__nicematrix_create_medium_nodes: } + } +\cs_new_protected:Npn \__nicematrix_create_medium_and_large_nodes: + { + \begin { tikzpicture } [ remember~picture , overlay ] + \__nicematrix_computations_for_medium_nodes: + \tikzset { name~suffix = -medium } + \__nicematrix_create_nodes: + \__nicematrix_computations_for_large_nodes: + \tikzset { name~suffix = -large } + \__nicematrix_create_nodes: + \__nicematrix_compute_width_of_array: + \end { tikzpicture } + \__nicematrix_compute_width_of_array: + \cs_set_protected:Npn \__nicematrix_create_medium_and_large_nodes: { } + \cs_set_protected:Npn \__nicematrix_create_medium_nodes: { } + \cs_set_protected:Npn \__nicematrix_create_large_nodes: { } } -\cs_new_protected:Nn \__nicematrix_create_nodes: +\cs_new_protected:Npn \__nicematrix_computations_for_large_nodes: + { + \int_set:Nn \l__nicematrix_first_row_int 1 + \int_set:Nn \l__nicematrix_first_col_int 1 + \int_step_variable:nNn { \c@iRow - 1 } \__nicematrix_i: + { + \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } + { + ( + \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } + + \dim_use:c { l__nicematrix_row _ \int_eval:n { \__nicematrix_i: + 1 } _ max _ dim } + ) + / 2 + } + \dim_set_eq:cc { l__nicematrix_row _ \int_eval:n { \__nicematrix_i: + 1 } _ max _ dim } + { l__nicematrix_row_\__nicematrix_i: _min_dim } + } + \int_step_variable:nNn { \c@jCol - 1 } \__nicematrix_j: + { + \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } + { + ( + \dim_use:c + { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } + + \dim_use:c + { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: + 1 } _ min _ dim } + ) + / 2 + } + \dim_set_eq:cc { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: + 1 } _ min _ dim } + { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } + } + \dim_sub:cn + { l__nicematrix_column _ 1 _ min _ dim } + \l__nicematrix_left_margin_dim + \dim_add:cn + { l__nicematrix_column _ \int_use:N \c@jCol _ max _ dim } + \l__nicematrix_right_margin_dim + } +\cs_new_protected:Npn \__nicematrix_create_nodes: { \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i: { @@ -2177,6 +2217,25 @@ \g__nicematrix_multicolumn_sizes_seq \__nicematrix_node_for_multicolumn:nn } +\cs_new_protected:Npn \__nicematrix_compute_width_of_array: + { + \begin { tikzpicture } [ remember~picture , overlay ] + \tikz@parse@node \pgfutil@firstofone + ( nm - \int_use:N \g__nicematrix_env_int - 1 - 1 - large .north~west ) + \dim_gset:Nn \g_tmpa_dim \pgf@x + \tikz@parse@node \pgfutil@firstofone + ( nm - \int_use:N \g__nicematrix_env_int - 1 - + \int_use:N \c@jCol - large .north~east ) + \dim_gset:Nn \g_tmpb_dim \pgf@x + \end { tikzpicture } + \iow_now:Nn \@mainaux \ExplSyntaxOn + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { __nicematrix_width_ \int_use:N \g__nicematrix_env_int } + { \dim_eval:n { \g_tmpb_dim - \g_tmpa_dim } } + } + \iow_now:Nn \@mainaux \ExplSyntaxOff + } \cs_new_protected:Npn \__nicematrix_extract_coords: #1 - #2 \q_stop { \cs_set:Npn \__nicematrix_i: { #1 } @@ -2222,7 +2281,7 @@ - \int_use:N \c@jCol ) ; \end { tikzpicture } } - \bool_gset_true:N \g__nicematrix_extra_nodes_bool + \bool_gset_true:N \g__nicematrix_medium_nodes_bool \tl_gput_left:Nx \g__nicematrix_code_after_tl { \__nicematrix_Block_iii:nnnnn @@ -2427,6 +2486,9 @@ code-for-first-row,~ code-for-last-col,~ code-for-last-row,~ + create-extra-nodes,~ + create-medium-nodes,~ + create-large-nodes,~ exterior-arraycolsep,~ hlines,~ left-margin,~ @@ -2457,6 +2519,8 @@ code-for-last-row,~ columns-width,~ create-extra-nodes,~ + create-medium-nodes,~ + create-large-nodes,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -2489,6 +2553,8 @@ code-for-last-row,~ columns-width,~ create-extra-nodes,~ + create-medium-nodes,~ + create-large-nodes,~ extra-left-margin,~ extra-right-margin,~ first-col,~ -- cgit v1.2.3