summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty')
-rw-r--r--Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty227
1 files changed, 195 insertions, 32 deletions
diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
index 671bc44ef0c..da3db9af6f1 100644
--- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
+++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
@@ -18,8 +18,8 @@
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
-\def\myfileversion{5.12}
-\def\myfiledate{2021/03/10}
+\def\myfileversion{5.13}
+\def\myfiledate{2021/03/23}
\RequirePackage{pgfcore}
\usepgfmodule{shapes}
\RequirePackage{l3keys2e}
@@ -319,6 +319,7 @@
\int_new:N \g__nicematrix_static_num_of_col_int
\tl_new:N \l__nicematrix_fill_tl
\tl_new:N \l__nicematrix_draw_tl
+\clist_new:N \l__nicematrix_borders_clist
\dim_new:N \l__nicematrix_rounded_corners_dim
\tl_new:N \l__nicematrix_color_tl
\dim_new:N \l__nicematrix_line_width_dim
@@ -331,6 +332,8 @@
\dim_new:N \l__nicematrix_submatrix_right_xshift_dim
\clist_new:N \l__nicematrix_hlines_clist
\clist_new:N \l__nicematrix_vlines_clist
+\clist_new:N \l__nicematrix_submatrix_hlines_clist
+\clist_new:N \l__nicematrix_submatrix_vlines_clist
\int_new:N \l__nicematrix_first_row_int
\int_set:Nn \l__nicematrix_first_row_int 1
\int_new:N \l__nicematrix_first_col_int
@@ -1242,11 +1245,12 @@
\cs_set_eq:NN \roundedrectanglecolor \__nicematrix_roundedrectanglecolor
\cs_set_eq:NN \rowcolor \__nicematrix_rowcolor
\cs_set_eq:NN \rowcolors \__nicematrix_rowcolors
+ \cs_set_eq:NN \arraycolor \__nicematrix_arraycolor
\cs_set_eq:NN \columncolor \__nicematrix_columncolor
\cs_set_eq:NN \chessboardcolors \__nicematrix_chessboardcolors
\cs_set_eq:NN \SubMatrix \__nicematrix_SubMatrix_in_code_before
\bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token
- \seq_clear_new:N \l__nicematrix_colors_seq
+ \seq_gclear_new:N \g__nicematrix_colors_seq
\exp_last_unbraced:NV \__nicematrix_CodeAfter_keys: \l__nicematrix_code_before_tl
\__nicematrix_actually_color:
\bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token
@@ -2381,14 +2385,7 @@
}
\iow_now:Nn \@mainaux \ExplSyntaxOff
}
- \__nicematrix_create_diag_nodes:
- \str_if_empty:NF \l__nicematrix_name_str
- {
- \pgfpicture
- \pgfrememberpicturepositiononpagetrue
- \pgfnodealias { \l__nicematrix_name_str - ##1 } { \__nicematrix_env: - ##1 }
- \endpgfpicture
- }
+ \__nicematrix_create_diag_nodes:
\bool_if:NT \l__nicematrix_parallelize_diags_bool
{
\int_gzero_new:N \g__nicematrix_ddots_int
@@ -2514,14 +2511,38 @@
}
\cs_new_protected:Npn \__nicematrix_create_diag_nodes:
{
+ \pgfpicture
+ \pgfrememberpicturepositiononpagetrue
\int_step_inline:nn { \int_max:nn \c@iRow \c@jCol + 1 }
{
- \pgfpicture
- \pgfrememberpicturepositiononpagetrue
\__nicematrix_qpoint:n { row - \int_min:nn { ##1 } { \c@iRow + 1 } }
\dim_set_eq:NN \l_tmpa_dim \pgf@y
\__nicematrix_qpoint:n { col - \int_min:nn { ##1 } { \c@jCol + 1 } }
\pgfcoordinate { \__nicematrix_env: - ##1 } { \pgfpoint \pgf@x \l_tmpa_dim }
+ }
+ \pgfnodealias
+ { \__nicematrix_env: - last }
+ { \__nicematrix_env: - \int_eval:n { \int_max:nn \c@iRow \c@jCol + 1 } }
+ \endpgfpicture
+ }
+\bool_if:nT
+ { \sys_if_engine_xetex_p: || \sys_if_engine_luatex_p: }
+ { \tl_put_right:Nn \__nicematrix_create_diag_nodes: \__nicematrix_create_half_nodes: }
+\cs_new_protected:Npn \__nicematrix_create_half_nodes:
+ {
+ \int_step_inline:nn { \int_max:nn \c@iRow \c@jCol }
+ {
+ \pgfpicture
+ \pgfrememberpicturepositiononpagetrue
+ \pgfcoordinate { \__nicematrix_env: - ##1 ½ }
+ {
+ \pgfpointscale { 0.5 }
+ {
+ \pgfpointadd
+ { \__nicematrix_qpoint:n { ##1 } }
+ { \__nicematrix_qpoint:n { \int_eval:n { ##1 + 1 } } }
+ }
+ }
\endpgfpicture
}
}
@@ -3646,24 +3667,25 @@
\cs_new_protected:Npn \__nicematrix_add_to_colors_seq:nn #1 #2
{
\int_zero:N \l_tmpa_int
- \seq_map_indexed_inline:Nn \l__nicematrix_colors_seq
+ \seq_map_indexed_inline:Nn \g__nicematrix_colors_seq
{ \tl_if_eq:nnT { #1 } { ##2 } { \int_set:Nn \l_tmpa_int { ##1 } } }
\int_compare:nNnTF \l_tmpa_int = \c_zero_int
{
- \seq_put_right:Nn \l__nicematrix_colors_seq { #1 }
- \tl_set:cn { l__nicematrix_color _ \seq_count:N \l__nicematrix_colors_seq _ tl } { #2 }
+ \seq_gput_right:Nn \g__nicematrix_colors_seq { #1 }
+ \tl_gset:cx { g__nicematrix_color _ \seq_count:N \g__nicematrix_colors_seq _ tl } { #2 }
}
- { \tl_put_right:cn { l__nicematrix_color _ \int_use:N \l_tmpa_int _tl } { #2 } }
+ { \tl_gput_right:cx { g__nicematrix_color _ \int_use:N \l_tmpa_int _tl } { #2 } }
}
\cs_generate_variant:Nn \__nicematrix_add_to_colors_seq:nn { x n }
\cs_new_protected:Npn \__nicematrix_actually_color:
{
\pgfpicture
\pgf@relevantforpicturesizefalse
- \seq_map_indexed_inline:Nn \l__nicematrix_colors_seq
+ \seq_map_indexed_inline:Nn \g__nicematrix_colors_seq
{
\color ##2
- \use:c { l__nicematrix_color _ ##1 _tl }
+ \use:c { g__nicematrix_color _ ##1 _tl }
+ \tl_gclear:c { g__nicematrix_color _ ##1 _tl }
\pgfusepath { fill }
}
\endpgfpicture
@@ -3751,6 +3773,47 @@
}
}
}
+\keys_define:nn { NiceMatrix / arraycolor }
+ {
+ except-corners .clist_set:N = \l_tmpa_clist ,
+ except-corners .default:n = { NW , SW , NE , SE }
+ }
+\NewDocumentCommand \__nicematrix_arraycolor { O { } m O { } }
+ {
+ \keys_set:nn { NiceMatrix / arraycolor } { #3 }
+ \clist_if_empty:NTF \l_tmpa_clist
+ {
+ \__nicematrix_rectanglecolor [ #1 ] { #2 }
+ { 1 - 1 } { \int_use:N \c@iRow - \int_use:N \c@jCol }
+ }
+ {
+ \tl_gput_left:Nx \g__nicematrix_internal_code_after_tl
+ {
+ \__nicematrix_arraycolor_code_after:nnn
+ { #1 }
+ { \exp_not:n { #2 } }
+ { \l_tmpa_clist }
+ }
+ }
+ }
+\cs_new_protected:Npn \__nicematrix_arraycolor_code_after:nnn #1 #2 #3
+ {
+ \group_begin:
+ \clist_set:Nn \l__nicematrix_except_corners_clist { #3 }
+ \__nicematrix_compute_corners:
+ \int_step_inline:nn \c@iRow
+ {
+ \int_step_inline:nn \c@jCol
+ {
+ \seq_if_in:NnF \l__nicematrix_empty_corner_cells_seq { ##1 - ####1 }
+ {
+ \tl_gput_left:Nx \g_nicematrix_code_before_tl
+ { \__nicematrix_cellcolor [ #1 ] { \exp_not:n { #2 } } { ##1 - ####1 } }
+ }
+ }
+ }
+ \group_end:
+ }
\keys_define:nn { NiceMatrix / rowcolors }
{
respect-blocks .bool_set:N = \l__nicematrix_respect_blocks_bool ,
@@ -4877,6 +4940,8 @@
rounded-corners .default:n = 4 pt ,
color .code:n = \color { #1 } \tl_set:Nn \l__nicematrix_draw_tl { #1 } ,
color .value_required:n = true ,
+ borders .clist_set:N = \l__nicematrix_borders_clist ,
+ borders .value_required:n = true ,
line-width .dim_set:N = \l__nicematrix_line_width_dim ,
line-width .value_required:n = true ,
l .code:n = \tl_set:Nn \l__nicematrix_pos_of_block_tl l ,
@@ -4927,9 +4992,7 @@
\seq_gput_left:Nn \g__nicematrix_pos_of_blocks_seq { { #1 } { #2 } { #3 } { #4 } }
\group_begin:
\keys_set:nn { NiceMatrix / Block / SecondPass } { #5 }
- \bool_lazy_or:nnT
- { ! \tl_if_empty_p:N \l__nicematrix_draw_tl }
- { \dim_compare_p:nNn \l__nicematrix_line_width_dim > \c_zero_dim }
+ \tl_if_empty:NF \l__nicematrix_draw_tl
{
\tl_gput_right:Nx \g_nicematrix_code_after_tl
{
@@ -4941,6 +5004,16 @@
\seq_gput_right:Nn \g__nicematrix_pos_of_stroken_blocks_seq
{ { #1 } { #2 } { #3 } { #4 } }
}
+ \clist_if_empty:NF \l__nicematrix_borders_clist
+ {
+ \tl_gput_right:Nx \g_nicematrix_code_after_tl
+ {
+ \__nicematrix_stroke_borders_block:nnn
+ { \exp_not:n { #5 } }
+ { #1 - #2 }
+ { \int_use:N \l__nicematrix_last_row_int - \int_use:N \l__nicematrix_last_col_int }
+ }
+ }
\tl_if_empty:NF \l__nicematrix_fill_tl
{
\tl_gput_right:Nx \g_nicematrix_code_before_tl
@@ -5164,6 +5237,71 @@
rounded-corners .dim_set:N = \l__nicematrix_rounded_corners_dim ,
rounded-corners .default:n = 4 pt
}
+\cs_new_protected:Npn \__nicematrix_stroke_borders_block:nnn #1 #2 #3
+ {
+ \dim_set_eq:NN \l__nicematrix_line_width_dim \arrayrulewidth
+ \keys_set_known:nn { NiceMatrix / BlockBorders } { #1 }
+ \dim_compare:nNnTF \l__nicematrix_rounded_corners_dim > \c_zero_dim
+ { \__nicematrix_error:n { borders~forbidden } }
+ {
+ \clist_map_inline:Nn \l__nicematrix_borders_clist
+ {
+ \clist_if_in:nnF { top , bottom , left , right } { ##1 }
+ { \__nicematrix_error:nn { bad~border } { ##1 } }
+ }
+ \__nicematrix_cut_on_hyphen:w #2 \q_stop
+ \tl_set_eq:NN \l_tmpc_tl \l_tmpa_tl
+ \tl_set_eq:NN \l_tmpd_tl \l_tmpb_tl
+ \__nicematrix_cut_on_hyphen:w #3 \q_stop
+ \tl_set:Nx \l_tmpa_tl { \int_eval:n { \l_tmpa_tl + 1 } }
+ \tl_set:Nx \l_tmpb_tl { \int_eval:n { \l_tmpb_tl + 1 } }
+ \pgfpicture
+ \pgfrememberpicturepositiononpagetrue
+ \pgf@relevantforpicturesizefalse
+ \CT@arc@
+ \pgfsetlinewidth { 1.1 \l__nicematrix_line_width_dim }
+ \clist_if_in:NnT \l__nicematrix_borders_clist { right }
+ { \__nicematrix_stroke_vertical:n \l_tmpb_tl }
+ \clist_if_in:NnT \l__nicematrix_borders_clist { left }
+ { \__nicematrix_stroke_vertical:n \l_tmpd_tl }
+ \clist_if_in:NnT \l__nicematrix_borders_clist { bottom }
+ { \__nicematrix_stroke_horizontal:n \l_tmpa_tl }
+ \clist_if_in:NnT \l__nicematrix_borders_clist { top }
+ { \__nicematrix_stroke_horizontal:n \l_tmpc_tl }
+ \endpgfpicture
+ }
+ }
+\cs_new_protected:Npn \__nicematrix_stroke_vertical:n #1
+ {
+ \__nicematrix_qpoint:n \l_tmpc_tl
+ \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \l__nicematrix_line_width_dim }
+ \__nicematrix_qpoint:n \l_tmpa_tl
+ \dim_set:Nn \l_tmpc_dim { \pgf@y + 0.5 \l__nicematrix_line_width_dim }
+ \__nicematrix_qpoint:n { #1 }
+ \pgfpathmoveto { \pgfpoint \pgf@x \l_tmpb_dim }
+ \pgfpathlineto { \pgfpoint \pgf@x \l_tmpc_dim }
+ \pgfusepathqstroke
+ }
+\cs_new_protected:Npn \__nicematrix_stroke_horizontal:n #1
+ {
+ \__nicematrix_qpoint:n \l_tmpd_tl
+ \clist_if_in:NnTF \l__nicematrix_borders_clist { left }
+ { \dim_set:Nn \l_tmpa_dim { \pgf@x - 0.5 \l__nicematrix_line_width_dim } }
+ { \dim_set:Nn \l_tmpa_dim { \pgf@x + 0.5 \l__nicematrix_line_width_dim } }
+ \__nicematrix_qpoint:n \l_tmpb_tl
+ \dim_set:Nn \l_tmpb_dim { \pgf@x + 0.5 \l__nicematrix_line_width_dim }
+ \__nicematrix_qpoint:n { #1 }
+ \pgfpathmoveto { \pgfpoint \l_tmpa_dim \pgf@y }
+ \pgfpathlineto { \pgfpoint \l_tmpb_dim \pgf@y }
+ \pgfusepathqstroke
+ }
+\keys_define:nn { NiceMatrix / BlockBorders }
+ {
+ borders .clist_set:N = \l__nicematrix_borders_clist ,
+ rounded-corners .dim_set:N = \l__nicematrix_rounded_corners_dim ,
+ rounded-corners .default:n = 4 pt ,
+ line-width .dim_set:N = \l__nicematrix_line_width_dim
+ }
\cs_set_protected:Npn \__nicematrix_renew_matrix:
{
\RenewDocumentEnvironment { pmatrix } { }
@@ -5298,7 +5436,10 @@
\endpgfpicture
}
\keys_define:nn { NiceMatrix }
- { CodeAfter / rules .inherit:n = NiceMatrix / rules }
+ {
+ CodeAfter / rules .inherit:n = NiceMatrix / rules ,
+ CodeAfter / sub-matrix .inherit:n = NiceMatrix / sub-matrix
+ }
\keys_define:nn { NiceMatrix / CodeAfter }
{
sub-matrix .code:n = \keys_set:nn { NiceMatrix / sub-matrix } { #1 } ,
@@ -5393,17 +5534,27 @@
delimiters / color .value_required:n = true ,
slim .bool_set:N = \l__nicematrix_submatrix_slim_bool ,
slim .default:n = true ,
+ hlines .clist_set:N = \l__nicematrix_submatrix_hlines_clist ,
+ hlines .default:n = all ,
+ vlines .clist_set:N = \l__nicematrix_submatrix_vlines_clist ,
+ vlines .default:n = all ,
+ hvlines .meta:n = { hlines, vlines } ,
+ hvlines .value_forbidden:n = true ,
}
\keys_define:nn { NiceMatrix }
{
SubMatrix .inherit:n = NiceMatrix / sub-matrix ,
CodeAfter / sub-matrix .inherit:n = NiceMatrix / sub-matrix ,
+ NiceMatrix / sub-matrix .inherit:n = NiceMatrix / sub-matrix ,
+ NiceArray / sub-matrix .inherit:n = NiceMatrix / sub-matrix ,
+ pNiceArray / sub-matrix .inherit:n = NiceMatrix / sub-matrix ,
+ NiceMatrixOptions / sub-matrix .inherit:n = NiceMatrix / sub-matrix ,
}
\keys_define:nn { NiceMatrix / SubMatrix }
{
- hlines .clist_set:N = \l__nicematrix_hlines_clist ,
+ hlines .clist_set:N = \l__nicematrix_submatrix_hlines_clist ,
hlines .default:n = all ,
- vlines .clist_set:N = \l__nicematrix_vlines_clist ,
+ vlines .clist_set:N = \l__nicematrix_submatrix_vlines_clist ,
vlines .default:n = all ,
hvlines .meta:n = { hlines, vlines } ,
hvlines .value_forbidden:n = true ,
@@ -5461,8 +5612,6 @@
{ \__nicematrix_error:n { SubMatrix~too~large } }
{
\str_clear_new:N \l__nicematrix_submatrix_name_str
- \clist_clear:N \l__nicematrix_hlines_clist
- \clist_clear:N \l__nicematrix_vlines_clist
\keys_set:nn { NiceMatrix / SubMatrix } { #5 }
\pgfpicture
\pgfrememberpicturepositiononpagetrue
@@ -5537,9 +5686,9 @@
}
}
}
- \tl_if_eq:NnTF \l__nicematrix_vlines_clist { all }
+ \tl_if_eq:NnTF \l__nicematrix_submatrix_vlines_clist { all }
{ \int_step_inline:nn { \l__nicematrix_last_j_tl - \l__nicematrix_first_j_tl } }
- { \clist_map_inline:Nn \l__nicematrix_vlines_clist }
+ { \clist_map_inline:Nn \l__nicematrix_submatrix_vlines_clist }
{
\bool_lazy_and:nnTF
{ \int_compare_p:nNn { ##1 } > 0 }
@@ -5554,9 +5703,9 @@
}
{ \__nicematrix_error:nnn { Wrong~line~in~SubMatrix } { vertical } { ##1 } }
}
- \tl_if_eq:NnTF \l__nicematrix_hlines_clist { all }
+ \tl_if_eq:NnTF \l__nicematrix_submatrix_hlines_clist { all }
{ \int_step_inline:nn { \l__nicematrix_last_i_tl - \l__nicematrix_first_i_tl } }
- { \clist_map_inline:Nn \l__nicematrix_hlines_clist }
+ { \clist_map_inline:Nn \l__nicematrix_submatrix_hlines_clist }
{
\bool_lazy_and:nnTF
{ \int_compare_p:nNn { ##1 } > 0 }
@@ -5986,6 +6135,13 @@
values~are:~NW,~SW,~NE~and~SE.\\
If~you~go~on,~this~specification~of~corner~will~be~ignored.
}
+\__nicematrix_msg_new:nn { bad~border }
+ {
+ #1~is~an~incorrect~specification~for~a~border~(in~the~key~
+ 'borders'~of~the~command~\token_to_str:N \Block).~The~available~
+ values~are:~left,~right,~top~and~bottom.\\
+ If~you~go~on,~this~specification~of~border~will~be~ignored.
+ }
\__nicematrix_msg_new:nn { last-col~non~empty~for~NiceArray }
{
In~the~\__nicematrix_full_name_env:,~you~must~use~the~key~
@@ -6028,6 +6184,13 @@
\{NiceTabular\},~\{NiceArray\}~and~\{NiceMatrix\}. \\
If~you~go~on,~this~command~will~be~ignored.
}
+\__nicematrix_msg_new:nn { borders~forbidden }
+ {
+ You~can't~use~the~key~'borders'~of~the~command~\token_to_str:N \Block\
+ because~the~option~'rounded-corners'~
+ is~in~force~with~a~non-zero~value.\\
+ If~you~go~on,~this~key~will~be~ignored.
+ }
\__nicematrix_msg_new:nn { bottomrule~without~booktabs }
{
You~can't~use~the~key~'tabular/bottomrule'~because~you~haven't~
@@ -6068,7 +6231,7 @@
For~a~list~of~the~available~keys,~type~H~<return>.
}
{
- The~available~keys~are~(in~alphabetic~order):~c,~draw,~fill,~l,~
+ The~available~keys~are~(in~alphabetic~order):~borders,~c,~draw,~fill,~l,~
line-width,~rounded-corners~and~r.
}
\__nicematrix_msg_new:nnn { Unknown~key~for~CodeAfter }