From 08ba64265f0add4eebf9496610c9e49d0470734f Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 1 May 2018 17:57:18 +0000 Subject: nicematrix (16apr18) git-svn-id: svn://tug.org/texlive/trunk@47545 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 197 ++++++++++++++++----- 1 file changed, 155 insertions(+), 42 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 fa0c20dbd66..ca85ddf7d2b 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.3} -\def\myfiledate{2018/03/31} +\def\myfileversion{1.4} +\def\myfiledate{2018/04/16} \RequirePackage{l3keys2e} \ProvidesExplPackage {nicematrix} @@ -42,6 +42,7 @@ \cs_new_protected:Nn \__nm_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 @@ -49,6 +50,7 @@ \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 \keys_define:nn {NiceMatrix/NiceMatrixOptions} {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, @@ -76,17 +78,46 @@ code-for-last-col .value_required:n = true, exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool , exterior-arraycolsep .default:n = true, - unknown .code:n = \msg_error:nn {nicematrix} {Option~unknown}} + unknown .code:n = \msg_error:nn {nicematrix} {Unknown~key~for~NiceMatrixOptions}} +\msg_new:nnnn {nicematrix} + {Unknown~key~for~NiceMatrixOptions} + {The~key~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~command + \token_to_str:N \NiceMatrixOptions.\\ + If~you~go~on,~it~will~be~ignored.\\ + For~a~list~of~the~available~keys,~type~H~.} + {The~available~keys~are~(in~alphabetic~order):~ + code-for-last-col,~ + exterior-arraycolsep,~ + nullify-dots,~ + parallelize-diags,~ + renew-dots,~ + renew-matrix~ + and~transparent} \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 .default:n = true, - renew-dots .bool_set:N = \l__nm_renew_dots_bool, - renew-dots .default:n = true, - nullify-dots .bool_set:N = \l__nm_nullify_dots_bool , - nullify-dots .default:n = true, - unknown .code:n = \msg_error:nn {nicematrix} {Option~unknown}} + {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, + parallelize-diags .default:n = true, + renew-dots .bool_set:N = \l__nm_renew_dots_bool, + renew-dots .default:n = true, + nullify-dots .bool_set:N = \l__nm_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}}, + unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceMatrix}} +\msg_new:nnnn {nicematrix} + {Unknown~option~for~NiceMatrix} + {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~ + \{NiceMatrix\}~and~its~variants.\\ + If~you~go~on,~it~will~be~ignored.\\ + For~a~list~of~the~available~options,~type~H~.} + {The~available~options~are~(in~alphabetic~order):~ + columns-width,~ + nullify-dots,~ + parallelize-diags~ + and~renew-dots.} \keys_define:nn {NiceMatrix/NiceArray} {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, parallelize-diags .default:n = true, @@ -96,45 +127,101 @@ nullify-dots .default:n = true, exterior-arraycolsep .bool_set:N = \l__nm_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}}, + 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, - unknown .code:n = \msg_error:nn {nicematrix} {Option~unknown}} + unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~NiceArray}} +\msg_new:nnnn {nicematrix} + {Unknown~option~for~NiceArray} + {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~for~the~environment~ + \{NiceArray\}.\\ + If~you~go~on,~it~will~be~ignored.\\ + For~a~list~of~the~available~options,~type~H~.} + {The~available~options~are~(in~alphabetic~order):~ + b,~ + c,~ + columns-width,~ + exterior-arraycolsep,~ + 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} + {\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: + {$ % $ + \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) - \bgroup $} % $ -\cs_new_protected:Nn \__nm_end_Cell: - {$\egroup ;} % $ + \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 - \NiceArray{*\c@MaxMatrixCols{C}}} + \NiceArray{*\c@MaxMatrixCols{C}} + } {\endarray \skip_horizontal:n {-\arraycolsep}} +\cs_generate_variant:Nn \dim_set:Nn {Nx} \NewDocumentEnvironment {NiceArray} {O{} m O{}} - {\aftergroup \__nm_draw_lines: + {\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 \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}}}} \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}} + \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}} \skip_zero:N \tabskip \cs_set:Npn \ialign {\everycr{} \skip_zero:N \tabskip \halign} \halign} - \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:}} + \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}}} + \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} + c + <{\__nm_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} + c + <{\__nm_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 @@ -150,7 +237,6 @@ \cs_set_eq:NN \iddots \__nm_Iddots} \bool_if:NF \l__nm_renew_matrix_bool {\cs_set_eq:NN \multicolumn \__nm_multicolumn:nn} - \int_gincr:N \g__nm_env_int \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 @@ -179,6 +265,12 @@ \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- \int_use:N #1- @@ -465,20 +557,33 @@ of~amsmath~is~also~forbidden~since~it~uses~ \token_to_str:N \multicolumn.~You~can~go~on~but~your~line~will~ probably~be~wrong.} -\msg_new:nnn {nicematrix} - {Option~unknown} - {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~or~ - meaningless~in~the~context.~If~you~go~on,~it~will~be~ignored.} \keys_define:nn {NiceMatrix/NiceArrayC} - {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, - parallelize-diags .default:n = true, - renew-dots .bool_set:N = \l__nm_renew_dots_bool, - renew-dots .default:n = true, - nullify-dots .bool_set:N = \l__nm_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 .value_required:n = true, - unknown .code:n = \msg_error:nn {nicematrix} {Option~unknown}} + {parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool, + parallelize-diags .default:n = true, + renew-dots .bool_set:N = \l__nm_renew_dots_bool, + renew-dots .default:n = true, + nullify-dots .bool_set:N = \l__nm_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 .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}}, + columns-width .value_required:n = true, + unknown .code:n = \msg_error:nn {nicematrix} {Unknown~option~for~pNiceArrayC}} +\msg_new:nnnn {nicematrix} + {Unknown~option~for~pNiceArrayC} + {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~.} + {The~available~options~are~(in~alphabetic~order):~ + code-for-last-col,~ + columns-width,~ + 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} @@ -486,15 +591,23 @@ \tl_set:Nn \l__nm_pos_env_tl c \begin{NiceArray} {#2 - >{\hbox_set:Nw \l_tmpa_box + >{\int_gincr:N \g__nm_column_int + \hbox_set:Nw \l_tmpa_box \l__nm_code_for_last_col_tl - \__nm_Cell:n l} - l - <{\__nm_end_Cell: + \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) + \bgroup $ % $ + } + l + <{ $ % $ + \egroup ; \hbox_set_end: \dim_gset:Nn \g__nm_width_last_col_dim {\dim_max:nn \g__nm_width_last_col_dim {\box_wd:N \l_tmpa_box}} + \tl_gput_right:Nn \g__nm_preamble_aux_tl {#1} \skip_horizontal:n {-2\arraycolsep} \hbox_overlap_right:n {\skip_horizontal:n {2\arraycolsep} -- cgit v1.2.3