diff options
author | Karl Berry <karl@freefriends.org> | 2018-07-06 21:31:37 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-07-06 21:31:37 +0000 |
commit | a721f45f8576209fefa4722a159acef42fb5e34d (patch) | |
tree | 4ba8959c919edae393cd8615c29e1c564f6588d4 /Master/texmf-dist/tex/latex | |
parent | 7a0530fc446c4a173b43abcb0302be9e8c08ebd2 (diff) |
nicematrix (6jul18)
git-svn-id: svn://tug.org/texlive/trunk@48154 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty | 1009 |
1 files changed, 619 insertions, 390 deletions
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index ca85ddf7d2b..a449b3af8c1 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{1.4} -\def\myfiledate{2018/04/16} +\def\myfileversion{2.0} +\def\myfiledate{2018/07/06} \RequirePackage{l3keys2e} \ProvidesExplPackage {nicematrix} @@ -39,34 +39,41 @@ \raise 7\p@ \vbox{\kern 7pt \hbox{.}} \mkern 1mu}} -\cs_new_protected:Nn \__nm_multicolumn:nn +\cs_new_protected:Nn \__nicem_multicolumn:nn {\msg_error:nn {nicematrix} {Multicolumn~forbidden}} -\int_new:N \g__nm_env_int -\dim_new:N \l__nm_columns_width_dim -\tl_new:N \l__nm_pos_env_tl -\tl_set:Nn \l__nm_pos_env_tl c -\bool_new:N \l__nm_exterior_arraycolsep_bool -\bool_new:N \l__nm_parallelize_diags_bool -\bool_set_true:N \l__nm_parallelize_diags_bool -\bool_new:N \l__nm_nullify_dots_bool -\bool_new:N \l__nm_renew_matrix_bool -\bool_new:N \l__nm_auto_columns_width_bool -\tl_new:N \l__nm_code_for_last_col_tl +\int_new:N \g__nicem_env_int +\dim_new:N \l__nicem_columns_width_dim +\seq_new:N \g__nicem_names_seq +\int_new:N \l__nicem_number_of_first_row_int +\bool_new:N \l__nicem_direct_NiceArray_bool +\bool_set_true:N \l__nicem_direct_NiceArray_bool +\tl_new:N \l__nicem_code_for_cell_tl +\tl_new:N \l__nicem_pos_env_tl +\tl_set:Nn \l__nicem_pos_env_tl c +\bool_new:N \l__nicem_exterior_arraycolsep_bool +\bool_new:N \l__nicem_parallelize_diags_bool +\bool_set_true:N \l__nicem_parallelize_diags_bool +\bool_new:N \l__nicem_nullify_dots_bool +\bool_new:N \l__nicem_renew_matrix_bool +\bool_new:N \l__nicem_auto_columns_width_bool +\tl_new:N \l__nicem_code_for_last_col_tl + +\tl_new:N \g__nicem_name_tl \keys_define:nn {NiceMatrix/NiceMatrixOptions} - {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, + {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool, parallelize-diags .default:n = true, ParallelizeDiagonals .meta:n = parallelize-diags, - renew-dots .bool_set:N = \l__nm_renew_dots_bool, + renew-dots .bool_set:N = \l__nicem_renew_dots_bool, renew-dots .default:n = true, RenewDots .meta:n = renew-dots, renew-matrix .code:n = {\cs_set_eq:NN \env@matrix \NiceMatrix - \bool_set_true:N \l__nm_renew_matrix_bool}, + \bool_set_true:N \l__nicem_renew_matrix_bool}, renew-matrix .value_forbidden:n = true, RenewMatrix .meta:n = renew-matrix, transparent .meta:n = {renew-dots,renew-matrix}, transparent .value_forbidden:n = true, Transparent .meta:n = transparent, - nullify-dots .bool_set:N = \l__nm_nullify_dots_bool , + nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool , nullify-dots .default:n = true, NullifyDots .meta:n = nullify-dots, silent .code:n = {\msg_redirect_name:nnn {nicematrix} @@ -74,10 +81,14 @@ {none}} , silent .value_forbidden:n = true, Silent .meta:n = silent, - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl, + code-for-last-col .tl_set:N = \l__nicem_code_for_last_col_tl, code-for-last-col .value_required:n = true, - exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool , + exterior-arraycolsep .bool_set:N = \l__nicem_exterior_arraycolsep_bool , exterior-arraycolsep .default:n = true, + columns-width .code:n = \str_if_eq:nnTF {#1} {auto} + {\msg_error:nn {nicematrix} + {Option~auto~for~columns-width}} + {\dim_set:Nn \l__nicem_columns_width_dim {#1}}, unknown .code:n = \msg_error:nn {nicematrix} {Unknown~key~for~NiceMatrixOptions}} \msg_new:nnnn {nicematrix} {Unknown~key~for~NiceMatrixOptions} @@ -93,19 +104,33 @@ renew-dots,~ renew-matrix~ and~transparent} +\msg_new:nnn {nicematrix} + {Option~auto~for~columns-width} + {You~can't~give~the~value~"auto"~to~the~option~"columns-width"~here.~ + If~you~go~on,~the~option~will~be~ignored.} \NewDocumentCommand \NiceMatrixOptions {m} {\keys_set:nn {NiceMatrix/NiceMatrixOptions} {#1}} \keys_define:nn {NiceMatrix/NiceMatrix} - {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, + {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool, parallelize-diags .default:n = true, - renew-dots .bool_set:N = \l__nm_renew_dots_bool, + renew-dots .bool_set:N = \l__nicem_renew_dots_bool, renew-dots .default:n = true, - nullify-dots .bool_set:N = \l__nm_nullify_dots_bool , + nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool , nullify-dots .default:n = true, columns-width .code:n = \str_if_eq:nnTF {#1} {auto} {\bool_set_true:N - \l__nm_auto_columns_width_bool} - {\dim_set:Nn \l__nm_columns_width_dim {#1}}, + \l__nicem_auto_columns_width_bool} + {\dim_set:Nn \l__nicem_columns_width_dim {#1}}, + name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1} + {\msg_error:nnn {nicematrix} + {Duplicate~name} + {#1}} + {\seq_gput_left:Nn \g__nicem_names_seq {#1}} + \tl_gset:Nn \g__nicem_name_tl {#1}}, + name .value_required:n = true, + code-after .tl_gset:N = \g__nicem_code_after_tl, + code-after .initial:n = \c_empty_tl, + code-after .value_required:n = true, unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceMatrix}} \msg_new:nnnn {nicematrix} {Unknown~option~for~NiceMatrix} @@ -114,26 +139,38 @@ If~you~go~on,~it~will~be~ignored.\\ For~a~list~of~the~available~options,~type~H~<return>.} {The~available~options~are~(in~alphabetic~order):~ + code-after,~ columns-width,~ + name,~ nullify-dots,~ parallelize-diags~ and~renew-dots.} \keys_define:nn {NiceMatrix/NiceArray} - {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, + {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool, parallelize-diags .default:n = true, - renew-dots .bool_set:N = \l__nm_renew_dots_bool, + renew-dots .bool_set:N = \l__nicem_renew_dots_bool, renew-dots .default:n = true, - nullify-dots .bool_set:N = \l__nm_nullify_dots_bool , + nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool , nullify-dots .default:n = true, - exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool , + exterior-arraycolsep .bool_set:N = \l__nicem_exterior_arraycolsep_bool , exterior-arraycolsep .default:n = true, columns-width .code:n = \str_if_eq:nnTF {#1} {auto} - {\bool_set_true:N \l__nm_auto_columns_width_bool} - {\dim_set:Nn \l__nm_columns_width_dim {#1}}, + {\bool_set_true:N \l__nicem_auto_columns_width_bool} + {\dim_set:Nn \l__nicem_columns_width_dim {#1}}, columns-width .value_required:n = true, - c .code:n = \tl_set:Nn \l__nm_pos_env_tl c, - t .code:n = \tl_set:Nn \l__nm_pos_env_tl t, - b .code:n = \tl_set:Nn \l__nm_pos_env_tl b, + name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1} + {\msg_error:nnn {nicematrix} + {Duplicate~name} + {#1}} + {\seq_gput_left:Nn \g__nicem_names_seq {#1}} + \tl_gset:Nn \g__nicem_name_tl {#1}}, + name .value_required:n = true, + c .code:n = \tl_set:Nn \l__nicem_pos_env_tl c, + t .code:n = \tl_set:Nn \l__nicem_pos_env_tl t, + b .code:n = \tl_set:Nn \l__nicem_pos_env_tl b, + code-after .tl_gset:N = \g__nicem_code_after_tl, + code-after .initial:n = \c_empty_tl, + code-after .value_required:n = true, unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArray}} \msg_new:nnnn {nicematrix} {Unknown~option~for~NiceArray} @@ -144,111 +181,140 @@ {The~available~options~are~(in~alphabetic~order):~ b,~ c,~ + code-after,~ columns-width,~ exterior-arraycolsep,~ + name,~ nullify-dots,~ parallelize-diags,~ renew-dots~ and~t.} -\cs_new_protected:Nn \__nm_Cell:n - {\tl_gput_right:Nn \g__nm_preamble_aux_tl {#1} - \int_gincr:N \g__nm_column_int - \hbox_set:Nw \l_tmpa_box $} % $ -\cs_new_protected:Nn \__nm_end_Cell: +\cs_new_protected:Nn \__nicem_Cell:n + {\tl_gput_right:Nn \g__nicem_preamble_aux_tl {#1} + \int_gincr:N \g__nicem_column_int + \hbox_set:Nw \l_tmpa_box $ % $ + \l__nicem_code_for_cell_tl } +\cs_new_protected:Nn \__nicem_end_Cell: {$ % $ \hbox_set_end: - \dim_gset:Nn \g__nm_max_cell_width_dim - {\dim_max:nn \g__nm_max_cell_width_dim {\box_wd:N \l_tmpa_box}} - \tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline] - \node [anchor=base] (nm-\int_use:N \g__nm_env_int- - \int_use:N \g__nm_row_int- - \int_use:N \g__nm_column_int) + \dim_gset:Nn \g__nicem_max_cell_width_dim + {\dim_max:nn \g__nicem_max_cell_width_dim {\box_wd:N \l_tmpa_box}} + \tl_if_empty:NTF \g__nicem_name_tl + {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline] + \node [anchor = base, + name = nm-\int_use:N \g__nicem_env_int- + \int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int] } + {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline] + \node [anchor = base, + name = nm-\int_use:N \g__nicem_env_int- + \int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int, + alias = \tl_use:N \g__nicem_name_tl- + \int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int] } \bgroup \box_use:N \l_tmpa_box \egroup ;} \NewDocumentEnvironment {NiceMatrix} {O{}} - {\keys_set:nn {NiceMatrix/NiceMatrix} {#1} - \tl_set:Nn \l__nm_pos_env_tl c - \bool_set_false:N \l__nm_exterior_arraycolsep_bool + {\bool_set_false:N \l__nicem_direct_NiceArray_bool + \tl_gclear:N \g__nicem_code_after_tl + \keys_set:nn {NiceMatrix/NiceMatrix} {#1} + \tl_set:Nn \l__nicem_pos_env_tl c + \bool_set_false:N \l__nicem_exterior_arraycolsep_bool \NiceArray{*\c@MaxMatrixCols{C}} } {\endarray \skip_horizontal:n {-\arraycolsep}} \cs_generate_variant:Nn \dim_set:Nn {Nx} \NewDocumentEnvironment {NiceArray} {O{} m O{}} - {\aftergroup \__nm_write_max_cell_width: - \aftergroup \__nm_draw_lines: - \int_gincr:N \g__nm_env_int - \dim_gzero_new:N \g__nm_max_cell_width_dim + {\cs_if_exist:NT \__nicem_in_NiceArray: + {\msg_error:nn {nicematrix} {We~are~yet~in~an~environment~NiceArray}} + \cs_set:Npn \__nicem_in_NiceArray: {--Void--} + \aftergroup \__nicem_draw_lines: + \int_gincr:N \g__nicem_env_int + \bool_if:NF \l__nicem_block_auto_columns_width_bool + {\dim_gzero_new:N \g__nicem_max_cell_width_dim} + \bool_if:NT \l__nicem_direct_NiceArray_bool + {\tl_gclear:N \g__nicem_code_after_tl} \keys_set:nn {NiceMatrix/NiceArray} {#1,#3} - \bool_if:NT \l__nm_auto_columns_width_bool - {\cs_if_free:cTF {__nm_max_cell_width_\int_use:N \g__nm_env_int} - {\dim_set:Nn \l__nm_columns_width_dim \c_zero_dim} - {\dim_set:Nx \l__nm_columns_width_dim - {\use:c {__nm_max_cell_width_\int_use:N \g__nm_env_int}}}} + \bool_if:NT \l__nicem_auto_columns_width_bool + {\aftergroup \__nicem_write_max_cell_width: + \cs_if_free:cTF {__nicem_max_cell_width_\int_use:N \g__nicem_env_int} + {\dim_set:Nn \l__nicem_columns_width_dim \c_zero_dim} + {\dim_set:Nx \l__nicem_columns_width_dim + {\use:c {__nicem_max_cell_width_\int_use:N \g__nicem_env_int}}} + \tl_if_empty:NF \g__nicem_name_tl + {\cs_if_free:cF {__nicem_max_cell_width_\g__nicem_name_tl} + {\dim_set:Nx \l__nicem_columns_width_dim + {\use:c {__nicem_max_cell_width_\g__nicem_name_tl}}}} + } \cs_set:Npn \ialign - {\everycr{\noalign{\int_gincr:N \g__nm_row_int - \int_gzero:N \g__nm_column_int - \int_compare:nNnT {\tl_count:N \g__nm_preamble_aux_tl} - > {\tl_count:N \g__nm_preamble_tl} - {\tl_gset_eq:NN \g__nm_preamble_tl \g__nm_preamble_aux_tl} - \tl_gclear:N \g__nm_preamble_aux_tl}} + {\everycr{\noalign{\int_gincr:N \g__nicem_row_int + \int_gzero:N \g__nicem_column_int + \int_compare:nNnT {\tl_count:N \g__nicem_preamble_aux_tl} + > {\tl_count:N \g__nicem_preamble_tl} + {\tl_gset_eq:NN \g__nicem_preamble_tl \g__nicem_preamble_aux_tl} + \tl_gclear:N \g__nicem_preamble_aux_tl}} \skip_zero:N \tabskip \cs_set:Npn \ialign {\everycr{} \skip_zero:N \tabskip \halign} \halign} - \dim_compare:nNnTF \l__nm_columns_width_dim = \c_zero_dim - {\newcolumntype{L}{>{\__nm_Cell:n l}l<{\__nm_end_Cell:}} - \newcolumntype{C}{>{\__nm_Cell:n c}c<{\__nm_end_Cell:}} - \newcolumntype{R}{>{\__nm_Cell:n r}r<{\__nm_end_Cell:}}} - {\newcolumntype{L}{wl{\dim_use:N \l__nm_columns_width_dim}} - \newcolumntype{C}{wc{\dim_use:N \l__nm_columns_width_dim}} - \newcolumntype{R}{wr{\dim_use:N \l__nm_columns_width_dim}}} + \dim_compare:nNnTF \l__nicem_columns_width_dim = \c_zero_dim + {\newcolumntype{L}{>{\__nicem_Cell:n l}l<{\__nicem_end_Cell:}} + \newcolumntype{C}{>{\__nicem_Cell:n c}c<{\__nicem_end_Cell:}} + \newcolumntype{R}{>{\__nicem_Cell:n r}r<{\__nicem_end_Cell:}}} + {\newcolumntype{L}{wl{\dim_use:N \l__nicem_columns_width_dim}} + \newcolumntype{C}{wc{\dim_use:N \l__nicem_columns_width_dim}} + \newcolumntype{R}{wr{\dim_use:N \l__nicem_columns_width_dim}}} \cs_set_eq:NN \NC@find@w \relax \cs_set_eq:NN \NC@find@W \relax \newcolumntype{w}[2] {>{\hbox_set:Nw \l_tmpa_box - \__nm_Cell:n ##1} + \__nicem_Cell:n ##1} c - <{\__nm_end_Cell: + <{\__nicem_end_Cell: \hbox_set_end: \makebox[##2][##1]{\box_use:N \l_tmpa_box}}} \newcolumntype{W}[2] {>{\hbox_set:Nw \l_tmpa_box - \__nm_Cell:n ##1} + \__nicem_Cell:n ##1} c - <{\__nm_end_Cell: + <{\__nicem_end_Cell: \hbox_set_end: \cs_set_eq:NN \hss \hfil \makebox[##2][##1]{\box_use:N \l_tmpa_box}}} - \cs_set_eq:NN \Ldots \__nm_Ldots - \cs_set_eq:NN \Cdots \__nm_Cdots - \cs_set_eq:NN \Vdots \__nm_Vdots - \cs_set_eq:NN \Ddots \__nm_Ddots - \cs_set_eq:NN \Iddots \__nm_Iddots - \cs_set_eq:NN \Hspace \__nm_Hspace: - \cs_set_eq:NN \NiceMatrixEndPoint \__nm_NiceMatrixEndPoint: - \bool_if:NT \l__nm_renew_dots_bool - {\cs_set_eq:NN \ldots \__nm_Ldots - \cs_set_eq:NN \cdots \__nm_Cdots - \cs_set_eq:NN \vdots \__nm_Vdots - \cs_set_eq:NN \ddots \__nm_Ddots - \cs_set_eq:NN \iddots \__nm_Iddots} - \bool_if:NF \l__nm_renew_matrix_bool - {\cs_set_eq:NN \multicolumn \__nm_multicolumn:nn} - \tl_clear_new:N \g__nm_preamble_tl - \tl_clear_new:N \g__nm_preamble_aux_tl - \seq_gclear_new:N \g__nm_empty_cells_seq - \int_gzero_new:N \g__nm_instruction_int - \int_gzero_new:N \g__nm_row_int - \int_gzero_new:N \g__nm_column_int + \cs_set_eq:NN \Ldots \__nicem_Ldots + \cs_set_eq:NN \Cdots \__nicem_Cdots + \cs_set_eq:NN \Vdots \__nicem_Vdots + \cs_set_eq:NN \Ddots \__nicem_Ddots + \cs_set_eq:NN \Iddots \__nicem_Iddots + \cs_set_eq:NN \Hspace \__nicem_Hspace: + \cs_set_eq:NN \NiceMatrixEndPoint \__nicem_NiceMatrixEndPoint: + \cs_set_eq:NN \Hdotsfor \__nicem_Hdotsfor + \bool_if:NT \l__nicem_renew_dots_bool + {\cs_set_eq:NN \ldots \__nicem_Ldots + \cs_set_eq:NN \cdots \__nicem_Cdots + \cs_set_eq:NN \vdots \__nicem_Vdots + \cs_set_eq:NN \ddots \__nicem_Ddots + \cs_set_eq:NN \iddots \__nicem_Iddots + \cs_set_eq:NN \hdotsfor \__nicem_Hdotsfor} + \bool_if:NF \l__nicem_renew_matrix_bool + {\cs_set_eq:NN \multicolumn \__nicem_multicolumn:nn} + \tl_clear_new:N \g__nicem_preamble_tl + \tl_clear_new:N \g__nicem_preamble_aux_tl + \seq_gclear_new:N \g__nicem_empty_cells_seq + \int_gzero_new:N \g__nicem_instruction_int + \int_gzero_new:N \g__nicem_row_int + \int_gset_eq:NN \g__nicem_row_int \l__nicem_number_of_first_row_int + \int_gzero_new:N \g__nicem_column_int \cs_set_eq:NN \@ifnextchar \new@ifnextchar - \bool_if:NF \l__nm_exterior_arraycolsep_bool + \bool_if:NF \l__nicem_exterior_arraycolsep_bool {\skip_horizontal:n {-\arraycolsep}} - \array[\l__nm_pos_env_tl]{#2}} + \array[\l__nicem_pos_env_tl]{#2}} {\endarray - \bool_if:NF \l__nm_exterior_arraycolsep_bool + \bool_if:NF \l__nicem_exterior_arraycolsep_bool {\skip_horizontal:n {-\arraycolsep}}} \NewDocumentEnvironment {pNiceMatrix} {} {\left(\begin{NiceMatrix}} @@ -265,21 +331,24 @@ \NewDocumentEnvironment {VNiceMatrix} {} {\left\lVert\begin{NiceMatrix}} {\end{NiceMatrix}\right\rVert} -\cs_new:Nn \__nm_write_max_cell_width: - {\iow_now:Nx \@mainaux - {\ExplSyntaxOn - \cs_gset:cpn {__nm_max_cell_width_\int_use:N \g__nm_env_int} - {\dim_use:N \g__nm_max_cell_width_dim} - \ExplSyntaxOff}} -\prg_set_conditional:Npnn \__nm_if_not_empty_cell:nn #1#2 {T} - {\cs_if_exist:cTF {pgf@sh@ns@nm-\int_use:N \g__nm_env_int- +\cs_new_protected:Nn \__nicem_write_max_cell_width: + {\bool_if:NF \l__nicem_block_auto_columns_width_bool + {\iow_now:Nn \@mainaux {\ExplSyntaxOn} + \iow_now:Nx \@mainaux {\cs_gset:cpn {__nicem_max_cell_width_\int_use:N \g__nicem_env_int} + {\dim_use:N \g__nicem_max_cell_width_dim} } + \iow_now:Nx \@mainaux {\cs_gset:cpn {__nicem_max_cell_width_\g__nicem_name_tl} + {\dim_use:N \g__nicem_max_cell_width_dim} } + \iow_now:Nn \@mainaux {\ExplSyntaxOff}} + \tl_gclear:N \g__nicem_name_tl} +\prg_set_conditional:Npnn \__nicem_if_not_empty_cell:nn #1#2 {T} + {\cs_if_exist:cTF {pgf@sh@ns@nm-\int_use:N \g__nicem_env_int- \int_use:N #1- \int_use:N #2} - {\seq_if_in:NxTF \g__nm_empty_cells_seq + {\seq_if_in:NxTF \g__nicem_empty_cells_seq {\int_use:N #1-\int_use:N #2} {\prg_return_false:} {\begin{pgfpicture} - \tl_set:Nx \l_tmpa_tl {nm-\int_use:N \g__nm_env_int- + \tl_set:Nx \l_tmpa_tl {nm-\int_use:N \g__nicem_env_int- \int_use:N #1- \int_use:N #2} \pgfpointanchor \l_tmpa_tl {east} @@ -293,257 +362,282 @@ }} {\prg_return_false:} } -\cs_new_protected:Nn \__nm_instruction_of_type:n - {\int_gincr:N \g__nm_instruction_int +\cs_new_protected:Nn \__nicem_instruction_of_type:n + {\int_gincr:N \g__nicem_instruction_int \prop_put:Nnn \l_tmpa_prop {type} {#1} - \prop_put:NnV \l_tmpa_prop {row} \g__nm_row_int - \prop_put:NnV \l_tmpa_prop {column} \g__nm_column_int + \prop_put:NnV \l_tmpa_prop {row} \g__nicem_row_int + \prop_put:NnV \l_tmpa_prop {column} \g__nicem_column_int \prop_gclear_new:c - {g__nm_instruction_\int_use:N\g__nm_instruction_int _prop} + {g__nicem_instruction_\int_use:N\g__nicem_instruction_int _prop} \prop_gset_eq:cN - {g__nm_instruction_\int_use:N\g__nm_instruction_int _prop} + {g__nicem_instruction_\int_use:N\g__nicem_instruction_int _prop} \l_tmpa_prop } - -\cs_new_protected:Nn \__nm_draw_lines: +\cs_new_protected:Nn \__nicem_draw_lines: { - \int_decr:N \g__nm_row_int - \int_set:Nn \g__nm_column_int {\tl_count:N \g__nm_preamble_tl} - \seq_clear_new:N \l__nm_yet_drawn_seq - \int_zero_new:N \l__nm_type_int - \int_zero_new:N \l__nm_row_int - \int_zero_new:N \l__nm_column_int - \int_zero_new:N \l__nm_di_int - \int_zero_new:N \l__nm_dj_int - \bool_if:NT \l__nm_parallelize_diags_bool - {\int_zero_new:N \l__nm_ddots_int - \int_zero_new:N \l__nm_iddots_int - \dim_zero_new:N \l__nm_delta_x_one_dim - \dim_zero_new:N \l__nm_delta_y_one_dim - \dim_zero_new:N \l__nm_delta_x_two_dim - \dim_zero_new:N \l__nm_delta_y_two_dim} - \int_zero_new:N \l__nm_instruction_int - \int_incr:N \l__nm_instruction_int - \int_until_do:nNnn \l__nm_instruction_int > \g__nm_instruction_int + \int_decr:N \g__nicem_row_int + \int_set:Nn \g__nicem_column_int {\tl_count:N \g__nicem_preamble_tl} + \seq_clear_new:N \l__nicem_yet_drawn_seq + \int_zero_new:N \l__nicem_type_int + \int_zero_new:N \l__nicem_row_int + \int_zero_new:N \l__nicem_column_int + \int_zero_new:N \l__nicem_di_int + \int_zero_new:N \l__nicem_dj_int + \bool_if:NT \l__nicem_parallelize_diags_bool + {\int_zero_new:N \l__nicem_ddots_int + \int_zero_new:N \l__nicem_iddots_int + \dim_zero_new:N \l__nicem_delta_x_one_dim + \dim_zero_new:N \l__nicem_delta_y_one_dim + \dim_zero_new:N \l__nicem_delta_x_two_dim + \dim_zero_new:N \l__nicem_delta_y_two_dim} + \int_zero_new:N \l__nicem_instruction_int + \int_incr:N \l__nicem_instruction_int + \int_until_do:nNnn \l__nicem_instruction_int > \g__nicem_instruction_int { - \prop_get:cnN {g__nm_instruction_\int_use:N \l__nm_instruction_int _prop} + \prop_get:cnN {g__nicem_instruction_\int_use:N \l__nicem_instruction_int _prop} {type} \l_tmpa_tl - \int_set:Nn \l__nm_type_int {\l_tmpa_tl} - \prop_get:cnN {g__nm_instruction_\int_use:N \l__nm_instruction_int _prop} + \int_set:Nn \l__nicem_type_int {\l_tmpa_tl} + \prop_get:cnN {g__nicem_instruction_\int_use:N \l__nicem_instruction_int _prop} {row} \l_tmpa_tl - \int_set:Nn \l__nm_row_int {\l_tmpa_tl} - \prop_get:cnN {g__nm_instruction_\int_use:N \l__nm_instruction_int _prop} + \int_set:Nn \l__nicem_row_int {\l_tmpa_tl} + \prop_get:cnN {g__nicem_instruction_\int_use:N \l__nicem_instruction_int _prop} {column} \l_tmpa_tl - \int_set:Nn \l__nm_column_int {\l_tmpa_tl} - \int_case:nn \l__nm_type_int - { 0 {\int_set:Nn \l__nm_di_int 0 - \int_set:Nn \l__nm_dj_int 1} - 1 {\int_set:Nn \l__nm_di_int 0 - \int_set:Nn \l__nm_dj_int 1} - 2 {\int_set:Nn \l__nm_di_int 1 - \int_set:Nn \l__nm_dj_int 0} - 3 {\int_set:Nn \l__nm_di_int 1 - \int_set:Nn \l__nm_dj_int 1} - 4 {\int_set:Nn \l__nm_di_int 1 - \int_set:Nn \l__nm_dj_int {-1}}} - \bool_if_exist:NTF \l__nm_impossible_instruction_bool - {\bool_set_false:N \l__nm_impossible_instruction_bool} - {\bool_new:N \l__nm_impossible_instruction_bool} - \int_zero_new:N \l__nm_final_i_int - \int_zero_new:N \l__nm_final_j_int - \int_set:Nn \l__nm_final_i_int \l__nm_row_int - \int_set:Nn \l__nm_final_j_int \l__nm_column_int - \bool_if_exist:NTF \l__nm_stop_loop_bool - {\bool_set_false:N \l__nm_stop_loop_bool} - {\bool_new:N \l__nm_stop_loop_bool} - \bool_do_until:Nn \l__nm_stop_loop_bool - {\int_add:Nn \l__nm_final_i_int \l__nm_di_int - \int_add:Nn \l__nm_final_j_int \l__nm_dj_int - \bool_if:nTF { \int_compare_p:nNn \l__nm_final_i_int < 1 - || \int_compare_p:nNn \l__nm_final_i_int > \g__nm_row_int - || \int_compare_p:nNn \l__nm_final_j_int < 1 - || \int_compare_p:nNn \l__nm_final_j_int > \g__nm_column_int} - {\bool_set_true:N \l__nm_impossible_instruction_bool - \bool_set_true:N \l__nm_stop_loop_bool} - {\__nm_if_not_empty_cell:nnT \l__nm_final_i_int \l__nm_final_j_int - {\bool_set_true:N \l__nm_stop_loop_bool}} + \int_set:Nn \l__nicem_column_int {\l_tmpa_tl} + \int_case:nn \l__nicem_type_int + { 0 {\int_set:Nn \l__nicem_di_int 0 + \int_set:Nn \l__nicem_dj_int 1} + 1 {\int_set:Nn \l__nicem_di_int 0 + \int_set:Nn \l__nicem_dj_int 1} + 2 {\int_set:Nn \l__nicem_di_int 1 + \int_set:Nn \l__nicem_dj_int 0} + 3 {\int_set:Nn \l__nicem_di_int 1 + \int_set:Nn \l__nicem_dj_int 1} + 4 {\int_set:Nn \l__nicem_di_int 1 + \int_set:Nn \l__nicem_dj_int {-1}}} + \bool_if_exist:NTF \l__nicem_impossible_instruction_bool + {\bool_set_false:N \l__nicem_impossible_instruction_bool} + {\bool_new:N \l__nicem_impossible_instruction_bool} + \int_zero_new:N \l__nicem_final_i_int + \int_zero_new:N \l__nicem_final_j_int + \int_set:Nn \l__nicem_final_i_int \l__nicem_row_int + \int_set:Nn \l__nicem_final_j_int \l__nicem_column_int + \bool_if_exist:NTF \l__nicem_stop_loop_bool + {\bool_set_false:N \l__nicem_stop_loop_bool} + {\bool_new:N \l__nicem_stop_loop_bool} + \bool_do_until:Nn \l__nicem_stop_loop_bool + {\int_add:Nn \l__nicem_final_i_int \l__nicem_di_int + \int_add:Nn \l__nicem_final_j_int \l__nicem_dj_int + \bool_if:nTF { \int_compare_p:nNn \l__nicem_final_i_int < \l__nicem_number_of_first_row_int + || \int_compare_p:nNn \l__nicem_final_i_int > \g__nicem_row_int + || \int_compare_p:nNn \l__nicem_final_j_int < 1 + || \int_compare_p:nNn \l__nicem_final_j_int > \g__nicem_column_int} + {\bool_set_true:N \l__nicem_impossible_instruction_bool + \bool_set_true:N \l__nicem_stop_loop_bool} + {\__nicem_if_not_empty_cell:nnT \l__nicem_final_i_int \l__nicem_final_j_int + {\bool_set_true:N \l__nicem_stop_loop_bool}} } - \int_zero_new:N \l__nm_initial_i_int - \int_zero_new:N \l__nm_initial_j_int - \int_set:Nn \l__nm_initial_i_int \l__nm_row_int - \int_set:Nn \l__nm_initial_j_int \l__nm_column_int - \bool_set_eq:NN \l__nm_stop_loop_bool \l__nm_impossible_instruction_bool - \bool_do_until:Nn \l__nm_stop_loop_bool - {\int_sub:Nn \l__nm_initial_i_int \l__nm_di_int - \int_sub:Nn \l__nm_initial_j_int \l__nm_dj_int + \int_zero_new:N \l__nicem_initial_i_int + \int_zero_new:N \l__nicem_initial_j_int + \int_set:Nn \l__nicem_initial_i_int \l__nicem_row_int + \int_set:Nn \l__nicem_initial_j_int \l__nicem_column_int + \bool_set_eq:NN \l__nicem_stop_loop_bool \l__nicem_impossible_instruction_bool + \bool_do_until:Nn \l__nicem_stop_loop_bool + {\int_sub:Nn \l__nicem_initial_i_int \l__nicem_di_int + \int_sub:Nn \l__nicem_initial_j_int \l__nicem_dj_int \bool_if:nTF - { \int_compare_p:nNn \l__nm_initial_i_int < 1 - || \int_compare_p:nNn \l__nm_initial_i_int > \g__nm_row_int - || \int_compare_p:nNn \l__nm_initial_j_int < 1 - || \int_compare_p:nNn \l__nm_initial_j_int > \g__nm_column_int} - {\bool_set_true:N \l__nm_impossible_instruction_bool - \bool_set_true:N \l__nm_stop_loop_bool} - {\__nm_if_not_empty_cell:nnT \l__nm_initial_i_int \l__nm_initial_j_int - {\bool_set_true:N \l__nm_stop_loop_bool}} + { \int_compare_p:nNn \l__nicem_initial_i_int < \l__nicem_number_of_first_row_int + || \int_compare_p:nNn \l__nicem_initial_i_int > \g__nicem_row_int + || \int_compare_p:nNn \l__nicem_initial_j_int < 1 + || \int_compare_p:nNn \l__nicem_initial_j_int > \g__nicem_column_int} + {\bool_set_true:N \l__nicem_impossible_instruction_bool + \bool_set_true:N \l__nicem_stop_loop_bool} + {\__nicem_if_not_empty_cell:nnT \l__nicem_initial_i_int \l__nicem_initial_j_int + {\bool_set_true:N \l__nicem_stop_loop_bool}} } - \bool_if:NTF \l__nm_impossible_instruction_bool + \bool_if:NTF \l__nicem_impossible_instruction_bool {\msg_error:nn {nicematrix} {Impossible~instruction}} - {\tl_set:Nx \l_tmpa_tl {\int_use:N \l__nm_initial_i_int- - \int_use:N \l__nm_initial_j_int- - \int_use:N \l__nm_final_i_int- - \int_use:N \l__nm_final_j_int} - \seq_if_in:NVF \l__nm_yet_drawn_seq \l_tmpa_tl - {\seq_put_left:NV \l__nm_yet_drawn_seq \l_tmpa_tl - \dim_zero_new:N \g__nm_x_initial_dim - \dim_zero_new:N \g__nm_y_initial_dim - \dim_zero_new:N \g__nm_x_final_dim - \dim_zero_new:N \g__nm_y_final_dim - \int_case:nn \l__nm_type_int - {0 \__nm_draw_ldots_line: - 1 \__nm_draw_cdots_line: - 2 \__nm_draw_vdots_line: - 3 \__nm_draw_ddots_line: - 4 \__nm_draw_iddots_line:}}} - \int_incr:N \l__nm_instruction_int + {\tl_set:Nx \l_tmpa_tl {\int_use:N \l__nicem_initial_i_int- + \int_use:N \l__nicem_initial_j_int- + \int_use:N \l__nicem_final_i_int- + \int_use:N \l__nicem_final_j_int} + \seq_if_in:NVF \l__nicem_yet_drawn_seq \l_tmpa_tl + {\seq_put_left:NV \l__nicem_yet_drawn_seq \l_tmpa_tl + \dim_zero_new:N \g__nicem_x_initial_dim + \dim_zero_new:N \g__nicem_y_initial_dim + \dim_zero_new:N \g__nicem_x_final_dim + \dim_zero_new:N \g__nicem_y_final_dim + \int_case:nn \l__nicem_type_int + {0 \__nicem_draw_ldots_line: + 1 \__nicem_draw_cdots_line: + 2 \__nicem_draw_vdots_line: + 3 \__nicem_draw_ddots_line: + 4 \__nicem_draw_iddots_line:}}} + \int_incr:N \l__nicem_instruction_int } + \group_begin: + \tikzset{every~picture/.style = {overlay, + remember~picture, + name~prefix = nm-\int_use:N \g__nicem_env_int-}} + \cs_set_eq:NN \line \__nicem_line:nn + \g__nicem_code_after_tl + \group_end: } -\cs_new_protected:Nn \__nm_retrieve_coords:nn +\cs_new_protected:Nn \__nicem_retrieve_coords:nn {\begin{tikzpicture}[remember~picture] \tikz@parse@node\pgfutil@firstofone - (nm-\int_use:N \g__nm_env_int- - \int_use:N \l__nm_initial_i_int- - \int_use:N \l__nm_initial_j_int.#1) - \dim_gset:Nn \g__nm_x_initial_dim \pgf@x - \dim_gset:Nn \g__nm_y_initial_dim \pgf@y + (nm-\int_use:N \g__nicem_env_int- + \int_use:N \l__nicem_initial_i_int- + \int_use:N \l__nicem_initial_j_int.#1) + \dim_gset:Nn \g__nicem_x_initial_dim \pgf@x + \dim_gset:Nn \g__nicem_y_initial_dim \pgf@y \tikz@parse@node\pgfutil@firstofone - (nm-\int_use:N \g__nm_env_int- - \int_use:N \l__nm_final_i_int- - \int_use:N \l__nm_final_j_int.#2) - \dim_gset:Nn \g__nm_x_final_dim \pgf@x - \dim_gset:Nn \g__nm_y_final_dim \pgf@y + (nm-\int_use:N \g__nicem_env_int- + \int_use:N \l__nicem_final_i_int- + \int_use:N \l__nicem_final_j_int.#2) + \dim_gset:Nn \g__nicem_x_final_dim \pgf@x + \dim_gset:Nn \g__nicem_y_final_dim \pgf@y \end{tikzpicture} } -\cs_new_protected:Nn \__nm_draw_ldots_line: - {\__nm_retrieve_coords:nn {south~east} {south~west} - \__nm_draw_tikz_line:} -\cs_new_protected:Nn \__nm_draw_cdots_line: - {\__nm_retrieve_coords:nn {mid~east} {mid~west} - \__nm_draw_tikz_line:} -\cs_new_protected:Nn \__nm_draw_vdots_line: - {\__nm_retrieve_coords:nn {south} {north} - \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \g__nm_preamble_tl \l__nm_initial_j_int} - \tl_set:Nn \l_tmpb_tl {l} - \tl_if_eq:NNT \l_tmpa_tl \l_tmpb_tl - {\dim_set:Nn \l_tmpa_dim {\dim_min:nn \g__nm_x_initial_dim \g__nm_x_final_dim} - \dim_set_eq:NN \g__nm_x_initial_dim \l_tmpa_dim - \dim_set_eq:NN \g__nm_x_final_dim \l_tmpa_dim} - \tl_set:Nn \l_tmpb_tl {r} - \tl_if_eq:NNT \l_tmpa_tl \l_tmpb_tl - {\dim_set:Nn \l_tmpa_dim {\dim_max:nn \g__nm_x_initial_dim \g__nm_x_final_dim} - \dim_set_eq:NN \g__nm_x_initial_dim \l_tmpa_dim - \dim_set_eq:NN \g__nm_x_final_dim \l_tmpa_dim} - \__nm_draw_tikz_line:} -\cs_new_protected:Nn \__nm_draw_ddots_line: - {\__nm_retrieve_coords:nn {south~east} {north~west} - \bool_if:NT \l__nm_parallelize_diags_bool - {\int_incr:N \l__nm_ddots_int - \int_compare:nNnTF \l__nm_ddots_int = 1 - {\dim_set:Nn \l__nm_delta_x_one_dim {\g__nm_x_final_dim - \g__nm_x_initial_dim } - \dim_set:Nn \l__nm_delta_y_one_dim {\g__nm_y_final_dim - \g__nm_y_initial_dim }} - {\dim_gset:Nn \g__nm_y_final_dim - {\g__nm_y_initial_dim + - (\g__nm_x_final_dim - \g__nm_x_initial_dim) - * \dim_ratio:nn \l__nm_delta_y_one_dim \l__nm_delta_x_one_dim }}} - \__nm_draw_tikz_line:} -\cs_new_protected:Nn \__nm_draw_iddots_line: - {\__nm_retrieve_coords:nn {south~west} {north~east} - \bool_if:NT \l__nm_parallelize_diags_bool - {\int_incr:N \l__nm_iddots_int - \int_compare:nNnTF \l__nm_iddots_int = 1 - {\dim_set:Nn \l__nm_delta_x_two_dim {\g__nm_x_final_dim - \g__nm_x_initial_dim } - \dim_set:Nn \l__nm_delta_y_two_dim {\g__nm_y_final_dim - \g__nm_y_initial_dim }} - {\dim_gset:Nn \g__nm_y_final_dim - {\g__nm_y_initial_dim + - (\g__nm_x_final_dim - \g__nm_x_initial_dim) - * \dim_ratio:nn \l__nm_delta_y_two_dim \l__nm_delta_x_two_dim }}} - \__nm_draw_tikz_line:} -\cs_new_protected:Nn \__nm_draw_tikz_line: - { - \dim_zero_new:N \l__nm_l_dim - \dim_set:Nn \l__nm_l_dim - { \fp_to_dim:n - { sqrt( ( \dim_use:N \g__nm_x_final_dim - -\dim_use:N \g__nm_x_initial_dim) ^2 - +( \dim_use:N \g__nm_y_final_dim - -\dim_use:N \g__nm_y_initial_dim) ^2 )} - } - \int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l__nm_l_dim - 0.54em} - {0.45em}} - \dim_set:Nn \l_tmpa_dim { (\g__nm_x_final_dim - \g__nm_x_initial_dim) - * \dim_ratio:nn {0.45em} \l__nm_l_dim} - \dim_set:Nn \l_tmpb_dim { (\g__nm_y_final_dim - \g__nm_y_initial_dim) - * \dim_ratio:nn {0.45em} \l__nm_l_dim} - \dim_gadd:Nn \g__nm_x_initial_dim - { (\g__nm_x_final_dim - \g__nm_x_initial_dim) - * \dim_ratio:nn {\l__nm_l_dim - 0.45 em * \l_tmpa_int} - {\l__nm_l_dim * 2}} - \dim_gadd:Nn \g__nm_y_initial_dim - { (\g__nm_y_final_dim - \g__nm_y_initial_dim) - * \dim_ratio:nn {\l__nm_l_dim - 0.45 em * \l_tmpa_int} - {\l__nm_l_dim * 2}} - \begin{tikzpicture}[overlay] - \int_step_inline:nnnn 0 1 \l_tmpa_int - { \pgfpathcircle{\pgfpoint{\g__nm_x_initial_dim} - {\g__nm_y_initial_dim}} - {0.53pt} - \pgfusepath{fill} - \dim_gadd:Nn \g__nm_x_initial_dim \l_tmpa_dim - \dim_gadd:Nn \g__nm_y_initial_dim \l_tmpb_dim } - \end{tikzpicture} +\cs_new_protected:Nn \__nicem_draw_ldots_line: + {\__nicem_retrieve_coords:nn {south~east} {south~west} + \__nicem_draw_tikz_line:} +\cs_new_protected:Nn \__nicem_draw_cdots_line: + {\__nicem_retrieve_coords:nn {mid~east} {mid~west} + \__nicem_draw_tikz_line:} +\cs_new_protected:Nn \__nicem_draw_vdots_line: + {\__nicem_retrieve_coords:nn {south} {north} + \tl_set:Nx \l_tmpa_tl {\tl_item:Nn \g__nicem_preamble_tl \l__nicem_initial_j_int} + \str_if_eq:VnT \l_tmpa_tl {l} + {\dim_set:Nn \g__nicem_x_initial_dim {\dim_min:nn \g__nicem_x_initial_dim \g__nicem_x_final_dim} + \dim_set_eq:NN \g__nicem_x_final_dim \g__nicem_x_initial_dim} + \str_if_eq:VnT \l_tmpa_tl {r} + {\dim_set:Nn \g__nicem_x_initial_dim {\dim_max:nn \g__nicem_x_initial_dim \g__nicem_x_final_dim} + \dim_set_eq:NN \g__nicem_x_final_dim \g__nicem_x_initial_dim} + \__nicem_draw_tikz_line:} +\cs_new_protected:Nn \__nicem_draw_ddots_line: + {\__nicem_retrieve_coords:nn {south~east} {north~west} + \bool_if:NT \l__nicem_parallelize_diags_bool + {\int_incr:N \l__nicem_ddots_int + \int_compare:nNnTF \l__nicem_ddots_int = 1 + {\dim_set:Nn \l__nicem_delta_x_one_dim {\g__nicem_x_final_dim - \g__nicem_x_initial_dim } + \dim_set:Nn \l__nicem_delta_y_one_dim {\g__nicem_y_final_dim - \g__nicem_y_initial_dim }} + {\dim_gset:Nn \g__nicem_y_final_dim + {\g__nicem_y_initial_dim + + (\g__nicem_x_final_dim - \g__nicem_x_initial_dim) + * \dim_ratio:nn \l__nicem_delta_y_one_dim \l__nicem_delta_x_one_dim }}} + \__nicem_draw_tikz_line:} +\cs_new_protected:Nn \__nicem_draw_iddots_line: + {\__nicem_retrieve_coords:nn {south~west} {north~east} + \bool_if:NT \l__nicem_parallelize_diags_bool + {\int_incr:N \l__nicem_iddots_int + \int_compare:nNnTF \l__nicem_iddots_int = 1 + {\dim_set:Nn \l__nicem_delta_x_two_dim {\g__nicem_x_final_dim - \g__nicem_x_initial_dim } + \dim_set:Nn \l__nicem_delta_y_two_dim {\g__nicem_y_final_dim - \g__nicem_y_initial_dim }} + {\dim_gset:Nn \g__nicem_y_final_dim + {\g__nicem_y_initial_dim + + (\g__nicem_x_final_dim - \g__nicem_x_initial_dim) + * \dim_ratio:nn \l__nicem_delta_y_two_dim \l__nicem_delta_x_two_dim }}} + \__nicem_draw_tikz_line:} +\cs_new_protected:Nn \__nicem_draw_tikz_line: + { + \dim_zero_new:N \l__nicem_l_dim + \dim_set:Nn \l__nicem_l_dim + { \fp_to_dim:n + { sqrt( ( \dim_use:N \g__nicem_x_final_dim + -\dim_use:N \g__nicem_x_initial_dim) ^2 + +( \dim_use:N \g__nicem_y_final_dim + -\dim_use:N \g__nicem_y_initial_dim) ^2 )} + } + \dim_compare:nNnF \l__nicem_l_dim = \c_zero_dim + {\int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l__nicem_l_dim - 0.54em} + {0.45em}} + \dim_set:Nn \l_tmpa_dim { (\g__nicem_x_final_dim - \g__nicem_x_initial_dim) + * \dim_ratio:nn {0.45em} \l__nicem_l_dim} + \dim_set:Nn \l_tmpb_dim { (\g__nicem_y_final_dim - \g__nicem_y_initial_dim) + * \dim_ratio:nn {0.45em} \l__nicem_l_dim} + \dim_gadd:Nn \g__nicem_x_initial_dim + { (\g__nicem_x_final_dim - \g__nicem_x_initial_dim) + * \dim_ratio:nn {\l__nicem_l_dim - 0.45 em * \l_tmpa_int} + {\l__nicem_l_dim * 2}} + \dim_gadd:Nn \g__nicem_y_initial_dim + { (\g__nicem_y_final_dim - \g__nicem_y_initial_dim) + * \dim_ratio:nn {\l__nicem_l_dim - 0.45 em * \l_tmpa_int} + {\l__nicem_l_dim * 2}} + \begin{tikzpicture}[overlay] + \int_step_inline:nnn 0 \l_tmpa_int + { \pgfpathcircle{\pgfpoint{\g__nicem_x_initial_dim} + {\g__nicem_y_initial_dim}} + {0.53pt} + \pgfusepath{fill} + \dim_gadd:Nn \g__nicem_x_initial_dim \l_tmpa_dim + \dim_gadd:Nn \g__nicem_y_initial_dim \l_tmpb_dim } + \end{tikzpicture}} } -\cs_set_eq:NN \__nm_ldots \ldots -\cs_set_eq:NN \__nm_cdots \cdots -\cs_set_eq:NN \__nm_vdots \vdots -\cs_set_eq:NN \__nm_ddots \ddots -\cs_set_eq:NN \__nm_iddots \iddots -\cs_new_protected:Nn \__nm_add_to_empty_cells: - {\seq_gput_right:Nx \g__nm_empty_cells_seq - {\int_use:N \g__nm_row_int- - \int_use:N \g__nm_column_int}} -\NewDocumentCommand \__nm_Ldots {s} - {\IfBooleanF {#1} {\__nm_instruction_of_type:n 0} - \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_ldots} - \__nm_add_to_empty_cells:} -\NewDocumentCommand \__nm_Cdots {s} - {\IfBooleanF {#1} {\__nm_instruction_of_type:n 1} - \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_cdots} - \__nm_add_to_empty_cells:} -\NewDocumentCommand \__nm_Vdots {s} - {\IfBooleanF {#1} {\__nm_instruction_of_type:n 2} - \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_vdots} - \__nm_add_to_empty_cells:} -\NewDocumentCommand \__nm_Ddots {s} - {\IfBooleanF {#1} {\__nm_instruction_of_type:n 3} - \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_ddots} - \__nm_add_to_empty_cells:} -\NewDocumentCommand \__nm_Iddots {s} - {\IfBooleanF {#1} {\__nm_instruction_of_type:n 4} - \bool_if:NF \l__nm_nullify_dots_bool {\phantom \__nm_iddots} - \__nm_add_to_empty_cells:} -\cs_new_protected:Nn \__nm_Hspace: - {\__nm_add_to_empty_cells: +\cs_set_eq:NN \__nicem_ldots \ldots +\cs_set_eq:NN \__nicem_cdots \cdots +\cs_set_eq:NN \__nicem_vdots \vdots +\cs_set_eq:NN \__nicem_ddots \ddots +\cs_set_eq:NN \__nicem_iddots \iddots +\cs_new_protected:Nn \__nicem_add_to_empty_cells: + {\seq_gput_right:Nx \g__nicem_empty_cells_seq + {\int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int}} +\NewDocumentCommand \__nicem_Ldots {s} + {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 0} + \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_ldots} + \__nicem_add_to_empty_cells:} +\NewDocumentCommand \__nicem_Cdots {s} + {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 1} + \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_cdots} + \__nicem_add_to_empty_cells:} +\NewDocumentCommand \__nicem_Vdots {s} + {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 2} + \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_vdots} + \__nicem_add_to_empty_cells:} +\NewDocumentCommand \__nicem_Ddots {s} + {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 3} + \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_ddots} + \__nicem_add_to_empty_cells:} +\NewDocumentCommand \__nicem_Iddots {s} + {\IfBooleanF {#1} {\__nicem_instruction_of_type:n 4} + \bool_if:NF \l__nicem_nullify_dots_bool {\phantom \__nicem_iddots} + \__nicem_add_to_empty_cells:} +\cs_new_protected:Nn \__nicem_Hspace: + {\__nicem_add_to_empty_cells: \hspace} -\cs_new_protected:Nn \__nm_NiceMatrixEndPoint: +\cs_new_protected:Nn \__nicem_NiceMatrixEndPoint: {\kern 0.5pt} +\NewDocumentCommand \__nicem_Hdotsfor {O{} m} + {\int_set:Nn \l_tmpa_int {\g__nicem_column_int - 1} + \int_set:Nn \l_tmpb_int {\g__nicem_column_int + #2} + \tl_gput_right:Nx \g__nicem_code_after_tl + {\exp_not:N \line {\int_use:N\g__nicem_row_int-\int_use:N\l_tmpa_int} + {\int_use:N\g__nicem_row_int-\int_use:N\l_tmpb_int}} + \prg_replicate:nn {#2-1} {&}} \ProcessKeysOptions {NiceMatrix} +\cs_new_protected:Nn \__nicem_line:nn + {\dim_zero_new:N \g__nicem_x_initial_dim + \dim_zero_new:N \g__nicem_y_initial_dim + \dim_zero_new:N \g__nicem_x_final_dim + \dim_zero_new:N \g__nicem_y_final_dim + \begin{tikzpicture} + \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ; + \tikz@parse@node\pgfutil@firstofone (i) + \dim_gset:Nn \g__nicem_x_initial_dim \pgf@x + \dim_gset:Nn \g__nicem_y_initial_dim \pgf@y + \tikz@parse@node\pgfutil@firstofone (f) + \dim_gset:Nn \g__nicem_x_final_dim \pgf@x + \dim_gset:Nn \g__nicem_y_final_dim \pgf@y + \end{tikzpicture} + \__nicem_draw_tikz_line:} \msg_new:nnnn {nicematrix} {Impossible~instruction} {It's~not~possible~to~execute~the~instruction~ - \int_case:nn \l__nm_type_int + \int_case:nn \l__nicem_type_int {0 {\token_to_str:N \Ldots} 1 {\token_to_str:N \Cdots} 2 {\token_to_str:N \Vdots} - 3 {\token_to_str:N \Ddots}}~in~the~row~\int_use:N\l__nm_row_int\ - ~and~the~column~\int_use:N\l__nm_column_int\space of~the~matrix~ + 3 {\token_to_str:N \Ddots}}~in~the~row~\int_use:N\l__nicem_row_int\ + ~and~the~column~\int_use:N\l__nicem_column_int\space of~the~matrix~ because~it's~impossible~to~find~one~of~its~extremities~ (both~extremities~must~be~non~empty~cells~of~the~matrix).~ If~you~go~on,~the~instruction~will~be~ignored.} @@ -552,103 +646,238 @@ \msg_new:nnn {nicematrix} {Multicolumn~forbidden} {The~command~\token_to_str:N \multicolumn\ - is~forbidden~in~the~environment~\{NiceMatrix\}~ + is~forbidden~in~the~environment~\{\@currenvir\}~ and~its~variants.~The~command~\token_to_str:N \hdotsfor\ of~amsmath~is~also~forbidden~since~it~uses~ - \token_to_str:N \multicolumn.~You~can~go~on~but~your~line~will~ - probably~be~wrong.} + \token_to_str:N \multicolumn\ ~(but~you~can~use~\token_to_str:N \Hdotsfor\ + ~instead).~You~can~go~on~but~your~matrix~may~be~wrong.} +\msg_new:nnn {nicematrix} + {We~are~yet~in~an~environment~NiceArray} + {Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ + nested.~We~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~ + result.} +\msg_new:nnnn {nicematrix} + {Duplicate~name} + {The~name~"#1"~is~already~used~and~you~shouldn't~use~ + the~same~environment~name~twice.~You~can~go~on,~but,~ + maybe,~you~will~have~incorrect~results~especially~ + if~you~use~"columns-width=auto".\\ + For~a~list~of~the~names~already~used,~type~H~<return>.} + {The~names~already~defined~in~this~document~are:~ + \seq_use:Nnnn~\g__nicem_names_seq~{,~} {,~} {~and~}.} +\bool_new:N \l__nicem_block_auto_columns_width_bool +\keys_define:nn {NiceMatrix/NiceMatrixBlock} + {auto-columns-width .code:n = {\bool_set_true:N \l__nicem_block_auto_columns_width_bool + \dim_gzero_new:N \g__nicem_max_cell_width_dim + \bool_set_true:N \l__nicem_auto_columns_width_bool}} +\NewDocumentEnvironment {NiceMatrixBlock} {O{}} + {\keys_set:nn {NiceMatrix/NiceMatrixBlock} {#1} + \int_zero_new:N \l__nicem_first_env_block_int + \int_set:Nn \l__nicem_first_env_block_int {\g__nicem_env_int + 1}} + {\bool_if:NT \l__nicem_block_auto_columns_width_bool + {\iow_now:Nn \@mainaux {\ExplSyntaxOn} + \int_step_inline:nnn \l__nicem_first_env_block_int \g__nicem_env_int + {\iow_now:Nx \@mainaux + {\cs_gset:cpn {__nicem_max_cell_width_##1} + {\dim_use:N \g__nicem_max_cell_width_dim}}} + \iow_now:Nn \@mainaux {\ExplSyntaxOff}}} \keys_define:nn {NiceMatrix/NiceArrayC} - {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, + {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool, parallelize-diags .default:n = true, - renew-dots .bool_set:N = \l__nm_renew_dots_bool, + renew-dots .bool_set:N = \l__nicem_renew_dots_bool, renew-dots .default:n = true, - nullify-dots .bool_set:N = \l__nm_nullify_dots_bool , + nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool , nullify-dots .default:n = true, - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl, + code-for-last-col .tl_set:N = \l__nicem_code_for_last_col_tl, code-for-last-col .value_required:n = true, columns-width .code:n = \str_if_eq:nnTF {#1} {auto} {\bool_set_true:N - \l__nm_auto_columns_width_bool} - {\dim_set:Nn \l__nm_columns_width_dim {#1}}, + \l__nicem_auto_columns_width_bool} + {\dim_set:Nn \l__nicem_columns_width_dim {#1}}, columns-width .value_required:n = true, - unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~pNiceArrayC}} + name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1} + {\msg_error:nnn {nicematrix} + {Duplicate~name} + {#1}} + {\seq_gput_left:Nn \g__nicem_names_seq {#1}} + \tl_gset:Nn \g__nicem_name_tl {#1}}, + name .value_required:n = true, + code-after .tl_gset:N = \g__nicem_code_after_tl, + code-after .initial:n = \c_empty_tl, + code-after .value_required:n = true, + unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArrayC}} \msg_new:nnnn {nicematrix} - {Unknown~option~for~pNiceArrayC} + {Unknown~option~for~NiceArrayC} {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~ \{\@currenvir\}.\\ If~you~go~on,~it~will~be~ignored.\\ For~a~list~of~the~available~options,~type~H~<return>.} {The~available~options~are~(in~alphabetic~order):~ + code-after,~ code-for-last-col,~ columns-width,~ + name,~ nullify-dots,~ parallelize-diags~ and~renew-dots.} -\cs_new_protected:Nn \__nm_NiceArrayC:nn - {\dim_gzero_new:N \g__nm_width_last_col_dim - \keys_set:nn {NiceMatrix/NiceArrayC} {#1} - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \tl_set:Nn \l__nm_pos_env_tl c +\cs_new_protected:Nn \__nicem_NiceArrayC:n + { \begin{NiceArray} - {#2 - >{\int_gincr:N \g__nm_column_int + {#1 + >{\int_gincr:N \g__nicem_column_int \hbox_set:Nw \l_tmpa_box - \l__nm_code_for_last_col_tl - \tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline] - \node [anchor=base] (nm-\int_use:N \g__nm_env_int- - \int_use:N \g__nm_row_int- - \int_use:N \g__nm_column_int) + \tl_if_empty:NTF \g__nicem_name_tl + {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline] + \node [anchor=base, + name = nm-\int_use:N \g__nicem_env_int- + \int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int] } + {\tikz[remember~picture, inner~sep = 0pt, minimum~width = 0pt, baseline] + \node [anchor=base, + name = nm-\int_use:N \g__nicem_env_int- + \int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int, + alias = \g__nicem_name_tl- + \int_use:N \g__nicem_row_int- + \int_use:N \g__nicem_column_int] } \bgroup $ % $ + \l__nicem_code_for_last_col_tl } l <{ $ % $ \egroup ; \hbox_set_end: - \dim_gset:Nn \g__nm_width_last_col_dim - {\dim_max:nn \g__nm_width_last_col_dim + \dim_gset:Nn \g__nicem_width_last_col_dim + {\dim_max:nn \g__nicem_width_last_col_dim {\box_wd:N \l_tmpa_box}} - \tl_gput_right:Nn \g__nm_preamble_aux_tl {#1} + \tl_gput_right:Nn \g__nicem_preamble_aux_tl {#1} \skip_horizontal:n {-2\arraycolsep} \hbox_overlap_right:n {\skip_horizontal:n {2\arraycolsep} \box_use:N \l_tmpa_box}}}} -\cs_new:Nn \__nm_after_last_col: - {\dim_compare:nNnF \g__nm_width_last_col_dim = \c_zero_dim - {\skip_horizontal:n {\g__nm_width_last_col_dim}{}}} -\NewDocumentEnvironment {pNiceArrayC} {O{} m O{}} - {\left( - \__nm_NiceArrayC:nn {#1,#3} {#2}} - {\end{NiceArray} - \right) - \__nm_after_last_col:} - -\NewDocumentEnvironment {vNiceArrayC} {O{} m O{}} - {\left| - \__nm_NiceArrayC:nn {#1,#3} {#2}} - {\end{NiceArray} - \right| - \__nm_after_last_col:} - -\NewDocumentEnvironment {VNiceArrayC} {O{} m O{}} - {\left\| - \__nm_NiceArrayC:nn {#1,#3} {#2}} - {\end{NiceArray} - \right\| - \__nm_after_last_col:} - -\NewDocumentEnvironment {bNiceArrayC} {O{} m O{}} - {\left[ - \__nm_NiceArrayC:nn {#1,#3} {#2}} +\NewDocumentEnvironment{NiceArrayCwithDelims} {mm O{} m O{}} + {\bool_set_false:N \l__nicem_direct_NiceArray_bool + \tl_gclear:N \g__nicem_code_after_tl + \dim_gzero_new:N \g__nicem_width_last_col_dim + \keys_set:nn {NiceMatrix/NiceArrayC} {#3,#5} + \bool_set_false:N \l__nicem_exterior_arraycolsep_bool + \tl_set:Nn \l__nicem_pos_env_tl c + \left#1 + \__nicem_NiceArrayC:n {#4}} {\end{NiceArray} - \right] - \__nm_after_last_col:} - -\NewDocumentEnvironment {BNiceArrayC} {O{} m O{}} - {\left\{ - \__nm_NiceArrayC:nn {#1,#3} {#2}} + \right#2 + \skip_horizontal:n \g__nicem_width_last_col_dim + } +\NewDocumentEnvironment {pNiceArrayC} {} + {\NiceArrayCwithDelims{(}{)}} + {\endNiceArrayCwithDelims} +\NewDocumentEnvironment {vNiceArrayC} {} + {\NiceArrayCwithDelims{|}{|}} + {\endNiceArrayCwithDelims} +\NewDocumentEnvironment {VNiceArrayC} {} + {\NiceArrayCwithDelims{\|}{\|}} + {\endNiceArrayCwithDelims} +\NewDocumentEnvironment {bNiceArrayC} {} + {\NiceArrayCwithDelims{[}{]}} + {\endNiceArrayCwithDelims} +\NewDocumentEnvironment {BNiceArrayC} {} + {\NiceArrayCwithDelims{\{}{\}}} + {\endNiceArrayCwithDelims} +\keys_define:nn {NiceMatrix/NiceArrayRC} + {parallelize-diags .bool_set:N = \l__nicem_parallelize_diags_bool, + parallelize-diags .default:n = true, + renew-dots .bool_set:N = \l__nicem_renew_dots_bool, + renew-dots .default:n = true, + nullify-dots .bool_set:N = \l__nicem_nullify_dots_bool , + nullify-dots .default:n = true, + code-for-first-row .tl_set:N = \l__nicem_code_for_first_row_tl, + code-for-last-col .tl_set:N = \l__nicem_code_for_last_col_tl, + code-for-last-col .value_required:n = true, + columns-width .tl_set:N = \l__nicem_columns_width_tl, + name .code:n = {\seq_if_in:NnTF \g__nicem_names_seq {#1} + {\msg_error:nnn {nicematrix} + {Duplicate~name} + {#1}} + {\seq_gput_left:Nn \g__nicem_names_seq {#1}} + \tl_gset:Nn \l__nicem_name_tl {#1}}, + code-after .tl_set:N = \l__nicem_code_after_tl, + unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArrayRC}} +\msg_new:nnnn {nicematrix} + {Unknown~option~for~NiceArrayRC} + {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~ + \{\@currenvir\}.\\ + If~you~go~on,~it~will~be~ignored.\\ + For~a~list~of~the~available~options,~type~H~<return>.} + {The~available~options~are~(in~alphabetic~order):~ + code-after,~ + code-for-last-col,~ + code-for-first-row,~ + columns-width~(in~fact~mandatory),~ + name,~ + nullify-dots,~ + parallelize-diags~ + and~renew-dots.} +\msg_new:nnn {nicematrix} + {The~key~columns-width~is~mandatory} + {In~the~environment~\{\@currenvir\}~you~must~use~the~ + key~"columns-width"~either~with~a~numerical~value~ + or~the~special~value~"auto".\\ + If~you~go~on,~the~value~"auto"~will~be~used~for~ + "columns-width".} +\NewDocumentEnvironment{NiceArrayRCwithDelims} {mm O{} m O{}} + {\tl_clear_new:N \l__nicem_columns_width_tl + \tl_clear_new:N \l__nicem_name_tl + \tl_clear_new:N \l__nicem_code_after_tl + \keys_set:nn {NiceMatrix/NiceArrayRC} {#3,#5} + \tl_gset_eq:NN \g__nicem_name_tl \l__nicem_name_tl + \tl_if_empty:NT \l__nicem_columns_width_tl + {\msg_error:nn {nicematrix} {The~key~columns-width~is~mandatory} + \tl_set:Nn \l__nicem_columns_width_tl {auto}} + \str_if_eq:nVTF {auto} \l__nicem_columns_width_tl + {\begin{NiceMatrixBlock}[auto-columns-width]} + {\NiceMatrixOptions{columns-width = \l__nicem_columns_width_tl} } + \vbox\bgroup\hbox\bgroup + \hbox_set:Nn \l_tmpa_box {$\left#1\vbox_to_ht:nn{2cm}{}\right.$} + \skip_horizontal:n {\box_wd:N \l_tmpa_box - \nulldelimiterspace} + \int_set:Nn \l__nicem_number_of_first_row_int {-1} + \tl_set_eq:NN \l__nicem_code_for_cell_tl \l__nicem_code_for_first_row_tl + \cs_set:Npn \__nicem_replace_first_line ##1\\{ + $\begin{NiceArray}{*\c@MaxMatrixCols{C}} + ##1 + \end{NiceArray}$ + \egroup \hbox\bgroup + \int_gdecr:N \g__nicem_env_int + \tl_gset_eq:NN \g__nicem_name_tl \l__nicem_name_tl + \tl_gset_eq:NN \g__nicem_code_after_tl \l__nicem_code_after_tl + \bool_set_false:N \l__nicem_direct_NiceArray_bool + \dim_gzero_new:N \g__nicem_width_last_col_dim + \bool_set_false:N \l__nicem_exterior_arraycolsep_bool + \tl_set:Nn \l__nicem_pos_env_tl c + $\left#1 % $ + \__nicem_NiceArrayC:n {#4}} + \__nicem_replace_first_line + } {\end{NiceArray} - \right\} - \__nm_after_last_col:} + \right#2$ % $ + \skip_horizontal:n \g__nicem_width_last_col_dim + \egroup\egroup + \str_if_eq:nVT {auto} \l__nicem_columns_width_tl + {\end{NiceMatrixBlock}} } +\NewDocumentEnvironment {pNiceArrayRC} {} + {\NiceArrayRCwithDelims{(}{)}} + {\endNiceArrayRCwithDelims} +\NewDocumentEnvironment {bNiceArrayRC} {} + {\NiceArrayRCwithDelims{[}{]}} + {\endNiceArrayRCwithDelims} +\NewDocumentEnvironment {vNiceArrayRC} {} + {\NiceArrayRCwithDelims{|}{|}} + {\endNiceArrayRCwithDelims} +\NewDocumentEnvironment {VNiceArrayRC} {} + {\NiceArrayRCwithDelims{\|}{\|}} + {\endNiceArrayRCwithDelims} +\NewDocumentEnvironment {BNiceArrayRC} {} + {\NiceArrayRCwithDelims{\{}{\}}} + {\endNiceArrayRCwithDelims} \endinput %% %% End of file `nicematrix.sty'. |