diff options
author | Karl Berry <karl@freefriends.org> | 2020-04-12 22:31:28 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-04-12 22:31:28 +0000 |
commit | ad187abec4c90e663b357445e6c9777b5d68e573 (patch) | |
tree | a56138544cb7d02b8604e0209d48700130496df1 /Master/texmf-dist/tex/latex | |
parent | cccfc34acdcf78c43f347ada30968db554b62137 (diff) |
nicematrix
git-svn-id: svn://tug.org/texlive/trunk@54712 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty | 329 |
1 files changed, 247 insertions, 82 deletions
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index eb8221367fb..4b5e8ce16bf 100644 --- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty +++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty @@ -18,11 +18,10 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{3.14} -\def\myfiledate{2020/03/23} +\def\myfileversion{3.15} +\def\myfiledate{2020/04/06} \RequirePackage{pgfcore} \usepgfmodule{shapes} -\RequirePackage{expl3}[2020/02/08] \RequirePackage{l3keys2e} \ProvidesExplPackage {nicematrix} @@ -43,7 +42,7 @@ \ProcessOptions \relax \RequirePackage { array } \RequirePackage { amsmath } -\RequirePackage { xparse } [ 2018-07-01 ] +\RequirePackage { xparse } \cs_new_protected:Npn \__nicematrix_error:n { \msg_error:nn { nicematrix } } \cs_new_protected:Npn \__nicematrix_error:nn { \msg_error:nnn { nicematrix } } \cs_new_protected:Npn \__nicematrix_error:nnn { \msg_error:nnnn { nicematrix } } @@ -292,6 +291,8 @@ color .value_required:n = true , shorten .dim_set:N = \l__nicematrix_xdots_shorten_dim , shorten .value_required:n = true , + down .tl_set:N = \l__nicematrix_xdots_down_tl , + up .tl_set:N = \l__nicematrix_xdots_up_tl , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~xdots } } \keys_define:nn { NiceMatrix / Global } @@ -336,6 +337,11 @@ } \keys_define:nn { NiceMatrix / Env } { + c .code:n = \str_set:Nn \l__nicematrix_baseline_str c , + t .code:n = \str_set:Nn \l__nicematrix_baseline_str t , + b .code:n = \str_set:Nn \l__nicematrix_baseline_str b , + baseline .tl_set:N = \l__nicematrix_baseline_str , + baseline .value_required:n = true , columns-width .code:n = \str_if_eq:nnTF { #1 } { auto } { \bool_set_true:N \l__nicematrix_auto_columns_width_bool } @@ -427,11 +433,6 @@ } \keys_define:nn { NiceMatrix / NiceArray } { - c .code:n = \str_set:Nn \l__nicematrix_baseline_str c , - t .code:n = \str_set:Nn \l__nicematrix_baseline_str t , - b .code:n = \str_set:Nn \l__nicematrix_baseline_str b , - baseline .tl_set:N = \l__nicematrix_baseline_str , - baseline .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 , @@ -563,7 +564,7 @@ \use:c { __nicematrix _ draw _ #1 : nnn } { \int_use:N \c@iRow } { \int_use:N \c@jCol } - { #2 } + { \exp_not:n { #2 } } } } } @@ -678,6 +679,7 @@ \cs_set_eq:NN \Block \__nicematrix_Block: \cs_set_eq:NN \rotate \__nicematrix_rotate: \cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n + \cs_set_eq:NN \CodeAfter \__nicematrix_CodeAfter:n \bool_if:NT \l__nicematrix_renew_dots_bool { \cs_set_eq:NN \ldots \__nicematrix_Ldots @@ -865,7 +867,7 @@ } { \tl_put_right:Nn \l_tmpa_tl { @ { } } } } - \tl_put_right:Nn \l_tmpa_tl { > { \__nicematrix_error_too_much_cols: } l } + \tl_put_right:Nn \l_tmpa_tl { > { \__nicematrix_error_too_much_cols: } L } \hbox_set:Nw \l__nicematrix_the_array_box \bool_if:NT \l__nicematrix_vlines_bool { @@ -1003,6 +1005,38 @@ { \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } \box_set_dp:Nn \l_tmpa_box { \box_dp:N \l_tmpa_box + \l_tmpb_dim } + \str_if_eq:VnTF \l__nicematrix_baseline_str { c } + { \box_use_drop:N \l_tmpa_box } + \__nicematrix_put_box_in_flow_i: + } +\cs_new_protected:Npn \__nicematrix_put_box_in_flow_i: + { + \str_case:VnF \l__nicematrix_baseline_str + { + { t } { \int_set:Nn \l_tmpa_int 1 } + { b } { \int_set_eq:NN \l_tmpa_int \c@iRow } + } + { \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str } + \bool_if:nT + { + \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int + || \int_compare_p:nNn \l_tmpa_int > \g__nicematrix_row_total_int + } + { + \__nicematrix_error:n { bad~value~for~baseline } + \int_set:Nn \l_tmpa_int 1 + } + \pgfpicture + \__nicematrix_qpoint: { row - 1 } + \dim_gset_eq:NN \g_tmpa_dim \pgf@y + \__nicematrix_qpoint: { row - \__nicematrix_succ:n \c@iRow } + \dim_gadd:Nn \g_tmpa_dim \pgf@y + \dim_gset:Nn \g_tmpa_dim { 0.5 \g_tmpa_dim } + \__nicematrix_qpoint: { row - \int_use:N \l_tmpa_int - base } + \dim_gsub:Nn \g_tmpa_dim \pgf@y + \dim_gsub:Nn \g_tmpa_dim { \fontdimen22 \textfont2 } + \endpgfpicture + \box_move_up:nn \g_tmpa_dim { \box_use_drop:N \l_tmpa_box } \box_use_drop:N \l_tmpa_box } \cs_new_protected:Npn \__nicematrix_put_box_in_flow_bis:nn #1 #2 @@ -1099,7 +1133,18 @@ { \crcr \int_compare:nNnT \c@iRow = 0 { \__nicematrix_fatal:n { Zero~row } } - \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & } + \int_compare:nNnT \l__nicematrix_first_col_int = 0 + { + \omit + \skip_horizontal:N -2\arraycolsep + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate { \__nicematrix_env: - col - 0 } \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { \pgfnodealias { \__nicematrix_env: - col - 0 } { \l__nicematrix_name_str - col - 0 } } + \endpgfpicture + & + } \omit \bool_gset_true:N \g__nicematrix_row_of_col_done_bool \pgfpicture @@ -1150,6 +1195,22 @@ } \endpgfpicture } + \bool_if:NT \g__nicematrix_last_col_found_bool + { + \skip_horizontal:N 2\arraycolsep + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgfcoordinate { \__nicematrix_env: - col - \__nicematrix_succ:n \g__nicematrix_col_total_int } + \pgfpointorigin + \str_if_empty:NF \l__nicematrix_name_str + { + \pgfnodealias + { \__nicematrix_env: - col - \__nicematrix_succ:n \g__nicematrix_col_total_int } + { \l__nicematrix_name_str - col - \__nicematrix_succ:n \g__nicematrix_col_total_int } + } + \endpgfpicture + \skip_horizontal:N -2\arraycolsep + } \cr } \tl_const:Nn \c__nicematrix_preamble_first_col_tl @@ -1449,8 +1510,12 @@ \bool_set_false:N \l__nicematrix_final_open_bool \int_compare:nNnTF \l__nicematrix_final_i_int > \c@iRow { - \int_compare:nNnT { #3 } = 1 + \int_compare:nNnTF { #3 } = 1 { \bool_set_true:N \l__nicematrix_final_open_bool } + { + \int_compare:nNnT \l__nicematrix_final_j_int > \c@jCol + { \bool_set_true:N \l__nicematrix_final_open_bool } + } } { \int_compare:nNnTF \l__nicematrix_final_j_int < 1 @@ -1513,8 +1578,12 @@ \bool_set_false:N \l__nicematrix_initial_open_bool \int_compare:nNnTF \l__nicematrix_initial_i_int < 1 { - \int_compare:nNnT { #3 } = 1 + \int_compare:nNnTF { #3 } = 1 { \bool_set_true:N \l__nicematrix_initial_open_bool } + { + \int_compare:nNnT \l__nicematrix_initial_j_int = 0 + { \bool_set_true:N \l__nicematrix_initial_open_bool } + } } { \int_compare:nNnTF \l__nicematrix_initial_j_int < 1 @@ -1884,11 +1953,63 @@ shorten~< = \l__nicematrix_xdots_shorten_dim , ] ( \l__nicematrix_x_initial_dim , \l__nicematrix_y_initial_dim ) - -- ( \l__nicematrix_x_final_dim , \l__nicematrix_y_final_dim ) ; + -- node [ sloped , above ] + { \c_math_toggle_token \scriptstyle \l__nicematrix_xdots_up_tl \c_math_toggle_token } + node [ sloped , below ] + { + \c_math_toggle_token + \scriptstyle \l__nicematrix_xdots_down_tl + \c_math_toggle_token + } + ( \l__nicematrix_x_final_dim , \l__nicematrix_y_final_dim ) ; \end { scope } } \cs_new_protected:Npn \__nicematrix_draw_standard_dotted_line: { + \bool_lazy_and:nnF + { \tl_if_empty_p:N \l__nicematrix_xdots_up_tl } + { \tl_if_empty_p:N \l__nicematrix_xdots_down_tl } + { + \pgfscope + \pgftransformshift + { + \pgfpointlineattime { 0.5 } + { \pgfpoint \l__nicematrix_x_initial_dim \l__nicematrix_y_initial_dim } + { \pgfpoint \l__nicematrix_x_final_dim \l__nicematrix_y_final_dim } + } + \pgftransformrotate + { + \fp_eval:n + { + atand + ( + \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim , + \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim + ) + } + } + \pgfnode + { rectangle } + { south } + { + \c_math_toggle_token + \scriptstyle \l__nicematrix_xdots_up_tl + \c_math_toggle_token + } + { } + { \pgfusepath { } } + \pgfnode + { rectangle } + { north } + { + \c_math_toggle_token + \scriptstyle \l__nicematrix_xdots_down_tl + \c_math_toggle_token + } + { } + { \pgfusepath { } } + \endpgfscope + } \pgfrememberpicturepositiononpagetrue \pgf@relevantforpicturesizefalse \group_begin: @@ -1908,11 +2029,11 @@ \bool_lazy_or:nnF { \dim_compare_p:nNn { \dim_abs:n \l__nicematrix_l_dim } > \c__nicematrix_max_l_dim } { \dim_compare_p:nNn \l__nicematrix_l_dim = \c_zero_dim } - \__nicematrix_actually_draw_line: + \__nicematrix_draw_standard_dotted_line_i: \group_end: } \dim_const:Nn \c__nicematrix_max_l_dim { 50 cm } -\cs_new_protected:Npn \__nicematrix_actually_draw_line: +\cs_new_protected:Npn \__nicematrix_draw_standard_dotted_line_i: { \bool_if:NTF \l__nicematrix_initial_open_bool { @@ -1992,45 +2113,50 @@ } \pgfusepathqfill } -\NewDocumentCommand \__nicematrix_Ldots { s O { } } - { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } - { \__nicematrix_instruction_of_type:nn { Ldots } { #2 } } - \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_ldots } - \bool_gset_true:N \g__nicematrix_empty_cell_bool - } -\NewDocumentCommand \__nicematrix_Cdots { s O { } } - { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } - { \__nicematrix_instruction_of_type:nn { Cdots } { #2 } } - \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_cdots } - \bool_gset_true:N \g__nicematrix_empty_cell_bool - } -\NewDocumentCommand \__nicematrix_Vdots { s O { } } - { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } - { \__nicematrix_instruction_of_type:nn { Vdots } { #2 } } - \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_vdots } - \bool_gset_true:N \g__nicematrix_empty_cell_bool - } -\NewDocumentCommand \__nicematrix_Ddots { s O { } } - { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } - { \__nicematrix_instruction_of_type:nn { Ddots } { #2 } } - \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_ddots } - \bool_gset_true:N \g__nicematrix_empty_cell_bool - } -\NewDocumentCommand \__nicematrix_Iddots { s O { } } +\AtBeginDocument { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } - { \__nicematrix_instruction_of_type:nn { Iddots } { #2 } } - \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_iddots } - \bool_gset_true:N \g__nicematrix_empty_cell_bool + \tl_set:Nn \l__nicematrix_argspec_tl { s O { } E { _ ^ } { { } { } } } + \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl + \exp_args:NNV \NewDocumentCommand \__nicematrix_Ldots \l__nicematrix_argspec_tl + { + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Ldots } { #2 , down = #3 , up = #4 } } + \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_ldots } + \bool_gset_true:N \g__nicematrix_empty_cell_bool + } + \exp_args:NNV \NewDocumentCommand \__nicematrix_Cdots \l__nicematrix_argspec_tl + { + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Cdots } { #2 , down = #3 , up = #4 } } + \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_cdots } + \bool_gset_true:N \g__nicematrix_empty_cell_bool + } + \exp_args:NNV \NewDocumentCommand \__nicematrix_Vdots \l__nicematrix_argspec_tl + { + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Vdots } { #2 , down = #3 , up = #4 } } + \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_vdots } + \bool_gset_true:N \g__nicematrix_empty_cell_bool + } + \exp_args:NNV \NewDocumentCommand \__nicematrix_Ddots \l__nicematrix_argspec_tl + { + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Ddots } { #2 , down = #3 , up = #4 } } + \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_ddots } + \bool_gset_true:N \g__nicematrix_empty_cell_bool + } + \exp_args:NNV \NewDocumentCommand \__nicematrix_Iddots \l__nicematrix_argspec_tl + { + \bool_if:nTF { #1 } + { \__nicematrix_error:n { starred~commands } } + { \__nicematrix_instruction_of_type:nn { Iddots } { #2 , down = #3 , up = #4 } } + \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_iddots } + \bool_gset_true:N \g__nicematrix_empty_cell_bool + } } \cs_new_protected:Npn \__nicematrix_Hspace: { @@ -2054,23 +2180,32 @@ \multicolumn { 1 } { C } { } \__nicematrix_Hdotsfor_i } -\bool_if:NTF \c__nicematrix_draft_bool - { - \NewDocumentCommand \__nicematrix_Hdotsfor_i { O { } m O { } } - { \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } - } +\ExplSyntaxOff +\def \@tempa { O { } m O { } E { _ ^ } { { } { } } } +\ExplSyntaxOn +\tl_set_eq:NN \l__nicematrix_a_signature_tl \@tempa +\AtBeginDocument { - \NewDocumentCommand \__nicematrix_Hdotsfor_i { O { } m O { } } + \tl_set:Nn \l__nicematrix_argspec_tl { O { } m O { } E { _ ^ } { { } { } } } + \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl + \bool_if:NTF \c__nicematrix_draft_bool { - \tl_gput_right:Nx \g__nicematrix_Hdotsfor_lines_tl + \exp_args:NNV \NewDocumentCommand \__nicematrix_Hdotsfor_i \l__nicematrix_argspec_tl + { \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } + } + { + \exp_args:NNV \NewDocumentCommand \__nicematrix_Hdotsfor_i \l__nicematrix_argspec_tl { - \__nicematrix_Hdotsfor:nnnn - { \int_use:N \c@iRow } - { \int_use:N \c@jCol } - { #2 } - { #3 } + \tl_gput_right:Nx \g__nicematrix_Hdotsfor_lines_tl + { + \__nicematrix_Hdotsfor:nnnn + { \int_use:N \c@iRow } + { \int_use:N \c@jCol } + { #2 } + { #1 , #3 , down = #4 , up = #5 } + } + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } - \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } \cs_new_protected:Npn \__nicematrix_Hdotsfor:nnnn #1 #2 #3 #4 @@ -2147,18 +2282,27 @@ } \cs_new:Npn \__nicematrix_double_int_eval:n #1-#2 \q_stop { \int_eval:n { #1 } - \int_eval:n { #2 } } -\NewDocumentCommand \__nicematrix_line { O { } m m ! O { } } +\ExplSyntaxOff +\def \@tempa { O { } m m ! O { } E { _ ^ } { { } { } } } +\ExplSyntaxOn +\tl_set_eq:NN \l__nicematrix_a_signature_tl \@tempa +\AtBeginDocument { - \group_begin: - \keys_set:nn { NiceMatrix / xdots } { #1 , #4 } - \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } - \use:x - { - \__nicematrix_line_i:nn - { \__nicematrix_double_int_eval:n #2 \q_stop } - { \__nicematrix_double_int_eval:n #3 \q_stop } - } - \group_end: + \tl_set:Nn \l__nicematrix_argspec_tl { O { } m m ! O { } E { _ ^ } { { } { } } } + \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl + \exp_args:NNV \NewDocumentCommand \__nicematrix_line \l__nicematrix_argspec_tl + { + \group_begin: + \keys_set:nn { NiceMatrix / xdots } { #1 , #4 , down = #5 , up = #6 } + \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } } + \use:x + { + \__nicematrix_line_i:nn + { \__nicematrix_double_int_eval:n #2 \q_stop } + { \__nicematrix_double_int_eval:n #3 \q_stop } + } + \group_end: + } } \bool_if:NTF \c__nicematrix_draft_bool { \cs_new_protected:Npn \__nicematrix_line_i:nn #1 #2 { } } @@ -2751,6 +2895,20 @@ \__nicematrix_define_com:nnn v | | \__nicematrix_define_com:nnn V \| \| \__nicematrix_define_com:nnn B \{ \} +\cs_new_protected:Npn \__nicematrix_CodeAfter:n #1 \end + { + \tl_gput_right:Nn \g__nicematrix_code_after_tl { #1 } + \__nicematrix_CodeAfter_i:n + } +\cs_new_protected:Npn \__nicematrix_CodeAfter_i:n #1 + { + \bool_if:NTF { \str_if_eq_p:Vn \g__nicematrix_name_env_str { #1 } } + { \end { #1 } } + { + \tl_gput_right:Nn \g__nicematrix_code_after_tl { \end { #1 } } + \__nicematrix_CodeAfter:n + } + } \bool_new:N \c__nicematrix_obsolete_environments_bool \keys_define:nn { NiceMatrix / Package } { @@ -2792,16 +2950,19 @@ { \seq_if_in:NVTF \c__nicematrix_types_of_matrix_seq \g__nicematrix_name_env_str { - \int_compare:nNnTF \l__nicematrix_last_col_int = { -1 } + \int_compare:nNnTF \l__nicematrix_last_col_int = { -2 } { \__nicematrix_fatal:n { too~much~cols~for~matrix } } - { \__nicematrix_fatal:n { too~much~cols~for~matrix~with~last~col } } + { + \bool_if:NF \l__nicematrix_last_col_without_value_bool + { \__nicematrix_fatal:n { too~much~cols~for~matrix~with~last~col } } + } } { \__nicematrix_fatal:n { too~much~cols~for~array } } } \cs_new:Npn \__nicematrix_message_hdotsfor: { \tl_if_empty:VF \g__nicematrix_Hdotsfor_lines_tl - { ~Maybe~your~use~of~\token_to_str:N \Hdotsfor\ is~incorrect.} + { ~Maybe~your~use~of~\token_to_str:N \Hdotsfor\ is~incorrect.} } \__nicematrix_msg_new:nn { too~much~cols~for~matrix~with~last~col } { @@ -3001,6 +3162,9 @@ } { The~available~options~are~(in~alphabetic~order):~ + b,~ + baseline,~ + c,~ code-after,~ code-for-first-col,~ code-for-first-row,~ @@ -3029,6 +3193,7 @@ renew-dots,~ right-margin,~ small,~ + t,~ vlines,~ xdots/color,~ xdots/shorten~and~ |