texlive[56142] Master/texmf-dist: nicematrix (20aug20)

commits+karl at tug.org commits+karl at tug.org
Thu Aug 20 23:11:01 CEST 2020


Revision: 56142
          http://tug.org/svn/texlive?view=revision&revision=56142
Author:   karl
Date:     2020-08-20 23:11:01 +0200 (Thu, 20 Aug 2020)
Log Message:
-----------
nicematrix (20aug20)

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	2020-08-20 21:10:48 UTC (rev 56141)
+++ trunk/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex	2020-08-20 21:11:01 UTC (rev 56142)
@@ -10,7 +10,7 @@
 \usepackage{nicematrix}
 
 \usepackage{tikz}
-\usetikzlibrary{fit}
+\usetikzlibrary{fit,patterns}
 
 
 \usepackage{enumitem}
@@ -300,7 +300,7 @@
 immédiatement après un |\item| de liste. On remarquera que la présence d'un
 |\hline| initial n'empêche pas l'alignement sur la ligne de base de la première
 rangée (avec |{tabular}| ou |{array}| de \pkg{array}, il faut utiliser
-|\firsthline|.
+|\firsthline|).
 
 \smallskip
 \begin{BVerbatim}[baseline=c,boxwidth=9cm]
@@ -367,7 +367,40 @@
 \end{minipage}
 
 
+\bigskip
+\colorbox{yellow!50}{\textbf{Nouveau 5.2}}\enskip On peut aussi utiliser la clé
+|baseline| pour aligner une matrice sur un filet horizontal (tracé par
+|\hline|). On doit pour cela donner la valeur |line-|\textsl{i} où \textsl{i}
+est le numéro de la rangée qui suit ce filet horizontal.
 
+\smallskip
+\begin{Verbatim}
+\NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}
+\end{Verbatim}
+
+\smallskip
+\begin{BVerbatim}[baseline=c,boxwidth=9cm]
+$A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
+\dfrac1A & \dfrac1B & 0 & 0 \\
+\dfrac1C & \dfrac1D & 0 & 0 \\
+\hline
+0 & 0 & A & B \\
+0 & 0 & D & D \\
+\end{pNiceArray}$
+\end{BVerbatim}
+\begin{scope}
+\NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}
+\raisebox{-5mm}{$A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
+\dfrac1A & \dfrac1B & 0 & 0 \\
+\dfrac1C & \dfrac1D & 0 & 0 \\
+\hline
+0 & 0 & A & B \\
+0 & 0 & D & D \\
+\end{pNiceArray}$}
+\end{scope}
+
+
+
 \section{Les blocs}
 
 \label{Block}
@@ -528,6 +561,11 @@
 
 
 \bigskip
+\colorbox{yellow!50}{\textbf{Nouveau 5.2}}\enskip En revanche, les filets
+verticaux ne sont pas tracés à l'intérieur des blocs.
+
+
+\bigskip
 Si vous utilisez \pkg{booktabs} (qui fournit |\toprule|, |\midrule|,
 |\bottomrule|, etc.) et que vous tenez absolument à mettre des filets verticaux
 (ce qui est contraire à l'esprit à \pkg{booktabs}), vous constaterez que les
@@ -680,7 +718,8 @@
 \subsection{Les clés hlines et vlines}
 
 La clé |hlines| demande un tracé de tous les filets horizontaux et la clé
-|vlines| demande un tracé de tous les filets verticaux. En fait, dans les
+|vlines| demande un tracé de tous les filets verticaux (sauf dans les blocs et
+dans les blocs virtuels déterminés par des lignes en pointillés). En fait, dans les
 environnements avec délimiteurs (comme |{pNiceMatrix}| ou |{bNiceArray}|), les
 filets extérieurs ne sont pas tracés (ce qui est le comportement certainement
 attendu).
@@ -706,10 +745,8 @@
 \label{hvlines}
 
 La clé |hvlines| demande le tracé de tous les filets horizontaux et verticaux
-\emph{sauf dans les blocs}.\footnote{En fait, quand la clé |hvlines| (ou la clé
-  |hvlines-except-corners| décrite juste après) est utilisée, les filets ne sont
-  pas non plus tracés dans les blocs virtuels délimités par des cases reliées
-  par des lignes pointillées (cf. p. \pageref{dotted-and-hvlines}).}
+(sauf dans les blocs et dans les blocks virtuels déterminés par des
+lignes en pointillés).
 
 \medskip
 \begin{Verbatim}
@@ -734,7 +771,8 @@
 \subsection{La clé hvlines-except-corners}
 
 La clé |hvlines-except-corners| demande le tracé de tous les filets horizontaux
-et verticaux \emph{sauf dans les blocs} et sauf dans les coins vides.
+et verticaux sauf dans les blocs (y compris dans les blocks virtuels déterminés par des
+lignes en pointillés) et sauf dans les coins vides. 
 
 \medskip
 \begin{Verbatim}
@@ -769,9 +807,15 @@
 rectangles vides partant de la case située exactement dans le coin.
 
 \bigskip
+\colorbox{yellow!50}{\textbf{Nouveau 5.2}}\enskip On peut passer en argument de
+|\hvlines-except-corners| une liste de coins à prendre en considération. Les
+coins étant désignés par |NW|, |SW|, |NE| et |SE| (\emph{north west},
+\emph{south west}, \emph{north east} et \emph{south east}).
+
+\medskip
 \begin{BVerbatim}[boxwidth=11cm,baseline=c]
 \begin{NiceTabular}{*{6}{c}}%
-  [~emphase#hvlines-except-corners@,cell-space-top-limit=3pt]
+  [~emphase#hvlines-except-corners=NE@,cell-space-top-limit=3pt]
 1\\
 1&1\\
 1&2&1\\
@@ -781,7 +825,7 @@
 \end{NiceTabular}
 \end{BVerbatim}
 \begin{NiceTabular}{*{6}{c}}%
-  [c,hvlines-except-corners,cell-space-top-limit=3pt]
+  [c,hvlines-except-corners=NE,cell-space-top-limit=3pt]
 1\\
 1&1\\
 1&2&1\\
@@ -904,12 +948,30 @@
 
 \item L'extension \pkg{colortbl} construit le tableau ligne par ligne, en
 alternant rectangles colorés, filets et contenu des cases. Le \textsc{pdf}
-résultant déroute certains lecteurs de \textsc{pdf} et on a des artefacts
-d'affichage : des filets verticaux semblent disparaître ; au contraire, de fines
-lignes blanches peuvent apparaître. L'extension \pkg{nicematrix} proposent des
-outils qui évitent ces inconvénients.
+résultant déroute certains lecteurs de \textsc{pdf} et on a parfois des artefacts
+d'affichage.
+
+\begin{itemize}
+\item Certains filets semblent disparaître. Ce phénomène est dû au fait que les
+lecteurs de PDF donnent souvent la priorité aux éléments graphiques qui ont été
+tracés postérieurement (conformément à l'esprit du «modèle du peintre» de
+PostScript et PDF). De ce point de vue, MuPDF (qui est utilisé par exemple par
+SumatraPDF) donne de meilleurs résultats que Adobe Reader.
+
+\item Une fine ligne blanche semble apparaître entre deux cellules de même
+couleur. Ce phénomène se produit quand chaque cellule est coloriée avec sa
+propre instruction |fill| (opérateur |fill| de PostScript noté |f| en PDF).
+C'est le cas avec \pkg{colortbl} avec lequel chaque cellule est coloriée
+individuellement même si on utilise |\columncolor| ou |\rowcolor|.
+
+Concernant ce phénomène, Adobe Reader donne de meilleurs résultats que
+MuPDF.
 \end{itemize}
 
+L'extension \pkg{nicematrix} proposent des outils qui permettent d'éviter ces
+inconvénients. 
+\end{itemize}
+
 \subsection{Les outils de nicematrix dans le code-before}
 
 L'extension \pkg{nicematrix} proposent des outils (indépendants de
@@ -958,6 +1020,10 @@
 \end{NiceTabular}
 \end{scope}
 
+\medskip
+Une commande |\cellcolor| ne produit qu'une instruction |fill| (codée |f|) dans
+le \textsc{pdf}.
+
 \bigskip
 \item La commande |\rectanglecolor| prend trois arguments obligatoires. Le
 premier est la couleur, les deux suivants fournissent la case en haut à gauche
@@ -1025,7 +1091,11 @@
 \end{NiceArray}$
 \end{scope}
 
+\medskip
+Une commande |\rowcolor| ne produit qu'une instruction |fill| (codée |f|) dans
+le \textsc{pdf}.
 
+
 \bigskip
 \item La commande |\columncolor| doit son nom à la commande |\columncolor| de
 \pkg{colortbl}. Sa syntaxe est similaire à celle de |\rowcolor|.
@@ -1061,8 +1131,47 @@
 \end{NiceTabular}
 \end{scope}
 
+\bigskip
+\colorbox{yellow!50}{\textbf{Nouveau 5.2}}\enskip Il existe une option |respect-blocks|
+pour la commande |\rowcolor|. Avec cette option, les ``rangées'' colorées
+alternativement peuvent s'étendre sur plusieurs rangées réelles du tableau pour
+englober les blocs.
 
+\medskip
+\begin{scope}
+\hfuzz=10cm
+\begin{BVerbatim}[baseline=c,boxwidth=9cm]
+\begin{NiceTabular}{cr}[hvlines,code-before =
+~emphase#\rowcolors{1}{blue!10}{}[respect-blocks]@]
+\Block{2-1}{Pierre} & 12 \\
+                    & 13 \\
+Jacques & 8 \\
+\Block{3-1}{Stéphanie} & 18 \\
+                       & 17 \\
+                       & 15 \\
+Amélie & 20 \\
+Henri & 14 \\
+\Block{2-1}{Estelle} & 15 \\
+                     & 19
+\end{NiceTabular}
+\end{BVerbatim}
+\begin{NiceTabular}{cr}[hvlines,code-before = \rowcolors{1}{blue!10}{}[respect-blocks],baseline=c]
+\Block{2-1}{Pierre} & 12 \\
+                    & 13 \\
+Jacques & 8 \\
+\Block{3-1}{Stéphanie} & 18 \\
+                       & 17 \\
+                       & 15 \\
+Amélie & 20 \\
+Henri & 14 \\
+\Block{2-1}{Estelle} & 15 \\
+                     & 19
+\end{NiceTabular}
+\end{scope}
 
+
+
+
 \bigskip
 \item La commande |\chessboardcolors| prend en arguments obligatoires deux
 couleurs et colorie les cases en quinconces avec les deux couleurs.
@@ -1142,7 +1251,7 @@
 On peut accéder aux outils de coloriage précédents avec une syntaxe proche de
 celle proposée par \pkg{colortbl}. On doit pour cela utiliser la clé
 |colortbl-like| dans l'environnement concerné.\footnote{Pour le moment, cette
-  clé n'est pas disponible disponible dans |\NiceMatrixOptions|.}
+  clé n'est pas disponible dans |\NiceMatrixOptions|.}
 
 On a alors accès aux trois commandes suivantes :
 \begin{itemize}
@@ -1157,7 +1266,7 @@
 
 \medskip
 \begin{Verbatim}
-\begin{NiceTabular}[colortbl-like]{>{~emphase#\columncolor{blue!15}}@ccc}
+\begin{NiceTabular}[colortbl-like]{*{2}{>{~emphase#\columncolor{blue!15}@}c}c} 
 \toprule
 ~emphase#\rowcolor{red!15}@
 Nom & Prénom & Année de naissance \\
@@ -1172,7 +1281,7 @@
 
 
 \begin{center}
-\begin{NiceTabular}[colortbl-like]{>{\columncolor{blue!15}}ccc}
+\begin{NiceTabular}[colortbl-like]{*{2}{>{\columncolor{blue!15}}c}c} 
 \toprule
 \rowcolor{red!15}
 Nom & Prénom & Année de naissance \\
@@ -1185,7 +1294,54 @@
 \end{NiceTabular}
 \end{center}
 
+\medskip
+\emph{Remarque}\par\nobreak
 
+Chacune de ces instructions |\cellcolor|, |\rowcolor| ou |\columncolor|
+(utilisée hors du |code-before|) produit une instruction |fill| (codée |f|) dans
+le \textsc{pdf} final. En cas de juxtaposition de rectangles de même couleur,
+une fine ligne blanche peut donc apparaître dans certains lecteurs de
+\textsc{pdf}\footnote{Par exemple SumatraPDF v3.1.2, qui utilise MuPDF de Artifex
+  Software, dont le moteur de rendu \textsc{pdf} est appelé Fitz.} (entre les
+deux premières colonnes dans l'exemple ci-dessus). Pour éviter cela, il convient
+d'utiliser les outils proposés dans le |code-before|. C'est ce que l'on fait
+dans le codage qui suit. 
+
+
+\medskip
+\begin{Verbatim}
+\begin{NiceTabular}[colortbl-like]{ccc}%
+  [code-before = ~emphase#\columncolor{blue!15}{1,2}@]
+\toprule
+\rowcolor{red!15}
+Nom & Prénom & Année de naissance \\
+\midrule
+Achard & Jacques & 5 juin 1962 \\
+Lefebvre & Mathilde & 23 mai 1988 \\
+Vanesse & Stéphanie & 30 octobre 1994 \\
+Dupont & Chantal & 15 janvier 1998 \\
+\bottomrule
+\end{NiceTabular}
+\end{Verbatim}
+
+
+\begin{center}
+\begin{NiceTabular}[colortbl-like]{ccc}%
+  [code-before = \columncolor{blue!15}{1,2}]
+\toprule
+\rowcolor{red!15}
+Nom & Prénom & Année de naissance \\
+\midrule
+Achard & Jacques & 5 juin 1962 \\
+Lefebvre & Mathilde & 23 mai 1988 \\
+Vanesse & Stéphanie & 30 octobre 1994 \\
+Dupont & Chantal & 15 janvier 1998 \\
+\bottomrule
+\end{NiceTabular}
+\end{center}
+
+
+
 \section{La largeur des colonnes}
 \label{width}
 
@@ -1946,15 +2102,17 @@
 \end{pNiceMatrix}\]
 
 
-\subsection{Les lignes pointillées et la clé hvlines}
+\subsection{Les lignes pointillées et les filets}
 
-\label{dotted-and-hvlines}
+\label{dotted-and-rules}
 
-On a dit (cf. p. \pageref{hvlines}) que la clé |hvlines| trace tous les filets
-horizontaux et verticaux, exceptés dans les blocs. En fait, avec cette clé, les
-filets ne sont pas non plus tracés dans les blocs virtuels délimités par des
-cases reliées par des lignes pointillées.
+Les lignes pointillées délimitent des blocs virtuels qui ont le même
+comportement vis à vis des filets que les blocs créés par |\Block| (les filets
+spécifiés par le spécificateur \verb+|+ dans le préambule et par les clés
+|vlines|, |hlines|, |hvlines| et |hvlines-except-corners| ne sont pas tracés
+dans les blocs).
 
+
 \medskip
 \begin{BVerbatim}[baseline=c,boxwidth=10.6cm]
 $\begin{bNiceMatrix}[margin,~emphase#hvlines@]
@@ -2397,11 +2555,6 @@
 \sin x & \cos x 
 \end{bNiceMatrix}$
 
-\medskip
-Il existe aussi l'option |S| qui impose que toutes les colonnes soient des
-colonnes |S| de \pkg{siunitx} (si cette extension est chargée).\footnote{Cela
-  reprend une partie des fonctionnalités proposées par les environnements
-  |{pmatrix*}|, |{bmatrix*}|, etc. de \pkg{mathtools}.}
 
 
 \subsection{La commande \textbackslash rotate}
@@ -3044,54 +3197,59 @@
 \end{NiceMatrix}\]
 
 
-\section{Outils pour les développeurs}
+\section{API pour les développeurs}
 
-Comme son nom l'indique, la liste de tokens |\g_nicematrix_code_after_tl| est
-publique (conformément aux conventions de LaTeX3, toute variable dont le nom
-débute par |\g_nicematrix| ou |\l_nicematrix| est publique alors que toute variable
-dont le nom débute par |\g__nicematrix| ou par |\l__nicematrix| est privée).
+L'extension \pkg{nicematrix} fournit deux variables internes mais publiques\footnote{Conformément aux conventions de LaTeX3,
+  toute variable dont le nom commence par |\g_nicematrix| ou |\l_nicematrix| est
+  publique alors que toute variable dont le nom débute par |\g__nicematrix| ou
+  par |\l__nicematrix| est privée.} :
+\begin{itemize}
+\item \colorbox{yellow!50}{\textbf{Nouveau 5.2}}\enskip |\g_nicematrix_code_before_tl| ;
+\item |\g_nicematrix_code_after_tl|.
+\end{itemize}
 
 \medskip
-Cette variable contient le code qui constitue le «|code-after|». Le développeur
-peut donc l'utiliser pour y ajouter du code à partir d'une cellule du tableau
-(l'affectation devra être globale, ce qui permettra de sortir de la cellule, qui
-est un groupe au sens de TeX).
+Ces variables constituent le code du «|code-before|» et du «|code-after|». Le
+développeur peut donc les utiliser pour y ajouter du code à partir d'une cellule
+du tableau (l'affectation devra être globale, ce qui permettra de sortir de la
+cellule, qui est un groupe au sens de TeX).
 
 \medskip
-\emph{Exemple} : On souhaite écrire une commande |\crossbox| qui barre en croix
-la cellule courante. Cette commande prendra en argument optionnel une liste de
-couples \textsl{clé}-\textsl{valeur} qui sera passée à Tikz avant que la croix
-ne soit tracée.
+On remarquera que l'utilisation de |\g_nicematrix_code_before_tl| nécessite une
+compilation supplémentaire (car les instructions sont écrites dans le fichier
+|aux| pour être utilisées à la compilation suivante).
 
+\bigskip
+\emph{Example} : On souhaite écrire une commande |\hatchcell| pour hachurer la
+cellule courante (avec un argument optionnel entre crochets pour la couleur des
+hachures). Il est possible de programmer une telle commande |\hatchcell| comme
+suit, en utilisant explicitement la variable publique
+|\g_nicematrix_code_before_tl| (ce code nécessite le chargement préalable de la
+bibliothèque Tikz \pkg{patterns}).
 
-On peut alors programmer cette commande |\crossbox| de la manière suivante, qui
-utilise explicitement la variable publique |\g_nicematrix_code_after_tl|.
 
-
 \begin{scope}
 \fvset{commandchars=\§\¤\μ}
 \begin{Verbatim}
 \ExplSyntaxOn
-\cs_new_protected:Nn \__pantigny_crossbox:nnn
+\cs_new_protected:Nn \__pantigny_hatchcell:nnn
   {
     \begin { tikzpicture }
-    \draw [ #3 ] 
-          ( row-#1 -| col-\int_eval:n { #2 + 1 } ) 
-       -- ( row-\int_eval:n { #1 + 1 } -| col-#2 ) 
-          ( row-#1 -| col-\int_eval:n #2 ) 
-       -- ( row-\int_eval:n { #1 + 1 } -| col-\int_eval:n { #2 + 1 } ) ; 
+    \fill [ pattern = north~west~lines , pattern~color = #3 ]
+          ( row - #1 -| col - #2) 
+          rectangle 
+          ( row - \int_eval:n { #1 + 1 } -| col - \int_eval:n { #2 + 1 } ) ;
     \end { tikzpicture }
   }
 
-
-\NewDocumentCommand \crossbox { ! O { } }
+\NewDocumentCommand \hatchcell { ! O { black } }
   {
-    \tl_gput_right:Nx §emphase¤\g_nicematrix_code_after_tlμ
+    \tl_gput_right:Nx §emphase¤\g_nicematrix_code_before_tlμ
       { 
-        \__pantigny_crossbox:nnn 
+        \__pantigny_hatchcell:nnn
           { \int_use:c { c at iRow } } 
           { \int_use:c { c at jCol } }
-          { \exp_not:n { #1 } }
+          { #1 }
       }
   }
 \ExplSyntaxOff
@@ -3100,47 +3258,47 @@
 
 
 \ExplSyntaxOn
-\cs_new_protected:Nn \__pantigny_crossbox:nnn
+\cs_new_protected:Nn \__pantigny_hatchcell:nnn
   {
     \begin { tikzpicture }
-    \draw [ #3 ] 
-          ( row-#1 -| col-\int_eval:n { #2 + 1 } ) 
-       -- ( row-\int_eval:n { #1 + 1 } -| col-#2 ) 
-          ( row-#1 -| col-\int_eval:n #2 ) 
-       -- ( row-\int_eval:n { #1 + 1 } -| col-\int_eval:n { #2 + 1 } ) ; 
+    \fill [ pattern = north~west~lines , pattern~color = #3 ]
+          ( row - #1 -| col - #2) 
+          rectangle 
+          ( row - \int_eval:n { #1 + 1 } -| col - \int_eval:n { #2 + 1 } ) ;
     \end { tikzpicture }
   }
 
-
-\NewDocumentCommand \crossbox { ! O { } }
+\NewDocumentCommand \hatchcell { ! O { black } }
   {
-    \tl_gput_right:Nx \g_nicematrix_code_after_tl
+    \tl_gput_right:Nx \g_nicematrix_code_before_tl
       { 
-        \__pantigny_crossbox:nnn 
+        \__pantigny_hatchcell:nnn
           { \int_use:c { c at iRow } } 
           { \int_use:c { c at jCol } }
-          { \exp_not:n { #1 } }
+          { #1 }
       }
   }
 \ExplSyntaxOff
 
+
 \bigskip
-Voici un exemple d'utilisation :
+Voici un exemple d'utilisation.
 
 \medskip
 \begin{BVerbatim}[baseline=c,boxwidth=9cm]
 \begin{NiceTabular}{ccc}[hvlines]
-merlan & requin & cabillaud \\
-baleine & ~emphase#\crossbox[red]@ & morue \\
-mante & raie & poule 
+Tokyo & Paris & London \\
+Roma & ~emphase#\hatchcell[blue!30]@Oslo & Miami \\
+Los Angeles & Madrid & Roma
 \end{NiceTabular}
 \end{BVerbatim}
 \begin{NiceTabular}{ccc}[hvlines]
-merlan & requin & cabillaud \\
-baleine & \crossbox[red] & morue \\
-mante & raie & poule 
+Tokyo & Paris & London \\
+Lima & \hatchcell[blue!30]Oslo & Miami \\
+Los Angeles & Madrid & Roma
 \end{NiceTabular}
 
+
 \section{Remarques techniques}
 
 Première remarque : l'extension \pkg{nicematrix} doit être chargée après

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	2020-08-20 21:10:48 UTC (rev 56141)
+++ trunk/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx	2020-08-20 21:11:01 UTC (rev 56142)
@@ -15,8 +15,8 @@
 %
 % \fi
 % \iffalse
-\def\myfileversion{5.1}
-\def\myfiledate{2020/07/31}
+\def\myfileversion{5.2}
+\def\myfiledate{2020/08/19}
 %
 %
 %<*batchfile>
@@ -52,7 +52,7 @@
 \geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
 
 \usepackage{tikz}
-\usetikzlibrary{fit}
+\usetikzlibrary{fit,patterns}
 \usepackage{nicematrix}
 \usepackage{siunitx}
 
@@ -408,7 +408,39 @@
 % \end{enumerate}
 % \end{minipage}
 % 
+% \bigskip
+% \colorbox{yellow!50}{\textbf{New 5.2}}\enskip It's also possible to use the
+% key |baseline| to align a matrix on an horizontal rule (drawn by |\hline|). In
+% this aim, one should give the value |line-|\textsl{i} where \textsl{i} is the
+% number of the row following the horizontal rule.
 %
+% \smallskip
+% \begin{Verbatim}
+% \NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}
+% \end{Verbatim}
+%
+% \smallskip
+% \begin{BVerbatim}[baseline=c,boxwidth=9cm]
+% $A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
+% \dfrac1A & \dfrac1B & 0 & 0 \\
+% \dfrac1C & \dfrac1D & 0 & 0 \\
+% \hline
+% 0 & 0 & A & B \\
+% 0 & 0 & D & D \\
+% \end{pNiceArray}$
+% \end{BVerbatim}
+% \begin{scope}
+% \NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}
+% \raisebox{-5mm}{$A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
+% \dfrac1A & \dfrac1B & 0 & 0 \\
+% \dfrac1C & \dfrac1D & 0 & 0 \\
+% \hline
+% 0 & 0 & A & B \\
+% 0 & 0 & D & D \\
+% \end{pNiceArray}$}
+% \end{scope}
+%
+%
 % \section{The blocks}
 % \label{Block}
 %
@@ -569,7 +601,12 @@
 % Mary  & George \\ \hline
 % \end{NiceTabular}
 %
+%
 % \bigskip
+% \colorbox{yellow!50}{\textbf{New 5.2}}\enskip However, the vertical rules are
+% not drawn in the blocks.
+%
+% \bigskip
 % If you use \pkg{booktabs} (which provides |\toprule|, |\midrule|,
 % |\bottomrule|, etc.) and if you really want to add vertical rules (which is
 % not in the spirit of \pkg{booktabs}), you should notice that the vertical rules
@@ -712,9 +749,10 @@
 % \subsection{The keys hlines and vlines}
 % 
 % The key |hlines| draws all the horizontal rules and the key |vlines| draws all
-% the vertical rules. In fact, in the environments with delimiters (as
+% the vertical rules excepted in the blocks (and the virtual blocks determined
+% by dotted lines). In fact, in the environments with delimiters (as
 % |{pNiceMatrix}| or |{bNiceArray}|) the exteriors rules are not drawn (as
-% expected). 
+% expected).
 % 
 % \medskip
 % \begin{BVerbatim}[baseline=c,boxwidth=10.6cm]
@@ -735,11 +773,8 @@
 % \subsection{The key hvlines}
 % \label{hvlines}
 %
-% The key |hvlines| draws all the vertical and horizontal rules \emph{excepted
-% in the blocks}.\footnote{In fact, when the key |hvlines| (or the key
-% |hvlines-except-corners| described just after) is in force, the
-% rules are also not drawn in the virtual blocks delimited by cells relied par
-% dotted lines (cf. p. \pageref{dotted-and-hvlines}).}
+% The key |hvlines| draws all the vertical and horizontal rules excepted
+% in the blocks (and the virtual blocks determined by dotted lines).
 %
 % \medskip
 % \begin{Verbatim}
@@ -766,7 +801,8 @@
 % \subsection{The key hvlines-except-corners}
 %
 % The key |hvlines-except-corners| draws all the horizontal and vertical rules,
-% \emph{excepted in the blocks} and excepted in the empty corners.
+% excepted in the blocks (and the virtual blocks determined by dotted lines) and
+% excepted in the empty corners. 
 %
 % \medskip
 % \begin{Verbatim}
@@ -801,9 +837,16 @@
 % rectangles starting from the cell actually in the corner of the array.
 %
 % \bigskip
+% \colorbox{yellow!50}{\textbf{New 5.2}}\enskip It's possible to give as value to the
+% key |\hvlines-except-corners| a list of the corners to take into
+% consideration. The corners are designed by |NW|, |SW|, |NE| and |SE|
+% (\emph{north west}, \emph{south west}, \emph{north east} and \emph{south
+% east}).
+%
+% \bigskip
 % \begin{BVerbatim}[boxwidth=11cm,baseline=c]
 % \begin{NiceTabular}{*{6}{c}}%
-%   [~emphase#hvlines-except-corners@,cell-space-top-limit=3pt]
+%   [~emphase#hvlines-except-corners=NE@,cell-space-top-limit=3pt]
 % 1\\
 % 1&1\\
 % 1&2&1\\
@@ -812,7 +855,7 @@
 % 1&5&10&10&5&1
 % \end{NiceTabular}
 % \end{BVerbatim}
-% \begin{NiceTabular}{*{6}{c}}[c,hvlines-except-corners,cell-space-top-limit=3pt]
+% \begin{NiceTabular}{*{6}{c}}[c,hvlines-except-corners=NE,cell-space-top-limit=3pt]
 % 1\\
 % 1&1\\
 % 1&2&1\\
@@ -912,7 +955,7 @@
 %
 %\section{The color of the rows and columns}
 %
-% \subsection{Utilisation of colortbl}
+% \subsection{Use of colortbl}
 %
 % We recall that the package \pkg{colortbl} can be loaded directly with
 % |\usepackage{colortbl}| or by loading \pkg{xcolor} with the key |table|:
@@ -931,11 +974,25 @@
 % \item The package \pkg{colortbl} constructs the array row by row, alterning
 % colored rectangles, rules and contents of the cells. The resulting
 % \textsc{pdf} is difficult to interpret by some \textsc{pdf} viewers and may
-% lead to artefacts on the screen : some rules seem to disappear and on the
-% other side, some thin white lines appear. The package \pkg{nicematrix}
-% provides some tools without those drawbacks.
+% lead to artefacts on the screen.
+% \begin{itemize}
+% \item Some rules seem to disappear. This is because many PDF viewers give
+% priority to graphical element drawn posteriorly (which is in the spirit of the
+% ``painting model'' of PostScript and PDF). Concerning this problem, MuPDF
+% (which is used, for instance, by SumatraPDF) gives better results than Adobe
+% Reader).
+% \item A thin white line may appear between two cells of the same color. This
+% phenomenon occurs when each cell is colored with its own instruction |fill|
+% (the PostScript operator |fill| noted |f| in PDF). This is the case with
+% \pkg{colortbl}: each cell is colored on its own, even when |\columncolor| or
+% |\rowcolor| is used.
+% 
+% As for this phenomenon, Adobe Reader gives better results than MuPDF.
 % \end{itemize}
 %
+% The package \pkg{nicematrix} provides tools to avoid those problems.
+% \end{itemize}
+%
 % \subsection{The tools of nicematrix in the code-before}
 %
 % The package \pkg{nicematrix} provides some tools (independent of
@@ -985,6 +1042,10 @@
 % h & i & j \\ \hline
 % \end{NiceTabular}
 % \end{scope}
+%
+% \medskip
+% A command |\cellcolor| generates only one instruction |fill| (coded |f|) in the
+% resulting \textsc{pdf}.
 % 
 % \bigskip
 % \item The command |\rectanglecolor| takes three mandatory arguments. The first
@@ -1050,6 +1111,10 @@
 % a_{10} & b_{10} & c_{10} \\
 % \end{NiceArray}$
 % \end{scope}
+%
+% \medskip
+% A command |\rowcolor| generates only one instruction |fill| (coded |f|) in the
+% resulting \textsc{pdf}.
 % 
 %
 % \bigskip
@@ -1088,6 +1153,44 @@
 % Madison & 15 
 % \end{NiceTabular}
 % \end{scope}
+%
+% \bigskip
+% \colorbox{yellow!50}{\textbf{New 5.2}}\enskip There is a key |respect-blocks|
+% for the instruction |\rowcolor|. With that key, the ``rows'' alternately
+% colored may extend over several row if they have to incorporate blocks.
+%
+% \medskip
+% \begin{scope}
+% \hfuzz=10cm
+% \begin{BVerbatim}[baseline=c,boxwidth=9cm]
+% \begin{NiceTabular}{cr}[hvlines,code-before =
+% ~emphase#\rowcolors{1}{blue!10}{}[respect-blocks]@]
+% \Block{2-1}{John} & 12 \\
+%                     & 13 \\
+% Stephen & 8 \\
+% \Block{3-1}{Sarah} & 18 \\
+%                        & 17 \\
+%                        & 15 \\
+% Ashley & 20 \\
+% Henry & 14 \\
+% \Block{2-1}{Madison} & 15 \\
+%                      & 19
+% \end{NiceTabular}
+% \end{BVerbatim}
+% \begin{NiceTabular}{cr}[hvlines,code-before = \rowcolors{1}{blue!10}{}[respect-blocks],baseline=c]
+% \Block{2-1}{John} & 12 \\
+%                     & 13 \\
+% Stephen & 8 \\
+% \Block{3-1}{Sarah} & 18 \\
+%                        & 17 \\
+%                        & 15 \\
+% Ashley & 20 \\
+% Henry & 14 \\
+% \Block{2-1}{Madison} & 15 \\
+%                      & 19
+% \end{NiceTabular}
+% \end{scope}
+%
 % 
 % \bigskip
 % \item The command |\chessboardcolors| takes in as mandatory arguments two colors
@@ -1184,7 +1287,7 @@
 %
 % \medskip
 % \begin{Verbatim}
-% \begin{NiceTabular}[colortbl-like]{>{~emphase#\columncolor{blue!15}}@ccc}
+% \begin{NiceTabular}[colortbl-like]{*{2}{>{~emphase#\columncolor{blue!15}@}c}c}
 % \toprule
 % ~emphase#\rowcolor{red!15}@
 % Last name & First name & Birth day \\
@@ -1199,7 +1302,7 @@
 %
 %
 % \begin{center}
-% \begin{NiceTabular}[colortbl-like]{>{\columncolor{blue!15}}ccc}
+% \begin{NiceTabular}[colortbl-like]{*{2}{>{\columncolor{blue!15}}c}c}
 % \toprule
 % \rowcolor{red!15}
 % Last name & First name & Birth day \\
@@ -1212,7 +1315,48 @@
 % \end{NiceTabular}
 % \end{center}
 %
+% \medskip
+% Each instruction |\cellcolor|, |\rowcolor| or |\columncolor| will generate an
+% instruction |fill| (coded~|f|) in the resulting \textsc{pdf}. In cases of
+% juxtaposed colored rectangles, one may have a thin white color line in some
+% \textsc{pdf} viewers\footnote{For example SumatraPDF v3.1.2, which uses MuPDF
+% of Artifex Software, whose \textsc{pdf} renderer is called Fitz.} (between the
+% two first columns in the above example). In you want to avoid this problem,
+% you should use the tools in the |code-before|. That's what we do with the
+% following code.
+% 
 %
+% \medskip
+% \begin{Verbatim}
+% \begin{NiceTabular}[colortbl-like]{ccc}%
+%   [code-before = ~emphase#\columncolor{blue!15}{1,2}@]
+% \toprule
+% \rowcolor{red!15}
+% Last name & First name & Birth day \\
+% \midrule
+% Achard  & Jacques & 5 juin 1962 \\
+% Lefebvre & Mathilde & 23 mai 1988 \\
+% Vanesse & Stephany & 30 octobre 1994 \\
+% Dupont & Chantal & 15 janvier 1998 \\
+% \bottomrule
+% \end{NiceTabular}
+% \end{Verbatim}
+%
+%
+% \begin{center}
+% \begin{NiceTabular}[colortbl-like]{ccc}[code-before = \columncolor{blue!15}{1,2}]
+% \toprule
+% \rowcolor{red!15}
+% Last name & First name & Birth day \\
+% \midrule
+% Achard  & Jacques & 5 juin 1962 \\
+% Lefebvre & Mathilde & 23 mai 1988 \\
+% Vanesse & Stephany & 30 octobre 1994 \\
+% Dupont & Chantal & 15 janvier 1998 \\
+% \bottomrule
+% \end{NiceTabular}
+% \end{center}
+%
 % \section{The width of the columns}
 % \label{width}
 %
@@ -1957,14 +2101,14 @@
 % \end{pNiceMatrix}\]
 %
 %
-% \subsection{The dotted lines and the key hvlines}
+% \subsection{The dotted lines and the rules}
 %
-% \label{dotted-and-hvlines}
+% \label{dotted-and-rules}
 % 
-% We have said (cf. p. \pageref{hvlines}) that the key |hvlines| draws all the
-% horizontal and vertical rules, excepted in the blocks. In fact, when this key
-% is in force, the rules are also not drawn in the virtual blocks delimited by
-% cells relied par dotted lines.
+% The dotted lines determine virtual blocks which have the same behaviour
+% regarding the rules (the rules specified by the specifier \verb+|+ in the
+% preamble and by the keys |hlines|, |vlines|, |hvlines| and
+% |hvlines-except-corners| are not drawn within the blocks).
 %
 % \medskip
 % \begin{BVerbatim}[baseline=c,boxwidth=10.6cm]
@@ -2145,7 +2289,7 @@
 % \begin{table}
 % \setlength{\belowcaptionskip}{1ex}
 % \centering
-% \caption{Utilisation of \texttt{\textbackslash tabularnote}~emphase#\tabularnote{It's possible!
+% \caption{Use of \texttt{\textbackslash tabularnote}~emphase#\tabularnote{It's possible!
 %     ~emphase#to put a note in the caption.}}!
 % \label{t:tabularnote}
 % \begin{NiceTabular}{@{}llc@{}[~emphase#notes/bottomrule!]
@@ -2169,7 +2313,7 @@
 % \begin{table}
 % \setlength{\belowcaptionskip}{1ex}
 % \centering
-% \caption{Utilisation of \texttt{\textbackslash tabularnote}\tabularnote{It's possible
+% \caption{Use of \texttt{\textbackslash tabularnote}\tabularnote{It's possible
 %     to put a note in the caption.}}
 % \label{t:tabularnote}
 % \begin{NiceTabular}{@{}llc@{}}[notes/bottomrule]
@@ -2255,7 +2399,7 @@
 % puts several consecutive commands |\tabularnote|. The marker |#1| is meant to
 % be the name of a LaTeX counter.
 %
-% Initial value: |\emph{\alph{#1}}|
+% Initial value: |\textit{\alph{#1}}|
 %
 % Another possible value should be a mere |\arabic{#1}|
 %
@@ -2334,7 +2478,7 @@
 % For an example of customization of the tabular notes, see p.~\pageref{ex:notes}.
 %
 %
-% \subsection{Utilisation of \{NiceTabular\} with threeparttable}
+% \subsection{Use of \{NiceTabular\} with threeparttable}
 %
 %
 % If you wish to use the environment |{NiceTabular}| in an environment
@@ -2404,11 +2548,6 @@
 % \sin x & \cos x 
 % \end{bNiceMatrix}$
 %
-% \medskip
-% There is also a key |S| which sets all the columns all type |S| of
-% \pkg{siunitx} (if this package is loaded).\footnote{This is a part of the
-% functionality provided by the environments |{pmatrix*}|, |{bmatrix*}|, etc. of
-% \pkg{mathtools}.}
 %
 % \subsection{The command \textbackslash rotate}
 %
@@ -2655,7 +2794,7 @@
 %
 %
 % 
-% \section{Utilisation of Tikz with nicematrix}
+% \section{Use of Tikz with nicematrix}
 % 
 % \label{name}
 % \subsection{The nodes corresponding to the contents of the cells}
@@ -2936,7 +3075,7 @@
 %
 % \vspace{1cm}
 % \begin{minipage}[c]{7cm}
-% Here are the ``large nodes'' of this array (without utilisation of |margin|
+% Here are the ``large nodes'' of this array (without use of |margin|
 % nor |extra-margin|).
 % \end{minipage}
 % \hspace{1.5cm}
@@ -3041,53 +3180,60 @@
 % 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
 % \end{NiceMatrix}\]
 %
-% \section{Tools for the developpers}
+% \section{API for the developpers}
 %
-% As its name implies, the token list |\g_nicematrix_code_after_tl| is public
-% (according to the LaTeX3 conventions, each variable with name beginning with
-% |\g_nicematrix| ou |\l_nicematrix| is public and each variable with name
-% beginning with |\g__nicematrix| or |\l__nicematrix| is private).
+% The package \pkg{nicematrix} provides two variables which are internal but
+% public\footnote{According to the LaTeX3 conventions,
+% each variable with name beginning with |\g_nicematrix| ou |\l_nicematrix| is
+% public and each variable with name beginning with |\g__nicematrix| or
+% |\l__nicematrix| is private.}: 
+% \begin{itemize}
+% \item \colorbox{yellow!50}{\textbf{New 5.2}}\enskip |\g_nicematrix_code_before_tl| ;
+% \item |\g_nicematrix_code_after_tl|.
+% \end{itemize}
+% 
 %
-%
 % \medskip
-% This variable contains the code of what we have called the ``|code-after|''.
-% The developper can use it to add code from a cell of the array (the
-% affectation must be global, allowing to exit the cell, which is a TeX group).
+% These variables contain the code of what we have called the ``|code-before|''
+% and the ``|code-after|''. The developper can use them to add code from a cell
+% of the array (the affectation must be global, allowing to exit the cell, which
+% is a TeX group).
 %
 % \medskip
-% \emph{Example} : We want to write a command |\crossbox| to draw a cross in the
-% current cell. This command will take in an optional argument between square
-% brackets for a list of pairs \textsl{key}-\textsl{value} which will be given to
-% Tikz before the drawing.
+% One should remark that the use of |\g_nicematrix_code_before_tl| needs one
+% compilation more (because the instructions are written on the |aux| file to be
+% used during the next run).
 %
-% It's possible to program such command |\crossbox| as follows, explicitely
-% using the public variable |\g_nicematrix_code_after_tl|.
+% \bigskip
+% \emph{Example} : We want to write a command |\hatchcell| to hatch the current
+% cell (with an optional argument between brackets for the color). It's possible
+% to program such command |\hatchcell| as follows, explicitely using the public
+% variable |\g_nicematrix_code_before_tl| (this code requires the Tikz library
+% \pkg{patterns}).
 %
 %
 % \begin{scope}
 % \fvset{commandchars=\§\¤\μ}
 % \begin{Verbatim}
-% \ExplSyntaxOn
-% \cs_new_protected:Nn \__pantigny_crossbox:nnn
+%\ExplSyntaxOn
+% \cs_new_protected:Nn \__pantigny_hatchcell:nnn
 %   {
 %     \begin { tikzpicture }
-%     \draw [ #3 ] 
-%           ( row-#1 -| col-\int_eval:n { #2 + 1 } ) 
-%        -- ( row-\int_eval:n { #1 + 1 } -| col-#2 ) 
-%           ( row-#1 -| col-\int_eval:n #2 ) 
-%        -- ( row-\int_eval:n { #1 + 1 } -| col-\int_eval:n { #2 + 1 } ) ; 
+%     \fill [ pattern = north~west~lines , pattern~color = #3 ]
+%           ( row - #1 -| col - #2) 
+%           rectangle 
+%           ( row - \int_eval:n { #1 + 1 } -| col - \int_eval:n { #2 + 1 } ) ;
 %     \end { tikzpicture }
 %   }
 %
-%
-% \NewDocumentCommand \crossbox { ! O { } }
+% \NewDocumentCommand \hatchcell { ! O { black } }
 %   {
-%     \tl_gput_right:Nx §emphase¤\g_nicematrix_code_after_tlμ
+%     \tl_gput_right:Nx §emphase¤\g_nicematrix_code_before_tlμ
 %       { 
-%         \__pantigny_crossbox:nnn 
+%         \__pantigny_hatchcell:nnn
 %           { \int_use:c { c at iRow } } 
 %           { \int_use:c { c at jCol } }
-%           { \exp_not:n { #1 } }
+%           { #1 }
 %       }
 %   }
 % \ExplSyntaxOff
@@ -3095,45 +3241,44 @@
 % \end{scope}
 %
 %
-% \ExplSyntaxOn
-% \cs_new_protected:Nn \__pantigny_crossbox:nnn
+%\ExplSyntaxOn
+% \cs_new_protected:Nn \__pantigny_hatchcell:nnn
 %   {
 %     \begin { tikzpicture }
-%     \draw [ #3 ] 
-%           ( row-#1 -| col-\int_eval:n { #2 + 1 } ) 
-%        -- ( row-\int_eval:n { #1 + 1 } -| col-#2 ) 
-%           ( row-#1 -| col-\int_eval:n #2 ) 
-%        -- ( row-\int_eval:n { #1 + 1 } -| col-\int_eval:n { #2 + 1 } ) ; 
+%     \fill [ pattern = north~west~lines , pattern~color = #3 ]
+%           ( row - #1 -| col - #2) 
+%           rectangle 
+%           ( row - \int_eval:n { #1 + 1 } -| col - \int_eval:n { #2 + 1 } ) ;
 %     \end { tikzpicture }
 %   }
 %
-%
-% \NewDocumentCommand \crossbox { ! O { } }
+% \NewDocumentCommand \hatchcell { ! O { black } }
 %   {
-%     \tl_gput_right:Nx \g_nicematrix_code_after_tl
+%     \tl_gput_right:Nx \g_nicematrix_code_before_tl
 %       { 
-%         \__pantigny_crossbox:nnn 
+%         \__pantigny_hatchcell:nnn
 %           { \int_use:c { c at iRow } } 
 %           { \int_use:c { c at jCol } }
-%           { \exp_not:n { #1 } }
+%           { #1 }
 %       }
 %   }
 % \ExplSyntaxOff
 %
+%
 % \bigskip
-% Here is an example of utilisation:
+% Here is an example of use:
 %
 % \medskip
 % \begin{BVerbatim}[baseline=c,boxwidth=9cm]
 % \begin{NiceTabular}{ccc}[hvlines]
 % Tokyo & Paris & London \\
-% Cap Town & ~emphase#\crossbox[red]@ & Miami \\
+% Roma & ~emphase#\hatchcell[blue!30]@Oslo & Miami \\
 % Los Angeles & Madrid & Roma
 % \end{NiceTabular}
 % \end{BVerbatim}
 % \begin{NiceTabular}{ccc}[hvlines]
 % Tokyo & Paris & London \\
-% Cap Town & \crossbox[red] & Miami \\
+% Lima & \hatchcell[blue!30]Oslo & Miami \\
 % Los Angeles & Madrid & Roma
 % \end{NiceTabular}
 %
@@ -4330,7 +4475,7 @@
 %    \end{macrocode}
 % The command |\CT at arc@| is a command of \pkg{colortbl} which sets the color of
 % the rules in the array. We will use it to store the instruction of color for
-% the rules even if \pkg{colortbl} is not loaded.
+% the rules even if \pkg{colortbl} is not loaded. Idem for 
 %    \begin{macrocode}
         \cs_set_protected:Npn \CT at arc@ { }
         \cs_set:Npn \arrayrulecolor #1 # { \CT at arc { #1 } }
@@ -4337,8 +4482,18 @@
         \cs_set:Npn \CT at arc #1 #2
           {
             \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign 
-             { \cs_gset:Npn \CT at arc@ { \color #1 { #2 } } }
+            { \cs_gset:Npn \CT at arc@ { \color #1 { #2 } } } 
           }
+%    \end{macrocode}
+% Idem for |\CT at drs@|.
+%    \begin{macrocode}
+        \cs_set_protected:Npn \CT at drsc@ { }
+        \cs_set:Npn \doublerulesepcolor #1 # { \CT at drs { #1 } }
+        \cs_set:Npn\CT at drs #1 #2 
+          {
+            \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign 
+            { \cs_gset:Npn \CT at drsc@ { \color #1 { #2 } } }
+          }
         \cs_set:Npn \hline
           {
             \noalign { \ifnum 0 = `} \fi
@@ -4364,8 +4519,17 @@
     \int_compare:nNnT \l_@@_first_col_int = 0 { \omit & }
     \int_compare:nNnT { #1 } > 1 { \multispan { \@@_pred:n { #1 } } & }
     \multispan { \int_eval:n { #2 - #1 + 1 } } 
-    { \CT at arc@ \leaders \hrule \@height \arrayrulewidth \hfill }
+    { 
+      \CT at arc@ 
+      \leaders \hrule \@height \arrayrulewidth \hfill 
 %    \end{macrocode}
+% The following |\skip_horizontal:N \c_zero_dim| is to prevent a potential
+% |\unskip| to delete the |\leaders|\footnote{See question 99041 on TeX
+% StackExchange.} 
+%    \begin{macrocode}
+      \skip_horizontal:N \c_zero_dim
+    }
+%    \end{macrocode}
 % Our |\everycr| has been modified. In particular, the creation of the |row|
 % node is in the |\everycr| (maybe we should put it with the incrementation of
 % |\c at iRow|). Since the following |\cr| correspond to a ``false row'', we have
@@ -4379,7 +4543,7 @@
 %
 % \bigskip
 % The following version of |\cline| spreads the array of a quantity equal
-% to |\arrayrulewidth| as does |\hline|. It will be loaded except if the key
+% to |\arrayrulewidth| as does |\hline|. It will be loaded excepted if the key
 % |standard-cline| has been used.
 %    \begin{macrocode}
 \cs_set:Npn \@@_cline 
@@ -4403,7 +4567,11 @@
     \int_compare:nNnT { #1 } < { #2 }
       { \multispan { \int_eval:n { #2 - #1 } } & }
     \multispan { \int_eval:n { #3 - #2 + 1 } }
-      { \CT at arc@ \leaders \hrule \@height \arrayrulewidth \hfill }
+      { 
+        \CT at arc@ 
+        \leaders \hrule \@height \arrayrulewidth \hfill 
+        \skip_horizontal:N \c_zero_dim
+      }
 %    \end{macrocode}
 % You look whether there is another |\cline| to draw (the final user may put
 % several |\cline|).
@@ -4596,7 +4764,7 @@
       {
         \ExplSyntaxOn
         \cs_if_free:NT \pgfsyspdfmark
-          { \cs_set_eq:NN \pgfsyspdfmark \use:nnn }
+          { \cs_set_eq:NN \pgfsyspdfmark \@gobblethree }
         \ExplSyntaxOff
       }
     \cs_gset_eq:NN \@@_provide_pgfsyspdfmark: \prg_do_nothing:
@@ -4750,7 +4918,7 @@
 % \emph{environment} whether we are in a command of \pkg{nicematrix} or in an
 % environment of \pkg{nicematrix}. The default value is \emph{environment}.
 %    \begin{macrocode} 
-\str_set:Nn \g_@@_com_or_env_str { environment }
+\tl_set:Nn \g_@@_com_or_env_str { environment }
 %    \end{macrocode}
 % 
 % \bigskip
@@ -4813,6 +4981,7 @@
 \bool_new:N \g_@@_row_of_col_done_bool
 %    \end{macrocode}
 % 
+% 
 % \bigskip
 % |\l_@@_code_before_tl| may contain two types of informations:
 % \begin{itemize}
@@ -4889,7 +5058,7 @@
 %    \end{macrocode}
 % In fact, this sequence will also contain the positions of the cells with a
 % |\diagbox|. The sequence |\g_@@_pos_of_blocks_seq| will be used when we will
-% draw the rules required by the keys |hvlines| or |hvlines-except-corners|.
+% draw the rules (which respect the blocks).
 %
 % \bigskip
 % We will also manage a sequence for the positions of the dotted lines. These
@@ -5031,10 +5200,10 @@
 %
 % \bigskip
 % The following counter will be used to count the number of successive tabular
-% notes such as in 
+% notes such as in  
 % |\tabularnote{Note 1}\tabularnote{Note 2}\tabularnote{Note 3}|. 
 % In the tabular, the labels of those nodes are composed as a comma
-% separated list (e.g. \textsuperscript{\emph{a},\emph{b},\emph{c}}).
+% separated list (e.g. \textsuperscript{\textit{a},\textit{b},\textit{c}}).
 %    \begin{macrocode}
 \int_new:N \l_@@_number_of_notes_int
 %    \end{macrocode}
@@ -5042,7 +5211,7 @@
 % \bigskip
 % The following function can be redefined by using the key |notes/style|.
 %    \begin{macrocode}
-\cs_new:Npn \@@_notes_style:n #1 { \emph { \alph { #1 } } }
+\cs_new:Npn \@@_notes_style:n #1 { \textit { \alph { #1 } } }
 %    \end{macrocode}
 % 
 % \bigskip
@@ -5134,7 +5303,7 @@
 %    \begin{macrocode}
                 \int_incr:N \l_@@_number_of_notes_int
 %    \end{macrocode}
-% We expand the content of the note at the point of utilisation of
+% We expand the content of the note at the point of use of
 % |\tabularnote| as does |\footnote|.
 %    \begin{macrocode}
                 \seq_gput_right:Nx \g_@@_tabularnotes_seq { #1 } 
@@ -5339,7 +5508,7 @@
 % array). 
 %    \begin{macrocode}
 \str_new:N \l_@@_baseline_str 
-\str_set:Nn \l_@@_baseline_str c
+\tl_set:Nn \l_@@_baseline_str c
 %    \end{macrocode}
 % 
 % \bigskip
@@ -5360,22 +5529,29 @@
 %    \end{macrocode}
 %
 % \bigskip
-% The flag |\l_@@_hlines_bool| corresponds to the key |hlines|, the flag
-% |\l_@@_vlines_bool| to the key |vlines| and the flag |hvlines| to the key
-% |hvlines|. The key |hvlines| is not a mere alias for the conjonction of
-% |hlines| and |vlines|. Indeed, with |hvlines|, the vertical and horizontal
-% rules are \emph{not} drawn within the blocks (created by |\Block|).
+% If the flag |\l_@@_vlines_bool| is raised, horizontal space will be reserved
+% in the the preamble of the array (for the vertical rules) and, after the
+% construction of the array, the vertical rules will be drawn.
 %    \begin{macrocode}
-\bool_new:N \l_@@_hlines_bool
 \bool_new:N \l_@@_vlines_bool
-\bool_new:N \l_@@_hvlines_bool
 %    \end{macrocode}
 %
 % \bigskip
-% The flag |\l_@@_hlines_except_corners_bool| corresponds to the key |hlines-except-corners|.
+% If the flag |\l_@@_hlines_bool| is raised, vertical space will be reserved
+% between the rows of the array (for the horizontal rules) and, after the
+% construction of the array, the vertical rules will be drawn.
 %    \begin{macrocode}
-\bool_new:N \l_@@_hvlines_except_corners_bool
+\bool_new:N \l_@@_hlines_bool
 %    \end{macrocode}
+%
+% \bigskip
+% The flag |\l_@@_except_corners_bool| will be raised when the key
+% |except-corners| will be used. In that case, the corners will be computed
+% before we draw rules and the rules won't be drawn in the corners. As expected,
+% the key |hvlines-except-corners| raises the key |except-corners|.
+%    \begin{macrocode}
+\clist_new:N \l_@@_except_corners_clist
+%    \end{macrocode}
 % 
 %    \begin{macrocode}
 \dim_new:N \l_@@_notes_above_space_dim 
@@ -5553,7 +5729,6 @@
     vlines .bool_set:N = \l_@@_vlines_bool ,
     hvlines .code:n = 
       { 
-        \bool_set_true:N \l_@@_hvlines_bool 
         \bool_set_true:N \l_@@_vlines_bool 
         \bool_set_true:N \l_@@_hlines_bool 
       } ,
@@ -5590,30 +5765,37 @@
 % We define a set of keys used by the environments of \pkg{nicematrix} (but not
 % by the command |\NiceMatrixOptions|). 
 %    \begin{macrocode}
-\keys_define:nn { NiceMatrix / Env }
-  {
-    hvlines-except-corners .bool_set:N = \l_@@_hvlines_except_corners_bool , 
-    hvlines-except-corners .default:n = true ,
-    code-before .code:n = 
+\keys_define:nn { NiceMatrix / Env } 
+  { 
+    except-corners .clist_set:N = \l_@@_except_corners_clist , 
+    except-corners .default:n = { NW , SW , NE , SE } ,
+    hvlines-except-corners .code:n = 
       { 
-        \tl_if_empty:nF { #1 } 
-          {
-            \tl_put_right:Nn \l_@@_code_before_tl { #1 }
-            \bool_set_true:N \l_@@_code_before_bool 
-          }
+        \clist_set:Nn \l_@@_except_corners_clist { #1 }
+        \bool_set_true:N \l_@@_vlines_bool 
+        \bool_set_true:N \l_@@_hlines_bool 
       } ,
+    hvlines-except-corners .default:n = { NW , SW , NE , SE } ,
+    code-before .code:n = 
+     {
+       \tl_if_empty:nF { #1 } 
+         { 
+           \tl_put_right:Nn \l_@@_code_before_tl { #1 }
+           \bool_set_true:N \l_@@_code_before_bool 
+         } 
+     } ,
 %    \end{macrocode}
 % \bigskip
 % The options |c|, |t| and |b| of the environment |{NiceArray}| have the same
 % meaning as the option of the classical environment |{array}|.
 %    \begin{macrocode}
-    c .code:n = \str_set:Nn \l_@@_baseline_str c ,
-    t .code:n = \str_set:Nn \l_@@_baseline_str t ,
-    b .code:n = \str_set:Nn \l_@@_baseline_str b ,
+    c .code:n = \tl_set:Nn \l_@@_baseline_str c ,
+    t .code:n = \tl_set:Nn \l_@@_baseline_str t ,
+    b .code:n = \tl_set:Nn \l_@@_baseline_str b ,
     baseline .tl_set:N = \l_@@_baseline_str ,
     baseline .value_required:n = true ,
     columns-width .code:n = 
-      \str_if_eq:nnTF { #1 } { auto }
+      \tl_if_eq:nnTF { #1 } { auto }
         { \bool_set_true:N \l_@@_auto_columns_width_bool }
         { \dim_set:Nn \l_@@_columns_width_dim { #1 } } , 
     columns-width .value_required:n = true ,
@@ -5778,7 +5960,7 @@
 % In |\NiceMatrixOptions|, the special value |auto| is not available.
 %    \begin{macrocode}
     columns-width .code:n = 
-      \str_if_eq:nnTF { #1 } { auto }
+      \tl_if_eq:nnTF { #1 } { auto }
         { \@@_error:n { Option~auto~for~columns-width } }
         { \dim_set:Nn \l_@@_columns_width_dim { #1 } } ,
 %    \end{macrocode}
@@ -5803,7 +5985,7 @@
 %    \begin{macrocode}
     letter-for-dotted-lines .code:n = 
       {
-        \int_compare:nTF { \tl_count:n { #1 } = 1 }
+        \tl_if_single_token:nTF { #1 }
           { \str_set:Nx \l_@@_letter_for_dotted_lines_str { #1 } }
           { \@@_error:n { Bad~value~for~letter~for~dotted~lines } } 
       } ,
@@ -5845,9 +6027,6 @@
                          { \int_set:Nn \l_@@_last_col_int { #1 } } ,
     l .code:n = \tl_set:Nn \l_@@_type_of_col_tl l ,
     r .code:n = \tl_set:Nn \l_@@_type_of_col_tl r ,
-    S .code:n = \bool_if:NTF \c_@@_siunitx_loaded_bool
-                  { \tl_set:Nn \l_@@_type_of_col_tl S }
-                  { \@@_error:n { option~S~without~siunitx } } ,
     small .bool_set:N = \l_@@_small_bool ,
     small .value_forbidden:n = true ,
     unknown .code:n = \@@_error:n { Unknown~option~for~NiceMatrix } 
@@ -6466,6 +6645,7 @@
     \cs_set_eq:NN \Ddots \@@_Ddots
     \cs_set_eq:NN \Iddots \@@_Iddots
     \cs_set_eq:NN \hdottedline \@@_hdottedline:
+    \cs_set_eq:NN \Hline \@@_Hline:
     \cs_set_eq:NN \Hspace \@@_Hspace:
     \cs_set_eq:NN \Hdotsfor \@@_Hdotsfor:
     \cs_set_eq:NN \Vdotsfor \@@_Vdotsfor:
@@ -6473,7 +6653,7 @@
     \cs_set_eq:NN \Block \@@_Block:
     \cs_set_eq:NN \rotate \@@_rotate:
     \cs_set_eq:NN \OnlyMainNiceMatrix \@@_OnlyMainNiceMatrix:n
-    \cs_set_eq:NN \dotfill \@@_dotfill:
+    \cs_set_eq:NN \dotfill \@@_old_dotfill:
     \cs_set_eq:NN \CodeAfter \@@_CodeAfter:n
     \cs_set_eq:NN \diagbox \@@_diagbox:nn
     \bool_if:NT \l_@@_colortbl_like_bool \@@_colortbl_like:
@@ -6542,7 +6722,7 @@
 %
 % \medskip
 %    \begin{macrocode}
-    \tl_gclear_new:N \g_@@_code_before_tl
+    \tl_gclear_new:N \g_nicematrix_code_before_tl
   }
 %    \end{macrocode}
 % This is the end of |\@@_pre_array:|.
@@ -6575,7 +6755,7 @@
     \bool_set_true:N \l_@@_in_env_bool
 %    \end{macrocode}
 % The command |\CT at arc@| contains the instruction of color for the rules of the
-% array\footnote{e.g. |\color[rgb]{0.5,0.5,0}|)}. This command is used by |\CT at arc@| but
+% array\footnote{e.g. |\color[rgb]{0.5,0.5,0}|}. This command is used by |\CT at arc@| but
 % we use it also for compatibility with \pkg{colortbl}. But we want also to be
 % able to use color for the rules of the array when \pkg{colortbl} is \emph{not}
 % loaded. That's why we do the following instruction which is in the patch of
@@ -6605,20 +6785,14 @@
 %    \end{macrocode}
 %
 % 
-% We do a redefinition of |\@arrayrule| because we want that the vertical rules
-% drawn by "|" in the preamble of the array don't extend in the potential
-% exterior rows.
-%    \begin{macrocode}
-    \cs_set_protected:Npn \@arrayrule { \@addtopreamble \@@_vline: }
-%    \end{macrocode}
-% 
 % The sequence |\g_@@_blocks_seq| will contain the carateristics of the blocks
 % (specified by |\Block|) of the array. The sequence |\g_@@_pos_of_blocks_seq|
 % will contain only the position of the blocks. Of course, this is redundant but
 % it's for efficiency.
 %    \begin{macrocode}
-    \seq_clear:N \g_@@_blocks_seq
-    \seq_clear:N \g_@@_pos_of_blocks_seq
+    \seq_gclear:N \g_@@_blocks_seq
+    \seq_gclear:N \g_@@_pos_of_blocks_seq
+    \seq_gclear:N \g_@@_pos_of_xdots_seq
 %    \end{macrocode}
 % In fact, the sequence |\g_@@_pos_of_blocks_seq| will also contain the
 % positions of the cells with a |\diagbox|.
@@ -7217,7 +7391,6 @@
         l { \@@_patch_preamble_i:n #1 }
         r { \@@_patch_preamble_i:n #1 }
         > { \@@_patch_preamble_ii:nn #1 }
-        < { \@@_patch_preamble_ii:nn #1 }
         ! { \@@_patch_preamble_ii:nn #1 }
         @ { \@@_patch_preamble_ii:nn #1 }
         | { \@@_patch_preamble_iii:n #1 }
@@ -7247,17 +7420,14 @@
 % We increment the counter of columns.
 %    \begin{macrocode}
     \int_gincr:N \c at jCol
-    \bool_if:NT \l_@@_vlines_bool
-      { 
-        \tl_gput_right:Nn \g_@@_preamble_tl 
-          { ! { \skip_horizontal:N \arrayrulewidth } }
-      }
-    \@@_patch_preamble:n
+    \@@_patch_preamble_viii:n
   }
 %    \end{macrocode}
 %
+% 
+% 
 % \medskip
-% For |>|, |<|, |!| and |@|
+% For |>|, |!| and |@|
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_patch_preamble_ii:nn #1 #2
   {  
@@ -7301,7 +7471,7 @@
               } 
           }
         \tl_gput_right:Nx \g_@@_internal_code_after_tl
-          { \@@_vline:nn { \int_use:N \c at jCol } { \int_use:N \l_tmpa_int } }
+          { \@@_vline:nn { \@@_succ:n \c at jCol } { \int_use:N \l_tmpa_int } }
         \int_zero:N \l_tmpa_int
         \@@_patch_preamble:n #1 
       }
@@ -7329,7 +7499,7 @@
 % We increment the counter of columns.
 %    \begin{macrocode}
     \int_gincr:N \c at jCol
-    \@@_patch_preamble:n
+    \@@_patch_preamble_viii:n
   }
 %    \end{macrocode}
 % 
@@ -7356,7 +7526,7 @@
 % We increment the counter of columns.
 %    \begin{macrocode}
     \int_gincr:N \c at jCol
-    \@@_patch_preamble:n
+    \@@_patch_preamble_viii:n
   }
 %    \end{macrocode}
 %
@@ -7371,12 +7541,7 @@
 % We increment the counter of columns.
 %    \begin{macrocode}
     \int_gincr:N \c at jCol
-    \bool_if:NT \l_@@_vlines_bool
-      { 
-        \tl_gput_right:Nn \g_@@_preamble_tl 
-          { ! { \skip_horizontal:N \arrayrulewidth } }
-      }
-    \@@_patch_preamble:n
+    \@@_patch_preamble_viii:n
   }
 %    \end{macrocode}
 %
@@ -7383,10 +7548,6 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_patch_preamble_vii:n #1
   {
-%    \end{macrocode}
-% Here, we have a problem in the cases of the use in the first column or the ``last
-% one''. 
-%    \begin{macrocode}
     \tl_gput_right:Nn \g_@@_preamble_tl
       { ! { \skip_horizontal:N 2\l_@@_radius_dim } }
 %    \end{macrocode}
@@ -7399,7 +7560,34 @@
   }
 %    \end{macrocode}
 % 
+% After a specifier of column, we have to test whether there is one or several
+% |<{..}| because, after those potential |<{...}|, we have to insert
+% |!{\skip_horizontal:N ...}| when the key |vlines| is used.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_viii:n #1
+  {
+    \str_if_eq:nnTF { #1 } { < }
+      \@@_patch_preamble_ix:n 
+      { 
+        \bool_if:NT \l_@@_vlines_bool
+          { 
+            \tl_gput_right:Nn \g_@@_preamble_tl 
+              { ! { \skip_horizontal:N \arrayrulewidth } }
+          } 
+        \@@_patch_preamble:n { #1 }
+      }
+  }
+%    \end{macrocode}
 % 
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_patch_preamble_ix:n #1
+  {
+    \tl_gput_right:Nn \g_@@_preamble_tl { < { #1 } }
+    \@@_patch_preamble_viii:n
+  }
+%    \end{macrocode}
+%
+% 
 % \bigskip
 % The command |\@@_put_box_in_flow:| puts the box |\l_tmpa_box| (which contains
 % the array) in the flow. It is used for the environments with delimiters.
@@ -7425,21 +7613,6 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_put_box_in_flow_i:
   {
-    \str_case:VnF \l_@@_baseline_str
-      {
-        { t } { \int_set:Nn \l_tmpa_int 1 }
-        { b } { \int_set_eq:NN \l_tmpa_int \c at iRow }
-      }
-      { \int_set:Nn \l_tmpa_int \l_@@_baseline_str }
-    \bool_if:nT
-      { 
-           \int_compare_p:nNn \l_tmpa_int < \l_@@_first_row_int
-        || \int_compare_p:nNn \l_tmpa_int > \g_@@_row_total_int 
-      }
-      { 
-        \@@_error:n { bad~value~for~baseline }
-        \int_set:Nn \l_tmpa_int 1
-      }
     \pgfpicture
       \@@_qpoint:n { row - 1 } 
       \dim_gset_eq:NN \g_tmpa_dim \pgf at y
@@ -7450,12 +7623,38 @@
 % Now, |\g_tmpa_dim| contains the $y$-value of the center of the array (the
 % delimiters are centered in relation with this value).
 %    \begin{macrocode}
-      \@@_qpoint:n { row - \int_use:N \l_tmpa_int - base }
-      \dim_gsub:Nn \g_tmpa_dim \pgf at y
+      \str_if_in:NnTF \l_@@_baseline_str { line- }
+        {
+          \int_set:Nn \l_tmpa_int
+            {
+              \str_range:Nnn 
+                \l_@@_baseline_str 
+                6 
+                { \str_count:N \l_@@_baseline_str } 
+            }
+          \@@_qpoint:n { row - \int_use:N \l_tmpa_int }
+        }
+        {
+          \str_case:VnF \l_@@_baseline_str
+            {
+              { t } { \int_set:Nn \l_tmpa_int 1 }
+              { b } { \int_set_eq:NN \l_tmpa_int \c at iRow }
+            }
+            { \int_set:Nn \l_tmpa_int \l_@@_baseline_str }
+          \bool_lazy_or:nnT
+            { \int_compare_p:nNn \l_tmpa_int < \l_@@_first_row_int }
+            { \int_compare_p:nNn \l_tmpa_int > \g_@@_row_total_int }
+            { 
+              \@@_error:n { bad~value~for~baseline }
+              \int_set:Nn \l_tmpa_int 1
+            }
+          \@@_qpoint:n { row - \int_use:N \l_tmpa_int - base }
 %    \end{macrocode}
 % We take into account the position of the mathematical axis.
 %    \begin{macrocode}
-      \dim_gsub:Nn \g_tmpa_dim { \fontdimen22 \textfont2 }
+          \dim_gsub:Nn \g_tmpa_dim { \fontdimen22 \textfont2 }
+        }
+      \dim_gsub:Nn \g_tmpa_dim \pgf at y
 %    \end{macrocode}
 % Now, |\g_tmpa_dim| contains the value of the $y$ translation we have to to.
 %    \begin{macrocode}
@@ -7561,7 +7760,7 @@
 % We convert a value of |t| to a value of |1|.
 %    \begin{macrocode}
     \str_if_eq:VnT \l_@@_baseline_str { t } 
-      { \str_set:Nn \l_@@_baseline_str { 1 } } 
+      { \tl_set:Nn \l_@@_baseline_str { 1 } } 
 %    \end{macrocode}
 % Now, we convert the value of |\l_@@_baseline_str| (which should represent an
 % integer) to an integer stored in |\l_tmpa_int|.
@@ -8173,7 +8372,7 @@
         \str_gset:Nn \g_@@_name_env_str { #1 NiceMatrix } 
         \tl_set:Nn \l_@@_type_of_col_tl c
         \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
-        \exp_args:Nnx \@@_begin_of_NiceMatrix:nn { #1 } \l_@@_type_of_col_tl 
+        \exp_args:Nne \@@_begin_of_NiceMatrix:nn { #1 } \l_@@_type_of_col_tl 
       }
       { \use:c { end #1 NiceArray } }
   }
@@ -8317,6 +8516,13 @@
                   \int_use:N 
                 \g_@@_col_total_int 
               }
+%    \end{macrocode}
+% We write also the potential content of |\g_@@_pos_of_blocks_seq| (it will be
+% useful if the commands |\rowcolors| is used with the key |respect-blocks|.
+%    \begin{macrocode}
+            \seq_gset_from_clist:cn
+              { c_@@_pos_of_blocks_ \int_use:N \g_@@_env_int _ seq }
+              { \seq_use:Nnnn \g_@@_pos_of_blocks_seq , , , }
           }   
         \iow_now:Nn \@mainaux \ExplSyntaxOff
       } 
@@ -8385,29 +8591,54 @@
 %    \end{macrocode}
 %
 % \bigskip
-% Now, we actually draw the dotted lines. 
+% Now, we actually draw the dotted lines (specified by |\Cdots|, |\Vdots|,
+% etc.). 
 %    \begin{macrocode}
     \@@_draw_dotted_lines:
 %    \end{macrocode}
 % 
+% \bigskip
+% The following computes the ``corners'' (made up of empty cells) but if there
+% is no corner to compute, it will do nothing.
 %    \begin{macrocode}
-    \bool_if:NTF \l_@@_hvlines_bool 
-      \@@_draw_hvlines:
-      { 
-        \bool_if:NT \l_@@_hlines_bool \@@_draw_hlines: 
-        \bool_if:NT \l_@@_vlines_bool \@@_draw_vlines: 
-        \bool_if:NT \l_@@_hvlines_except_corners_bool
-          \@@_draw_hvlines_except_corners:
-      }
+    \@@_compute_corners:
 %    \end{macrocode}
+% 
+% \bigskip
+% The following code is only for efficiency. We determine whether the potential
+% horizontal and vertical rules are ``complete'', that is to say drawn in the
+% whole array. We are sure that all the rules will be complete when there is no
+% block, no virtual block (determined by a command such as |\Cdots|, |\Vdots|,
+% etc.) and no corners. In that case, we switch to a shortcut version of
+% |\@@_vline_i:nn| and |\@@_hline:nn|.
+%    \begin{macrocode}
+    % \bool_lazy_all:nT
+    %   { 
+    %     { \seq_if_empty_p:N \g_@@_pos_of_blocks_seq }
+    %     { \seq_if_empty_p:N \g_@@_pos_of_xdots_seq }
+    %     { \seq_if_empty_p:N \l_@@_empty_corner_cells_seq }
+    %   }
+    %   { 
+    %     \cs_set_eq:NN \@@_vline_i:nn \@@_vline_i_complete:nn 
+    %     \cs_set_eq:NN \@@_hline_i:nn \@@_hline_i_complete:nn 
+    %   }
+    \bool_if:NT \l_@@_hlines_bool \@@_draw_hlines: 
+    \bool_if:NT \l_@@_vlines_bool \@@_draw_vlines: 
+    \g_@@_internal_code_after_tl
+    \tl_gclear:N \g_@@_internal_code_after_tl
+%    \end{macrocode}
 %
-% We have to revert to a clean version of |\ialign| because there may be
-% tabulars in the |\Block| instructions that will be composed now.
+% \bigskip
+% We draw the blocks. We have to revert to a clean version of |\ialign| because
+% there may be tabulars in the |\Block| instructions that will be composed now. 
 %    \begin{macrocode}
     \cs_set_eq:NN \ialign \@@_old_ialign:
-    \seq_if_empty:NF \g_@@_blocks_seq \@@_draw_blocks:
-    \g_@@_internal_code_after_tl
-    \tl_gclear:N \g_@@_internal_code_after_tl
+    \seq_if_empty:NF \g_@@_blocks_seq \@@_draw_blocks: 
+%    \end{macrocode}
+% 
+% \bigskip
+% Now, the |code-after|.
+%    \begin{macrocode}
     \bool_if:NT \c_@@_tikz_loaded_bool
       {  
         \tikzset
@@ -8438,17 +8669,17 @@
 % 
 % 
 % \medskip
-% |\g_@@_code_before_tl| is for instructions in the cells of the array such as
+% |\g_nicematrix_code_before_tl| is for instructions in the cells of the array such as
 % |\rowcolor| and |\cellcolor| (when the key |colortbl-like| is in
 % force). These instructions will be written on the |aux| file to be added to
 % the |code-before| in the next run.
 %    \begin{macrocode}
-    \tl_if_empty:NF \g_@@_code_before_tl
+    \tl_if_empty:NF \g_nicematrix_code_before_tl
       {
 %    \end{macrocode}
 % The command |\rowcolor| in tabular will in fact use |\rectanglecolor| in order
 % to follow the behaviour of |\rowcolor| of \pkg{colortbl}. That's why there may
-% be a command |\rectanglecolor| in |\g_@@_code_before_tl|. In order to avoid an
+% be a command |\rectanglecolor| in |\g_nicematrix_code_before_tl|. In order to avoid an
 % error during the expansion, we define a protected version of |\rectanglecolor|.
 %    \begin{macrocode}
         \cs_set_protected:Npn \rectanglecolor { }
@@ -8458,7 +8689,7 @@
           {
             \tl_gset:cn 
               { g_@@_code_before_ \int_use:N \g_@@_env_int _ tl }
-              { \g_@@_code_before_tl }
+              { \g_nicematrix_code_before_tl }
           }
         \iow_now:Nn \@mainaux \ExplSyntaxOff
         \bool_set_true:N \l_@@_code_before_bool
@@ -8751,19 +8982,16 @@
           }
       }
 %    \end{macrocode}
-% If the key |hvlines| is used, we remind the rectangle described by all the
-% dotted lines in order to respect the corresponding virtual ``block'' when
-% drawing the horizontal and vertical rules.
+% We remind the rectangle described by all the dotted lines in order to respect
+% the corresponding virtual ``block'' when drawing the horizontal and vertical
+% rules.
 %    \begin{macrocode}
-    \bool_if:NT \l_@@_hvlines_bool
-      {
-        \seq_gput_right:Nx \g_@@_pos_of_xdots_seq
-          { 
-            { \int_use:N \l_@@_initial_i_int }
-            { \int_use:N \l_@@_initial_j_int }
-            { \int_use:N \l_@@_final_i_int }
-            { \int_use:N \l_@@_final_j_int }
-          }
+    \seq_gput_right:Nx \g_@@_pos_of_xdots_seq
+      { 
+        { \int_use:N \l_@@_initial_i_int }
+        { \int_use:N \l_@@_initial_j_int }
+        { \int_use:N \l_@@_final_i_int }
+        { \int_use:N \l_@@_final_j_int }
       }
   } 
 %    \end{macrocode}
@@ -9700,11 +9928,22 @@
 % since |\tl_lower_case:n| seems to be deprecated.
 %    \begin{macrocode}
       { 
-        > \@@_Cell: 
-        \bool_if:NT \c_@@_define_L_C_R_bool \tl_lower_case:n 
-        #2 
-        < \@@_end_Cell: 
-      } 
+        \exp_args:Ne \str_case:nn { \tl_lower_case:n { #2 } }
+          {
+             l { > \@@_Cell: l < \@@_end_Cell: }
+             r { > \@@_Cell: r < \@@_end_Cell: }
+             c { > \@@_Cell: c < \@@_end_Cell: }
+             { l | } { > \@@_Cell: l < \@@_end_Cell: | }
+             { r | } { > \@@_Cell: r < \@@_end_Cell: | }
+             { c | } { > \@@_Cell: c < \@@_end_Cell: | }
+             { | l } { | > \@@_Cell: l < \@@_end_Cell: }
+             { | r } { | > \@@_Cell: r < \@@_end_Cell: }
+             { | c } { | > \@@_Cell: c < \@@_end_Cell: }
+             { | l | } { | > \@@_Cell: l < \@@_end_Cell: | }
+             { | r | } { | > \@@_Cell: r < \@@_end_Cell: | }
+             { | c | } { | > \@@_Cell: c < \@@_end_Cell: | }
+          }
+      }       
       { #3 } 
 %    \end{macrocode}
 % The |\peek_remove_spaces:n| is mandatory.
@@ -9990,7 +10229,7 @@
             \vbox_to_zero:n { }
 %    \end{macrocode}
 % |0.8 ex| will be the distance between the principal part of the array and our
-% element (which is composed with |\rotate|.
+% element (which is composed with |\rotate|).
 %    \begin{macrocode}
             \skip_vertical:n { - \box_ht:N \@arstrutbox + 0.8 ex } 
             \box_use:N \l_@@_cell_box 
@@ -10033,7 +10272,7 @@
         \group_begin:
         \keys_set:nn { NiceMatrix / xdots } { #1 , #4 , down = #5 , up = #6 }
         \tl_if_empty:VF \l_@@_xdots_color_tl { \color { \l_@@_xdots_color_tl } } 
-          \use:x
+          \use:e
             {
               \@@_line_i:nn 
                 { \@@_double_int_eval:n #2 \q_stop }
@@ -10295,22 +10534,132 @@
 % The command |\rowcolors| (accessible in the |code-before|) is inspired by the
 % command |\rowcolors| of the package \pkg{xcolor} (with the option |table|).
 % However, the command |\rowcolors| of \pkg{nicematrix} has \emph{not} the
-% optional argument of the command |\rowcolors| of \pkg{xcolor}.
+% optional argument of the command |\rowcolors| of \pkg{xcolor}. Here is an
+% example: |\rowcolors{1}{blue!10}{}[respect-blocks]|.
+%
+% The last optional argument is for options. As of now, there is only one key
+% available : |respect-blocks|.
+%
 %    \begin{macrocode}
-\NewDocumentCommand \@@_rowcolors { O { } m m m }
+\keys_define:nn { NiceMatrix / rowcolors }
   {
-    \int_step_inline:nnn { #2 } { \int_use:N \c at iRow }
+    respect-blocks .bool_set:N = \l_@@_respect_blocks_bool ,
+    respect-blocks .default:n = true ,
+    unknown .code:n = \@@_error:n { Unknown~option~for~rowcolors } 
+  }
+%    \end{macrocode}
+% 
+%    \begin{macrocode}
+\NewDocumentCommand \@@_rowcolors { O { } m m m O { } }
+  {
+    \keys_set:nn { NiceMatrix / rowcolors } { #5 }
+    \bool_lazy_and:nnTF 
+      \l_@@_respect_blocks_bool
+      { \cs_if_exist_p:c { c_@@_pos_of_blocks_ \int_use:N \g_@@_env_int _ seq } } 
+      { \@@_rowcolors_i:nnnn { #1 } { #2 } { #3 } { #4 } }
       {
-        \int_if_odd:nTF { ##1 }
-          { \@@_rowcolor [ #1 ] { #3 } }
-          { \@@_rowcolor [ #1 ] { #4 } }
-        { ##1 }
-      } 
+        \int_step_inline:nnn { #2 } { \int_use:N \c at iRow }
+          {
+            \int_if_odd:nTF { ##1 }
+              { \@@_rowcolor [ #1 ] { #3 } }
+              { \@@_rowcolor [ #1 ] { #4 } }
+            { ##1 }
+          } 
+      }
   }
 %    \end{macrocode}
 %
+%
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_rowcolors_i:nnnn #1 #2 #3 #4
+  {
+    \seq_set_eq:Nc \l_tmpb_seq 
+      { c_@@_pos_of_blocks_ \int_use:N \g_@@_env_int _ seq } 
+%    \end{macrocode}
+% We don't want to take into account a block which is completely in the ``first
+% column'' of (number $0$) or in the ``last column''. 
+%    \begin{macrocode}
+    \seq_set_filter:NNn \l_tmpa_seq \l_tmpb_seq
+      { \@@_not_in_exterior_p:nnnn ##1 }
+%    \end{macrocode} 
+% The counter |\l_tmpa_int| will be the index of the loop.
+%    \begin{macrocode}
+    \int_set:Nn \l_tmpa_int { #2 }
+%    \end{macrocode}
+% The boolean |\l_tmpa_bool| will indicate whereas we are in a row of the first
+% color or of the second color.
+%    \begin{macrocode}
+    \bool_set_false:N \l_tmpa_bool
+%    \end{macrocode}
+%  We recall that, in the |code-before|, |\c at iRow| is the total number of rows of
+% the array (excepted the potential exterior rows).
+%    \begin{macrocode}
+    \int_do_until:nNnn \l_tmpa_int > \c at iRow
+      {
+        \seq_set_filter:NNn \l_tmpb_seq \l_tmpa_seq 
+          { \@@_intersect_our_row_p:nnnn ##1 }
+%    \end{macrocode}
+% We compute in |\l_tmpb_int| the last row covered by a block.
+%    \begin{macrocode}
+        \int_set_eq:NN \l_tmpb_int \l_tmpa_int
+        \seq_map_inline:Nn \l_tmpb_seq { \@@_rowcolors_ii:nnnn ##1 }
+        \bool_if:NTF \l_tmpa_bool
+          { 
+            \@@_rowcolor [ #1 ] { #4 } 
+              { \int_use:N \l_tmpa_int - \int_use:N \l_tmpb_int } 
+            \bool_set_false:N \l_tmpa_bool
+          }
+          { 
+            \@@_rowcolor [ #1 ] { #3 } 
+              { \int_use:N \l_tmpa_int - \int_use:N \l_tmpb_int } 
+            \bool_set_true:N \l_tmpa_bool
+          }
+        \int_set:Nn \l_tmpa_int { \l_tmpb_int + 1 }
+      }
+  }
+%    \end{macrocode}
+%
+% \bigskip 
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_rowcolors_ii:nnnn #1 #2 #3 #4
+  { 
+    \int_compare:nNnT { #3 } > \l_tmpb_int
+      { \int_set:Nn \l_tmpb_int { #3 } }
+  }
+%    \end{macrocode}
+%
+%
+% \bigskip 
+%    \begin{macrocode}
+\prg_new_conditional:Nnn \@@_not_in_exterior:nnnn p
+  {
+    \bool_lazy_or:nnTF 
+      { \int_compare_p:nNn { #4 } = \c_zero_int }
+      { \int_compare_p:nNn { #2 } = { \@@_succ:n { \c at jCol } } }
+      \prg_return_false:
+      \prg_return_true:
+  }
+%    \end{macrocode}
+%
 % \bigskip
+% The following command return |true| when the block intersects the row
+% |\l_tmpa_int|. 
 %    \begin{macrocode}
+\prg_new_conditional:Nnn \@@_intersect_our_row:nnnn p
+  {
+    \bool_if:nTF
+      { 
+        \int_compare_p:n { #1 <= \l_tmpa_int }
+        && 
+        \int_compare_p:n { \l_tmpa_int <= #3 }
+      }
+      \prg_return_true:
+      \prg_return_false:
+  }
+%    \end{macrocode}
+%
+% \bigskip
+%    \begin{macrocode}
 \NewDocumentCommand \@@_chessboardcolors { O { } m m  }
   {
     \int_step_inline:nn { \int_use:N \c at iRow }
@@ -10332,7 +10681,7 @@
 %    \begin{macrocode}
 \NewDocumentCommand \@@_cellcolor_tabular { O { } m }
   {
-    \tl_gput_right:Nx \g_@@_code_before_tl
+    \tl_gput_right:Nx \g_nicematrix_code_before_tl
       { \cellcolor [ #1 ] { #2 } { \int_use:N \c at iRow - \int_use:N \c at jCol } }  
   }
 %    \end{macrocode}
@@ -10343,7 +10692,7 @@
 %    \begin{macrocode}
 \NewDocumentCommand \@@_rowcolor_tabular { O { } m }
   {
-    \tl_gput_right:Nx \g_@@_code_before_tl      
+    \tl_gput_right:Nx \g_nicematrix_code_before_tl      
       { 
         \exp_not:N \rectanglecolor [ #1 ] { #2 } 
           { \int_use:N \c at iRow - \int_use:N \c at jCol } 
@@ -10362,7 +10711,7 @@
 % You use |gput_left| because we want the specification of colors for the
 % columns drawn before the specifications of color for the rows (and the cells).
 %    \begin{macrocode}
-        \tl_gput_left:Nx \g_@@_code_before_tl
+        \tl_gput_left:Nx \g_nicematrix_code_before_tl
           { \exp_not:N \columncolor [ #1 ] { #2 } { \int_use:N \c at jCol } }
       }
   }
@@ -10424,25 +10773,23 @@
 % |\l_@@_last_row_int| may be equal to $-2$ or $-1$ (we can't write 
 % |\int_compare:nNnT \c at iRow < \l_@@_last_row_int|).
 % 
-% 
 %
-%
 % \bigskip
-% The following command will be executed in the |internal-code-after|. |#1| is
-% the number the column where to draw the rule and |#2| is the number of
-% consecutive occurrences of \verb+|+.
+% The following command will be executed in the |internal-code-after|. The rule
+% will be drawn \emph{before} the column |#1|. |#2| is the number of consecutive
+% occurrences of \verb+|+.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_vline:nn #1 #2
   {
-    \bool_if:NTF \c_@@_tikz_loaded_bool
+%    \end{macrocode}
+% The following test is for the case where the user don't use all the columns
+% specified in the preamble of the environment (for instance, a preamble of
+% \verb+|c|c|c|+ but only two columns used).
+%    \begin{macrocode}
+    \int_compare:nNnT { #1 } < { \c at jCol + 2 }
       {
-        \tikzpicture
-        \@@_vline_i:nn { #1 } { #2 }
-        \endtikzpicture
-      }
-      {
         \pgfpicture
-        \@@_vline_i:nn { #1 } { #2 }
+        \@@_vline_i:nn { #1 } { #2 } 
         \endpgfpicture
       }
   }
@@ -10449,20 +10796,95 @@
 %    \end{macrocode}
 %
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_vline_i:nn #1 #2 
+\cs_new_protected:Npn \@@_vline_i:nn #1 #2
   {
-    \CT at arc@
+%    \end{macrocode}
+% |\l_tmpa_tl| is the number of row and |\l_tmpb_tl| the number of column.
+%    \begin{macrocode}
+    \tl_set:Nx \l_tmpb_tl { #1 }
+    \int_step_variable:nNn \c at iRow \l_tmpa_tl
+      {
+%    \end{macrocode}
+% The boolean |\g_tmpa_bool| indicates whether the small vertical rule will be
+% drawn. If we find that it is in a block (a real block, created by |\Block| or
+% a virtual block corresponding to a dotted line, created by |\Cdots|, |\Vdots|,
+% etc.), we will set |\g_tmpa_bool| to |false| and the small vertical rule won't
+% be drawn.
+%    \begin{macrocode}
+         \bool_gset_true:N \g_tmpa_bool
+         \seq_map_inline:Nn \g_@@_pos_of_blocks_seq
+           { \@@_test_if_vline_in_block:nnnn ##1 }
+         \seq_map_inline:Nn \g_@@_pos_of_xdots_seq
+           { \@@_test_if_vline_in_block:nnnn ##1 }
+         \clist_if_empty:NF \l_@@_except_corners_clist
+           \@@_test_in_corner_v:
+         \bool_if:NT \g_tmpa_bool
+           { \@@_vline_ii:nnnn { #1 } { #2 } \l_tmpa_tl \l_tmpa_tl }
+      }
+  }
+%    \end{macrocode}
+%
+% \bigskip
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_test_in_corner_v:
+   {
+     \int_compare:nNnTF \l_tmpb_tl = { \@@_succ:n \c at jCol } 
+       {
+         \seq_if_in:NxT
+           \l_@@_empty_corner_cells_seq 
+           { \l_tmpa_tl - \@@_pred:n \l_tmpb_tl }
+           { \bool_set_false:N \g_tmpa_bool }
+       }
+       {
+         \seq_if_in:NxT
+           \l_@@_empty_corner_cells_seq 
+           { \l_tmpa_tl - \l_tmpb_tl }
+           { 
+             \int_compare:nNnTF \l_tmpb_tl = 1 
+               { \bool_set_false:N \g_tmpa_bool }
+               {
+                 \seq_if_in:NxT
+                   \l_@@_empty_corner_cells_seq 
+                   { \l_tmpa_tl - \@@_pred:n \l_tmpb_tl }
+                   { \bool_set_false:N \g_tmpa_bool }
+               }
+           } 
+       }
+   }
+%    \end{macrocode}
+% 
+% \bigskip
+% |#1| is the number of the column; |#2| is the number of vertical rules to
+% draw (with potentially a color between); |#3| and |#4| are the number of the
+% rows between which the rule has to be drawn.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_vline_ii:nnnn #1 #2 #3 #4
+  {
     \pgfrememberpicturepositiononpagetrue
     \pgf at relevantforpicturesizefalse
-    \pgfsetlinewidth { 1.1 \arrayrulewidth }
-    \pgfsetrectcap
-    \@@_qpoint:n { row - 1 }
+    \@@_qpoint:n { row - #3 }
     \dim_set_eq:NN \l_tmpa_dim \pgf at y
-    \@@_qpoint:n { col - \int_eval:n { #1 + 1 } }
+    \@@_qpoint:n { col - #1 }
     \dim_set_eq:NN \l_tmpb_dim \pgf at x
+    \@@_qpoint:n { row - \@@_succ:n { #4 } }
+    \dim_set_eq:NN \l_tmpc_dim \pgf at y
+    \bool_lazy_and:nnT
+      { \int_compare_p:nNn { #2 } > 1 }
+      { ! \tl_if_blank_p:V \CT at drsc@ }
+      {
+        \group_begin:
+        \CT at drsc@
+        \dim_add:Nn \l_tmpa_dim { 0.5 \arrayrulewidth }
+        \dim_sub:Nn \l_tmpc_dim { 0.5 \arrayrulewidth }
+        \dim_set:Nn \l_tmpd_dim
+          { \l_tmpb_dim - ( \doublerulesep + \arrayrulewidth ) * ( #2 - 1 ) } 
+        \pgfpathrectanglecorners
+          { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
+          { \pgfpoint \l_tmpd_dim \l_tmpc_dim }
+        \pgfusepathqfill
+        \group_end:
+      } 
     \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
-    \@@_qpoint:n { row - \@@_succ:n \c at iRow }
-    \dim_set_eq:NN \l_tmpc_dim \pgf at y
     \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
     \prg_replicate:nn { #2 - 1 }
       {
@@ -10471,269 +10893,216 @@
         \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
         \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
       }
+    \CT at arc@
+    \pgfsetlinewidth { 1.1 \arrayrulewidth }
+    \pgfsetrectcap
     \pgfusepathqstroke
   }
 %    \end{macrocode}
 %
 % \bigskip
-% The command |\@@_draw_vlines| will be executed when the user uses the option
-% |vlines| (which draws all the vlines of the array).
+% The following draws a complete vertical rule in the column |#1| (|#2| is the
+% number of consecutive rules specified by the number of \verb+|+ in the
+% preamble). This command will be used if there is no block in the array (and
+% the key |except-corners| is not used).
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_draw_vlines:
-  {
-    \group_begin:
+\cs_new_protected:Npn \@@_vline_i_complete:nn #1 #2
+  { \@@_vline_ii:nnnn { #1 } { #2 } 1 { \int_use:N \c at iRow } }
 %    \end{macrocode}
 %
-% The command |\CT at arc@| is a command of \pkg{colortbl} which sets the color of
-% the rules in the array. The package \pkg{nicematrix} uses it even when
-% \pkg{colortbl} is not loaded.
+% \bigskip
+% The command |\@@_draw_hlines:| draws all the vertical rules excepted in the
+% blocks, in the virtual blocks (determined by a command such as |\Cdots|) and in
+% the corners (if the key |except-corners| is used).
 %    \begin{macrocode}
-    \CT at arc@
-    \pgfpicture 
-    \pgfrememberpicturepositiononpagetrue
-    \pgf at relevantforpicturesizefalse
-    \pgfsetlinewidth \arrayrulewidth 
-    \pgfsetrectcap
-    \@@_qpoint:n { row - 1 }
-    \dim_set_eq:NN \l_tmpa_dim \pgf at y
-    \@@_qpoint:n { row - \@@_succ:n \c at iRow }
-    \dim_set_eq:NN \l_tmpb_dim \pgf at y
-%    \end{macrocode}
-%
-% Now, we can draw the vertical rules with a loop. 
-%    \begin{macrocode}
+\cs_new_protected:Npn \@@_draw_vlines:
+  {
     \int_step_inline:nnn 
-      { \bool_if:NTF \l_@@_NiceArray_bool 1 2 } 
-      { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c at jCol } \c at jCol } 
-      { 
-        \@@_qpoint:n { col - ##1 }
-        \dim_set_eq:NN \l_tmpc_dim \pgf at x
-        \pgfpathmoveto { \pgfpoint \l_tmpc_dim \l_tmpa_dim }
-        \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
-      }
-    \pgfusepathqstroke
-    \endpgfpicture
-    \group_end:
+      { \bool_if:NTF \l_@@_NiceArray_bool 1 2 }
+      { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c at jCol } \c at jCol }
+      { \@@_vline:nn { ##1 } 1 }
   }
 %    \end{macrocode}
 %
 %
-% \subsection*{The key hvlines}
+% 
+% \subsection*{The horizontal rules}
 %
-% \subsubsection*{The key hvlines}
-%
+% \bigskip
+% The following command will be executed in the |internal-code-after|. The row
+% will be drawn \emph{before} the row |#1|. |#2| is the number of consecutive
+% occurrences of |\Hline|.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_draw_hlines:
+\cs_new_protected:Npn \@@_hline:nn #1 #2
   {
     \pgfpicture
-    \CT at arc@
-    \pgfrememberpicturepositiononpagetrue
-    \pgf at relevantforpicturesizefalse    
-    \pgfsetlinewidth \arrayrulewidth 
-    \int_step_inline:nnn 
-      { \bool_if:NTF \l_@@_NiceArray_bool 1 2 } 
-      { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c at iRow } \c at iRow } 
-      {
-        \@@_qpoint:n { row - ##1 }
-        \dim_set_eq:NN \l_tmpa_dim \pgf at y
-        \pgfpathmoveto { \pgfpoint \pgf at x \pgf at y }
-        \@@_qpoint:n { col - \@@_succ:n { \c at jCol } }
-        \dim_set:Nn \l_tmpb_dim { \pgf at x + 0.5 \arrayrulewidth }
-        \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
-      }
-    \pgfusepathqstroke 
+    \@@_hline_i:nn { #1 } { #2 } 
     \endpgfpicture
   }
 %    \end{macrocode}
-% 
-% \bigskip
-% Since version 4.1, the key |hvlines| is no longer a mere alias for
-% the conjonction of |hlines| and |vlines|. Indeed, with |hvlines|, the vertical
-% and horizontal rules are \emph{not} drawn within the blocks (created by
-% |\Block|) nor within the ``virtual blocks'' (corresponding to the dotted lines
-% drawn by |\Cdots|, |\Vdots|, etc.).
-%    \begin{macrocode}
-\cs_new_protected:Npn \@@_draw_hvlines:
-  { 
-    \bool_lazy_and:nnTF
-     { \seq_if_empty_p:N \g_@@_pos_of_blocks_seq }
-     { \seq_if_empty_p:N \g_@@_pos_of_xdots_seq }
-     \@@_draw_hvlines_i:
-     \@@_draw_hvlines_ii:
-  }
-%    \end{macrocode}
 %
-% \bigskip 
-% This version is only for efficiency. The general case (in
-% |\@@_draw_hvlines_ii:|) does the job in all case (but slower).
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_draw_hvlines_i:
+\cs_new_protected:Npn \@@_hline_i:nn #1 #2
   {
-    \@@_draw_hlines:
-    \@@_draw_vlines:
-  }
 %    \end{macrocode}
-%
-% \bigskip
-% Now, the general case, where there are blocks or dots in the array.
+% |\l_tmpa_tl| is the number of row and |\l_tmpb_tl| the number of column.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_draw_hvlines_ii:
-  {
-    \group_begin:
-    \CT at arc@
-%    \end{macrocode}
-% 
-% The horizontal rules.
-%    \begin{macrocode}
-    \int_step_variable:nnNn 
-      { \bool_if:NTF \l_@@_NiceArray_bool 1 2 }
-      { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c at iRow } \c at iRow }
-      \l_tmpa_tl
+    \tl_set:Nn \l_tmpa_tl { #1 }
+    \int_step_variable:nNn \c at jCol \l_tmpb_tl
       {
-        \int_step_variable:nNn \c at jCol \l_tmpb_tl
-          {
 %    \end{macrocode}
 % The boolean |\g_tmpa_bool| indicates whether the small horizontal rule will be
 % drawn. If we find that it is in a block (a real block, created by |\Block| or
 % a virtual block corresponding to a dotted line, created by |\Cdots|, |\Vdots|,
-% etc.), we will set |\g_tmpa_bool| to |false| and the small horizontal rule
-% won't be drawn.
+% etc.), we will set |\g_tmpa_bool| to |false| and the small horizontal rule won't
+% be drawn.
 %    \begin{macrocode}
-            \bool_gset_true:N \g_tmpa_bool
-            \seq_map_inline:Nn \g_@@_pos_of_blocks_seq
-              { \@@_test_if_hline_in_block:nnnn ##1 }
-            \seq_map_inline:Nn \g_@@_pos_of_xdots_seq
-              { \@@_test_if_hline_in_block:nnnn ##1 }
+         \bool_gset_true:N \g_tmpa_bool
+         \seq_map_inline:Nn \g_@@_pos_of_blocks_seq
+           { \@@_test_if_hline_in_block:nnnn ##1 }
+         \seq_map_inline:Nn \g_@@_pos_of_xdots_seq
+           { \@@_test_if_hline_in_block:nnnn ##1 }
+         \clist_if_empty:NF \l_@@_except_corners_clist \@@_test_in_corner_h: 
+         \bool_if:NT \g_tmpa_bool
+           { \@@_hline_ii:nnnn { #1 } { #2 } \l_tmpb_tl \l_tmpb_tl }
+      }
+  }
 %    \end{macrocode}
+%
+% \bigskip
 %    \begin{macrocode}
-            \bool_if:NT \l_@@_hvlines_except_corners_bool
-              {
-                \int_compare:nNnTF \l_tmpa_tl = { \c at iRow + 1 }
-                  {
-                    \seq_if_in:NxT
-                      \l_@@_empty_corner_cells_seq 
-                      { \@@_pred:n \l_tmpa_tl - \l_tmpb_tl }
-                      { \bool_set_false:N \g_tmpa_bool }
-                  }
-                  {
-                    \seq_if_in:NxT
-                      \l_@@_empty_corner_cells_seq 
-                      { \l_tmpa_tl - \l_tmpb_tl }
-                      { 
-                        \int_compare:nNnTF \l_tmpa_tl = 1 
-                          { \bool_set_false:N \g_tmpa_bool }
-                          {
-                            \seq_if_in:NxT
-                              \l_@@_empty_corner_cells_seq 
-                              { \@@_pred:n \l_tmpa_tl - \l_tmpb_tl }
-                              { \bool_set_false:N \g_tmpa_bool }
-                          }
-                      } 
-                  }
-              }
+\cs_new_protected:Npn \@@_test_in_corner_h:
+   {
+     \int_compare:nNnTF \l_tmpa_tl = { \@@_succ:n \c at iRow }
+       {
+         \seq_if_in:NxT
+           \l_@@_empty_corner_cells_seq 
+           { \@@_pred:n \l_tmpa_tl - \l_tmpb_tl }
+           { \bool_set_false:N \g_tmpa_bool }
+       }
+       {
+         \seq_if_in:NxT
+           \l_@@_empty_corner_cells_seq 
+           { \l_tmpa_tl - \l_tmpb_tl }
+           { 
+             \int_compare:nNnTF \l_tmpa_tl = 1 
+               { \bool_set_false:N \g_tmpa_bool }
+               {
+                 \seq_if_in:NxT
+                   \l_@@_empty_corner_cells_seq 
+                   { \@@_pred:n \l_tmpa_tl - \l_tmpb_tl }
+                   { \bool_set_false:N \g_tmpa_bool }
+               }
+           } 
+       }
+   }
 %    \end{macrocode}
+% 
+% \bigskip
+% |#1| is the number of the row; |#2| is the number of horizontal rules to
+% draw (with potentially a color between); |#3| and |#4| are the number of the
+% columns between which the rule has to be drawn.
 %    \begin{macrocode}
-            \bool_if:NT \g_tmpa_bool
-              {
-                \pgfpicture
-                \pgfrememberpicturepositiononpagetrue
-                \pgf at relevantforpicturesizefalse
-                \pgfsetlinewidth \arrayrulewidth 
-                \pgfsetrectcap
-                \@@_qpoint:n { row - \l_tmpa_tl }
-                \dim_set_eq:NN \l_tmpb_dim \pgf at y
-                \@@_qpoint:n { col - \l_tmpb_tl }
-                \dim_set_eq:NN \l_tmpa_dim \pgf at x
-                \@@_qpoint:n { col - \@@_succ:n \l_tmpb_tl }
-                \dim_set_eq:NN \l_tmpc_dim \pgf at x
-                \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
-                \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
-                \pgfusepathqstroke 
-                \endpgfpicture
-              }
-          }
+\cs_new_protected:Npn \@@_hline_ii:nnnn #1 #2 #3 #4
+  {
+    \pgfrememberpicturepositiononpagetrue
+    \pgf at relevantforpicturesizefalse
+    \@@_qpoint:n { col - #3 }
+    \dim_set_eq:NN \l_tmpa_dim \pgf at x
+    \@@_qpoint:n { row - #1 }
+    \dim_set_eq:NN \l_tmpb_dim \pgf at y
+    \@@_qpoint:n { col - \@@_succ:n { #4 } }
+    \dim_set_eq:NN \l_tmpc_dim \pgf at x
+    \bool_lazy_and:nnT
+      { \int_compare_p:nNn { #2 } > 1 }
+      { ! \tl_if_blank_p:V \CT at drsc@ }
+      {
+        \group_begin:
+        \CT at drsc@
+        \dim_set:Nn \l_tmpd_dim
+          { \l_tmpb_dim - ( \doublerulesep + \arrayrulewidth ) * ( #2 - 1 ) } 
+        \pgfpathrectanglecorners
+          { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
+          { \pgfpoint \l_tmpc_dim \l_tmpd_dim }
+        \pgfusepathqfill
+        \group_end:
+      } 
+    \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
+    \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
+    \prg_replicate:nn { #2 - 1 }
+      {
+        \dim_sub:Nn \l_tmpb_dim \arrayrulewidth
+        \dim_sub:Nn \l_tmpb_dim \doublerulesep
+        \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
+        \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
       }
+    \CT at arc@
+    \pgfsetlinewidth { 1.1 \arrayrulewidth }
+    \pgfsetrectcap
+    \pgfusepathqstroke
+  }
 %    \end{macrocode}
-% Now, the vertical rules.
+%
+% \bigskip
 %    \begin{macrocode}
-    \int_step_variable:nNn \c at iRow \l_tmpa_tl
-      {
-        \int_step_variable:nnNn 
-          { \bool_if:NTF \l_@@_NiceArray_bool 1 2 }
-          { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c at jCol } \c at jCol }  
-          \l_tmpb_tl
-          {
+\cs_new_protected:Npn \@@_hline_i_complete:nn #1 #2
+  { \@@_hline_ii:nnnn #1 #2 1 { \int_use:N \c at jCol } }
 %    \end{macrocode}
-% The boolean |\g_tmpa_bool| indicates whether the small vertical rule will be
-% drawn. If we find that it is in a block (a real block, created by |\Block| or
-% a virtual block corresponding to a dotted line, created by |\Cdots|, |\Vdots|,
-% etc.), we will set |\g_tmpa_bool| to |false| and the small vertical rule won't
-% be drawn.
+% 
+% \bigskip
+% The command |\@@_draw_hlines:| draws all the horizontal rules excepted in the
+% blocks (even the virtual drawn determined by commands such as |\Cdots| and in
+% the corners (if the key |except-corners| is used).
 %    \begin{macrocode}
-            \bool_gset_true:N \g_tmpa_bool
-            \seq_map_inline:Nn \g_@@_pos_of_blocks_seq
-              { \@@_test_if_vline_in_block:nnnn ##1 }
-            \seq_map_inline:Nn \g_@@_pos_of_xdots_seq
-              { \@@_test_if_vline_in_block:nnnn ##1 }
+\cs_new_protected:Npn \@@_draw_hlines:
+  {
+    \int_step_inline:nnn 
+      { \bool_if:NTF \l_@@_NiceArray_bool 1 2 }
+      { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c at iRow } \c at iRow }  
+      { \@@_hline:nn { ##1 } 1 }
+  }
 %    \end{macrocode}
 %
+%
+% \medskip
+% The command |\@@_Hline:| will be linked to |\Hline| in the environments of \pkg{nicematrix}.
 %    \begin{macrocode}
-            \bool_if:NT \l_@@_hvlines_except_corners_bool
-              {
-                \int_compare:nNnTF \l_tmpb_tl = { \@@_succ:n \c at jCol } 
-                  {
-                    \seq_if_in:NxT
-                      \l_@@_empty_corner_cells_seq 
-                      { \l_tmpa_tl - \@@_pred:n \l_tmpb_tl }
-                      { \bool_set_false:N \g_tmpa_bool }
-                  }
-                  {
-                    \seq_if_in:NxT
-                      \l_@@_empty_corner_cells_seq 
-                      { \l_tmpa_tl - \l_tmpb_tl }
-                      { 
-                        \int_compare:nNnTF \l_tmpb_tl = 1 
-                          { \bool_set_false:N \g_tmpa_bool }
-                          {
-                            \seq_if_in:NxT
-                              \l_@@_empty_corner_cells_seq 
-                              { \l_tmpa_tl - \@@_pred:n \l_tmpb_tl }
-                              { \bool_set_false:N \g_tmpa_bool }
-                          }
-                      } 
-                  }
-              }
+\cs_set:Npn \@@_Hline: { \noalign { \ifnum 0 = `} \fi \@@_Hline_i:n { 1 } }
 %    \end{macrocode}
+%
+% \medskip
+% The argument of the command |\@@_Hline_i:n| is the number of successive
+% |\Hline| found.
+%    \begin{macrocode}
+\cs_set:Npn \@@_Hline_i:n #1
+  { 
+    \peek_meaning_ignore_spaces:NTF \Hline
+      { \@@_Hline_ii:nn { #1 + 1 } } 
+      { \@@_Hline_iii:n { #1 } }
+  }
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+\cs_set:Npn \@@_Hline_ii:nn #1 #2 { \@@_Hline_i:n { #1 } }
+%    \end{macrocode}
 % 
 %    \begin{macrocode}
-            \bool_if:NT \g_tmpa_bool
-              {
-                \pgfpicture
-                \pgfrememberpicturepositiononpagetrue
-                \pgf at relevantforpicturesizefalse
-                \pgfsetlinewidth \arrayrulewidth 
-                \pgfsetrectcap
-                \@@_qpoint:n { row - \l_tmpa_tl }
-                \dim_set_eq:NN \l_tmpb_dim \pgf at y
-                \@@_qpoint:n { col - \l_tmpb_tl }
-                \dim_set_eq:NN \l_tmpa_dim \pgf at x
-                \@@_qpoint:n { row - \@@_succ:n \l_tmpa_tl }
-                \dim_set_eq:NN \l_tmpc_dim \pgf at y
-                \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
-                \pgfpathlineto { \pgfpoint \l_tmpa_dim \l_tmpc_dim }
-                \pgfusepathqstroke 
-                \endpgfpicture
-              }
-          }
+\cs_set:Npn \@@_Hline_iii:n #1 
+  {
+    \skip_vertical:n 
+      {
+        \arrayrulewidth * ( #1 )
+        + \doublerulesep * ( \int_max:nn 0 { #1 - 1 } ) 
       }
-%    \end{macrocode}
-% The group was for the color of the rules.
-%    \begin{macrocode}
-    \group_end:
-    \seq_gclear:N \g_@@_pos_of_xdots_seq
+    \tl_gput_right:Nx \g_@@_internal_code_after_tl
+      { \@@_hline:nn { \@@_succ:n { \c at iRow } } { #1 } }
+    \ifnum 0 = `{ \fi } 
   }
 %    \end{macrocode}
+% 
+% \subsection*{The key hvlines}
 %
+%
 % The following command tests wether the current position in the array (given by
 % |\l_tmpa_tl| for the row and |\l_tmpb_tl| for the col) would provide an
 % horizontal rule towards the right in the block delimited by the four arguments
@@ -10770,25 +11139,39 @@
 %
 %
 % \bigskip
-% \subsubsection*{The key hvlines-except-corners}
+% \subsubsection*{The key except-corners}
 %
+% When the key |except-corners| is raised, the rules are not drawn in the
+% corners. Of course, we have to compute the corners before we begin to draw the
+% rules. 
 % 
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_draw_hvlines_except_corners:
+\cs_new_protected:Npn \@@_compute_corners:
   {
 %    \end{macrocode}
 % The sequence |\l_@@_empty_corner_cells_seq| will be the sequence of all the
-% cells empty (and not in a block) considered in the corners of the array.
+% empty cells (and not in a block) considered in the corners of the array.
 %    \begin{macrocode}
     \seq_clear_new:N \l_@@_empty_corner_cells_seq
-    \@@_compute_a_corner:nnnnnn 1 1 1 1 \c at iRow \c at jCol
-    \@@_compute_a_corner:nnnnnn 1 \c at jCol 1 { -1 } \c at iRow 1
-    \@@_compute_a_corner:nnnnnn \c at iRow 1 { -1 } 1 1 \c at jCol
-    \@@_compute_a_corner:nnnnnn \c at iRow \c at jCol { -1 } { -1 } 1 1
-    \@@_draw_hvlines_ii:
+    \clist_map_inline:Nn \l_@@_except_corners_clist 
+      {
+        \str_case:nnF { ##1 }
+          {
+            { NW } 
+            { \@@_compute_a_corner:nnnnnn 1 1 1 1 \c at iRow \c at jCol }
+            { NE } 
+            { \@@_compute_a_corner:nnnnnn 1 \c at jCol 1 { -1 } \c at iRow 1 }
+            { SW } 
+            { \@@_compute_a_corner:nnnnnn \c at iRow 1 { -1 } 1 1 \c at jCol }
+            { SE } 
+            { \@@_compute_a_corner:nnnnnn \c at iRow \c at jCol { -1 } { -1 } 1 1 } 
+          }
+          { \@@_error:nn { bad~corner } { ##1 } }
+      }
   }
 %    \end{macrocode}
 %
+%
 % \bigskip
 % ``Computing a corner'' is determining all the empty cells (which are not in a
 % block) that belong to that corner. These cells will be added to the sequence 
@@ -10798,11 +11181,11 @@
 % The six arguments of |\@@_compute_a_corner:nnnnnn| are as follow:
 % \begin{itemize}
 % \item |#1| and |#2| are the number of row and column of the cell which is
-% actually in the corner ;
-% \item |#3| and |#4| are the step in rows and the step in columns when moving
-% from the corner ;
+% actually in the corner;
+% \item |#3| and |#4| are the steps in rows and the step in columns when moving
+% from the corner;
 % \item |#5| is the number of the final row when scanning the rows from the
-% corner ;
+% corner;
 % \item |#6| is the number of the final column when scanning the columns from
 % the corner.
 % \end{itemize}
@@ -10818,17 +11201,17 @@
 % |\l_tmpa_bool| will be raised when a non-empty cell is found.
 %    \begin{macrocode}
     \bool_set_false:N \l_tmpa_bool
-    \int_zero_new:N \l_@@_last_empty_row_int
+    \int_zero_new:N \l_@@_last_empty_row_int 
+    \int_set:Nn \l_@@_last_empty_row_int { #1 }
     \int_step_inline:nnnn { #1 } { #3 } { #5 }
       {
         \@@_test_if_cell_in_a_block:nn { ##1 } { \int_eval:n { #2 } }
-        \bool_if:nTF
+        \bool_lazy_or:nnTF
           {
              \cs_if_exist_p:c
                { pgf @ sh @ ns @ \@@_env: - ##1 - \int_eval:n { #2 } }
-             ||
-             \l_tmpb_bool
           }
+          \l_tmpb_bool
           { \bool_set_true:N \l_tmpa_bool }
           { 
             \bool_if:NF \l_tmpa_bool
@@ -10839,15 +11222,16 @@
 % Now, you determine the last empty cell in the row of number~$1$.
 %    \begin{macrocode}
     \bool_set_false:N \l_tmpa_bool
-    \int_zero_new:N \l_@@_last_empty_column_int
+    \int_zero_new:N \l_@@_last_empty_column_int 
+    \int_set:Nn \l_@@_last_empty_column_int { #2 }
     \int_step_inline:nnnn { #2 } { #4 } { #6 }
       {
         \@@_test_if_cell_in_a_block:nn { \int_eval:n { #1 } } { ##1 } 
-        \bool_if:nTF
+        \bool_lazy_or:nnTF
+          \l_tmpb_bool
           {
             \cs_if_exist_p:c
               { pgf @ sh @ ns @ \@@_env: - \int_eval:n { #1 } - ##1 }
-            || \l_tmpb_bool
           }
           { \bool_set_true:N \l_tmpa_bool }
           { 
@@ -10867,11 +11251,11 @@
         \int_step_inline:nnnn { #2 } { #4 } \l_@@_last_empty_column_int
           {
             \@@_test_if_cell_in_a_block:nn { ##1 } { ####1 }
-            \bool_if:nTF
+            \bool_lazy_or:nnTF
+              \l_tmpb_bool
               {
-                 \cs_if_exist_p:c
-                   { pgf @ sh @ ns @ \@@_env: - ##1 - ####1 }
-                 || \l_tmpb_bool
+                \cs_if_exist_p:c
+                  { pgf @ sh @ ns @ \@@_env: - ##1 - ####1 }
               }
               { \bool_set_true:N \l_tmpa_bool }
               { 
@@ -10901,7 +11285,7 @@
     \int_set:Nn \l_tmpb_int { #2 }
     \bool_set_false:N \l_tmpb_bool
     \seq_map_inline:Nn \g_@@_pos_of_blocks_seq 
-      { \@@_test_if_cell_in_block:nnnnnnn { \l_tmpa_int } { \l_tmpb_int } ##1 }
+      { \@@_test_if_cell_in_block:nnnnnnn \l_tmpa_int \l_tmpb_int ##1 }
   }
 %    \end{macrocode}
 % 
@@ -10909,14 +11293,17 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_test_if_cell_in_block:nnnnnnn #1 #2 #3 #4 #5 #6
   {
-    \bool_lazy_all:nT
-      {
-        { \int_compare_p:n { #3 <= #1 } }
-        { \int_compare_p:n { #1 <= #5 } }
-        { \int_compare_p:n { #4 <= #2 } }
-        { \int_compare_p:n { #2 <= #6 } }
+    \int_compare:nNnT { #3 } < { \@@_succ:n { #1 } } 
+      { 
+        \int_compare:nNnT { #1 } < { \@@_succ:n { #5 } }
+          { 
+            \int_compare:nNnT { #4 } < { \@@_succ:n { #2 } } 
+              {
+                \int_compare:nNnT { #2 } < { \@@_succ:n { #6 } } 
+                  { \bool_set_true:N \l_tmpb_bool }
+              }
+          }
       }
-    { \bool_set_true:N \l_tmpb_bool }
   }
 %    \end{macrocode}
 %
@@ -11564,7 +11951,7 @@
 % put before the math mode of the label)
 %
 % It's mandatory to use a expandable command (probably because of the first
-% optional argument ?).
+% optional argument?).
 %    \begin{macrocode}
 \NewExpandableDocumentCommand \@@_Block: { O { } m D < > { } m }
   { \@@_Block_i #2 \q_stop { #1 } { #3 } { #4 } }
@@ -11663,7 +12050,7 @@
 %    \begin{macrocode}
     \tl_if_empty:NF \l_@@_color_tl
       {
-        \tl_gput_right:Nx \g_@@_code_before_tl
+        \tl_gput_right:Nx \g_nicematrix_code_before_tl
           { 
             \exp_not:N \rectanglecolor 
               { \l_@@_color_tl } 
@@ -11690,7 +12077,7 @@
 %    \begin{macrocode}
     \bool_lazy_or:nnTF
       { \int_compare_p:nNn { #3 } > \g_@@_row_total_int } 
-      { \int_compare_p:nNn { #4 } > \c at jCol }
+      { \int_compare_p:nNn { #4 } > \g_@@_col_total_int }
       { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } }
       {
 %    \end{macrocode}
@@ -11995,7 +12382,7 @@
 % \subsection*{The redefinition of the command \textbackslash dotfill }
 %
 %    \begin{macrocode}
-\cs_set_eq:NN \@@_dotfill \dotfill
+\cs_set_eq:NN \@@_old_dotfill \dotfill
 \cs_new_protected:Npn \@@_dotfill: 
   { 
 %    \end{macrocode}
@@ -12002,7 +12389,7 @@
 % First, we insert |\@@_dotfill| (which is the saved version of |\dotfill|) in
 % case of use of |\dotfill| ``internally'' in the cell (e.g. |\hbox to 1cm {\dotfill}|).
 %    \begin{macrocode}
-    \@@_dotfill
+    \@@_old_dotfill
     \bool_if:NT \l_@@_NiceTabular_bool
       { \group_insert_after:N \@@_dotfill_ii: }
       { \group_insert_after:N \@@_dotfill_i: }
@@ -12016,7 +12403,7 @@
 % array, and it will extend, since it is no longer in |\l_@@_cell_box|.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_dotfill_iii: 
-  { \dim_compare:nNnT { \box_wd:N \l_@@_cell_box } = \c_zero_dim  \@@_dotfill } 
+  { \dim_compare:nNnT { \box_wd:N \l_@@_cell_box } = \c_zero_dim  \@@_old_dotfill } 
 %    \end{macrocode}
 % 
 % \bigskip
@@ -12041,7 +12428,7 @@
 %    \end{macrocode}
 % We put the cell with |\diagbox| in the sequence |\g_@@_pos_of_blocks_seq|
 % because a cell with |\diagbox| must be considered as non empty by the key 
-% |hvlines-except-corners|.
+% |except-corners|.
 %    \begin{macrocode}
     \seq_gput_right:Nx \g_@@_pos_of_blocks_seq
       {
@@ -12425,15 +12812,6 @@
   }
 %    \end{macrocode}
 %
-%
-%    \begin{macrocode}
-\@@_msg_new:nn { option~S~without~siunitx }
-  {
-    You~can't~use~the~option~'S'~in~your~environment~\@@_full_name_env:
-    because~you~have~not~loaded~siunitx.\\
-    If~you~go~on,~this~option~will~be~ignored.
-  }
-%    \end{macrocode}
 % 
 %    \begin{macrocode}  
 \@@_msg_new:nn { bad~option~for~line-style }
@@ -12452,6 +12830,14 @@
   }
 %    \end{macrocode}
 %
+%    \begin{macrocode}
+\@@_msg_new:nn { Unknown~option~for~rowcolors } 
+  {
+    As~for~now~there~is~only~one~option~available~here:~'respect-blocks'~
+    (and~you~try~to~use~'\l_keys_key_tl').~If~you~go~on,~
+    this~option~will~be~ignored. 
+  }
+%    \end{macrocode}
 %
 %    \begin{macrocode}
 \@@_msg_new:nn { ampersand~in~light-syntax }
@@ -12504,8 +12890,17 @@
   }
 %    \end{macrocode}
 %
-%
 %    \begin{macrocode}
+\@@_msg_new:nn { bad~corner }
+  {
+    #1~is~an~incorrect~specification~for~a~corner~(in~the~keys~
+    'except-corners'~and~'hvlines-except-corners').~The~available~
+    values~are:~NW,~SW,~NE~and~SE.\\
+    If~you~go~on,~this~specification~of~corner~will~be~ignored.
+  }
+%    \end{macrocode}
+% 
+%    \begin{macrocode}
 \@@_msg_new:nn { last-col~non~empty~for~NiceArray }
   {
     In~the~\@@_full_name_env:,~you~must~use~the~option~
@@ -12780,7 +13175,6 @@
     right-margin,~
     rules/color,~
     rules/width,~
-    S,~
     small,~
     t,~
     vlines,~
@@ -12849,7 +13243,8 @@
     the~same~environment~name~twice.~You~can~go~on,~but,~
     maybe,~you~will~have~incorrect~results~especially~ 
     if~you~use~'columns-width=auto'.~If~you~don't~want~to~see~this~
-    message~again,~use~the~option~'allow-duplicate-names'.\\
+    message~again,~use~the~option~'allow-duplicate-names'~in~
+    '\token_to_str:N \NiceMatrixOptions'.\\
     For~a~list~of~the~names~already~used,~type~H~<return>. \\ 
   }
   {
@@ -13208,7 +13603,20 @@
 %
 % The variable |\g_nicematrix_code_after_tl| is now public.
 %
+% \subsection*{Changes between versions 5.1 and 5.2}
 %
+% The vertical rules specified by \verb+|+ or \verb+||+ in the preamble respect
+% the blocks.
+% 
+% Key |respect-blocks| for |\rowcolors| (with a \emph{s}) in the |code-before|.
+%
+% The variable |\g_nicematrix_code_before_tl| is now public.
+%
+% The key |baseline| can take in as value of the form \textsl{line-i} to align
+% the |\hline| in the row \textsl{i}.
+%
+% The key |hvlines-except-corners| may take in as value a list of corner (eg: NW,SE).
+%
 % \PrintIndex
 % 
 % \tableofcontents

Modified: trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty	2020-08-20 21:10:48 UTC (rev 56141)
+++ trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty	2020-08-20 21:11:01 UTC (rev 56142)
@@ -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.1}
-\def\myfiledate{2020/07/31}
+\def\myfileversion{5.2}
+\def\myfiledate{2020/08/19}
 
 \RequirePackage{pgfcore}
 \usepgfmodule{shapes}
@@ -113,8 +113,15 @@
         \cs_set:Npn \CT at arc #1 #2
           {
             \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign
-             { \cs_gset:Npn \CT at arc@ { \color #1 { #2 } } }
+            { \cs_gset:Npn \CT at arc@ { \color #1 { #2 } } }
           }
+        \cs_set_protected:Npn \CT at drsc@ { }
+        \cs_set:Npn \doublerulesepcolor #1 # { \CT at drs { #1 } }
+        \cs_set:Npn\CT at drs #1 #2
+          {
+            \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign
+            { \cs_gset:Npn \CT at drsc@ { \color #1 { #2 } } }
+          }
         \cs_set:Npn \hline
           {
             \noalign { \ifnum 0 = `} \fi
@@ -133,7 +140,11 @@
     \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & }
     \int_compare:nNnT { #1 } > 1 { \multispan { \__nicematrix_pred:n { #1 } } & }
     \multispan { \int_eval:n { #2 - #1 + 1 } }
-    { \CT at arc@ \leaders \hrule \@height \arrayrulewidth \hfill }
+    {
+      \CT at arc@
+      \leaders \hrule \@height \arrayrulewidth \hfill
+      \skip_horizontal:N \c_zero_dim
+    }
     \everycr { }
     \cr
     \noalign { \skip_vertical:N -\arrayrulewidth }
@@ -146,7 +157,11 @@
     \int_compare:nNnT { #1 } < { #2 }
       { \multispan { \int_eval:n { #2 - #1 } } & }
     \multispan { \int_eval:n { #3 - #2 + 1 } }
-      { \CT at arc@ \leaders \hrule \@height \arrayrulewidth \hfill }
+      {
+        \CT at arc@
+        \leaders \hrule \@height \arrayrulewidth \hfill
+        \skip_horizontal:N \c_zero_dim
+      }
     \peek_meaning_remove_ignore_spaces:NTF \cline
       { & \__nicematrix_cline_i:en { \__nicematrix_succ:n { #3 } } }
       { \everycr { } \cr }
@@ -217,7 +232,7 @@
       {
         \ExplSyntaxOn
         \cs_if_free:NT \pgfsyspdfmark
-          { \cs_set_eq:NN \pgfsyspdfmark \use:nnn }
+          { \cs_set_eq:NN \pgfsyspdfmark \@gobblethree }
         \ExplSyntaxOff
       }
     \cs_gset_eq:NN \__nicematrix_provide_pgfsyspdfmark: \prg_do_nothing:
@@ -252,7 +267,7 @@
 \colorlet { nicematrix-last-col } { . }
 \colorlet { nicematrix-last-row } { . }
 \str_new:N \g__nicematrix_name_env_str
-\str_set:Nn \g__nicematrix_com_or_env_str { environment }
+\tl_set:Nn \g__nicematrix_com_or_env_str { environment }
 \cs_new:Npn \__nicematrix_full_name_env:
   {
     \str_if_eq:VnTF \g__nicematrix_com_or_env_str { command }
@@ -296,7 +311,7 @@
 \newcounter { tabularnote }
 \seq_new:N \g__nicematrix_tabularnotes_seq
 \int_new:N \l__nicematrix_number_of_notes_int
-\cs_new:Npn \__nicematrix_notes_style:n #1 { \emph { \alph { #1 } } }
+\cs_new:Npn \__nicematrix_notes_style:n #1 { \textit { \alph { #1 } } }
 \cs_new:Npn \__nicematrix_notes_label_in_tabular:n #1 { \textsuperscript { #1 } }
 \cs_new:Npn \__nicematrix_notes_label_in_list:n #1 { \textsuperscript { #1 } }
 \cs_set:Npn \thetabularnote { { \__nicematrix_notes_style:n { tabularnote } } }
@@ -420,14 +435,13 @@
 \tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl
 \bool_new:N \l__nicematrix_light_syntax_bool
 \str_new:N \l__nicematrix_baseline_str
-\str_set:Nn \l__nicematrix_baseline_str c
+\tl_set:Nn \l__nicematrix_baseline_str c
 \bool_new:N \l__nicematrix_exterior_arraycolsep_bool
 \bool_new:N \l__nicematrix_parallelize_diags_bool
 \bool_set_true:N \l__nicematrix_parallelize_diags_bool
+\bool_new:N \l__nicematrix_vlines_bool
 \bool_new:N \l__nicematrix_hlines_bool
-\bool_new:N \l__nicematrix_vlines_bool
-\bool_new:N \l__nicematrix_hvlines_bool
-\bool_new:N \l__nicematrix_hvlines_except_corners_bool
+\clist_new:N \l__nicematrix_except_corners_clist
 \dim_new:N \l__nicematrix_notes_above_space_dim
 \dim_set:Nn \l__nicematrix_notes_above_space_dim { 1 mm }
 \bool_new:N \l__nicematrix_nullify_dots_bool
@@ -499,7 +513,6 @@
     vlines .bool_set:N = \l__nicematrix_vlines_bool ,
     hvlines .code:n =
       {
-        \bool_set_true:N \l__nicematrix_hvlines_bool
         \bool_set_true:N \l__nicematrix_vlines_bool
         \bool_set_true:N \l__nicematrix_hlines_bool
       } ,
@@ -525,23 +538,30 @@
   }
 \keys_define:nn { NiceMatrix / Env }
   {
-    hvlines-except-corners .bool_set:N = \l__nicematrix_hvlines_except_corners_bool ,
-    hvlines-except-corners .default:n = true ,
-    code-before .code:n =
+    except-corners .clist_set:N = \l__nicematrix_except_corners_clist ,
+    except-corners .default:n = { NW , SW , NE , SE } ,
+    hvlines-except-corners .code:n =
       {
-        \tl_if_empty:nF { #1 }
-          {
-            \tl_put_right:Nn \l__nicematrix_code_before_tl { #1 }
-            \bool_set_true:N \l__nicematrix_code_before_bool
-          }
+        \clist_set:Nn \l__nicematrix_except_corners_clist { #1 }
+        \bool_set_true:N \l__nicematrix_vlines_bool
+        \bool_set_true:N \l__nicematrix_hlines_bool
       } ,
-    c .code:n = \str_set:Nn \l__nicematrix_baseline_str c ,
-    t .code:n = \str_set:Nn \l__nicematrix_baseline_str t ,
-    b .code:n = \str_set:Nn \l__nicematrix_baseline_str b ,
+    hvlines-except-corners .default:n = { NW , SW , NE , SE } ,
+    code-before .code:n =
+     {
+       \tl_if_empty:nF { #1 }
+         {
+           \tl_put_right:Nn \l__nicematrix_code_before_tl { #1 }
+           \bool_set_true:N \l__nicematrix_code_before_bool
+         }
+     } ,
+    c .code:n = \tl_set:Nn \l__nicematrix_baseline_str c ,
+    t .code:n = \tl_set:Nn \l__nicematrix_baseline_str t ,
+    b .code:n = \tl_set:Nn \l__nicematrix_baseline_str b ,
     baseline .tl_set:N = \l__nicematrix_baseline_str ,
     baseline .value_required:n = true ,
     columns-width .code:n =
-      \str_if_eq:nnTF { #1 } { auto }
+      \tl_if_eq:nnTF { #1 } { auto }
         { \bool_set_true:N \l__nicematrix_auto_columns_width_bool }
         { \dim_set:Nn \l__nicematrix_columns_width_dim { #1 } } ,
     columns-width .value_required:n = true ,
@@ -663,7 +683,7 @@
     transparent .value_forbidden:n = true,
     exterior-arraycolsep .bool_set:N = \l__nicematrix_exterior_arraycolsep_bool ,
     columns-width .code:n =
-      \str_if_eq:nnTF { #1 } { auto }
+      \tl_if_eq:nnTF { #1 } { auto }
         { \__nicematrix_error:n { Option~auto~for~columns-width } }
         { \dim_set:Nn \l__nicematrix_columns_width_dim { #1 } } ,
     allow-duplicate-names .code:n =
@@ -671,7 +691,7 @@
     allow-duplicate-names .value_forbidden:n = true ,
     letter-for-dotted-lines .code:n =
       {
-        \int_compare:nTF { \tl_count:n { #1 } = 1 }
+        \tl_if_single_token:nTF { #1 }
           { \str_set:Nx \l__nicematrix_letter_for_dotted_lines_str { #1 } }
           { \__nicematrix_error:n { Bad~value~for~letter~for~dotted~lines } }
       } ,
@@ -694,9 +714,6 @@
                          { \int_set:Nn \l__nicematrix_last_col_int { #1 } } ,
     l .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl l ,
     r .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl r ,
-    S .code:n = \bool_if:NTF \c__nicematrix_siunitx_loaded_bool
-                  { \tl_set:Nn \l__nicematrix_type_of_col_tl S }
-                  { \__nicematrix_error:n { option~S~without~siunitx } } ,
     small .bool_set:N = \l__nicematrix_small_bool ,
     small .value_forbidden:n = true ,
     unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceMatrix }
@@ -1002,6 +1019,7 @@
     \cs_set_eq:NN \Ddots \__nicematrix_Ddots
     \cs_set_eq:NN \Iddots \__nicematrix_Iddots
     \cs_set_eq:NN \hdottedline \__nicematrix_hdottedline:
+    \cs_set_eq:NN \Hline \__nicematrix_Hline:
     \cs_set_eq:NN \Hspace \__nicematrix_Hspace:
     \cs_set_eq:NN \Hdotsfor \__nicematrix_Hdotsfor:
     \cs_set_eq:NN \Vdotsfor \__nicematrix_Vdotsfor:
@@ -1009,7 +1027,7 @@
     \cs_set_eq:NN \Block \__nicematrix_Block:
     \cs_set_eq:NN \rotate \__nicematrix_rotate:
     \cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n
-    \cs_set_eq:NN \dotfill \__nicematrix_dotfill:
+    \cs_set_eq:NN \dotfill \__nicematrix_old_dotfill:
     \cs_set_eq:NN \CodeAfter \__nicematrix_CodeAfter:n
     \cs_set_eq:NN \diagbox \__nicematrix_diagbox:nn
     \bool_if:NT \l__nicematrix_colortbl_like_bool \__nicematrix_colortbl_like:
@@ -1028,7 +1046,7 @@
     \tl_gclear_new:N \g__nicematrix_Ddots_lines_tl
     \tl_gclear_new:N \g__nicematrix_Iddots_lines_tl
     \tl_gclear_new:N \g__nicematrix_HVdotsfor_lines_tl
-    \tl_gclear_new:N \g__nicematrix_code_before_tl
+    \tl_gclear_new:N \g_nicematrix_code_before_tl
   }
 \NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } }
   {
@@ -1056,9 +1074,9 @@
     \int_gincr:N \g__nicematrix_env_int
     \bool_if:NF \l__nicematrix_block_auto_columns_width_bool
       { \dim_gzero_new:N \g__nicematrix_max_cell_width_dim }
-    \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nicematrix_vline: }
-    \seq_clear:N \g__nicematrix_blocks_seq
-    \seq_clear:N \g__nicematrix_pos_of_blocks_seq
+    \seq_gclear:N \g__nicematrix_blocks_seq
+    \seq_gclear:N \g__nicematrix_pos_of_blocks_seq
+    \seq_gclear:N \g__nicematrix_pos_of_xdots_seq
     \tl_if_exist:cT { g__nicematrix_code_before_ \int_use:N \g__nicematrix_env_int _ tl }
       {
         \bool_set_true:N \l__nicematrix_code_before_bool
@@ -1364,7 +1382,6 @@
         l { \__nicematrix_patch_preamble_i:n #1 }
         r { \__nicematrix_patch_preamble_i:n #1 }
         > { \__nicematrix_patch_preamble_ii:nn #1 }
-        < { \__nicematrix_patch_preamble_ii:nn #1 }
         ! { \__nicematrix_patch_preamble_ii:nn #1 }
         @ { \__nicematrix_patch_preamble_ii:nn #1 }
         | { \__nicematrix_patch_preamble_iii:n #1 }
@@ -1386,12 +1403,7 @@
   {
     \tl_gput_right:Nn \g__nicematrix_preamble_tl { > \__nicematrix_Cell: #1 < \__nicematrix_end_Cell: }
     \int_gincr:N \c at jCol
-    \bool_if:NT \l__nicematrix_vlines_bool
-      {
-        \tl_gput_right:Nn \g__nicematrix_preamble_tl
-          { ! { \skip_horizontal:N \arrayrulewidth } }
-      }
-    \__nicematrix_patch_preamble:n
+    \__nicematrix_patch_preamble_viii:n
   }
 \cs_new_protected:Npn \__nicematrix_patch_preamble_ii:nn #1 #2
   {
@@ -1423,7 +1435,7 @@
               }
           }
         \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl
-          { \__nicematrix_vline:nn { \int_use:N \c at jCol } { \int_use:N \l_tmpa_int } }
+          { \__nicematrix_vline:nn { \__nicematrix_succ:n \c at jCol } { \int_use:N \l_tmpa_int } }
         \int_zero:N \l_tmpa_int
         \__nicematrix_patch_preamble:n #1
       }
@@ -1442,7 +1454,7 @@
         < { \box_use:N \@arstrutbox \end { minipage } \__nicematrix_end_Cell: }
       }
     \int_gincr:N \c at jCol
-    \__nicematrix_patch_preamble:n
+    \__nicematrix_patch_preamble_viii:n
   }
 \cs_new_protected:Npn \__nicematrix_patch_preamble_v:nnnn #1 #2 #3 #4
   {
@@ -1461,18 +1473,13 @@
           }
       }
     \int_gincr:N \c at jCol
-    \__nicematrix_patch_preamble:n
+    \__nicematrix_patch_preamble_viii:n
   }
 \cs_new_protected:Npn \__nicematrix_patch_preamble_vi:n #1
   {
     \tl_gput_right:Nn \g__nicematrix_preamble_tl { c }
     \int_gincr:N \c at jCol
-    \bool_if:NT \l__nicematrix_vlines_bool
-      {
-        \tl_gput_right:Nn \g__nicematrix_preamble_tl
-          { ! { \skip_horizontal:N \arrayrulewidth } }
-      }
-    \__nicematrix_patch_preamble:n
+    \__nicematrix_patch_preamble_viii:n
   }
 \cs_new_protected:Npn \__nicematrix_patch_preamble_vii:n #1
   {
@@ -1482,6 +1489,24 @@
       { \__nicematrix_vdottedline:n { \int_use:N \c at jCol } }
     \__nicematrix_patch_preamble:n
   }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_viii:n #1
+  {
+    \str_if_eq:nnTF { #1 } { < }
+      \__nicematrix_patch_preamble_ix:n
+      {
+        \bool_if:NT \l__nicematrix_vlines_bool
+          {
+            \tl_gput_right:Nn \g__nicematrix_preamble_tl
+              { ! { \skip_horizontal:N \arrayrulewidth } }
+          }
+        \__nicematrix_patch_preamble:n { #1 }
+      }
+  }
+\cs_new_protected:Npn \__nicematrix_patch_preamble_ix:n #1
+  {
+    \tl_gput_right:Nn \g__nicematrix_preamble_tl { < { #1 } }
+    \__nicematrix_patch_preamble_viii:n
+  }
 \cs_new_protected:Npn \__nicematrix_put_box_in_flow:
   {
     \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim }
@@ -1492,21 +1517,6 @@
   }
 \cs_new_protected:Npn \__nicematrix_put_box_in_flow_i:
   {
-    \str_case:VnF \l__nicematrix_baseline_str
-      {
-        { t } { \int_set:Nn \l_tmpa_int 1 }
-        { b } { \int_set_eq:NN \l_tmpa_int \c at iRow }
-      }
-      { \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str }
-    \bool_if:nT
-      {
-           \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int
-        || \int_compare_p:nNn \l_tmpa_int > \g__nicematrix_row_total_int
-      }
-      {
-        \__nicematrix_error:n { bad~value~for~baseline }
-        \int_set:Nn \l_tmpa_int 1
-      }
     \pgfpicture
       \__nicematrix_qpoint:n { row - 1 }
       \dim_gset_eq:NN \g_tmpa_dim \pgf at y
@@ -1513,9 +1523,35 @@
       \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c at iRow }
       \dim_gadd:Nn \g_tmpa_dim \pgf at y
       \dim_gset:Nn \g_tmpa_dim { 0.5 \g_tmpa_dim }
-      \__nicematrix_qpoint:n { row - \int_use:N \l_tmpa_int - base }
+      \str_if_in:NnTF \l__nicematrix_baseline_str { line- }
+        {
+          \int_set:Nn \l_tmpa_int
+            {
+              \str_range:Nnn
+                \l__nicematrix_baseline_str
+                6
+                { \str_count:N \l__nicematrix_baseline_str }
+            }
+          \__nicematrix_qpoint:n { row - \int_use:N \l_tmpa_int }
+        }
+        {
+          \str_case:VnF \l__nicematrix_baseline_str
+            {
+              { t } { \int_set:Nn \l_tmpa_int 1 }
+              { b } { \int_set_eq:NN \l_tmpa_int \c at iRow }
+            }
+            { \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str }
+          \bool_lazy_or:nnT
+            { \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int }
+            { \int_compare_p:nNn \l_tmpa_int > \g__nicematrix_row_total_int }
+            {
+              \__nicematrix_error:n { bad~value~for~baseline }
+              \int_set:Nn \l_tmpa_int 1
+            }
+          \__nicematrix_qpoint:n { row - \int_use:N \l_tmpa_int - base }
+          \dim_gsub:Nn \g_tmpa_dim { \fontdimen22 \textfont2 }
+        }
       \dim_gsub:Nn \g_tmpa_dim \pgf at y
-      \dim_gsub:Nn \g_tmpa_dim { \fontdimen22 \textfont2 }
     \endpgfpicture
     \box_move_up:nn \g_tmpa_dim { \box_use_drop:N \l_tmpa_box }
     \box_use_drop:N \l_tmpa_box
@@ -1578,7 +1614,7 @@
 \cs_new_protected:Npn \__nicematrix_use_arraybox_with_notes:
   {
     \str_if_eq:VnT \l__nicematrix_baseline_str { t }
-      { \str_set:Nn \l__nicematrix_baseline_str { 1 } }
+      { \tl_set:Nn \l__nicematrix_baseline_str { 1 } }
     \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str
     \bool_lazy_or:nnT
       { \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int }
@@ -1957,7 +1993,7 @@
         \str_gset:Nn \g__nicematrix_name_env_str { #1 NiceMatrix }
         \tl_set:Nn \l__nicematrix_type_of_col_tl c
         \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
-        \exp_args:Nnx \__nicematrix_begin_of_NiceMatrix:nn { #1 } \l__nicematrix_type_of_col_tl
+        \exp_args:Nne \__nicematrix_begin_of_NiceMatrix:nn { #1 } \l__nicematrix_type_of_col_tl
       }
       { \use:c { end #1 NiceArray } }
   }
@@ -2043,6 +2079,9 @@
                   \int_use:N
                 \g__nicematrix_col_total_int
               }
+            \seq_gset_from_clist:cn
+              { c__nicematrix_pos_of_blocks_ \int_use:N \g__nicematrix_env_int _ seq }
+              { \seq_use:Nnnn \g__nicematrix_pos_of_blocks_seq , , , }
           }
         \iow_now:Nn \@mainaux \ExplSyntaxOff
       }
@@ -2075,18 +2114,23 @@
         \dim_set:Nn \l__nicematrix_xdots_shorten_dim { 0.6 \l__nicematrix_xdots_shorten_dim }
       }
     \__nicematrix_draw_dotted_lines:
-    \bool_if:NTF \l__nicematrix_hvlines_bool
-      \__nicematrix_draw_hvlines:
-      {
-        \bool_if:NT \l__nicematrix_hlines_bool \__nicematrix_draw_hlines:
-        \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines:
-        \bool_if:NT \l__nicematrix_hvlines_except_corners_bool
-          \__nicematrix_draw_hvlines_except_corners:
-      }
+    \__nicematrix_compute_corners:
+    % \bool_lazy_all:nT
+    %   {
+    %     { \seq_if_empty_p:N \g__nicematrix_pos_of_blocks_seq }
+    %     { \seq_if_empty_p:N \g__nicematrix_pos_of_xdots_seq }
+    %     { \seq_if_empty_p:N \l__nicematrix_empty_corner_cells_seq }
+    %   }
+    %   {
+    %     \cs_set_eq:NN \__nicematrix_vline_i:nn \__nicematrix_vline_i_complete:nn
+    %     \cs_set_eq:NN \__nicematrix_hline_i:nn \__nicematrix_hline_i_complete:nn
+    %   }
+    \bool_if:NT \l__nicematrix_hlines_bool \__nicematrix_draw_hlines:
+    \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines:
+    \g__nicematrix_internal_code_after_tl
+    \tl_gclear:N \g__nicematrix_internal_code_after_tl
     \cs_set_eq:NN \ialign \__nicematrix_old_ialign:
     \seq_if_empty:NF \g__nicematrix_blocks_seq \__nicematrix_draw_blocks:
-    \g__nicematrix_internal_code_after_tl
-    \tl_gclear:N \g__nicematrix_internal_code_after_tl
     \bool_if:NT \c__nicematrix_tikz_loaded_bool
       {
         \tikzset
@@ -2104,7 +2148,7 @@
     \g_nicematrix_code_after_tl
     \tl_gclear:N \g_nicematrix_code_after_tl
     \group_end:
-    \tl_if_empty:NF \g__nicematrix_code_before_tl
+    \tl_if_empty:NF \g_nicematrix_code_before_tl
       {
         \cs_set_protected:Npn \rectanglecolor { }
         \cs_set_protected:Npn \columncolor { }
@@ -2113,7 +2157,7 @@
           {
             \tl_gset:cn
               { g__nicematrix_code_before_ \int_use:N \g__nicematrix_env_int _ tl }
-              { \g__nicematrix_code_before_tl }
+              { \g_nicematrix_code_before_tl }
           }
         \iow_now:Nn \@mainaux \ExplSyntaxOff
         \bool_set_true:N \l__nicematrix_code_before_bool
@@ -2290,15 +2334,12 @@
               }
           }
       }
-    \bool_if:NT \l__nicematrix_hvlines_bool
+    \seq_gput_right:Nx \g__nicematrix_pos_of_xdots_seq
       {
-        \seq_gput_right:Nx \g__nicematrix_pos_of_xdots_seq
-          {
-            { \int_use:N \l__nicematrix_initial_i_int }
-            { \int_use:N \l__nicematrix_initial_j_int }
-            { \int_use:N \l__nicematrix_final_i_int }
-            { \int_use:N \l__nicematrix_final_j_int }
-          }
+        { \int_use:N \l__nicematrix_initial_i_int }
+        { \int_use:N \l__nicematrix_initial_j_int }
+        { \int_use:N \l__nicematrix_final_i_int }
+        { \int_use:N \l__nicematrix_final_j_int }
       }
   }
 \cs_new_protected:Npn \__nicematrix_set_initial_coords:
@@ -2899,10 +2940,21 @@
       \__nicematrix_old_multicolumn
       { #1 }
       {
-        > \__nicematrix_Cell:
-        \bool_if:NT \c__nicematrix_define_L_C_R_bool \tl_lower_case:n
-        #2
-        < \__nicematrix_end_Cell:
+        \exp_args:Ne \str_case:nn { \tl_lower_case:n { #2 } }
+          {
+             l { > \__nicematrix_Cell: l < \__nicematrix_end_Cell: }
+             r { > \__nicematrix_Cell: r < \__nicematrix_end_Cell: }
+             c { > \__nicematrix_Cell: c < \__nicematrix_end_Cell: }
+             { l | } { > \__nicematrix_Cell: l < \__nicematrix_end_Cell: | }
+             { r | } { > \__nicematrix_Cell: r < \__nicematrix_end_Cell: | }
+             { c | } { > \__nicematrix_Cell: c < \__nicematrix_end_Cell: | }
+             { | l } { | > \__nicematrix_Cell: l < \__nicematrix_end_Cell: }
+             { | r } { | > \__nicematrix_Cell: r < \__nicematrix_end_Cell: }
+             { | c } { | > \__nicematrix_Cell: c < \__nicematrix_end_Cell: }
+             { | l | } { | > \__nicematrix_Cell: l < \__nicematrix_end_Cell: | }
+             { | r | } { | > \__nicematrix_Cell: r < \__nicematrix_end_Cell: | }
+             { | c | } { | > \__nicematrix_Cell: c < \__nicematrix_end_Cell: | }
+          }
       }
       { #3 }
     \peek_remove_spaces:n
@@ -3111,7 +3163,7 @@
         \group_begin:
         \keys_set:nn { NiceMatrix / xdots } { #1 , #4 , down = #5 , up = #6 }
         \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
-          \use:x
+          \use:e
             {
               \__nicematrix_line_i:nn
                 { \__nicematrix_double_int_eval:n #2 \q_stop }
@@ -3300,16 +3352,81 @@
         \endpgfpicture
       }
   }
-\NewDocumentCommand \__nicematrix_rowcolors { O { } m m m }
+\keys_define:nn { NiceMatrix / rowcolors }
   {
-    \int_step_inline:nnn { #2 } { \int_use:N \c at iRow }
+    respect-blocks .bool_set:N = \l__nicematrix_respect_blocks_bool ,
+    respect-blocks .default:n = true ,
+    unknown .code:n = \__nicematrix_error:n { Unknown~option~for~rowcolors }
+  }
+\NewDocumentCommand \__nicematrix_rowcolors { O { } m m m O { } }
+  {
+    \keys_set:nn { NiceMatrix / rowcolors } { #5 }
+    \bool_lazy_and:nnTF
+      \l__nicematrix_respect_blocks_bool
+      { \cs_if_exist_p:c { c__nicematrix_pos_of_blocks_ \int_use:N \g__nicematrix_env_int _ seq } }
+      { \__nicematrix_rowcolors_i:nnnn { #1 } { #2 } { #3 } { #4 } }
       {
-        \int_if_odd:nTF { ##1 }
-          { \__nicematrix_rowcolor [ #1 ] { #3 } }
-          { \__nicematrix_rowcolor [ #1 ] { #4 } }
-        { ##1 }
+        \int_step_inline:nnn { #2 } { \int_use:N \c at iRow }
+          {
+            \int_if_odd:nTF { ##1 }
+              { \__nicematrix_rowcolor [ #1 ] { #3 } }
+              { \__nicematrix_rowcolor [ #1 ] { #4 } }
+            { ##1 }
+          }
       }
   }
+\cs_new_protected:Npn \__nicematrix_rowcolors_i:nnnn #1 #2 #3 #4
+  {
+    \seq_set_eq:Nc \l_tmpb_seq
+      { c__nicematrix_pos_of_blocks_ \int_use:N \g__nicematrix_env_int _ seq }
+    \seq_set_filter:NNn \l_tmpa_seq \l_tmpb_seq
+      { \__nicematrix_not_in_exterior_p:nnnn ##1 }
+    \int_set:Nn \l_tmpa_int { #2 }
+    \bool_set_false:N \l_tmpa_bool
+    \int_do_until:nNnn \l_tmpa_int > \c at iRow
+      {
+        \seq_set_filter:NNn \l_tmpb_seq \l_tmpa_seq
+          { \__nicematrix_intersect_our_row_p:nnnn ##1 }
+        \int_set_eq:NN \l_tmpb_int \l_tmpa_int
+        \seq_map_inline:Nn \l_tmpb_seq { \__nicematrix_rowcolors_ii:nnnn ##1 }
+        \bool_if:NTF \l_tmpa_bool
+          {
+            \__nicematrix_rowcolor [ #1 ] { #4 }
+              { \int_use:N \l_tmpa_int - \int_use:N \l_tmpb_int }
+            \bool_set_false:N \l_tmpa_bool
+          }
+          {
+            \__nicematrix_rowcolor [ #1 ] { #3 }
+              { \int_use:N \l_tmpa_int - \int_use:N \l_tmpb_int }
+            \bool_set_true:N \l_tmpa_bool
+          }
+        \int_set:Nn \l_tmpa_int { \l_tmpb_int + 1 }
+      }
+  }
+\cs_new_protected:Npn \__nicematrix_rowcolors_ii:nnnn #1 #2 #3 #4
+  {
+    \int_compare:nNnT { #3 } > \l_tmpb_int
+      { \int_set:Nn \l_tmpb_int { #3 } }
+  }
+\prg_new_conditional:Nnn \__nicematrix_not_in_exterior:nnnn p
+  {
+    \bool_lazy_or:nnTF
+      { \int_compare_p:nNn { #4 } = \c_zero_int }
+      { \int_compare_p:nNn { #2 } = { \__nicematrix_succ:n { \c at jCol } } }
+      \prg_return_false:
+      \prg_return_true:
+  }
+\prg_new_conditional:Nnn \__nicematrix_intersect_our_row:nnnn p
+  {
+    \bool_if:nTF
+      {
+        \int_compare_p:n { #1 <= \l_tmpa_int }
+        &&
+        \int_compare_p:n { \l_tmpa_int <= #3 }
+      }
+      \prg_return_true:
+      \prg_return_false:
+  }
 \NewDocumentCommand \__nicematrix_chessboardcolors { O { } m m  }
   {
     \int_step_inline:nn { \int_use:N \c at iRow }
@@ -3325,12 +3442,12 @@
   }
 \NewDocumentCommand \__nicematrix_cellcolor_tabular { O { } m }
   {
-    \tl_gput_right:Nx \g__nicematrix_code_before_tl
+    \tl_gput_right:Nx \g_nicematrix_code_before_tl
       { \cellcolor [ #1 ] { #2 } { \int_use:N \c at iRow - \int_use:N \c at jCol } }
   }
 \NewDocumentCommand \__nicematrix_rowcolor_tabular { O { } m }
   {
-    \tl_gput_right:Nx \g__nicematrix_code_before_tl
+    \tl_gput_right:Nx \g_nicematrix_code_before_tl
       {
         \exp_not:N \rectanglecolor [ #1 ] { #2 }
           { \int_use:N \c at iRow - \int_use:N \c at jCol }
@@ -3341,7 +3458,7 @@
   {
     \int_compare:nNnT \c at iRow = 1
       {
-        \tl_gput_left:Nx \g__nicematrix_code_before_tl
+        \tl_gput_left:Nx \g_nicematrix_code_before_tl
           { \exp_not:N \columncolor [ #1 ] { #2 } { \int_use:N \c at jCol } }
       }
   }
@@ -3366,13 +3483,8 @@
   }
 \cs_new_protected:Npn \__nicematrix_vline:nn #1 #2
   {
-    \bool_if:NTF \c__nicematrix_tikz_loaded_bool
+    \int_compare:nNnT { #1 } < { \c at jCol + 2 }
       {
-        \tikzpicture
-        \__nicematrix_vline_i:nn { #1 } { #2 }
-        \endtikzpicture
-      }
-      {
         \pgfpicture
         \__nicematrix_vline_i:nn { #1 } { #2 }
         \endpgfpicture
@@ -3380,18 +3492,72 @@
   }
 \cs_new_protected:Npn \__nicematrix_vline_i:nn #1 #2
   {
-    \CT at arc@
+    \tl_set:Nx \l_tmpb_tl { #1 }
+    \int_step_variable:nNn \c at iRow \l_tmpa_tl
+      {
+         \bool_gset_true:N \g_tmpa_bool
+         \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq
+           { \__nicematrix_test_if_vline_in_block:nnnn ##1 }
+         \seq_map_inline:Nn \g__nicematrix_pos_of_xdots_seq
+           { \__nicematrix_test_if_vline_in_block:nnnn ##1 }
+         \clist_if_empty:NF \l__nicematrix_except_corners_clist
+           \__nicematrix_test_in_corner_v:
+         \bool_if:NT \g_tmpa_bool
+           { \__nicematrix_vline_ii:nnnn { #1 } { #2 } \l_tmpa_tl \l_tmpa_tl }
+      }
+  }
+\cs_new_protected:Npn \__nicematrix_test_in_corner_v:
+   {
+     \int_compare:nNnTF \l_tmpb_tl = { \__nicematrix_succ:n \c at jCol }
+       {
+         \seq_if_in:NxT
+           \l__nicematrix_empty_corner_cells_seq
+           { \l_tmpa_tl - \__nicematrix_pred:n \l_tmpb_tl }
+           { \bool_set_false:N \g_tmpa_bool }
+       }
+       {
+         \seq_if_in:NxT
+           \l__nicematrix_empty_corner_cells_seq
+           { \l_tmpa_tl - \l_tmpb_tl }
+           {
+             \int_compare:nNnTF \l_tmpb_tl = 1
+               { \bool_set_false:N \g_tmpa_bool }
+               {
+                 \seq_if_in:NxT
+                   \l__nicematrix_empty_corner_cells_seq
+                   { \l_tmpa_tl - \__nicematrix_pred:n \l_tmpb_tl }
+                   { \bool_set_false:N \g_tmpa_bool }
+               }
+           }
+       }
+   }
+\cs_new_protected:Npn \__nicematrix_vline_ii:nnnn #1 #2 #3 #4
+  {
     \pgfrememberpicturepositiononpagetrue
     \pgf at relevantforpicturesizefalse
-    \pgfsetlinewidth { 1.1 \arrayrulewidth }
-    \pgfsetrectcap
-    \__nicematrix_qpoint:n { row - 1 }
+    \__nicematrix_qpoint:n { row - #3 }
     \dim_set_eq:NN \l_tmpa_dim \pgf at y
-    \__nicematrix_qpoint:n { col - \int_eval:n { #1 + 1 } }
+    \__nicematrix_qpoint:n { col - #1 }
     \dim_set_eq:NN \l_tmpb_dim \pgf at x
+    \__nicematrix_qpoint:n { row - \__nicematrix_succ:n { #4 } }
+    \dim_set_eq:NN \l_tmpc_dim \pgf at y
+    \bool_lazy_and:nnT
+      { \int_compare_p:nNn { #2 } > 1 }
+      { ! \tl_if_blank_p:V \CT at drsc@ }
+      {
+        \group_begin:
+        \CT at drsc@
+        \dim_add:Nn \l_tmpa_dim { 0.5 \arrayrulewidth }
+        \dim_sub:Nn \l_tmpc_dim { 0.5 \arrayrulewidth }
+        \dim_set:Nn \l_tmpd_dim
+          { \l_tmpb_dim - ( \doublerulesep + \arrayrulewidth ) * ( #2 - 1 ) }
+        \pgfpathrectanglecorners
+          { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
+          { \pgfpoint \l_tmpd_dim \l_tmpc_dim }
+        \pgfusepathqfill
+        \group_end:
+      }
     \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
-    \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c at iRow }
-    \dim_set_eq:NN \l_tmpc_dim \pgf at y
     \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
     \prg_replicate:nn { #2 - 1 }
       {
@@ -3400,188 +3566,131 @@
         \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
         \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
       }
+    \CT at arc@
+    \pgfsetlinewidth { 1.1 \arrayrulewidth }
+    \pgfsetrectcap
     \pgfusepathqstroke
   }
+\cs_new_protected:Npn \__nicematrix_vline_i_complete:nn #1 #2
+  { \__nicematrix_vline_ii:nnnn { #1 } { #2 } 1 { \int_use:N \c at iRow } }
 \cs_new_protected:Npn \__nicematrix_draw_vlines:
   {
-    \group_begin:
-    \CT at arc@
+    \int_step_inline:nnn
+      { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 }
+      { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c at jCol } \c at jCol }
+      { \__nicematrix_vline:nn { ##1 } 1 }
+  }
+\cs_new_protected:Npn \__nicematrix_hline:nn #1 #2
+  {
     \pgfpicture
+    \__nicematrix_hline_i:nn { #1 } { #2 }
+    \endpgfpicture
+  }
+\cs_new_protected:Npn \__nicematrix_hline_i:nn #1 #2
+  {
+    \tl_set:Nn \l_tmpa_tl { #1 }
+    \int_step_variable:nNn \c at jCol \l_tmpb_tl
+      {
+         \bool_gset_true:N \g_tmpa_bool
+         \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq
+           { \__nicematrix_test_if_hline_in_block:nnnn ##1 }
+         \seq_map_inline:Nn \g__nicematrix_pos_of_xdots_seq
+           { \__nicematrix_test_if_hline_in_block:nnnn ##1 }
+         \clist_if_empty:NF \l__nicematrix_except_corners_clist \__nicematrix_test_in_corner_h:
+         \bool_if:NT \g_tmpa_bool
+           { \__nicematrix_hline_ii:nnnn { #1 } { #2 } \l_tmpb_tl \l_tmpb_tl }
+      }
+  }
+\cs_new_protected:Npn \__nicematrix_test_in_corner_h:
+   {
+     \int_compare:nNnTF \l_tmpa_tl = { \__nicematrix_succ:n \c at iRow }
+       {
+         \seq_if_in:NxT
+           \l__nicematrix_empty_corner_cells_seq
+           { \__nicematrix_pred:n \l_tmpa_tl - \l_tmpb_tl }
+           { \bool_set_false:N \g_tmpa_bool }
+       }
+       {
+         \seq_if_in:NxT
+           \l__nicematrix_empty_corner_cells_seq
+           { \l_tmpa_tl - \l_tmpb_tl }
+           {
+             \int_compare:nNnTF \l_tmpa_tl = 1
+               { \bool_set_false:N \g_tmpa_bool }
+               {
+                 \seq_if_in:NxT
+                   \l__nicematrix_empty_corner_cells_seq
+                   { \__nicematrix_pred:n \l_tmpa_tl - \l_tmpb_tl }
+                   { \bool_set_false:N \g_tmpa_bool }
+               }
+           }
+       }
+   }
+\cs_new_protected:Npn \__nicematrix_hline_ii:nnnn #1 #2 #3 #4
+  {
     \pgfrememberpicturepositiononpagetrue
     \pgf at relevantforpicturesizefalse
-    \pgfsetlinewidth \arrayrulewidth
-    \pgfsetrectcap
-    \__nicematrix_qpoint:n { row - 1 }
-    \dim_set_eq:NN \l_tmpa_dim \pgf at y
-    \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c at iRow }
+    \__nicematrix_qpoint:n { col - #3 }
+    \dim_set_eq:NN \l_tmpa_dim \pgf at x
+    \__nicematrix_qpoint:n { row - #1 }
     \dim_set_eq:NN \l_tmpb_dim \pgf at y
-    \int_step_inline:nnn
-      { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 }
-      { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c at jCol } \c at jCol }
+    \__nicematrix_qpoint:n { col - \__nicematrix_succ:n { #4 } }
+    \dim_set_eq:NN \l_tmpc_dim \pgf at x
+    \bool_lazy_and:nnT
+      { \int_compare_p:nNn { #2 } > 1 }
+      { ! \tl_if_blank_p:V \CT at drsc@ }
       {
-        \__nicematrix_qpoint:n { col - ##1 }
-        \dim_set_eq:NN \l_tmpc_dim \pgf at x
-        \pgfpathmoveto { \pgfpoint \l_tmpc_dim \l_tmpa_dim }
+        \group_begin:
+        \CT at drsc@
+        \dim_set:Nn \l_tmpd_dim
+          { \l_tmpb_dim - ( \doublerulesep + \arrayrulewidth ) * ( #2 - 1 ) }
+        \pgfpathrectanglecorners
+          { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
+          { \pgfpoint \l_tmpc_dim \l_tmpd_dim }
+        \pgfusepathqfill
+        \group_end:
+      }
+    \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
+    \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
+    \prg_replicate:nn { #2 - 1 }
+      {
+        \dim_sub:Nn \l_tmpb_dim \arrayrulewidth
+        \dim_sub:Nn \l_tmpb_dim \doublerulesep
+        \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
         \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
       }
+    \CT at arc@
+    \pgfsetlinewidth { 1.1 \arrayrulewidth }
+    \pgfsetrectcap
     \pgfusepathqstroke
-    \endpgfpicture
-    \group_end:
   }
+\cs_new_protected:Npn \__nicematrix_hline_i_complete:nn #1 #2
+  { \__nicematrix_hline_ii:nnnn #1 #2 1 { \int_use:N \c at jCol } }
 \cs_new_protected:Npn \__nicematrix_draw_hlines:
   {
-    \pgfpicture
-    \CT at arc@
-    \pgfrememberpicturepositiononpagetrue
-    \pgf at relevantforpicturesizefalse
-    \pgfsetlinewidth \arrayrulewidth
     \int_step_inline:nnn
       { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 }
       { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c at iRow } \c at iRow }
-      {
-        \__nicematrix_qpoint:n { row - ##1 }
-        \dim_set_eq:NN \l_tmpa_dim \pgf at y
-        \pgfpathmoveto { \pgfpoint \pgf at x \pgf at y }
-        \__nicematrix_qpoint:n { col - \__nicematrix_succ:n { \c at jCol } }
-        \dim_set:Nn \l_tmpb_dim { \pgf at x + 0.5 \arrayrulewidth }
-        \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
-      }
-    \pgfusepathqstroke
-    \endpgfpicture
+      { \__nicematrix_hline:nn { ##1 } 1 }
   }
-\cs_new_protected:Npn \__nicematrix_draw_hvlines:
+\cs_set:Npn \__nicematrix_Hline: { \noalign { \ifnum 0 = `} \fi \__nicematrix_Hline_i:n { 1 } }
+\cs_set:Npn \__nicematrix_Hline_i:n #1
   {
-    \bool_lazy_and:nnTF
-     { \seq_if_empty_p:N \g__nicematrix_pos_of_blocks_seq }
-     { \seq_if_empty_p:N \g__nicematrix_pos_of_xdots_seq }
-     \__nicematrix_draw_hvlines_i:
-     \__nicematrix_draw_hvlines_ii:
+    \peek_meaning_ignore_spaces:NTF \Hline
+      { \__nicematrix_Hline_ii:nn { #1 + 1 } }
+      { \__nicematrix_Hline_iii:n { #1 } }
   }
-\cs_new_protected:Npn \__nicematrix_draw_hvlines_i:
+\cs_set:Npn \__nicematrix_Hline_ii:nn #1 #2 { \__nicematrix_Hline_i:n { #1 } }
+\cs_set:Npn \__nicematrix_Hline_iii:n #1
   {
-    \__nicematrix_draw_hlines:
-    \__nicematrix_draw_vlines:
-  }
-\cs_new_protected:Npn \__nicematrix_draw_hvlines_ii:
-  {
-    \group_begin:
-    \CT at arc@
-    \int_step_variable:nnNn
-      { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 }
-      { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c at iRow } \c at iRow }
-      \l_tmpa_tl
+    \skip_vertical:n
       {
-        \int_step_variable:nNn \c at jCol \l_tmpb_tl
-          {
-            \bool_gset_true:N \g_tmpa_bool
-            \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq
-              { \__nicematrix_test_if_hline_in_block:nnnn ##1 }
-            \seq_map_inline:Nn \g__nicematrix_pos_of_xdots_seq
-              { \__nicematrix_test_if_hline_in_block:nnnn ##1 }
-            \bool_if:NT \l__nicematrix_hvlines_except_corners_bool
-              {
-                \int_compare:nNnTF \l_tmpa_tl = { \c at iRow + 1 }
-                  {
-                    \seq_if_in:NxT
-                      \l__nicematrix_empty_corner_cells_seq
-                      { \__nicematrix_pred:n \l_tmpa_tl - \l_tmpb_tl }
-                      { \bool_set_false:N \g_tmpa_bool }
-                  }
-                  {
-                    \seq_if_in:NxT
-                      \l__nicematrix_empty_corner_cells_seq
-                      { \l_tmpa_tl - \l_tmpb_tl }
-                      {
-                        \int_compare:nNnTF \l_tmpa_tl = 1
-                          { \bool_set_false:N \g_tmpa_bool }
-                          {
-                            \seq_if_in:NxT
-                              \l__nicematrix_empty_corner_cells_seq
-                              { \__nicematrix_pred:n \l_tmpa_tl - \l_tmpb_tl }
-                              { \bool_set_false:N \g_tmpa_bool }
-                          }
-                      }
-                  }
-              }
-            \bool_if:NT \g_tmpa_bool
-              {
-                \pgfpicture
-                \pgfrememberpicturepositiononpagetrue
-                \pgf at relevantforpicturesizefalse
-                \pgfsetlinewidth \arrayrulewidth
-                \pgfsetrectcap
-                \__nicematrix_qpoint:n { row - \l_tmpa_tl }
-                \dim_set_eq:NN \l_tmpb_dim \pgf at y
-                \__nicematrix_qpoint:n { col - \l_tmpb_tl }
-                \dim_set_eq:NN \l_tmpa_dim \pgf at x
-                \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl }
-                \dim_set_eq:NN \l_tmpc_dim \pgf at x
-                \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
-                \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
-                \pgfusepathqstroke
-                \endpgfpicture
-              }
-          }
+        \arrayrulewidth * ( #1 )
+        + \doublerulesep * ( \int_max:nn 0 { #1 - 1 } )
       }
-    \int_step_variable:nNn \c at iRow \l_tmpa_tl
-      {
-        \int_step_variable:nnNn
-          { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 }
-          { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c at jCol } \c at jCol }
-          \l_tmpb_tl
-          {
-            \bool_gset_true:N \g_tmpa_bool
-            \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq
-              { \__nicematrix_test_if_vline_in_block:nnnn ##1 }
-            \seq_map_inline:Nn \g__nicematrix_pos_of_xdots_seq
-              { \__nicematrix_test_if_vline_in_block:nnnn ##1 }
-            \bool_if:NT \l__nicematrix_hvlines_except_corners_bool
-              {
-                \int_compare:nNnTF \l_tmpb_tl = { \__nicematrix_succ:n \c at jCol }
-                  {
-                    \seq_if_in:NxT
-                      \l__nicematrix_empty_corner_cells_seq
-                      { \l_tmpa_tl - \__nicematrix_pred:n \l_tmpb_tl }
-                      { \bool_set_false:N \g_tmpa_bool }
-                  }
-                  {
-                    \seq_if_in:NxT
-                      \l__nicematrix_empty_corner_cells_seq
-                      { \l_tmpa_tl - \l_tmpb_tl }
-                      {
-                        \int_compare:nNnTF \l_tmpb_tl = 1
-                          { \bool_set_false:N \g_tmpa_bool }
-                          {
-                            \seq_if_in:NxT
-                              \l__nicematrix_empty_corner_cells_seq
-                              { \l_tmpa_tl - \__nicematrix_pred:n \l_tmpb_tl }
-                              { \bool_set_false:N \g_tmpa_bool }
-                          }
-                      }
-                  }
-              }
-            \bool_if:NT \g_tmpa_bool
-              {
-                \pgfpicture
-                \pgfrememberpicturepositiononpagetrue
-                \pgf at relevantforpicturesizefalse
-                \pgfsetlinewidth \arrayrulewidth
-                \pgfsetrectcap
-                \__nicematrix_qpoint:n { row - \l_tmpa_tl }
-                \dim_set_eq:NN \l_tmpb_dim \pgf at y
-                \__nicematrix_qpoint:n { col - \l_tmpb_tl }
-                \dim_set_eq:NN \l_tmpa_dim \pgf at x
-                \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpa_tl }
-                \dim_set_eq:NN \l_tmpc_dim \pgf at y
-                \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
-                \pgfpathlineto { \pgfpoint \l_tmpa_dim \l_tmpc_dim }
-                \pgfusepathqstroke
-                \endpgfpicture
-              }
-          }
-      }
-    \group_end:
-    \seq_gclear:N \g__nicematrix_pos_of_xdots_seq
+    \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl
+      { \__nicematrix_hline:nn { \__nicematrix_succ:n { \c at iRow } } { #1 } }
+    \ifnum 0 = `{ \fi }
   }
 \cs_new_protected:Npn \__nicematrix_test_if_hline_in_block:nnnn #1 #2 #3 #4
   {
@@ -3605,29 +3714,39 @@
       }
       { \bool_gset_false:N \g_tmpa_bool }
   }
-\cs_new_protected:Npn \__nicematrix_draw_hvlines_except_corners:
+\cs_new_protected:Npn \__nicematrix_compute_corners:
   {
     \seq_clear_new:N \l__nicematrix_empty_corner_cells_seq
-    \__nicematrix_compute_a_corner:nnnnnn 1 1 1 1 \c at iRow \c at jCol
-    \__nicematrix_compute_a_corner:nnnnnn 1 \c at jCol 1 { -1 } \c at iRow 1
-    \__nicematrix_compute_a_corner:nnnnnn \c at iRow 1 { -1 } 1 1 \c at jCol
-    \__nicematrix_compute_a_corner:nnnnnn \c at iRow \c at jCol { -1 } { -1 } 1 1
-    \__nicematrix_draw_hvlines_ii:
+    \clist_map_inline:Nn \l__nicematrix_except_corners_clist
+      {
+        \str_case:nnF { ##1 }
+          {
+            { NW }
+            { \__nicematrix_compute_a_corner:nnnnnn 1 1 1 1 \c at iRow \c at jCol }
+            { NE }
+            { \__nicematrix_compute_a_corner:nnnnnn 1 \c at jCol 1 { -1 } \c at iRow 1 }
+            { SW }
+            { \__nicematrix_compute_a_corner:nnnnnn \c at iRow 1 { -1 } 1 1 \c at jCol }
+            { SE }
+            { \__nicematrix_compute_a_corner:nnnnnn \c at iRow \c at jCol { -1 } { -1 } 1 1 }
+          }
+          { \__nicematrix_error:nn { bad~corner } { ##1 } }
+      }
   }
 \cs_new_protected:Npn \__nicematrix_compute_a_corner:nnnnnn #1 #2 #3 #4 #5 #6
   {
     \bool_set_false:N \l_tmpa_bool
     \int_zero_new:N \l__nicematrix_last_empty_row_int
+    \int_set:Nn \l__nicematrix_last_empty_row_int { #1 }
     \int_step_inline:nnnn { #1 } { #3 } { #5 }
       {
         \__nicematrix_test_if_cell_in_a_block:nn { ##1 } { \int_eval:n { #2 } }
-        \bool_if:nTF
+        \bool_lazy_or:nnTF
           {
              \cs_if_exist_p:c
                { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - \int_eval:n { #2 } }
-             ||
-             \l_tmpb_bool
           }
+          \l_tmpb_bool
           { \bool_set_true:N \l_tmpa_bool }
           {
             \bool_if:NF \l_tmpa_bool
@@ -3636,14 +3755,15 @@
       }
     \bool_set_false:N \l_tmpa_bool
     \int_zero_new:N \l__nicematrix_last_empty_column_int
+    \int_set:Nn \l__nicematrix_last_empty_column_int { #2 }
     \int_step_inline:nnnn { #2 } { #4 } { #6 }
       {
         \__nicematrix_test_if_cell_in_a_block:nn { \int_eval:n { #1 } } { ##1 }
-        \bool_if:nTF
+        \bool_lazy_or:nnTF
+          \l_tmpb_bool
           {
             \cs_if_exist_p:c
               { pgf @ sh @ ns @ \__nicematrix_env: - \int_eval:n { #1 } - ##1 }
-            || \l_tmpb_bool
           }
           { \bool_set_true:N \l_tmpa_bool }
           {
@@ -3657,11 +3777,11 @@
         \int_step_inline:nnnn { #2 } { #4 } \l__nicematrix_last_empty_column_int
           {
             \__nicematrix_test_if_cell_in_a_block:nn { ##1 } { ####1 }
-            \bool_if:nTF
+            \bool_lazy_or:nnTF
+              \l_tmpb_bool
               {
-                 \cs_if_exist_p:c
-                   { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - ####1 }
-                 || \l_tmpb_bool
+                \cs_if_exist_p:c
+                  { pgf @ sh @ ns @ \__nicematrix_env: - ##1 - ####1 }
               }
               { \bool_set_true:N \l_tmpa_bool }
               {
@@ -3682,18 +3802,21 @@
     \int_set:Nn \l_tmpb_int { #2 }
     \bool_set_false:N \l_tmpb_bool
     \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq
-      { \__nicematrix_test_if_cell_in_block:nnnnnnn { \l_tmpa_int } { \l_tmpb_int } ##1 }
+      { \__nicematrix_test_if_cell_in_block:nnnnnnn \l_tmpa_int \l_tmpb_int ##1 }
   }
 \cs_new_protected:Npn \__nicematrix_test_if_cell_in_block:nnnnnnn #1 #2 #3 #4 #5 #6
   {
-    \bool_lazy_all:nT
+    \int_compare:nNnT { #3 } < { \__nicematrix_succ:n { #1 } }
       {
-        { \int_compare_p:n { #3 <= #1 } }
-        { \int_compare_p:n { #1 <= #5 } }
-        { \int_compare_p:n { #4 <= #2 } }
-        { \int_compare_p:n { #2 <= #6 } }
+        \int_compare:nNnT { #1 } < { \__nicematrix_succ:n { #5 } }
+          {
+            \int_compare:nNnT { #4 } < { \__nicematrix_succ:n { #2 } }
+              {
+                \int_compare:nNnT { #2 } < { \__nicematrix_succ:n { #6 } }
+                  { \bool_set_true:N \l_tmpb_bool }
+              }
+          }
       }
-    { \bool_set_true:N \l_tmpb_bool }
   }
 \cs_new:Npn \__nicematrix_hdottedline:
   {
@@ -4034,7 +4157,7 @@
     \keys_set:nn { NiceMatrix / Block } { #5 }
     \tl_if_empty:NF \l__nicematrix_color_tl
       {
-        \tl_gput_right:Nx \g__nicematrix_code_before_tl
+        \tl_gput_right:Nx \g_nicematrix_code_before_tl
           {
             \exp_not:N \rectanglecolor
               { \l__nicematrix_color_tl }
@@ -4053,7 +4176,7 @@
        }
     \bool_lazy_or:nnTF
       { \int_compare_p:nNn { #3 } > \g__nicematrix_row_total_int }
-      { \int_compare_p:nNn { #4 } > \c at jCol }
+      { \int_compare_p:nNn { #4 } > \g__nicematrix_col_total_int }
       { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } }
       {
         \hbox_set:Nn \l__nicematrix_cell_box { #6 }
@@ -4207,10 +4330,10 @@
       \AutoNiceMatrixWithDelims . . { #2 } { #4 } [ #1 , #3 , #5 ]
     \group_end:
   }
-\cs_set_eq:NN \__nicematrix_dotfill \dotfill
+\cs_set_eq:NN \__nicematrix_old_dotfill \dotfill
 \cs_new_protected:Npn \__nicematrix_dotfill:
   {
-    \__nicematrix_dotfill
+    \__nicematrix_old_dotfill
     \bool_if:NT \l__nicematrix_NiceTabular_bool
       { \group_insert_after:N \__nicematrix_dotfill_ii: }
       { \group_insert_after:N \__nicematrix_dotfill_i: }
@@ -4218,7 +4341,7 @@
 \cs_new_protected:Npn \__nicematrix_dotfill_i: { \group_insert_after:N \__nicematrix_dotfill_ii: }
 \cs_new_protected:Npn \__nicematrix_dotfill_ii: { \group_insert_after:N \__nicematrix_dotfill_iii: }
 \cs_new_protected:Npn \__nicematrix_dotfill_iii:
-  { \dim_compare:nNnT { \box_wd:N \l__nicematrix_cell_box } = \c_zero_dim  \__nicematrix_dotfill }
+  { \dim_compare:nNnT { \box_wd:N \l__nicematrix_cell_box } = \c_zero_dim  \__nicematrix_old_dotfill }
 \cs_new_protected:Npn \__nicematrix_diagbox:nn #1 #2
   {
     \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl
@@ -4448,12 +4571,6 @@
     You~can't~use~the~command~#1 in~the~last~row~(exterior)~of~the~array.\\
     If~you~go~on,~this~command~will~be~ignored.
   }
-\__nicematrix_msg_new:nn { option~S~without~siunitx }
-  {
-    You~can't~use~the~option~'S'~in~your~environment~\__nicematrix_full_name_env:
-    because~you~have~not~loaded~siunitx.\\
-    If~you~go~on,~this~option~will~be~ignored.
-  }
 \__nicematrix_msg_new:nn { bad~option~for~line-style }
   {
     Since~you~haven't~loaded~Tikz,~the~only~value~you~can~give~to~'line-style'~
@@ -4465,6 +4582,12 @@
     and~'shorten'~(and~you~try~to~use~'\l_keys_key_tl').~If~you~go~on,~
     this~option~will~be~ignored.
   }
+\__nicematrix_msg_new:nn { Unknown~option~for~rowcolors }
+  {
+    As~for~now~there~is~only~one~option~available~here:~'respect-blocks'~
+    (and~you~try~to~use~'\l_keys_key_tl').~If~you~go~on,~
+    this~option~will~be~ignored.
+  }
 \__nicematrix_msg_new:nn { ampersand~in~light-syntax }
   {
     You~can't~use~an~ampersand~(\token_to_str &)~to~separate~columns~because
@@ -4496,6 +4619,13 @@
     can't~be~executed~because~a~cell~doesn't~exist.\\
     If~you~go~on~this~command~will~be~ignored.
   }
+\__nicematrix_msg_new:nn { bad~corner }
+  {
+    #1~is~an~incorrect~specification~for~a~corner~(in~the~keys~
+    'except-corners'~and~'hvlines-except-corners').~The~available~
+    values~are:~NW,~SW,~NE~and~SE.\\
+    If~you~go~on,~this~specification~of~corner~will~be~ignored.
+  }
 \__nicematrix_msg_new:nn { last-col~non~empty~for~NiceArray }
   {
     In~the~\__nicematrix_full_name_env:,~you~must~use~the~option~
@@ -4717,7 +4847,6 @@
     right-margin,~
     rules/color,~
     rules/width,~
-    S,~
     small,~
     t,~
     vlines,~
@@ -4779,7 +4908,8 @@
     the~same~environment~name~twice.~You~can~go~on,~but,~
     maybe,~you~will~have~incorrect~results~especially~
     if~you~use~'columns-width=auto'.~If~you~don't~want~to~see~this~
-    message~again,~use~the~option~'allow-duplicate-names'.\\
+    message~again,~use~the~option~'allow-duplicate-names'~in~
+    '\token_to_str:N \NiceMatrixOptions'.\\
     For~a~list~of~the~names~already~used,~type~H~<return>. \\
   }
   {



More information about the tex-live-commits mailing list.