texlive[52757] Master/texmf-dist: nicematrix (12nov19)

commits+karl at tug.org commits+karl at tug.org
Tue Nov 12 22:43:08 CET 2019


Revision: 52757
          http://tug.org/svn/texlive?view=revision&revision=52757
Author:   karl
Date:     2019-11-12 22:43:08 +0100 (Tue, 12 Nov 2019)
Log Message:
-----------
nicematrix (12nov19)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf
    trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex
    trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf
    trunk/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx
    trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty

Modified: trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex	2019-11-12 21:42:54 UTC (rev 52756)
+++ trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex	2019-11-12 21:43:08 UTC (rev 52757)
@@ -1192,9 +1192,9 @@
 \section{Les matrices par blocs}
 
 Dans les environnements de \pkg{nicematrix}, on peut utiliser la commande |\Block| pour placer un élément au centre
-d'un rectangle de cellules fusionnées.
+d'un rectangle de cases fusionnées.
 
-La commande |\Block| doit être utilisée dans la cellule supérieure gauche du bloc avec deux arguments. Le premier
+La commande |\Block| doit être utilisée dans la case supérieure gauche du bloc avec deux arguments. Le premier
 argument est la taille de ce bloc avec la syntaxe $i$-$j$ où $i$ est le nombre de rangées et $j$ le nombre de
 colonnes du bloc. Le deuxième argument, est, sans surprise, le contenu du bloc (en mode mathématique).
 
@@ -1303,9 +1303,10 @@
 \section{Les compteurs iRow et jCol}
 
 Dans les cases du tableau, il est possible d'utiliser les compteurs LaTeX |iRow| et |jCol| qui représentent le
-numéro de la rangée courante et le numéro de la colonne courante\footnote{On rappelle que la «permière rangée» (si
-  elle existe) est $0$ et que le numéro de la «première colonne» (si elle existe) est $0$ également.}. Bien entendu,
-l'utilisateur ne doit pas modifier les valeurs de ces compteurs qui sont utilisés en interne par \pkg{nicematrix}.
+numéro de la rangée courante et le numéro de la colonne courante\footnote{On rappelle que le numéro de la «première
+  rangée» (si elle existe) est $0$ et que le numéro de la «première colonne» (si elle existe) est $0$ également.}.
+Bien entendu, l'utilisateur ne doit pas modifier les valeurs de ces compteurs qui sont utilisés en interne par
+\pkg{nicematrix}.
 
 \medskip
 \begin{BVerbatim}[baseline=c,boxwidth=10.6cm]
@@ -1336,7 +1337,24 @@
 \pkg{nicematrix}.
 
 
+\bigskip
+L'extension \pkg{nicematrix} propose aussi des commandes pour composer automatiquement des matrices à partir d'un
+motif général. Ces commandes sont nommées |\pAutoNiceMatrix|, |\bAutoNiceMatrix|, |\vAutoNiceMatrix|,
+|\VAutoNiceMatrix| et |\BAutoNiceMatrix|.
 
+Chacune de ces commandes prend deux arguments obligatoires : le premier est la taille de la matrice, sous la forme 
+$n$-$p$, où $n$ est le nombre de lignes et $p$ est le nombre de colonnes et le deuxième est le motif (c'est-à-dire
+simplement des tokens qui seront insérés dans chaque case de la matrice, exceptées celles des éventuelles lignes et
+colonnes extérieures). 
+
+\medskip
+\begin{Verbatim}
+$C = ~emphase#\pAutoNiceMatrix@{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$
+\end{Verbatim}
+
+
+$C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$
+
 \section{L'option hlines}
 
 Dans les environnements de \pkg{nicematrix}, on peut bien entendu ajouter des filets horizontaux entre les lignes

Modified: trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx	2019-11-12 21:42:54 UTC (rev 52756)
+++ trunk/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx	2019-11-12 21:43:08 UTC (rev 52757)
@@ -15,8 +15,8 @@
 %
 % \fi
 % \iffalse
-\def\myfileversion{3.6}
-\def\myfiledate{2019/10/29}
+\def\myfileversion{3.7}
+\def\myfiledate{2019/11/11}
 %
 %
 %<*batchfile>
@@ -1362,11 +1362,11 @@
 % \section{The counters iRow and jCol}
 %
 % In the cells of the array, it's possible to use the LaTeX counters |iRow| and
-% |jCol| which represents the number of the current row and the number of the
+% |jCol| which represent the number of the current row and the number of the
 % current col\footnote{We recall that the first row (if it exists) has the
-% number~$0$ and that the first col (if it exists) has also the number~$0$).}. Of
-% course, the user must not change the value of the these counters which are
-% used internally by \pkg{nicematrix}.
+% number~$0$ and that the first col (if it exists) has also the number~$0$).}.
+% Of course, the user must not change the value of these counters which are used
+% internally by \pkg{nicematrix}.
 %
 % \medskip
 % \begin{BVerbatim}[baseline=c,boxwidth=10.6cm]
@@ -1391,11 +1391,31 @@
 % & 9 & 10 & 11 & 12
 % \end{pNiceMatrix}$
 % 
-% \smallskip
+% \medskip
 % If LaTeX counters called |iRow| and |jCol| are defined in the document by
 % extensions other than \pkg{nicematrix} (or by the user), they are shadowed in
-% the environements of \pkg{nicematrix}.
+% the environments of \pkg{nicematrix}.
 %
+% \bigskip
+% The extension \pkg{nicematrix} also provides commands in order to compose
+% automatically matrices from a general pattern. These commands are
+% |\pAutoNiceMatrix|, |\bAutoNiceMatrix|, |\vAutoNiceMatrix|,
+% |\VAutoNiceMatrix| and |\BAutoNiceMatrix|.
+%
+% These commands take two mandatory arguments. The first is the format of the
+% matrix, with the syntax $n$-$p$ where $n$ is the number of rows and $p$ the
+% number of columns. The second argument is the pattern (it's a list of tokens
+% which are inserted in each cell of the constructed matrix, excepted in the
+% cells of the eventual exterior rows and columns).
+%
+% \medskip
+% \begin{Verbatim}
+% $C = ~emphase#\pAutoNiceMatrix@{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$
+% \end{Verbatim}
+%
+%
+% $C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$
+%
 % \section{The option hlines}
 % 
 % You can add horizontal rules between rows in the environments of
@@ -2615,7 +2635,8 @@
 %    \end{macrocode}
 %
 % \bigskip
-% The name of the current environment (will be used only in the error messages).
+% The name of the current environment or the current command (will be used only
+% in the error messages). 
 %    \begin{macrocode}
 \str_new:N \g_@@_type_env_str
 %    \end{macrocode}
@@ -3004,11 +3025,11 @@
     columns-width .value_required:n = true ,
     name .code:n = 
       \unless \ifmeasuring@
-          \str_set:Nn \l_tmpa_str { #1 }
-          \seq_if_in:NVTF \g_@@_names_seq \l_tmpa_str
-             { \@@_error:nn { Duplicate~name } { #1 } }
-             { \seq_gput_left:NV \g_@@_names_seq \l_tmpa_str }
-          \str_set_eq:NN \l_@@_name_str \l_tmpa_str 
+         \str_set:Nn \l_tmpa_str { #1 }
+         \seq_if_in:NVTF \g_@@_names_seq \l_tmpa_str
+           { \@@_error:nn { Duplicate~name } { #1 } }
+           { \seq_gput_left:NV \g_@@_names_seq \l_tmpa_str }
+         \str_set_eq:NN \l_@@_name_str \l_tmpa_str 
       \fi ,
     name .value_required:n = true ,
     code-after .tl_gset:N = \g_@@_code_after_tl ,
@@ -3815,7 +3836,10 @@
 \NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } }
   { 
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { NiceArrayWithDelims } }
+      { 
+        \str_gset:Nn \g_@@_type_env_str 
+          { environment ~ { NiceArrayWithDelims } }
+      } 
     \@@_adapt_S_column:
     \@@_test_if_math_mode:
     \bool_if:NT \l_@@_in_env_bool { \@@_fatal:n { Yet~in~env } } 
@@ -4231,7 +4255,21 @@
         \hbox_set:Nw \l_tmpa_box 
         \c_math_toggle_token
         \bool_if:NT \l_@@_small_bool \scriptstyle
-        \int_compare:nNnT \c at iRow > \c_zero_int \l_@@_code_for_first_col_tl
+%    \end{macrocode}
+% We insert |\l_@@_code_for_first_col_tl|... but we don't insert it in the
+% potential ``first row'' and in the potential ``last row''.
+%    \begin{macrocode}
+        \bool_if:nT
+          {
+            \int_compare_p:nNn \c at iRow > \c_zero_int 
+            && 
+            (
+              \int_compare_p:nNn \l_@@_last_row_int < 0
+              ||
+              \int_compare_p:nNn \c at iRow < \l_@@_last_row_int
+            )
+          }
+          { \l_@@_code_for_first_col_tl }
       }
     l
     < 
@@ -4314,7 +4352,21 @@
         \hbox_set:Nw \l_tmpa_box 
           \c_math_toggle_token
           \bool_if:NT \l_@@_small_bool \scriptstyle 
-          \l_@@_code_for_last_col_tl
+%    \end{macrocode}
+% We insert |\l_@@_code_for_last_col_tl|... but we don't insert it in the
+% potential ``first row'' and in the potential ``last row''.
+%    \begin{macrocode}
+        \bool_if:nT
+          {
+            \int_compare_p:nNn \c at iRow > \c_zero_int 
+            && 
+            (
+              \int_compare_p:nNn \l_@@_last_row_int < 0
+              ||
+              \int_compare_p:nNn \c at iRow < \l_@@_last_row_int
+            )
+          }
+          { \l_@@_code_for_last_col_tl }
       }
     l
     < 
@@ -4385,7 +4437,7 @@
   { 
     \bool_set_true:N \l_@@_NiceArray_bool
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { NiceArray } }
+      { \str_gset:Nn \g_@@_type_env_str { environment ~ { NiceArray } } } 
 %    \end{macrocode}
 % We put . and . for the delimiters but, in fact, that doesn't matter because
 % these arguments won't be used in |{NiceArrayWithDelims}| (because the flag
@@ -4405,7 +4457,7 @@
 \NewDocumentEnvironment { pNiceArray } { }
   {
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { pNiceArray } }
+      { \str_gset:Nn \g_@@_type_env_str { environment ~ { pNiceArray } } }
     \@@_test_if_math_mode:
     \NiceArrayWithDelims ( )
   }
@@ -4416,7 +4468,7 @@
 \NewDocumentEnvironment { bNiceArray } { }
   {
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { NiceArray } }
+      { \str_gset:Nn \g_@@_type_env_str { environment ~ { bNiceArray } } }
     \@@_test_if_math_mode:
     \NiceArrayWithDelims [ ]
   }
@@ -4427,18 +4479,18 @@
 \NewDocumentEnvironment { BNiceArray } { }
   {
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { BNiceArray } }
+      { \str_gset:Nn \g_@@_type_env_str { environment ~ { BNiceArray } } }
     \@@_test_if_math_mode:
     \NiceArrayWithDelims \{ \}
   }
   { \endNiceArrayWithDelims }
-%    \end{macrocode}
+%    \end{macrocode} 
 %               
 %   \begin{macrocode}
 \NewDocumentEnvironment { vNiceArray } { }
   {
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { vNiceArray } }
+      { \str_gset:Nn \g_@@_type_env_str { environment ~ { vNiceArray } } }
     \@@_test_if_math_mode:
     \NiceArrayWithDelims | |
   }
@@ -4449,7 +4501,7 @@
 \NewDocumentEnvironment { VNiceArray } { }
   {
     \str_if_empty:NT \g_@@_type_env_str 
-      { \str_gset:Nn \g_@@_type_env_str { VNiceArray } }
+      { \str_gset:Nn \g_@@_type_env_str { environment ~ { VNiceArray } } }
     \@@_test_if_math_mode:
     \NiceArrayWithDelims \| \|
   }
@@ -4464,7 +4516,7 @@
   {
     \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } }
       {
-        \str_gset:Nn \g_@@_type_env_str { #1 NiceMatrix } 
+        \str_gset:Nn \g_@@_type_env_str { environment ~ { #1 NiceMatrix } }  
         \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
         \begin { #1 NiceArray } 
           { 
@@ -5742,9 +5794,38 @@
 % In the |code-after|, the command |\@@_line:nn| will be linked to |\line|. This
 % command takes two arguments which are the specification of two cells in the
 % array (in the format $i$-$j$) and draws a dotted line between these cells. 
+% 
+% \medskip
+% First, we write a command with an argument of the format $i$-$j$ and applies
+% the command |\int_eval:n| to $i$ and~$j$ ; this must \emph{not} be protected
+% (and is, of course fully expandable).\footnote{Indeed, we want that the user
+% may use the command |\line| in |code-after| with LaTeX counters in the
+% arguments --- with the command |\value|.}
 %    \begin{macrocode}
-\cs_new_protected:Nn \@@_line:nn
+\cs_new:Npn \@@_double_int_eval:n #1-#2 \q_stop
+  { \int_eval:n { #1 } - \int_eval:n { #2 } }
+%    \end{macrocode}
+%
+% \medskip
+% With the following construction, the command |\@@_double_int_eval:n| is
+% applied to both arguments before the application of |\@@_line_i:nn| (the
+% construction uses the fact the |\@@_line_i:nn| is protected and that
+% |\@@_double_int_eval:n| is fully expandable).
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_line:nn #1 #2
   {
+    \use:x
+      {
+        \@@_line_i:nn 
+          { \@@_double_int_eval:n #1 \q_stop }
+          { \@@_double_int_eval:n #2 \q_stop }
+      }
+  }
+%    \end{macrocode}
+% 
+%    \begin{macrocode}
+\cs_new_protected:Nn \@@_line_i:nn
+  {
     \bool_if:NF \c_@@_draft_bool
       {
         \dim_zero_new:N \g_@@_x_initial_dim
@@ -5761,13 +5842,13 @@
           }
           {
             \begin { tikzpicture }
-               \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ;
-               \tikz at parse@node \pgfutil at firstofone ( i )
-               \dim_gset:Nn \g_@@_x_initial_dim \pgf at x
-               \dim_gset:Nn \g_@@_y_initial_dim \pgf at y
-               \tikz at parse@node \pgfutil at firstofone ( f )
-               \dim_gset:Nn \g_@@_x_final_dim \pgf at x
-               \dim_gset:Nn \g_@@_y_final_dim \pgf at y
+              \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ;
+              \tikz at parse@node \pgfutil at firstofone ( i )
+              \dim_gset:Nn \g_@@_x_initial_dim \pgf at x
+              \dim_gset:Nn \g_@@_y_initial_dim \pgf at y
+              \tikz at parse@node \pgfutil at firstofone ( f )
+              \dim_gset:Nn \g_@@_x_final_dim \pgf at x
+              \dim_gset:Nn \g_@@_y_final_dim \pgf at y
             \end { tikzpicture }  
             \@@_draw_tikz_line:
           }
@@ -6403,9 +6484,7 @@
 % command |\multicolumn|. 
 %    \begin{macrocode}
 \NewExpandableDocumentCommand \@@_Block: { m D < > { } m }
-  {
-    \@@_Block_i #1 \q_stop { #2 } { #3 }
-  }
+  { \@@_Block_i #1 \q_stop { #2 } { #3 } }
 %    \end{macrocode}
 % 
 % \medskip
@@ -6413,10 +6492,7 @@
 % It must be of the form $i$|-|$j$ where $i$ and $j$ are the size (in rows and 
 % columns) of the block.
 %    \begin{macrocode}
-\cs_new:Npn \@@_Block_i #1-#2 \q_stop
-  {
-    \@@_Block_ii:nnnn { #1 } { #2 } 
-  }
+\cs_new:Npn \@@_Block_i #1-#2 \q_stop { \@@_Block_ii:nnnn { #1 } { #2 } }
 %    \end{macrocode}
 %
 % \medskip
@@ -6520,7 +6596,7 @@
   }
 %    \end{macrocode}
 %                          
-% % \subsection{How to draw the dotted lines transparently}
+% \subsection{How to draw the dotted lines transparently}
 %    \begin{macrocode}
 \cs_set_protected:Npn \@@_renew_matrix:
   { 
@@ -6543,7 +6619,75 @@
 %    \end{macrocode}
 %
 %
+% \medskip
+% \subsection{Automatic arrays}
 %
+% 
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_set_size:n #1-#2 \q_stop
+  {
+    \int_set:Nn \l_@@_nb_rows_int { #1 }
+    \int_set:Nn \l_@@_nb_cols_int { #2 }
+  }
+%    \end{macrocode}
+%
+%
+%    \begin{macrocode}
+\NewDocumentCommand \AutoNiceMatrixWithDelims { m m O { } m O { } m ! O { } } 
+  {
+    \int_zero_new:N \l_@@_nb_rows_int
+    \int_zero_new:N \l_@@_nb_cols_int
+    \@@_set_size:n #4 \q_stop
+    \begin { NiceArrayWithDelims } { #1 } { #2 } 
+      { * { \l_@@_nb_cols_int } { C } } [ #3 , #5 , #7 ] 
+    \int_compare:nNnT \l_@@_first_row_int = \c_zero_int
+      { 
+        \int_compare:nNnT \l_@@_first_col_int = \c_zero_int { & } 
+        \prg_replicate:nn { \l_@@_nb_cols_int - 1 } { & } 
+        \int_compare:nNnT \l_@@_last_col_int > { -1 } { & } \\ 
+      }
+    \prg_replicate:nn \l_@@_nb_rows_int
+      { 
+        \int_compare:nNnT \l_@@_first_col_int = \c_zero_int { & }
+%    \end{macrocode}
+% You put |{ }| before |#6| to avoid a hasty expansion of an eventual
+% |\arabic{iRow}| at the beginning of the row which would result in an incorrect
+% value of that |iRow| (since |iRow| is incremented in the first cell of the row
+% of the |\halign|).
+%    \begin{macrocode}
+        \prg_replicate:nn { \l_@@_nb_cols_int - 1 } { { } #6 & } #6
+        \int_compare:nNnT \l_@@_last_col_int > { -1 } { & } \\  
+      }
+    \int_compare:nNnT \l_@@_last_row_int > { -2 }
+      { 
+        \int_compare:nNnT \l_@@_first_col_int = \c_zero_int { & }
+        \prg_replicate:nn { \l_@@_nb_cols_int - 1 } { & } 
+        \int_compare:nNnT \l_@@_last_col_int > { -1 } { & } \\  
+      }
+    \end { NiceArrayWithDelims }
+  }
+%    \end{macrocode}
+% 
+%    \begin{macrocode}
+\cs_set_protected:Npn \@@_define_com:nnn #1 #2 #3
+  { 
+    \cs_set_protected:cpn { #1 AutoNiceMatrix }
+      {
+        \str_gset:Nx \g_@@_type_env_str 
+          { command ~ \c_backslash_str #1 AutoNiceMatrix } 
+        \AutoNiceMatrixWithDelims { #2 } { #3 }
+      }  
+  }
+%    \end{document}
+%    \begin{macrocode}
+\@@_define_com:nnn p ( ) 
+\@@_define_com:nnn b [ ]
+\@@_define_com:nnn v | |
+\@@_define_com:nnn V \| \|
+\@@_define_com:nnn B \{ \}
+%    \end{macrocode}
+% 
+% \medskip
 % \subsection{We process the options}
 %
 % We process the options when the package is loaded (with |\usepackage|) but we
@@ -6584,9 +6728,8 @@
 %    \begin{macrocode}
 \@@_msg_new:nn { last-col~non~empty~for~NiceArray }
   {
-    In~the~environment~\{\g_@@_type_env_str\},~you~must~use~the~option~
-    'last-col'~without~value~(the~number~of~columns~is~known~by~the~
-    preamble~of~the~environment).\\
+    In~the~\g_@@_type_env_str,~you~must~use~the~option~
+    'last-col'~without~value.\\
     However,~you~can~go~on~for~this~time~
     (the~value~'\l_keys_value_tl'~will~be~ignored). 
   }
@@ -6595,7 +6738,7 @@
 %    \begin{macrocode}
 \@@_msg_new:nn { last-col~empty~for~NiceMatrix }
   {
-    In~the~environment~\{\g_@@_type_env_str\}~you~can't~use~the~option~
+    In~the~\g_@@_type_env_str, you~can't~use~the~option~
     'last-col'~without~value.~You~must~give~the~number~of~that~last~column.\\
     If~you~go~on~this~option~will~be~ignored.
   }
@@ -6606,7 +6749,7 @@
   {
     You~try~to~draw~a~block~in~the~cell~#1-#2~of~your~matrix~but~the~matrix~is~
     too~small~for~that~block.\\
-    If~you~go~on,~this~command~line~will~be~ignored.
+    If~you~go~on,~this~command~will~be~ignored.
   }
 %    \end{macrocode}
 %
@@ -6623,10 +6766,10 @@
 %    \begin{macrocode}
 \@@_msg_new:nn { Wrong~last~row }
   { 
-    You~have~used~'last-row=\int_use:N \l_@@_last_row_int'~but~your~environment~
-    \{\g_@@_type_env_str\}~seems~to~have~\int_use:N \c at iRow 
-    rows.~If~you~go~on,~the~value~of~\int_use:N \c at iRow 
-    will~be~used~for~last~row.~You~can~avoid~this~problem~by~using~'last-row'~
+    You~have~used~'last-row=\int_use:N \l_@@_last_row_int'~but~your~
+    \g_@@_type_env_str\ seems~to~have~\int_use:N \c at iRow \ rows.~
+    If~you~go~on,~the~value~of~\int_use:N \c at iRow \ will~be~used~for~
+    last~row.~You~can~avoid~this~problem~by~using~'last-row'~  
     without~value~(more~compilations~might~be~necessary).
   }
 %    \end{macrocode}     
@@ -6643,7 +6786,7 @@
 %    \begin{macrocode}
 \@@_msg_new:nn { Outside~math~mode }
   {
-    The~environment~\{\g_@@_type_env_str\}~can~be~used~only~in~math~mode~
+    The~\g_@@_type_env_str\ can~be~used~only~in~math~mode~
     (and~not~in~\token_to_str:N \vcenter).\\
     This~error~is~fatal.
   }
@@ -6655,6 +6798,9 @@
     The~option~'Transparent'~has~been~renamed~'transparent'.\\
     However,~you~can~go~on~for~this~time.
   }
+%    \end{macrocode}
+%
+%    \begin{macrocode}
 \@@_msg_new:nn { Option~RenewMatrix~suppressed }
   { 
     The~option~'RenewMatrix'~has~been~renamed~'renew-matrix'.\\
@@ -6744,8 +6890,8 @@
 %    \begin{macrocode}
 \@@_msg_new:nnn { Unknown~option~for~NiceMatrix }
   { 
-    The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~
-    \{\g_@@_type_env_str\}. \\
+    The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~
+    \g_@@_type_env_str. \\
     If~you~go~on,~it~will~be~ignored. \\
     For~a~list~of~the~available~options,~type~H~<return>.
   }
@@ -6805,7 +6951,7 @@
 %    \begin{macrocode}
 \@@_msg_new:nn { Zero~row }
   { 
-    There~is~a~problem.~Maybe~your~environment~\{\g_@@_type_env_str\}~is~empty.~ 
+    There~is~a~problem.~Maybe~your~\g_@@_type_env_str\ is~empty.~ 
     Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~and~R~in~the~preamble~
     of~your~environment. \\
     If~you~go~on,~the~result~may~be~incorrect.
@@ -6816,7 +6962,7 @@
 \@@_msg_new:nn { Use~of~:~in~first~position }
   { 
     You~can't~use~the~column~specifier~'\l_@@_letter_for_dotted_lines_str'~in~the~
-    first~position~of~the~preamble~of~the~environment~\{\g_@@_type_env_str\}. \\
+    first~position~of~the~preamble~of~the~\g_@@_type_env_str. \\
     If~you~go~on,~this~dotted~line~will~be~ignored.
   }
 %    \end{macrocode}
@@ -6827,7 +6973,7 @@
 %    \begin{macrocode}
 \@@_msg_new:nn { Obsolete~environment }
   {
-    The~environment~\{\@currenvir\}~is~obsolete.~
+    The~environment~\{\@currenvir\}~is~obsolete~and~will~be~deleted~in~future~version.~ 
     We~should~use~#1~instead.
   }
 %    \end{macrocode}
@@ -7171,6 +7317,15 @@
 %
 % There is no longer artificial errors |Duplicate~name| in the environments of
 % \pkg{amsmath}. 
+%
+% \subsection*{Changes between version 3.6 and 3.7} 
+% 
+% The four ``corners'' of the matrix are correctly protected against the four
+% codes: |code-for-first-col|, |code-for-last-col|, |code-for-first-row| and
+% |code-for-last-row|. 
+%
+% New command |\pAutoNiceMatrix| and its variants (suggestion of Christophe Bal).
+% 
 % \PrintIndex
 % 
 % \tableofcontents

Modified: trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty	2019-11-12 21:42:54 UTC (rev 52756)
+++ trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty	2019-11-12 21:43:08 UTC (rev 52757)
@@ -18,8 +18,8 @@
 %% and version 1.3 or later is part of all distributions of
 %% LaTeX version 2005/12/01 or later.
 %% 
-\def\myfileversion{3.6}
-\def\myfiledate{2019/10/29}
+\def\myfileversion{3.7}
+\def\myfiledate{2019/11/11}
 \RequirePackage{tikz}
 \usetikzlibrary{fit}
 \RequirePackage{expl3}[2019/07/01]
@@ -203,11 +203,11 @@
     columns-width .value_required:n = true ,
     name .code:n =
       \unless \ifmeasuring@
-          \str_set:Nn \l_tmpa_str { #1 }
-          \seq_if_in:NVTF \g__nm_names_seq \l_tmpa_str
-             { \__nm_error:nn { Duplicate~name } { #1 } }
-             { \seq_gput_left:NV \g__nm_names_seq \l_tmpa_str }
-          \str_set_eq:NN \l__nm_name_str \l_tmpa_str
+         \str_set:Nn \l_tmpa_str { #1 }
+         \seq_if_in:NVTF \g__nm_names_seq \l_tmpa_str
+           { \__nm_error:nn { Duplicate~name } { #1 } }
+           { \seq_gput_left:NV \g__nm_names_seq \l_tmpa_str }
+         \str_set_eq:NN \l__nm_name_str \l_tmpa_str
       \fi ,
     name .value_required:n = true ,
     code-after .tl_gset:N = \g__nm_code_after_tl ,
@@ -592,7 +592,10 @@
 \NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } }
   {
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { NiceArrayWithDelims } }
+      {
+        \str_gset:Nn \g__nm_type_env_str
+          { environment ~ { NiceArrayWithDelims } }
+      }
     \__nm_adapt_S_column:
     \__nm_test_if_math_mode:
     \bool_if:NT \l__nm_in_env_bool { \__nm_fatal:n { Yet~in~env } }
@@ -840,7 +843,17 @@
         \hbox_set:Nw \l_tmpa_box
         \c_math_toggle_token
         \bool_if:NT \l__nm_small_bool \scriptstyle
-        \int_compare:nNnT \c at iRow > \c_zero_int \l__nm_code_for_first_col_tl
+        \bool_if:nT
+          {
+            \int_compare_p:nNn \c at iRow > \c_zero_int
+            &&
+            (
+              \int_compare_p:nNn \l__nm_last_row_int < 0
+              ||
+              \int_compare_p:nNn \c at iRow < \l__nm_last_row_int
+            )
+          }
+          { \l__nm_code_for_first_col_tl }
       }
     l
     <
@@ -901,7 +914,17 @@
         \hbox_set:Nw \l_tmpa_box
           \c_math_toggle_token
           \bool_if:NT \l__nm_small_bool \scriptstyle
-          \l__nm_code_for_last_col_tl
+        \bool_if:nT
+          {
+            \int_compare_p:nNn \c at iRow > \c_zero_int
+            &&
+            (
+              \int_compare_p:nNn \l__nm_last_row_int < 0
+              ||
+              \int_compare_p:nNn \c at iRow < \l__nm_last_row_int
+            )
+          }
+          { \l__nm_code_for_last_col_tl }
       }
     l
     <
@@ -955,7 +978,7 @@
   {
     \bool_set_true:N \l__nm_NiceArray_bool
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { NiceArray } }
+      { \str_gset:Nn \g__nm_type_env_str { environment ~ { NiceArray } } }
     \NiceArrayWithDelims . .
   }
   { \endNiceArrayWithDelims }
@@ -962,7 +985,7 @@
 \NewDocumentEnvironment { pNiceArray } { }
   {
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { pNiceArray } }
+      { \str_gset:Nn \g__nm_type_env_str { environment ~ { pNiceArray } } }
     \__nm_test_if_math_mode:
     \NiceArrayWithDelims ( )
   }
@@ -970,7 +993,7 @@
 \NewDocumentEnvironment { bNiceArray } { }
   {
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { NiceArray } }
+      { \str_gset:Nn \g__nm_type_env_str { environment ~ { bNiceArray } } }
     \__nm_test_if_math_mode:
     \NiceArrayWithDelims [ ]
   }
@@ -978,7 +1001,7 @@
 \NewDocumentEnvironment { BNiceArray } { }
   {
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { BNiceArray } }
+      { \str_gset:Nn \g__nm_type_env_str { environment ~ { BNiceArray } } }
     \__nm_test_if_math_mode:
     \NiceArrayWithDelims \{ \}
   }
@@ -986,7 +1009,7 @@
 \NewDocumentEnvironment { vNiceArray } { }
   {
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { vNiceArray } }
+      { \str_gset:Nn \g__nm_type_env_str { environment ~ { vNiceArray } } }
     \__nm_test_if_math_mode:
     \NiceArrayWithDelims | |
   }
@@ -994,7 +1017,7 @@
 \NewDocumentEnvironment { VNiceArray } { }
   {
     \str_if_empty:NT \g__nm_type_env_str
-      { \str_gset:Nn \g__nm_type_env_str { VNiceArray } }
+      { \str_gset:Nn \g__nm_type_env_str { environment ~ { VNiceArray } } }
     \__nm_test_if_math_mode:
     \NiceArrayWithDelims \| \|
   }
@@ -1003,7 +1026,7 @@
   {
     \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } }
       {
-        \str_gset:Nn \g__nm_type_env_str { #1 NiceMatrix }
+        \str_gset:Nn \g__nm_type_env_str { environment ~ { #1 NiceMatrix } }
         \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
         \begin { #1 NiceArray }
           {
@@ -1785,8 +1808,19 @@
     \int_step_inline:nnn { #2 } { #2 + #3 - 1 }
       { \cs_set:cpn { __nm _ dotted _ #1 - ##1 } { } }
   }
-\cs_new_protected:Nn \__nm_line:nn
+\cs_new:Npn \__nm_double_int_eval:n #1-#2 \q_stop
+  { \int_eval:n { #1 } - \int_eval:n { #2 } }
+\cs_new_protected:Npn \__nm_line:nn #1 #2
   {
+    \use:x
+      {
+        \__nm_line_i:nn
+          { \__nm_double_int_eval:n #1 \q_stop }
+          { \__nm_double_int_eval:n #2 \q_stop }
+      }
+  }
+\cs_new_protected:Nn \__nm_line_i:nn
+  {
     \bool_if:NF \c__nm_draft_bool
       {
         \dim_zero_new:N \g__nm_x_initial_dim
@@ -1803,13 +1837,13 @@
           }
           {
             \begin { tikzpicture }
-               \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ;
-               \tikz at parse@node \pgfutil at firstofone ( i )
-               \dim_gset:Nn \g__nm_x_initial_dim \pgf at x
-               \dim_gset:Nn \g__nm_y_initial_dim \pgf at y
-               \tikz at parse@node \pgfutil at firstofone ( f )
-               \dim_gset:Nn \g__nm_x_final_dim \pgf at x
-               \dim_gset:Nn \g__nm_y_final_dim \pgf at y
+              \path~(#1)~--~(#2)~node[at~start]~(i)~{}~node[at~end]~(f)~{} ;
+              \tikz at parse@node \pgfutil at firstofone ( i )
+              \dim_gset:Nn \g__nm_x_initial_dim \pgf at x
+              \dim_gset:Nn \g__nm_y_initial_dim \pgf at y
+              \tikz at parse@node \pgfutil at firstofone ( f )
+              \dim_gset:Nn \g__nm_x_final_dim \pgf at x
+              \dim_gset:Nn \g__nm_y_final_dim \pgf at y
             \end { tikzpicture }
             \__nm_draw_tikz_line:
           }
@@ -2184,13 +2218,8 @@
       ;
   }
 \NewExpandableDocumentCommand \__nm_Block: { m D < > { } m }
-  {
-    \__nm_Block_i #1 \q_stop { #2 } { #3 }
-  }
-\cs_new:Npn \__nm_Block_i #1-#2 \q_stop
-  {
-    \__nm_Block_ii:nnnn { #1 } { #2 }
-  }
+  { \__nm_Block_i #1 \q_stop { #2 } { #3 } }
+\cs_new:Npn \__nm_Block_i #1-#2 \q_stop { \__nm_Block_ii:nnnn { #1 } { #2 } }
 \cs_new:Npn \__nm_Block_ii:nnnn #1 #2 #3 #4
   {
     \int_compare:nNnTF { #1 } = 1
@@ -2263,6 +2292,52 @@
       { \BNiceMatrix }
       { \endBNiceMatrix }
   }
+\cs_new_protected:Npn \__nm_set_size:n #1-#2 \q_stop
+  {
+    \int_set:Nn \l__nm_nb_rows_int { #1 }
+    \int_set:Nn \l__nm_nb_cols_int { #2 }
+  }
+\NewDocumentCommand \AutoNiceMatrixWithDelims { m m O { } m O { } m ! O { } }
+  {
+    \int_zero_new:N \l__nm_nb_rows_int
+    \int_zero_new:N \l__nm_nb_cols_int
+    \__nm_set_size:n #4 \q_stop
+    \begin { NiceArrayWithDelims } { #1 } { #2 }
+      { * { \l__nm_nb_cols_int } { C } } [ #3 , #5 , #7 ]
+    \int_compare:nNnT \l__nm_first_row_int = \c_zero_int
+      {
+        \int_compare:nNnT \l__nm_first_col_int = \c_zero_int { & }
+        \prg_replicate:nn { \l__nm_nb_cols_int - 1 } { & }
+        \int_compare:nNnT \l__nm_last_col_int > { -1 } { & } \\
+      }
+    \prg_replicate:nn \l__nm_nb_rows_int
+      {
+        \int_compare:nNnT \l__nm_first_col_int = \c_zero_int { & }
+        \prg_replicate:nn { \l__nm_nb_cols_int - 1 } { { } #6 & } #6
+        \int_compare:nNnT \l__nm_last_col_int > { -1 } { & } \\
+      }
+    \int_compare:nNnT \l__nm_last_row_int > { -2 }
+      {
+        \int_compare:nNnT \l__nm_first_col_int = \c_zero_int { & }
+        \prg_replicate:nn { \l__nm_nb_cols_int - 1 } { & }
+        \int_compare:nNnT \l__nm_last_col_int > { -1 } { & } \\
+      }
+    \end { NiceArrayWithDelims }
+  }
+\cs_set_protected:Npn \__nm_define_com:nnn #1 #2 #3
+  {
+    \cs_set_protected:cpn { #1 AutoNiceMatrix }
+      {
+        \str_gset:Nx \g__nm_type_env_str
+          { command ~ \c_backslash_str #1 AutoNiceMatrix }
+        \AutoNiceMatrixWithDelims { #2 } { #3 }
+      }
+  }
+\__nm_define_com:nnn p ( )
+\__nm_define_com:nnn b [ ]
+\__nm_define_com:nnn v | |
+\__nm_define_com:nnn V \| \|
+\__nm_define_com:nnn B \{ \}
 \keys_define:nn { NiceMatrix / Package }
   {
     renew-dots .bool_set:N = \l__nm_renew_dots_bool ,
@@ -2281,15 +2356,14 @@
   }
 \__nm_msg_new:nn { last-col~non~empty~for~NiceArray }
   {
-    In~the~environment~\{\g__nm_type_env_str\},~you~must~use~the~option~
-    'last-col'~without~value~(the~number~of~columns~is~known~by~the~
-    preamble~of~the~environment).\\
+    In~the~\g__nm_type_env_str,~you~must~use~the~option~
+    'last-col'~without~value.\\
     However,~you~can~go~on~for~this~time~
     (the~value~'\l_keys_value_tl'~will~be~ignored).
   }
 \__nm_msg_new:nn { last-col~empty~for~NiceMatrix }
   {
-    In~the~environment~\{\g__nm_type_env_str\}~you~can't~use~the~option~
+    In~the~\g__nm_type_env_str, you~can't~use~the~option~
     'last-col'~without~value.~You~must~give~the~number~of~that~last~column.\\
     If~you~go~on~this~option~will~be~ignored.
   }
@@ -2297,7 +2371,7 @@
   {
     You~try~to~draw~a~block~in~the~cell~#1-#2~of~your~matrix~but~the~matrix~is~
     too~small~for~that~block.\\
-    If~you~go~on,~this~command~line~will~be~ignored.
+    If~you~go~on,~this~command~will~be~ignored.
   }
 \__nm_msg_new:nn { Impossible~line }
   {
@@ -2307,10 +2381,10 @@
   }
 \__nm_msg_new:nn { Wrong~last~row }
   {
-    You~have~used~'last-row=\int_use:N \l__nm_last_row_int'~but~your~environment~
-    \{\g__nm_type_env_str\}~seems~to~have~\int_use:N \c at iRow
-    rows.~If~you~go~on,~the~value~of~\int_use:N \c at iRow
-    will~be~used~for~last~row.~You~can~avoid~this~problem~by~using~'last-row'~
+    You~have~used~'last-row=\int_use:N \l__nm_last_row_int'~but~your~
+    \g__nm_type_env_str\ seems~to~have~\int_use:N \c at iRow \ rows.~
+    If~you~go~on,~the~value~of~\int_use:N \c at iRow \ will~be~used~for~
+    last~row.~You~can~avoid~this~problem~by~using~'last-row'~
     without~value~(more~compilations~might~be~necessary).
   }
 \__nm_msg_new:nn { Yet~in~env }
@@ -2320,7 +2394,7 @@
   }
 \__nm_msg_new:nn { Outside~math~mode }
   {
-    The~environment~\{\g__nm_type_env_str\}~can~be~used~only~in~math~mode~
+    The~\g__nm_type_env_str\ can~be~used~only~in~math~mode~
     (and~not~in~\token_to_str:N \vcenter).\\
     This~error~is~fatal.
   }
@@ -2401,8 +2475,8 @@
   }
 \__nm_msg_new:nnn { Unknown~option~for~NiceMatrix }
   {
-    The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~
-    \{\g__nm_type_env_str\}. \\
+    The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~
+    \g__nm_type_env_str. \\
     If~you~go~on,~it~will~be~ignored. \\
     For~a~list~of~the~available~options,~type~H~<return>.
   }
@@ -2451,7 +2525,7 @@
   }
 \__nm_msg_new:nn { Zero~row }
   {
-    There~is~a~problem.~Maybe~your~environment~\{\g__nm_type_env_str\}~is~empty.~
+    There~is~a~problem.~Maybe~your~\g__nm_type_env_str\ is~empty.~
     Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~and~R~in~the~preamble~
     of~your~environment. \\
     If~you~go~on,~the~result~may~be~incorrect.
@@ -2459,12 +2533,12 @@
 \__nm_msg_new:nn { Use~of~:~in~first~position }
   {
     You~can't~use~the~column~specifier~'\l__nm_letter_for_dotted_lines_str'~in~the~
-    first~position~of~the~preamble~of~the~environment~\{\g__nm_type_env_str\}. \\
+    first~position~of~the~preamble~of~the~\g__nm_type_env_str. \\
     If~you~go~on,~this~dotted~line~will~be~ignored.
   }
 \__nm_msg_new:nn { Obsolete~environment }
   {
-    The~environment~\{\@currenvir\}~is~obsolete.~
+    The~environment~\{\@currenvir\}~is~obsolete~and~will~be~deleted~in~future~version.~
     We~should~use~#1~instead.
   }
 \NewDocumentEnvironment { pNiceArrayC } { }



More information about the tex-live-commits mailing list