diff options
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf | bin | 286330 -> 300142 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex | 857 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf | bin | 559454 -> 621774 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx | 3383 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty | 1391 |
5 files changed, 3508 insertions, 2123 deletions
diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf Binary files differindex 8ea0c2f6433..e0d14dea9c1 100644 --- a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf +++ b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex index b3dbc988161..70064ad807c 100644 --- a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex +++ b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex @@ -7,15 +7,30 @@ \usepackage{amsmath} \usepackage{color} -\usepackage{colortbl} \usepackage{array} -\usepackage{arydshln} -\usepackage{verbatim} +\usepackage{colortbl} \usepackage{nicematrix} + + \usepackage{siunitx} +\newbox\ExampleOne + +\setbox\ExampleOne\hbox{% +$\begin{NiceArray}{|*{4}{C|}}[hlines,first-row,first-col] + & e & a & b & c \\ +e & e & a & b & c \\ +a & a & e & c & b \\ +b & b & c & e & a \\ +c & c & b & a & e +\end{NiceArray}$} + +\usepackage{arydshln} +\usepackage{verbatim} + + \usepackage{fancyvrb} \fvset{commandchars=\~\#\@,formatcom={\color{gray}}} @@ -33,6 +48,14 @@ \usepackage[hyperfootnotes = false]{hyperref} +\hypersetup{ + pdfinfo = { + Title = { L’extension nicematrix }, + Subject = { Une extension LaTeX } , + Author = { F. Pantigny } + } +} + \NewDocumentEnvironment {scope} {} {} {} @@ -83,21 +106,22 @@ suivantes : \texttt{draft} est utilisée, ces lignes en pointillés ne sont pas tracées pour accélérer la compilation.} ; -\textbullet\ une première rangée et une dernière colonne pour les labels ; +\textbullet\ des rangées et colonnes extérieures pour les labels ; \textbullet\ un contrôle sur la largeur des colonnes. \end{minipage} \end{savenotes} \hspace{1.4cm} -$\begin{bNiceArrayRC}{CCCC}[code-for-last-col=\color{blue}\scriptstyle, - code-for-first-row=\color{blue}\scriptstyle, - columns-width = auto] -C_1 & C_2 & \Cdots & C_n \\ -a_{11} & a_{12} & \Cdots & a_{1n} & L_1 \\ -a_{21} & a_{22} & \Cdots & a_{2n} & L_2 \\ -\Vdots & \Vdots & \Ddots & \Vdots & \Vdots \\ -a_{n1} & a_{n2} & \Cdots & a_{nn} & L_n -\end{bNiceArrayRC}$ +$\begin{bNiceArray}{CCCC}[first-row,first-col, + code-for-first-col=\color{blue}\scriptstyle, + code-for-first-row=\color{blue}\scriptstyle, + columns-width = auto] + & C_1 & C_2 & \Cdots & C_n \\ +L_1 & a_{11} & a_{12} & \Cdots & a_{1n} \\ +L_2 & a_{21} & a_{22} & \Cdots & a_{2n} \\ +\Vdots & \Vdots & \Vdots & \Ddots & \Vdots\\ +L_n & a_{n1} & a_{n2} & \Cdots & a_{nn} +\end{bNiceArray}$ @@ -164,18 +188,17 @@ L'extension \pkg{nicematrix} définit les nouveaux environnements suivants : \begin{ttfamily} \setlength{\tabcolsep}{3mm} \begin{tabular}{llll} -\{NiceMatrix\} & \{NiceArray\} & \{pNiceArrayC\} & \{pNiceArrayRC\} \\ -\{pNiceMatrix\} & & \{bNiceArrayC\} & \{bNiceArrayRC\} \\ -\{bNiceMatrix\} & & \{BNiceArrayC\} & \{BNiceArrayRC\} \\ -\{BNiceMatrix\} & & \{vNiceArrayC\} & \{vNiceArrayRC\} \\ -\{vNiceMatrix\} & & \{VNiceArrayC\} & \{VNiceArrayRC\} \\ -\{VNiceMatrix\} & & \{NiceArrayCwithDelims\} & \{NiceArrayRCwithDelims\} \\ +\{NiceMatrix\} & \{NiceArray\} & \{pNiceArray\} \\ +\{pNiceMatrix\} & & \{bNiceArray\} \\ +\{bNiceMatrix\} & & \{BNiceArray\} \\ +\{BNiceMatrix\} & & \{vNiceArray\} \\ +\{vNiceMatrix\} & & \{VNiceArray\} \\ +\{VNiceMatrix\} & & \{NiceArrayWithDelims\} \\ \end{tabular} \end{ttfamily} - \medskip Par défaut, les environnements \verb|{NiceMatrix}|, \verb|{pNiceMatrix}|, \verb|{bNiceMatrix}|, \verb|{BNiceMatrix}|, \verb|{vNiceMatrix}| et \verb|{VNiceMatrix}| se comportent quasiment comme les environnements correspondants de @@ -187,23 +210,12 @@ Par défaut, les environnements \verb|{NiceMatrix}|, \verb|{pNiceMatrix}|, \verb L'environnement \verb|{NiceArray}| est similaire à l'environnement \verb|{array}| de l'extension \verb|{array}|. Néanmoins, pour des raisons techniques, dans le préambule de l'environnement \verb|{NiceArray}|, l'utilisateur doit utiliser les lettres \verb|L|, \verb|C| et~\verb|R| au lieu de \verb|l|, \verb|c| et \verb|r|. Il est possible -d'utiliser les constructions \verb|w{...}{...}|, \verb|W{...}{...}|, \verb+|+, \verb|>{...}|, \verb|<{...}|, +d'utiliser les constructions \verb|w{...}{...}|, \verb|W{...}{...}|\footnote{Pour les colonnes de type \verb|w| et + \verb|W|, les cases sont composées en mode mathématique (dans les environnements de \pkg{nicematrix}) alors que + dans \verb|{array}| de \pkg{array}, elles sont composées en mode texte.}, \verb+|+, \verb|>{...}|, \verb|<{...}|, \verb|@{...}|, \verb|!{...}| et \verb|*{n}{...}| mais les lettres \verb|p|, \verb|m| et \verb|b| ne doivent pas -être employées. Voir p.~\pageref{NiceArray} la partie concernant \verb|{NiceArray}|. - -\medskip -Les environnements avec un \verb|C| à la fin de leur nom, \verb|{pNiceArrayC}|, \verb|{bNiceArrayC}|, -\verb|{BNiceArrayC}|, \verb|{vNiceArrayC}| et \verb|{VNiceArrayC}| sont similaires aux environnements -\verb|{NiceArray}| (en particulier les lettres spéciales \verb|L|, \verb|C| et \verb|R|) mais créent une colonne -extérieure (à droite du délimiteur). Voir p.~\pageref{pNiceArrayC} la partie concernant \verb|{pNiceArrayC}|. - -\medskip -Les environnements dont le nom se termine par \verb|RC| (\verb|{pNiceArrayRC}|, \verb|{bNiceArrayRC}|, \verb|{BNiceArrayRC}|, -\verb|{vNiceArrayRC}| et \verb|{VNiceArrayRC}|) sont similaires à l'environnement \verb|{NiceArray}| mais créent une -rangée extérieure (au-dessus de la matrice principale) et une colonne extérieure. Voir p.~\pageref{pNiceArrayRC} la -partie concernant \verb|{pNiceArrayRC}|. - - +être employées. L'environnement \verb|{NiceArray}| et ses variantes fournissent des options qui permettent de +tracer des rangées et colonnes extérieures. Voir p.~\pageref{NiceArray} la partie concernant \verb|{NiceArray}|. \section{Les lignes en pointillés continues} @@ -213,6 +225,8 @@ partie concernant \verb|{pNiceArrayRC}|. commande \verb|\iddots|, définie dans \pkg{nicematrix}, est une variante de \verb|\ddots| avec les points allant vers le haut : \smash{$\iddots$}. Si \pkg{mathdots} est chargée, la version de \pkg{mathdots} est utilisée. Elle correspond à la commande \verb|\adots| de \pkg{unicode-math}.} +\newcounter{fniddots} +\setcounter{fniddots}{\thefootnote} \smallskip Chacune de ces commandes doit être utilisée seule dans la case du tableau et elle trace une ligne en pointillés @@ -227,7 +241,7 @@ a_1 & \Cdots & & & a_1 \\ \Vdots & a_2 & \Cdots & & a_2 \\ & \Vdots & \Ddots \\ \\ -a_1 & a_2 & & & a_n \\ +a_1 & a_2 & & & a_n \end{bNiceMatrix} \end{BVerbatim} $\begin{bNiceMatrix} @@ -235,7 +249,7 @@ a_1 & \Cdots & & & a_1 \\ \Vdots & a_2 & \Cdots & & a_2 \\ & \Vdots & \Ddots \\ \\ -a_1 & a_2 & & & a_n \\ +a_1 & a_2 & & & a_n \end{bNiceMatrix}$ \interitem @@ -306,7 +320,7 @@ $\begin{bNiceMatrix} \bigskip En fait, dans cet exemple, il aurait été possible de tracer la même matrice -sans commandes étoilées avec le codage suivant :\par\nobreak +sans commande étoilée avec le codage suivant :\par\nobreak \bigskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] \begin{bNiceMatrix} @@ -324,17 +338,15 @@ $\begin{bNiceMatrix} \end{bNiceMatrix}$ \bigskip -Il y a aussi d'autres moyens de changer la taille d'une matrice. On pourrait -vouloir utiliser l'argument optionnel de la commande~\verb|\\| pour l'espacement -vertical et la commande~\verb|\hspace*| dans une case pour l'espacement -horizontal.\footnote{Le meilleur moyen de régler la largeur des colonnes est, -de toutes manières, d'utiliser l'environnement \verb|{NiceArray}| avec une colonne -de type~\verb|w| ou \verb|W|.} - -Toutefois, une commande~\verb|\hspace*| pourrait interférer dans la construction -des lignes en pointillés. C'est pourquoi l'extension \pkg{nicematrix} fournit -une commande~\verb|\Hspace| qui est une variante de \verb|\hspace| transparente pour la -construction des lignes en pointillés de \pkg{nicematrix}.\par\nobreak +Il y a aussi d'autres moyens de changer la taille d'une matrice. On pourrait vouloir utiliser l'argument optionnel +de la commande~\verb|\\| pour l'espacement vertical et la commande~\verb|\hspace*| dans une case pour l'espacement +horizontal.\footnote{Le meilleur moyen de régler la largeur des colonnes est, de toutes manières, d'utiliser + l'environnement \verb|{NiceArray}| (ou une de ses variantes) avec une colonne de type~\verb|w| ou \verb|W|: cf. + p.~\pageref{width}} + +Toutefois, une commande~\verb|\hspace*| pourrait interférer dans la construction des lignes en pointillés. C'est +pourquoi l'extension \pkg{nicematrix} fournit une commande~\verb|\Hspace| qui est une variante de \verb|\hspace| +transparente pour la construction des lignes en pointillés de \pkg{nicematrix}.\par\nobreak \bigskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] \begin{bNiceMatrix} @@ -472,14 +484,14 @@ $\begin{pNiceMatrix} 1 & 2 & 3 & 4 & 5 \\ 1 & ~emphase#\Hdotsfor{3}@ & 5 \\ 1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ \end{BVerbatim} $\begin{pNiceMatrix} 1 & 2 & 3 & 4 & 5 \\ 1 & \Hdotsfor{3} & 5 \\ 1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ \bigskip @@ -499,7 +511,7 @@ $\begin{pNiceMatrix} 1 & 2 & 3 & 4 & 5 \\ & \Hdotsfor{3} \\ 1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ \bigskip @@ -509,7 +521,8 @@ consécutifs. Par homogénéité, \verb|\Hdotsfor| prend aussi un argument optio mais cet argument est écarté silencieusement. Remarque : Contrairement à la commande \verb|\hdotsfor| de \pkg{amsmath}, la commande \verb|\Hdotsfor| est -compatible avec l'extension \pkg{colortbl}. +utilisable lorsque l'extension \pkg{colortbl} est chargée (mais vous risquez d'avoir des problèmes si vous utilisez +\verb|\rowcolor| sur la même rangée que \verb|\Hdotsfor|). \subsection{Comment créer les lignes en pointillés de manière transparente} @@ -523,12 +536,10 @@ En fait, cette option est un alias pour la conjonction de deux options : \verb|r \begin{itemize} \item L'option \verb|renew-dots|\par\nobreak Avec cette option, les commandes \verb|\ldots|, \verb|\cdots|, -\verb|\vdots|, \verb|\ddots|, \verb|\iddots|\footnote{La commande \verb|\iddots| n'est pas une commande de LaTeX mais - est définie dans l'extension \pkg{nicematrix}. Si \pkg{mathdots} est chargée, la version de \pkg{mathdots} est - utilisée.} et \verb|\hdotsfor| sont redéfinies dans les environnements de \pkg{nicematrix} et agissent comme -\verb|\Ldots|, \verb|\Cdots|, \verb|\Vdots|, \verb|\Ddots|, \verb|\Iddots| et \verb|\Hdotsfor| ; la commande -\verb|\dots| (points de suspension «automatiques» de \verb|amsmath|) est aussi redéfinie et se comporte comme -\verb|\Ldots|. +\verb|\vdots|, \verb|\ddots|, \verb|\iddots|\footnotemark[\thefniddots] et \verb|\hdotsfor| sont redéfinies dans +les environnements de \pkg{nicematrix} et agissent comme \verb|\Ldots|, \verb|\Cdots|, \verb|\Vdots|, +\verb|\Ddots|, \verb|\Iddots| et \verb|\Hdotsfor| ; la commande \verb|\dots| (points de suspension «automatiques» +de \verb|amsmath|) est aussi redéfinie et se comporte comme \verb|\Ldots|. \item L'option \verb|renew-matrix|\par\nobreak Avec cette option, l'environnement \verb|{matrix}| est redéfini et @@ -574,7 +585,7 @@ et $j$ les numéros de ligne et de colonne de la case considérée. $\begin{pNiceMatrix}[name=~emphase#ma-matrice@] 1 & 2 & 3 \\ 4 & 5 & 6 \\ -7 & 8 & 9 \\ +7 & 8 & 9 \end{pNiceMatrix}$ \tikz[remember picture,overlay] \draw ~emphase#(ma-matrice-2-2)@ circle (2mm) ; @@ -582,7 +593,7 @@ $\begin{pNiceMatrix}[name=~emphase#ma-matrice@] $\begin{pNiceMatrix}[name=ma-matrice] 1 & 2 & 3 \\ 4 & 5 & 6 \\ -7 & 8 & 9 \\ +7 & 8 & 9 \end{pNiceMatrix}$ \tikz[remember picture,overlay] \draw (ma-matrice-2-2) circle (2mm) ; @@ -638,8 +649,8 @@ a & a & a \medskip Les noms des «nœuds larges» s'obtiennent en ajoutant le suffixe «\verb|-large|» au nom des nœuds normaux. Dans l'exemple suivant, on a surligné tous les «nœuds larges». Nous considérons que cet exemple se suffit à lui-même comme -définition de ces nœuds.\footnote{Dans les environnements du type de \verb|{pNiceArrayC}| et \verb|{pNiceArrayRC}|, il - n'y a pas de «nœuds larges» créés dans la rangée supplémentaire et la colonne supplémentaire.} +définition de ces nœuds.\footnote{Il n'y a pas de «nœuds larges» créés dans les lignes et colonnes extérieures + (pour ces lignes et colonnes, voir p.~\pageref{exterior}).} \[\begin{pNiceMatrix}[ create-extra-nodes, @@ -692,7 +703,7 @@ a & a & a \end{pNiceMatrix}\] \medskip -Il est aussi possible d'ajouter de l'espace des deux côtés du tableau avec les options +Il est aussi possible d'ajouter de l'espace sur les côtés du tableau avec les options \verb|extra-left-margin| et \verb|extra-right-margin|. Ces marges ne sont pas incorporées dans les «nœuds larges». Dans l'exemple suivant, nous avons utilisé \verb|extra-left-margin| et \verb|extra-right-margin| avec la valeur $3$~pt. \[\begin{pNiceMatrix}[ @@ -759,13 +770,13 @@ entre les nœuds). $\begin{pNiceMatrix}[~emphase#code-after = {\line {1-1} {3-3}}@] 0 & 0 & 0 \\ 0 & & 0 \\ -0 & 0 & 0 \\ +0 & 0 & 0 \end{pNiceMatrix}$ \end{BVerbatim} $\begin{pNiceMatrix}[code-after = {\line {1-1} {3-3}}] 0 & 0 & 0 \\ 0 & & 0 \\ -0 & 0 & 0 \\ +0 & 0 & 0 \end{pNiceMatrix}$ @@ -799,219 +810,158 @@ $\left[\begin{NiceArray}{CCCC|C} a_1 & ? & \Cdots & ? & ? \\ 0 & & \Ddots & \Vdots & \Vdots\\ \Vdots & \Ddots & \Ddots & ? \\ -0 & \Cdots & 0 & a_n & ? \\ +0 & \Cdots & 0 & a_n & ? \end{NiceArray}\right]$ \end{BVerbatim} $\left[\begin{NiceArray}{CCCC|C} a_1 & ? & \Cdots & ? & ? \\ 0 & & \Ddots & \Vdots & \Vdots\\ \Vdots & \Ddots & \Ddots & ? \\ -0 & \Cdots & 0 & a_n & ? \\ +0 & \Cdots & 0 & a_n & ? \end{NiceArray}\right]$ \vspace{1cm} -Un exemple où on utilise \verb|{NiceArray}| parce que l'on veut utiliser les types de colonne \verb|L| et -\verb|R| : +Il existe également des variantes pour l'environnement \verb|{NiceArray}|: +\verb|{pNiceArray}|, \verb|{bNiceArray}|, \verb|{BNiceArray}|, \verb|{vNiceArray}| et +\verb|{VNiceArray}|. + + +Dans l'exemple suivant, on utilise un environnment \verb|{pNiceArray}| (on n'utilise pas \verb|{pNiceMatrix}| car +on souhaite utiliser les types de colonne \verb|L| et \verb|R| --- avec \verb|{pNiceMatrix}|, toutes les +colonnes sont de type \verb|C|). + \bigskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\left(\begin{NiceArray}{LCR} +$\begin{pNiceArray}{LCR} a_{11} & \Cdots & a_{1n} \\ a_{21} & & a_{2n} \\ \Vdots & & \Vdots \\ -a_{n-1,1} & \Cdots & a_{n-1,n} \\ -\end{NiceArray}\right)$ +a_{n-1,1} & \Cdots & a_{n-1,n} +\end{pNiceArray}$ \end{BVerbatim} -$\left(\begin{NiceArray}{LCR} +$\begin{pNiceArray}{LCR} a_{11} & \Cdots & a_{1n} \\ a_{21} & & a_{2n} \\ \Vdots & & \Vdots \\ -a_{n-1,1} & \Cdots & a_{n-1,n} \\ -\end{NiceArray}\right)$ - +a_{n-1,1} & \Cdots & a_{n-1,n} +\end{pNiceArray}$ +\vspace{1cm} +L'environnement \verb|{NiceArray}| et ses variantes permettent de composer des rangées et des colonnes «extérieures» grâce aux options +\verb|first-row|, \verb|last-row|, \verb|first-col| et \verb|last-col|. +\label{exterior} +Il n'y a pas de spécification de colonne à fournir pour l'éventuelle «première colonne» (qui sera automatiquement +une colonne de type \verb|R|) ou pour l'éventuelle «dernière colonne» (qui sera automatiquement de type \verb|L|). -\section{L'environnement \{pNiceArrayC\} et ses variantes} -\label{pNiceArrayC} -L'environnement \verb|{pNiceArrayC}| compose une matrice avec une colonne extérieure. +\begin{Verbatim} +$\begin{pNiceArray}{CCCC}[~emphase#first-row,last-row,first-col,last-col@] + & C_1 & C_2 & C_3 & C_4 & \\ +L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ + & C_1 & C_2 & C_3 & C_4 & +\end{pNiceArray}$ +\end{Verbatim} +% +\[\begin{pNiceArray}{CCCC}[first-row,last-row,first-col,last-col] + & C_1 & C_2 & C_3 & C_4 & \\ +L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ + & C_1 & C_2 & C_3 & C_4 & +\end{pNiceArray}\] -L'environnement \verb|{pNiceArrayC}| prend un argument obligatoire qui est le préambule du tableau. -Les types de colonne disponibles sont les mêmes que pour l'environnement \verb|{NiceArray}|. Néanmoins, aucune -spécification de colonne ne doit être donnée pour la dernière colonne. Ce sera automatiquement (et obligatoirement) -une colonne de type \verb|L|. +\bigskip -Une option spéciale, nommée \verb|code-for-last-col|, permet d'indiquer des tokens qui seront insérés au début de -chaque case de la dernière colonne. L'option \verb|columns-width| ne s'applique pas à la colonne extérieure. +Néanmoins, il y a une particularité avec l'option \verb|last-row| : quand LaTeX compose un tableau \verb|{array}| +(via une commande \verb|\halign| de TeX), il le compose rangée par rangée et il n'y a pas de moyen direct de savoir +que l'on est arrivé à la dernière rangée avant la composition de celle-ci. Pour remédier à ce problème, +\pkg{nicematrix} écrit dans le fichier \verb|aux| le nombre de rangées du tableau pour pouvoir l'utiliser à la +compilation suivante. Il est néanmoins également possible de passer directement le nombre de rangées en argument de +l'option \verb|last-row| et, ainsi, \pkg{nicematrix} le connaîtra dès la première compilation. \bigskip +On peut contrôler l'apparence de ces rangées et colonnes avec les options \verb|code-for-first-row|, +\verb|code-for-last-row|, \verb|code-for-first-col| et \verb|code-for-last-col|. Ces options sont des listes de +tokens qui seront insérées au début de chaque case de la rangée ou de la colonne considérée. \begin{Verbatim} -$\begin{pNiceArrayC}{*6C|C}[nullify-dots,~emphase#code-for-last-col={\scriptstyle}@] -1 & 1 & 1 &\Cdots & & 1 & 0 & \\ -0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ -0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ - & & &\Ddots & & & \Vdots & \Vdots \\ -\Vdots & & &\Ddots & & 0 & \\ -0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 -\end{pNiceArrayC}$ +\NiceMatrixOptions{~emphase#code-for-first-row@ = \color{red}, + ~emphase#code-for-first-col@ = \color{blue}, + ~emphase#code-for-last-row@ = \color{green}, + ~emphase#code-for-last-col@ = \color{magenta}} +$\begin{pNiceArray}{CC|CC}[first-row,last-row=5,first-col,last-col] + & C_1 & C_2 & C_3 & C_4 & \\ +L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +\hline +L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ + & C_1 & C_2 & C_3 & C_4 & +\end{pNiceArray}$ \end{Verbatim} +% +\begin{scope} +\NiceMatrixOptions{code-for-first-row = \color{red}, + code-for-first-col = \color{blue}, + code-for-last-row = \color{green}, + code-for-last-col = \color{magenta}} +\[\begin{pNiceArray}{CC|CC}[first-row,last-row=5,first-col,last-col] + & C_1 & \multicolumn1C{C_2} & C_3 & C_4 & \\ +L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +\hline +L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ + & C_1 & \multicolumn1C{C_2} & C_3 & C_4 & +\end{pNiceArray}\] +\end{scope} -\[\begin{pNiceArrayC}{*6C|C}[nullify-dots,code-for-last-col={\scriptstyle}] -1 & 1 & 1 &\Cdots & & 1 & 0 & \\ -0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ -0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ - & & &\Ddots & & & \Vdots & \Vdots \\ -\Vdots & & &\Ddots & & 0 & \\ -0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 -\end{pNiceArrayC}\] - - - -\bigskip -On remarquera qu'un trait horizontal tracé avec \verb|\hline| ne s'étend \emph{pas} dans la dernière colonne. -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{pNiceArrayC} -a_{11} & a_{12} & a_{13} \\ -a_{21} & a_{22} & a_{23} \\ -a_{31} & a_{32} & a_{33} \\ -~emphase#\hline@ -S_1 & S_2 & S_3 -\end{pNiceArrayC}$ -\end{BVerbatim} -$\begin{pNiceArrayC}{CCC} -a_{11} & a_{12} & a_{13} & L_1 \\ -a_{21} & a_{22} & a_{23} & L_2 \\ -a_{31} & a_{32} & a_{33} & L_3 \\ -\hline -S_1 & S_2 & S_3 -\end{pNiceArrayC}$ +\emph{Remarques} +\begin{itemize} +\item Comme on peut le voir dans l'exemple précédent, un filet horizontal (tracé avec \verb|\hline|) ne s'étend pas +dans les colonnes extérieures et un filet vertical (spécifié par un caractère «\verb+|+» dans le préambule du +tableau) ne s'étend pas dans les rangées extérieures.\footnote{Ce dernier point n'est pas valable si on a chargé, + en plus de \pkg{nicematrix}, l'extension \pkg{arydshln}. Les extensions \pkg{nicematrix} et \pkg{arydshln} ne + sont pas parfaitement compatibles car \pkg{arydshln} redéfinit beaucoup de structures internes à \pkg{array}.} +\item La «première rangée» d'un environnement \verb|{pNiceArray}| porte le numéro $0$, et non $1$ (de même pour la +«première colonne»). Ce numéro est utilisé, par exemple, pour les noms des nœuds Tikz (les noms de ces nœuds sont +utilisés, par exemple, par la commande \verb|\line| dans le \verb|code-after|). +\item Sans surprise, une éventuelle option \verb|columns-width| (décrite p.~\pageref{width}) ne s'applique pas à la +«première colonne» ni à la «dernière colonne». +\item Pour des raisons techniques, il n'est pas possible d'utiliser l'option de la commande \verb|\\| après la +«première rangée» ou avant la «dernière rangée» (le placement des délimiteurs serait erroné). +\end{itemize} \bigskip -En fait, l'environnement \verb|{pNiceArrayC}| et ses variantes sont fondés sur un environnement plus général, appelé -\verb|{NiceArrayCwithDelims}|. Les deux premiers arguments obligatoires de cet environnement sont les délimiteurs +En fait, l'environnement \verb|{pNiceArray}| et ses variantes sont fondés sur un environnement plus général, appelé +\verb|{NiceArrayWithDelims}|. Les deux premiers arguments obligatoires de cet environnement sont les délimiteurs gauche et droit qui seront utilisés dans la construction de la matrice. Il est possible d'utiliser -\verb|{NiceArrayCwithDelims}| si on a besoin de délimiteurs atypiques. +\verb|{NiceArrayWithDelims}| si on a besoin de délimiteurs atypiques. \medskip \begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{NiceArrayCwithDelims} - {\downarrow}{\downarrow}{CCC} +$\begin{~emphase#NiceArrayWithDelims@} + {\downarrow}{\downarrow}{CCC}[last-col] 1 & 2 & 3 & L_1 \\ 4 & 5 & 6 & L_2 \\ 7 & 8 & 9 & L_3 -\end{NiceArrayCwithDelims}$ +\end{~emphase#NiceArrayWithDelims@}$ \end{BVerbatim} -$\begin{NiceArrayCwithDelims} - {\downarrow}{\downarrow}{CCC} +$\begin{NiceArrayWithDelims} + {\downarrow}{\downarrow}{CCC}[last-col] 1 & 2 & 3 & L_1 \\ 4 & 5 & 6 & L_2 \\ 7 & 8 & 9 & L_3 -\end{NiceArrayCwithDelims}$ - - - - -\section{L'environnement \{pNiceArrayRC\} et ses variantes} -\label{pNiceArrayRC} - -L'environnement \verb|{pNiceArrayRC}| compose une matrice avec une rangée extérieure et une colonne extérieure. - -Cet environnement \verb|{pNiceArrayRC}| prend un argument obligatoire qui est le préambule du tableau. Comme pour -l'environnement \verb|{pNiceArrayC}|, aucune spécification ne doit être fournie pour la dernière colonne qui sera -automatiquement une colonne de type \verb|L|. - -Une option spéciale, appelée \verb|code-for-first-row|, permet d'indiquer des tokens qui seront insérés au début de -chaque case de la rangée extérieure. - - -\bigskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{pNiceArrayRC}{CCC}% (ici, % est obligatoire) - [columns-width = auto, - code-for-first-row = \color{blue}, - code-for-last-col = \color{blue}] -C_1 & C_2 & C_3 \\ -1 & 2 & 3 & L_1\\ -4 & 5 & 6 & L_2\\ -7 & 8 & 9 & L_3\\ -\end{pNiceArrayRC}$ -\end{BVerbatim} -$\begin{pNiceArrayRC}{CCC}[columns-width=auto, - code-for-first-row = \color{blue}, - code-for-last-col = \color{blue}] -C_1 & C_2 & C_3 \\ -1 & 2 & 3 & L_1 \\ -4 & 5 & 6 & L_2 \\ -7 & 8 & 9 & L_3 \\ -\end{pNiceArrayRC}$ - - -\bigskip -La première rangée d'un environnement \verb|{pNiceArrayRC}| a le numéro $0$, et non~$1$. Ce numéro est utilisé pour -les noms des nœuds Tikz (les noms de ces nœuds sont utilisés, par exemple, par la commande \verb|\line| dans le \verb|code-after|). - -Pour des raisons techniques, il n'est pas possible d'utiliser l'option de la commande \verb|\\| après la première -rangée (le placement des délimiteurs serait erroné). - - -\bigskip - -\bigskip -Si on veut écrire un système linéaire, on peut utiliser le code suivant, avec un préambule \verb"CCC|C":\par\nobreak - -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{pNiceArrayRC}{~emphase#CCC|C@} -C_1 & \Cdots & C_n \\ -a_{11} & \Cdots & a_{1n} & b_1 \\ -\Vdots & & \Vdots & \Vdots \\ -a_{n1} & \Cdots & a_{nn} & b_n \\ -\end{pNiceArrayRC}$ -\end{BVerbatim} -$\begin{pNiceArrayRC}{CCC|C} -C_1 & \Cdots & \multicolumn1C{C_n} \\ -a_{11} & \Cdots & a_{1n} & b_1 \\ -\Vdots & & \Vdots & \Vdots \\ -a_{n1} & \Cdots & a_{nn} & b_n \\ -\end{pNiceArrayRC}$ - -\medskip -On remarquera que le trait vertical ne s'étend pas dans la première rangée.\footnote{Il s'agit d'une - caractéristique apparue dans la version 2.3 de \pkg{nicematrix}. Dans les versions antérieures, le trait - s'étendait dans la première rangée. On doit remarquer que si \pkg{arydshln} est chargé, le trait va se prolonger - dans la première rangée (c'est parce que \pkg{arydshln} redéfinit de nombreuses macros internes de \pkg{array}).} - - -\bigskip -En fait, l'environnement \verb|{pNiceArrayRC}| et ses variantes sont fondés sur un environnement plus général, appelé -\verb|{NiceArrayRCwithDelims}|. Les deux premiers arguments obligatoires de cet environnement sont les délimiteurs -gauche et droit qui seront utilisés dans la construction de la matrice. Il est possible d'utiliser -\verb|{NiceArrayRCwithDelims}| si on a besoin de délimiteurs atypiques. - - -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{NiceArrayRCwithDelims} - {\downarrow}{\downarrow}{CCC}[columns-width=auto] -C_1 & C_2 & C_3 \\ -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 -\end{NiceArrayRCwithDelims}$ -\end{BVerbatim} -$\begin{NiceArrayRCwithDelims} - {\downarrow}{\downarrow}{CCC}[columns-width=auto] -C_1 & C_2 & C_3 \\ -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 -\end{NiceArrayRCwithDelims}$ +\end{NiceArrayWithDelims}$ @@ -1019,9 +969,9 @@ C_1 & C_2 & C_3 \\ \section[Les lignes en pointillés pour séparer les rangées et les colonnes]{Les lignes en pointillés pour séparer les rangées\\ et les colonnes} -Dans les environnements \pkg{nicematrix}, il est possible d'utiliser la commande -\verb|\hdottedline| (fournie par \pkg{nicematrix}) qui est l'équivalent pour les pointillés des commandes -\verb|\hline| et \verb|\hdashline| (de \pkg{arydshln}). +Dans les environnements de \pkg{nicematrix}, il est possible d'utiliser la commande \verb|\hdottedline| (fournie +par \pkg{nicematrix}) qui est l'équivalent pour les pointillés des commandes \verb|\hline| et \verb|\hdashline| +(cette dernière étant une commande de \pkg{arydshln}). \medskip \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] @@ -1041,103 +991,106 @@ $\begin{pNiceMatrix} \bigskip -Dans les environnements avec un préambule explicite (comme -\verb|{NiceArray}|, etc.), il est possible de dessiner un trait vertical en pointillés avec le spécificateur -«\verb|:|». +Dans les environnements avec un préambule explicite (comme \verb|{NiceArray}|, \verb|{pNiceArray}|, etc.), il est +possible de dessiner un trait vertical en pointillés avec le spécificateur «\verb|:|». \medskip \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -\left(\begin{NiceArray}{CCCC~emphase#:@C} +\begin{pNiceArray}{CCCC~emphase#:@C} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 -\end{NiceArray}\right) +\end{pNiceArray} \end{BVerbatim} -$\left(\begin{NiceArray}{CCCC:C} +$\begin{pNiceArray}{CCCC:C} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 -\end{NiceArray}\right)$ +\end{pNiceArray}$ \bigskip -Ces lignes en pointillés ne s'étendent \emph{pas} dans la première rangée et la dernière colonne des environnements -qui proposent ces fonctionnalités (par ex. \verb|{pNiceArrayRC}|). +Ces lignes en pointillés ne s'étendent pas dans les rangées et colonnes extérieures. + \medskip \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -$\begin{pNiceArrayRC}{CCC:C}% - [ code-for-first-row = \color{blue}\scriptstyle, - code-for-last-col = \color{blue}\scriptstyle ] +$\begin{pNiceArray}{CCC:C}% + [first-row,last-col, + code-for-first-row = \color{blue}\scriptstyle, + code-for-last-col = \color{blue}\scriptstyle ] C_1 & C_2 & C_3 & C_4 \\ 1 & 2 & 3 & 4 & L_1 \\ 5 & 6 & 7 & 8 & L_2 \\ 9 & 10 & 11 & 12 & L_3 \\ \hdottedline 13 & 14 & 15 & 16 & L_4 -\end{pNiceArrayRC}$ +\end{pNiceArray}$ \end{BVerbatim} -$\begin{pNiceArrayRC}{CCC:C}[ code-for-first-row = \color{blue}\scriptstyle, - code-for-last-col = \color{blue}\scriptstyle ] +$\begin{pNiceArray}{CCC:C}% + [first-row,last-col, + code-for-first-row = \color{blue}\scriptstyle, + code-for-last-col = \color{blue}\scriptstyle ] C_1 & C_2 & C_3 & C_4 \\ 1 & 2 & 3 & 4 & L_1 \\ 5 & 6 & 7 & 8 & L_2 \\ 9 & 10 & 11 & 12 & L_3 \\ \hdottedline 13 & 14 & 15 & 16 & L_4 -\end{pNiceArrayRC}$ +\end{pNiceArray}$ \bigskip -Il est possible de changer dans -\pkg{nicematrix} la lettre utilisée pour indiquer dans le préambule un trait vertical en pointillés -avec l'option \verb|letter-for-dotted-lines| disponible dans \verb|\NiceMatrixOptions|. -Par exemple, dans ce document, nous avons chargé l'extension \pkg{arydshln} qui utilise la lettre «\verb|:|» -pour indiquer un trait vertical en tiretés. Par conséquent, en utilisant l'option \verb|letter-for-dotted-lines|, -on peut utiliser les traits verticaux fournis à la fois par \pkg{arydshln} et par \pkg{nicematrix}. +Il est possible de changer dans \pkg{nicematrix} la lettre utilisée pour indiquer dans le préambule un trait +vertical en pointillés avec l'option \verb|letter-for-dotted-lines| disponible dans \verb|\NiceMatrixOptions|. Par +exemple, dans ce document, nous avons chargé l'extension \pkg{arydshln} qui utilise la lettre «\verb|:|» pour +indiquer un trait vertical en tiretés. Par conséquent, en utilisant l'option \verb|letter-for-dotted-lines|, on +peut utiliser les traits verticaux fournis à la fois par \pkg{arydshln} et par \pkg{nicematrix}. + \medskip \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] \NiceMatrixOptions{letter-for-dotted-lines = V} -\left(\begin{NiceArray}{~emphase#C|C:CVC@} +\begin{pNiceArray}{~emphase#C|C:CVC@} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 -\end{NiceArray}\right) +\end{pNiceArray} \end{BVerbatim} \begin{scope} \NiceMatrixOptions{letter-for-dotted-lines = V} -$\left(\begin{NiceArray}{C|C:CVC} +$\begin{pNiceArray}{C|C:CVC} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 -\end{NiceArray}\right)$ +\end{pNiceArray}$ \end{scope} \section{La largeur des colonnes} \label{width} -Dans les environnements avec un préambule explicite -(comme \verb|{NiceArray}|, \verb|{pNiceArrayC}|, etc.), il est possible -de fixer la largeur d'une colonne avec les lettres classiques \verb|w| et \verb|W| de l'extension \pkg{array}. +Dans les environnements avec un préambule explicite (comme \verb|{NiceArray}|, \verb|{pNiceArray}|, etc.), il est +possible de fixer la largeur d'une colonne avec les lettres classiques \verb|w| et \verb|W| de l'extension +\pkg{array}. Dans les environnements de \pkg{nicematrix}, les cases des colonnes de ce type sont composées en mode +mathématique (alors que dans \verb|{array}| de \pkg{array}, elles sont composées en mode texte). \medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\left(\begin{NiceArray}{~emphase#wc{1cm}@CC} +$\begin{pNiceArray}{~emphase#Wc{1cm}@CC} 1 & 12 & -123 \\ 12 & 0 & 0 \\ 4 & 1 & 2 -\end{NiceArray}\right)$ +\end{pNiceArray}$ \end{BVerbatim} -$\left(\begin{NiceArray}{wc{1cm}CC} +$\begin{pNiceArray}{Wc{1cm}CC} 1 & 12 & -123 \\ 12 & 0 & 0 \\ 4 & 1 & 2 -\end{NiceArray}\right)$ +\end{pNiceArray}$ \bigskip -Il est aussi possible de fixer la largeur de toutes les colonnes de la matrice directement avec l'option -\verb|columns-width| (disponible dans tous les environnements de \pkg{nicematrix}). +Avec \pkg{nicematrix}, il est aussi possible de fixer la largeur de toutes les colonnes de la matrice directement +avec l'option \verb|columns-width| (disponible dans tous les environnements de \pkg{nicematrix}). \medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] @@ -1160,7 +1113,7 @@ possible de le supprimer en mettant \verb|\arraycolsep| à~$0$). \bigskip Il est possible de donner la valeur \verb|auto| à l'option \verb|columns-width| : toutes les colonnes du tableau auront alors une largeur égale à la largeur de la case la plus large du tableau. \textbf{Deux ou trois - compilations peuvent être nécessaires.}\par\nobreak + compilations successives peuvent être nécessaires.}\par\nobreak \medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] @@ -1183,23 +1136,23 @@ document avec la commande \verb|\NiceMatrixOptions|.\par\nobreak \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] ~emphase#\NiceMatrixOptions{columns-width=10mm}@ $\begin{pNiceMatrix} -a & b \\ c & d \\ +a & b \\ c & d \end{pNiceMatrix} = \begin{pNiceMatrix} -1 & 1245 \\ 345 & 2 \\ +1 & 1245 \\ 345 & 2 \end{pNiceMatrix}$ \end{BVerbatim} \begin{scope} \NiceMatrixOptions{columns-width=10mm} $\begin{pNiceMatrix} a & b \\ -c & d \\ +c & d \end{pNiceMatrix} = \begin{pNiceMatrix} 1 & 1245 \\ -345 & 2 \\ +345 & 2 \end{pNiceMatrix}$ \end{scope} @@ -1214,72 +1167,69 @@ utilise l'environnement \verb|{NiceMatrixBlock}| avec l'option \verb|auto-column \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ $\begin{pNiceMatrix} -a & b \\ c & d \\ +a & b \\ c & d \end{pNiceMatrix} = \begin{pNiceMatrix} -1 & 1245 \\ 345 & 2 \\ +1 & 1245 \\ 345 & 2 \end{pNiceMatrix}$ ~emphase#\end{NiceMatrixBlock}@ \end{BVerbatim} \begin{NiceMatrixBlock}[auto-columns-width] $\begin{pNiceMatrix} -a & b \\ c & d \\ +a & b \\ c & d \end{pNiceMatrix} = \begin{pNiceMatrix} -1 & 1245 \\ 345 & 2 \\ +1 & 1245 \\ 345 & 2 \end{pNiceMatrix}$ \end{NiceMatrixBlock} \section{L'option hlines} -Il est bien entendu possible d'ajouter des filets horizontaux entre les lignes avec la commande~\verb|\hline| dans les -environnements de \pkg{nicematrix} mais il est aussi possible de demander que tous les filets horizontaux soient -tracés avec l'option \verb|hlines|. - +Dans les environnements de \pkg{nicematrix}, on peut bien entendu ajouter des filets horizontaux entre les lignes +avec la commande~\verb|\hline|. Par souci de commodité, l'extension \pkg{nicemarix} fournit l'option \verb|hlines| +qui impose directement que tous les filets horizontaux soient tracés (à l'exception, très naturelle, du +filet avant l'éventuelle «première rangée» et après l'éventuelle «dernière rangée»). \medskip -\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] -$\begin{NiceArray}{|*{4}{C|}}[~emphase#hlines@] -e & a & b & c \\ -a & e & c & b \\ -b & c & e & a \\ -c & b & a & e +\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +$\begin{NiceArray}{|*{4}{C|}}[~emphase#hlines@,first-row,first-col] + & e & a & b & c \\ +e & e & a & b & c \\ +a & a & e & c & b \\ +b & b & c & e & a \\ +c & c & b & a & e \end{NiceArray}$ \end{BVerbatim} -$\begin{NiceArray}{|*{4}{C|}}[hlines] -e & a & b & c \\ -a & e & c & b \\ -b & c & e & a \\ -c & b & a & e -\end{NiceArray}$ +\raisebox{-5mm}{\box\ExampleOne} \section{Utilisation du type de colonne S de siunitx} Si l'extension \pkg{siunitx} est chargée (avant ou après \pkg{nicematrix}), il est possible d'utiliser les colonnes de type \verb|S| de \pkg{siunitx} dans les environnements de \pkg{nicematrix}. L'implémentation n'utilise -explicitement aucune macro privée de \pkg{siunitx}. +explicitement aucune macro privée de \pkg{siunitx}. Les colonnes \verb|d| de \pkg{dcolumn} ne sont pas prises en +charge par \pkg{nicematrix}. \medskip \begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] -$\begin{pNiceArrayRC}{~emphase#S@Cwc{1cm}C}[nullify-dots] +$\begin{pNiceArray}{~emphase#S@CWc{1cm}C}[nullify-dots,first-row] {C_1} & \Cdots & & C_n \\ 2.3 & 0 & \Cdots & 0 \\ 12.4 & \Vdots & & \Vdots \\ 1.45 \\ 7.2 & 0 & \Cdots & 0 -\end{pNiceArrayRC}$ +\end{pNiceArray}$ \end{BVerbatim} -$\begin{pNiceArrayRC}{SCwc{1cm}C}[nullify-dots] +$\begin{pNiceArray}{SCWc{1cm}C}[nullify-dots,first-row] {C_1} & \Cdots & & C_n \\ 2.3 & 0 & \Cdots & 0 \\ 12.4 & \Vdots & & \Vdots \\ 1.45 \\ 7.2 & 0 & \Cdots & 0 -\end{pNiceArrayRC}$ +\end{pNiceArray}$ \section{Remarques techniques} @@ -1418,7 +1368,7 @@ Néanmoins, l'utilisateur peut changer ce comportement avec l'option Cette option est seulement pour la «compatibilité» puisque l'extension \pkg{nicematrix} fournit un contrôle plus précis avec les options \verb|left-margin|, -\verb|right-margin|, \verb|extra-left-margin| et \verb|extra-right-margin|. +\verb|extra-left-margin|, etc. \subsection{L'option de classe draft} @@ -1434,7 +1384,7 @@ C'est pourquoi, avec l'option de classe \verb|draft|, les lignes en pointillés pour accélérer la compilation. -\subsection{Un problème technique ave l'argument de \textbackslash\textbackslash} +\subsection{Un problème technique avec l'argument de \textbackslash\textbackslash} Pour des raisons techniques, si vous utilisez l'argument optionnel de la commande \verb|\\|, @@ -1499,6 +1449,25 @@ a & \multicolumn1C{\frac AB} \\[2mm] b & c \end{pNiceMatrix}$ +\subsection{Environnements obsolètes} + +La version 3.0 de \pkg{nicematrix} a introduit l'environnement +\verb|{pNiceArray}| (et ses variantes) avec les options \verb|first-row|, \verb|last-row|, +\verb|first-col| et \verb|last-col|. + +Par conséquent, les environnements suivants, présents dans les versions précédentes de \pkg{nicematrix} sont devenus +obsolètes : +% +\begin{itemize} +\item \verb|{NiceArrayCwithDelims}| ; +\item \verb|{pNiceArrayC}|, \verb|{bNiceArrayC}|, \verb|{BNiceArrayC}|, \verb|{vNiceArrayC}|, +\verb|{VNiceArrayC}| ; +\item \verb|{NiceArrayRCwithDelims}| ; +\item \verb|{pNiceArrayRC}|, \verb|{bNiceArrayRC}|, \verb|{BNiceArrayRC}|, \verb|{vNiceArrayRC}|, +\verb|{VNiceArrayRC}|. +\end{itemize} + +Ils seront peut-être supprimés dans une version future de \pkg{nicematrix}. \section{Exemples} @@ -1579,21 +1548,21 @@ $\begin{pNiceMatrix} Un exemple avec \verb|\multicolumn|:\par\nobreak \bigskip \begin{BVerbatim} -\begin{pNiceMatrix}[nullify-dots] +\begin{BNiceMatrix}[nullify-dots] 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ \Cdots & & ~emphase#\multicolumn{6}{C}{10 \text{ autres lignes}}@ & \Cdots \\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 -\end{pNiceMatrix} +\end{BNiceMatrix} \end{BVerbatim} \bigskip -\[\begin{pNiceMatrix}[nullify-dots] +\[\begin{BNiceMatrix}[nullify-dots] 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ \Cdots & & \multicolumn{6}{C}{10 \text{ autres lignes}} & \Cdots \\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 -\end{pNiceMatrix}\] +\end{BNiceMatrix}\] \vspace{2cm} Un exemple avec \verb|\Hdotsfor|:\par\nobreak @@ -1625,32 +1594,56 @@ Un exemple pour le résultant de deux polynômes : \bigskip \begin{BVerbatim} \setlength{\extrarowheight}{1mm} -\[\begin{NiceArray}{|CCCC:CCC|}[columns-width=6mm] +\[\begin{vNiceArray}{CCCC:CCC}[columns-width=6mm] a_0 & && &b_0 & & \\ a_1 &\Ddots&& &b_1 &\Ddots& \\ \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\ a_p & &&a_0 & & &b_1 \\ &\Ddots&&a_1 &b_q & &\Vdots\\ & &&\Vdots & &\Ddots& \\ - & &&a_p & & &b_q \\ -\end{NiceArray}\] + & &&a_p & & &b_q +\end{vNiceArray}\] \end{BVerbatim} \bigskip \begin{scope} \setlength{\extrarowheight}{1mm} -\[\begin{NiceArray}{|CCCC:CCC|}[columns-width=6mm] +\[\begin{vNiceArray}{CCCC:CCC}[columns-width=6mm] a_0 & && &b_0 & & \\ a_1 &\Ddots&& &b_1 &\Ddots& \\ \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\ a_p & &&a_0 & & &b_1 \\ &\Ddots&&a_1 &b_q & &\Vdots\\ & &&\Vdots & &\Ddots& \\ - & &&a_p & & &b_q \\ -\end{NiceArray}\] + & &&a_p & & &b_q +\end{vNiceArray}\] \end{scope} +\vspace{2cm} +Un exemple avec un système linéaire:\par\nobreak + +\begin{Verbatim} +$\begin{pNiceArray}{*6C|C}[nullify-dots,last-col,code-for-last-col={\scriptstyle}] +1 & 1 & 1 &\Cdots & & 1 & 0 & \\ +0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ +0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ + & & &\Ddots & & & \Vdots & \Vdots \\ +\Vdots & & &\Ddots & & 0 & \\ +0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 +\end{pNiceArray}$ +\end{Verbatim} + +\[\begin{pNiceArray}{*6C|C}[nullify-dots,last-col,code-for-last-col={\scriptstyle}] +1 & 1 & 1 &\Cdots & & 1 & 0 & \\ +0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ +0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ + & & &\Ddots & & & \Vdots & \Vdots \\ +\Vdots & & &\Ddots & & 0 & \\ +0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 +\end{pNiceArray}\] + + \subsection{Largeur des colonnes} @@ -1664,12 +1657,12 @@ nous voulons la même largeur (automatique) pour toutes les colonnes. ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ \NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle} \setlength{\extrarowheight}{1mm} -\quad $\begin{pNiceArrayC}{CCCC:C} +\quad $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 2&4&8&16&9&\\ 3&9&27&81&36&\\ -4&16&64&256&100&\\ -\end{pNiceArrayC}$ +4&16&64&256&100& +\end{pNiceArray}$ ... ~emphase#\end{NiceMatrixBlock}@ \end{BVerbatim} @@ -1681,63 +1674,61 @@ nous voulons la même largeur (automatique) pour toutes les colonnes. \NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle} \setlength{\extrarowheight}{1mm} -\quad $\begin{pNiceArrayC}{CCCC:C} +\quad $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 2&4&8&16&9&\\ 3&9&27&81&36&\\ -4&16&64&256&100&\\ -\end{pNiceArrayC}$ +4&16&64&256&100& +\end{pNiceArray}$ \medskip -\quad $\begin{pNiceArrayC}{CCCC:C} +\enskip $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 0&2&6&14&7&L_2\gets-2L_1+L_2 \\ 0&6&24&78&33&L_3\gets-3L_1+L_3 \\ -0&12&60&252&96&L_4\gets-4L_1+L_4 \\ -\end{pNiceArrayC}$ +0&12&60&252&96&L_4\gets-4L_1+L_4 +\end{pNiceArray}$ \medskip -\quad $\begin{pNiceArrayC}{CCCC:C} +\enskip $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 0&1&3&7&\frac72&L_2\gets\frac12L_2\\ 0&3&12&39&\frac{33}2&L_3\gets\frac12L_3 \\ -0&1&5&21&8&L_4\gets\frac1{12}L_4 \\ -\end{pNiceArrayC}$ +0&1&5&21&8&L_4\gets\frac1{12}L_4 +\end{pNiceArray}$ \medskip -\quad $\begin{pNiceArrayC}{CCCC:C} +\enskip $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 0&1&3&7&\frac72&\\ 0&0&3&18&6&L_3 \gets -3L_2+L_3 \\ -0&0&-2&-14&-\frac92&L_4 \gets L_2-L_4 \\ -\end{pNiceArrayC}$ +0&0&-2&-14&-\frac92&L_4 \gets L_2-L_4 +\end{pNiceArray}$ \medskip -\quad $\begin{pNiceArrayC}{CCCC:C} +\enskip $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 0&1&3&7&\frac72&\\ 0&0&1&6&2&L_3 \gets \frac13L_3\\ -0&0&-2&-14&-\frac92&\\ -\end{pNiceArrayC}$ +0&0&-2&-14&-\frac92& +\end{pNiceArray}$ \medskip -\quad $\begin{pNiceArrayC}{CCCC:C} +\enskip $\begin{pNiceArray}{CCCC:C}[last-col] 1&1&1&1&1&\\ 0&1&3&7&\frac72&\\ 0&0&1&6&2& \\ -0&0&0&-2&-\frac12 & L_4 \gets 2L_3+L_4 \\ -\end{pNiceArrayC}$ +0&0&0&-2&-\frac12 & L_4 \gets 2L_3+L_4 +\end{pNiceArray}$ \end{NiceMatrixBlock} \end{multicols} - - \subsection{Comment surligner les cases} \label{highlight} @@ -1749,8 +1740,8 @@ moyen» ou le «nœud large»). Dans l'exemple suivant, on utilise les «nœuds des lignes, on doit fixer \verb|inner sep = -\pgflinewidth/2|. \begin{Verbatim} -$\left(\,\begin{NiceArray}{>{\strut}CCCC}% - [create-extra-nodes,left-margin,right-margin, +$\begin{pNiceArray}{>{\strut}CCCC}% + [create-extra-nodes,margin,extra-margin=2pt, code-after = {\begin{tikzpicture} [~emphase#name suffix = -large@, every node/.style = {draw, @@ -1764,12 +1755,12 @@ a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} -\end{NiceArray}\,\right)$ +\end{pNiceArray}$ \end{Verbatim} -\[\left(\,\begin{NiceArray}{>{\strut}CCCC}[ - create-extra-nodes,left-margin,right-margin, +\[\begin{pNiceArray}{>{\strut}CCCC}[ + create-extra-nodes,margin,extra-margin=2pt, code-after = {\begin{tikzpicture}[name suffix = -large, every node/.style = {draw, inner sep = -\pgflinewidth/2}] @@ -1782,35 +1773,19 @@ a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} -\end{NiceArray}\,\right)\] +\end{pNiceArray}\] \vspace{1cm} -L'extension \pkg{nicematrix} est construite au-dessus de l'environnement \verb|{array}| et, par conséquent, il est -possible d'utiliser l'extension \pkg{colortbl} dans les environnements de \pkg{nicematrix}. - -\medskip -\begin{BVerbatim}[baseline=c] -$\begin{bNiceMatrix} -0 & \Cdots & 0 \\ -~emphase#\rowcolor{red!15}@ 1 & \Cdots & 1 \\ -0 & \Cdots & 0 \\ -\end{bNiceMatrix}$ -\end{BVerbatim} -\hspace{2cm} -$\begin{bNiceMatrix} -0 & \Cdots & 0 \\ -\rowcolor{red!15} 1 & \Cdots & 1 \\ -0 & \Cdots & 0 \\ -\end{bNiceMatrix}$ -\medskip -Le résultat peut paraître décevant. C'est pourquoi nous proposons une autre méthode pour surligner une rangée de la -matrice. Nous créons un nœud Tikz rectangulaire qui englobe les nœuds de la deuxième rangée en uitlisant les outils -de la bibliothèque -Tikz \pkg{fit}. Ce nœud est rempli après la construction de la matrice. Pour que l'on puisse voir le texte -\emph{sous} le nœud, nous devons utiliser la transparence avec le \verb|blend mode| égal à \verb|multiply|. -Attention : certains lecteurs de \textsc{pdf} ne sont pas capables de rendre la transparence correctement. +L'extension \pkg{nicematrix} est construite au-dessus de l'environnement \verb|{array}| et, par conséquent, il est +possible d'utiliser l'extension \pkg{colortbl} dans les environnements de \pkg{nicematrix}. Les possibilités de +réglage de \pkg{colortbl} sont néanmoins assez limitées. C'est pourquoi nous proposons une autre méthode pour +surligner une rangée de la matrice. Nous créons un nœud Tikz rectangulaire qui englobe les nœuds de la deuxième +rangée en utilisant les outils de la bibliothèque Tikz \pkg{fit}. Ce nœud est rempli après la construction de la +matrice. Pour que l'on puisse voir le texte \emph{sous} le nœud, nous devons utiliser la transparence avec le +\verb|blend mode| égal à \verb|multiply|. Attention : certains lecteurs de \textsc{pdf} ne sont pas capables de +rendre la transparence correctement. \tikzset{highlight/.style={rectangle, @@ -1830,14 +1805,14 @@ Attention : certains lecteurs de \textsc{pdf} ne sont pas capables de rendre la $\begin{bNiceMatrix}[~emphase#code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}@] 0 & \Cdots & 0 \\ 1 & \Cdots & 1 \\ -0 & \Cdots & 0 \\ +0 & \Cdots & 0 \end{bNiceMatrix}$ \end{Verbatim} \[\begin{bNiceMatrix}[code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}] 0 & \Cdots & 0 \\ 1 & \Cdots & 1 \\ -0 & \Cdots & 0 \\ +0 & \Cdots & 0 \end{bNiceMatrix}\] @@ -1869,18 +1844,18 @@ On considère maintenant la matrice suivante que l'on a appelée \verb|exemple|. \medskip \begin{Verbatim} -$\begin{pNiceArrayC}{CCC}[~emphase#name=exemple@,create-extra-nodes] -a & a + b & a + b + c & L_1\\ +$\begin{pNiceArray}{CCC}[~emphase#name=exemple@,create-extra-nodes,last-col] +a & a + b & a + b + c & L_1 \\ a & a & a + b & L_2 \\ a & a & a & L_3 -\end{pNiceArrayC}$ +\end{pNiceArray}$ \end{Verbatim} -\[\begin{pNiceArrayC}{CCC} -a & a + b & a + b + c & L_1\\ +\[\begin{pNiceArray}{CCC}[last-col] +a & a + b & a + b + c & L_1 \\ a & a & a + b & L_2 \\ a & a & a & L_3 -\end{pNiceArrayC}\] +\end{pNiceArray}\] \bigskip Si on veut surligner chaque rangée de la matrice, on peut utiliser la technique précédente trois fois. @@ -1914,7 +1889,8 @@ Si on veut surligner chaque rangée de la matrice, on peut utiliser la technique \medskip On obtient la matrice suivante. -\[\begin{pNiceArrayC}{CCC}[ +\[\begin{pNiceArray}{CCC}[ + last-col, create-extra-nodes, code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15, blend mode = multiply, @@ -1923,10 +1899,10 @@ On obtient la matrice suivante. \node [fit = (2-1) (2-3)] {} ; \node [fit = (3-1) (3-3)] {} ; \end{tikzpicture}}] -a & a + b & a + b + c & L_1\\ +a & a + b & a + b + c & L_1 \\ a & a & a + b & L_2 \\ a & a & a & L_3 -\end{pNiceArrayC}\] +\end{pNiceArray}\] \medskip Le résultat peut paraître décevant. On peut l'améliorer en utilisant les «nœuds moyens» au lieu des «nœuds normaux». @@ -1942,7 +1918,8 @@ Le résultat peut paraître décevant. On peut l'améliorer en utilisant les «n \medskip On obtient la matrice suivante. -\[\begin{pNiceArrayC}{CCC}[ +\[\begin{pNiceArray}{CCC}[ + last-col, create-extra-nodes, code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15, blend mode = multiply, @@ -1952,10 +1929,10 @@ On obtient la matrice suivante. \node [fit = (2-1) (2-3)] {} ; \node [fit = (3-1) (3-3)] {} ; \end{tikzpicture}}] -a & a + b & a + b + c & L_1\\ +a & a + b & a + b + c & L_1 \\ a & a & a + b & L_2 \\ a & a & a & L_3 -\end{pNiceArrayC}\] +\end{pNiceArray}\] \vspace{1cm} @@ -1998,6 +1975,114 @@ A_{41} & A_{42} & A_{43} & A_{44} \end{NiceArray}\,\right)\] +\subsection{Utilisation directe des nœuds Tikz} + +Dans l'exemple suivant, on souhaite illustrer le produit mathématique de deux matrices. + +\medskip +L'utilisation de \verb|{NiceMatrixBlock}| avec l'option \verb|auto-columns-width| va permettre que toutes les +colonnes aient la même largeur ce qui permettra un alignement des deux matrices superposées. +\begin{Verbatim} +\begin{NiceMatrixBlock}[auto-columns-width] +\end{Verbatim} + +\begin{Verbatim} +\NiceMatrixOptions{nullify-dots} +\end{Verbatim} + +Les trois matrices vont être disposées les unes par rapport aux autres grâce à un tableau de LaTeX. +\begin{Verbatim} +$\begin{array}{cc} +& +\end{Verbatim} + +La matrice $B$ a une ``première rangée'' (pour $C_j$) d'où l'option \verb|first-row|. +\begin{Verbatim} +\begin{bNiceArray}{C>{\strut}CCCC}[name=B,first-row] + & & C_j \\ +b_{11} & \Cdots & b_{1j} & \Cdots & b_{1n} \\ +\Vdots & & \Vdots & & \Vdots \\ + & & b_{kj} \\ + & & \Vdots \\ + b_{n1} & \Cdots & b_{nj} & \Cdots & b_{nn} +\end{bNiceArray} \\ \\ +\end{Verbatim} + +La matrice $A$ a une ``première colonne'' (pour $L_i$) d'où l'option \verb|first-col|. +\begin{Verbatim} +\begin{bNiceArray}{CC>{\strut}CCC}[name=A,first-col] + & a_{11} & \Cdots & & & a_{nn} \\ + & \Vdots & & & & \Vdots \\ +L_i & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} \\ + & \Vdots & & & & \Vdots \\ + & a_{n1} & \Cdots & & & a_{nn} \\ +\end{bNiceArray} +& +\end{Verbatim} + +Dans la matrice produit, on remarquera que les lignes en pointillés sont «semi-ouvertes». +\begin{Verbatim} +\begin{bNiceArray}{CC>{\strut}CCC} + & & & & \\ + & & \Vdots \\ +\Cdots & & c_{ij} \\ +\\ +\\ +\end{bNiceArray} +\end{array}$ + +\end{NiceMatrixBlock} +\end{Verbatim} + +\begin{Verbatim} +\begin{tikzpicture}[remember picture, overlay] + \node [highlight, fit = (A-3-1) (A-3-5) ] {} ; + \node [highlight, fit = (B-1-3) (B-5-3) ] {} ; + \draw [color = gray] (A-3-3) to [bend left] (B-3-3) ; +\end{tikzpicture} +\end{Verbatim} + + +\begin{NiceMatrixBlock}[auto-columns-width] +\NiceMatrixOptions{nullify-dots} +$\begin{array}{cc} +& +\begin{bNiceArray}{C>{\strut}CCCC}[name=B,first-row] + & & C_j \\ +b_{11} & \Cdots & b_{1j} & \Cdots & b_{1n} \\ +\Vdots & & \Vdots & & \Vdots \\ + & & b_{kj} \\ + & & \Vdots \\ + b_{n1} & \Cdots & b_{nj} & \Cdots & b_{nn} +\end{bNiceArray} \\ \\ +\begin{bNiceArray}{CC>{\strut}CCC}[name=A,first-col] + & a_{11} & \Cdots & & & a_{nn} \\ + & \Vdots & & & & \Vdots \\ +L_i & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} \\ + & \Vdots & & & & \Vdots \\ + & a_{n1} & \Cdots & & & a_{nn} \\ +\end{bNiceArray} +& +\begin{bNiceArray}{CC>{\strut}CCC} + & & & & \\ + & & \Vdots \\ +\Cdots & & c_{ij} \\ +\\ +\\ +\end{bNiceArray} +\end{array}$ + +\end{NiceMatrixBlock} + +\begin{tikzpicture}[remember picture, overlay] + \node [highlight, fit = (A-3-1) (A-3-5) ] {} ; + \node [highlight, fit = (B-1-3) (B-5-3) ] {} ; + \draw [color = gray] (A-3-3) to [bend left] (B-3-3) ; +\end{tikzpicture} + + + + \subsection{Matrices par blocs} \medskip @@ -2005,8 +2090,8 @@ Dans l'exemple suivant, on utilise les «nœuds larges» pour construire une mat ont été tracées avec \pkg{arydshln}). \begin{Verbatim} \NiceMatrixOptions{letter-for-dotted-lines = V} -\left(\begin{NiceArray}{CC:CC}% - [create-extra-nodes, +\begin{pNiceArray}{CC:CC}% ici, % est obligatoire + [create-extra-nodes, ~emphase#code-after = { \tikz \node [fit = (1-1-large) (2-2-large), inner sep = 0 pt]@ ~emphase# {$0_{22}$} ; }@ ] & & a_{13} & a_{14} \\ @@ -2014,14 +2099,14 @@ ont été tracées avec \pkg{arydshln}). \hdashline a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{34} & a_{44} -\end{NiceArray}\right) +\end{pNiceArray} \end{Verbatim} \begin{scope} \NiceMatrixOptions{letter-for-dotted-lines = V} -\[D = \left(\begin{NiceArray}{CC:CC}[ - create-extra-nodes, +\[D = \begin{pNiceArray}{CC:CC}% + [create-extra-nodes, code-after = { \tikz \node [fit = (1-1-large) (2-2-large), inner sep = 0 pt] {$0_{22}$} ; } ] & & a_{13} & a_{14} \\ @@ -2029,7 +2114,7 @@ a_{41} & a_{42} & a_{34} & a_{44} \hdashline a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{34} & a_{44} -\end{NiceArray}\right)\] +\end{pNiceArray}\] \end{scope} diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf Binary files differindex c52a61126fd..35745735051 100644 --- a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf +++ b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf diff --git a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx index 90140a6ec28..8709af977d5 100644 --- a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx +++ b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx @@ -15,8 +15,8 @@ % % \fi % \iffalse -\def\myfileversion{2.3} -\def\myfiledate{2019/07/18} +\def\myfileversion{3.0} +\def\myfiledate{2019/08/15} % % %<*batchfile> @@ -44,15 +44,28 @@ version 2005/12/01 or later. \endgroup %</batchfile> % -%<@@=nm> %<*driver> \documentclass[dvipsnames]{l3doc}% dvipsnames is for xcolor (loaded by Tikz, loaded by nicematrix) \VerbatimFootnotes \usepackage{xltxtra} \usepackage[xetex]{geometry} \geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}} -\usepackage{siunitx} + +\usepackage{colortbl} \usepackage{nicematrix} +\usepackage{siunitx} + +\newbox\ExampleOne + +\setbox\ExampleOne\hbox{$\begin{NiceArray}{|*{4}{C|}}[hlines,first-row,first-col] + & e & a & b & c \\ +e & e & a & b & c \\ +a & a & e & c & b \\ +b & b & c & e & a \\ +c & c & b & a & e +\end{NiceArray}$} + + \NewDocumentEnvironment {scope} {} {} {} \def\interitem{\vskip 7mm plus 2 mm minus 3mm} \def\emphase{\bgroup\color{RoyalPurple}\let\next=} @@ -63,7 +76,6 @@ version 2005/12/01 or later. \usepackage{multicol} \usepackage{arydshln} \setlength{\columnseprule}{0.4pt} -\usepackage{colortbl} \usepackage{footnotehyper} \parindent 0pt @@ -76,6 +88,14 @@ version 2005/12/01 or later. % \title{The package \pkg{nicematrix}\thanks{This document corresponds to the version~\myfileversion\space of \pkg{nicematrix}, % at the date of~\myfiledate.}} \author{F. Pantigny \\ \texttt{fpantigny@wanadoo.fr}} % +% \hypersetup{ +% pdfinfo = { +% Title = { The extension 'nicematrix' }, +% Subject = { A LaTeX extension } , +% Author = { F. Pantigny } +% } +% } +% % % \maketitle % @@ -107,22 +127,22 @@ version 2005/12/01 or later. % \textbullet\ continuous dotted lines\footnote{If the class option |draft| is % used, these dotted lines will not be drawn for a faster compilation.}; % -% \textbullet\ a first row and a last column for labels; +% \textbullet\ exterior row and columns for labels; % % \textbullet\ a control of the width of the columns. % \end{minipage} % \end{savenotes} % \hspace{1.4cm} -% $\begin{bNiceArrayRC}{CCCC}[code-for-last-col=\color{blue}\scriptstyle, -% code-for-first-row=\color{blue}\scriptstyle, -% columns-width = auto] -% C_1 & C_2 & \Cdots & C_n \\ -% a_{11} & a_{12} & \Cdots & a_{1n} & L_1 \\ -% a_{21} & a_{22} & \Cdots & a_{2n} & L_2 \\ -% \Vdots & \Vdots & \Ddots & \Vdots & \Vdots \\ -% a_{n1} & a_{n2} & \Cdots & a_{nn} & L_n -% \end{bNiceArrayRC} -% $ +% $\begin{bNiceArray}{CCCC}[first-row,first-col, +% code-for-first-col=\color{blue}\scriptstyle, +% code-for-first-row=\color{blue}\scriptstyle, +% columns-width = auto] +% & C_1 & C_2 & \Cdots & C_n \\ +% L_1 & a_{11} & a_{12} & \Cdots & a_{1n} \\ +% L_2 & a_{21} & a_{22} & \Cdots & a_{2n} \\ +% \Vdots & \Vdots & \Vdots & \Ddots & \Vdots\\ +% L_n & a_{n1} & a_{n2} & \Cdots & a_{nn} +% \end{bNiceArray}$ % % \medskip % A command |\NiceMatrixOptions| is provided to fix the options (the scope of @@ -162,7 +182,7 @@ version 2005/12/01 or later. % \begin{scope} % \NiceMatrixOptions{transparent} % \begin{minipage}{10cm} -% Now, if we use the package \pkg{nicematrix} with the option |transparent|, the +% Now, if we use the package \pkg{nicematrix} with the option\\ |transparent|, the % same code will give the result on the right. % \end{minipage}\hspace{1cm} % $A = \begin{pmatrix} @@ -182,12 +202,12 @@ version 2005/12/01 or later. % \begin{ttfamily} % \setlength{\tabcolsep}{3mm} % \begin{tabular}{llll} -% \{NiceMatrix\} & \{NiceArray\} & \{pNiceArrayC\} & \{pNiceArrayRC\} \\ -% \{pNiceMatrix\} & & \{bNiceArrayC\} & \{bNiceArrayRC\} \\ -% \{bNiceMatrix\} & & \{BNiceArrayC\} & \{BNiceArrayRC\} \\ -% \{BNiceMatrix\} & & \{vNiceArrayC\} & \{vNiceArrayRC\} \\ -% \{vNiceMatrix\} & & \{VNiceArrayC\} & \{VNiceArrayRC\} \\ -% \{VNiceMatrix\} & & \{NiceArrayCwithDelims\} & \{NiceArrayRCwithDelims\} \\ +% \{NiceMatrix\} & \{NiceArray\} & \{pNiceArray\} \\ +% \{pNiceMatrix\} & & \{bNiceArray\} \\ +% \{bNiceMatrix\} & & \{BNiceArray\} \\ +% \{BNiceMatrix\} & & \{vNiceArray\} \\ +% \{vNiceMatrix\} & & \{VNiceArray\} \\ +% \{VNiceMatrix\} & & \{NiceArrayWithDelims\} \\ % \end{tabular} % \end{ttfamily} % @@ -204,25 +224,13 @@ version 2005/12/01 or later. % package |{array}|. However, for technical reasons, in the preamble of the % environment |{NiceArray}|, the user must use the letters |L|, |C| and~|R| % instead of |l|, |c| and |r|. It's possible to use the constructions -% |w{...}{...}|, |W{...}{...}|, "|", |>{...}|, |<{...}|, -% |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, |m| and |b| should not -% be used. See p.~\pageref{NiceArray} the section relating to |{NiceArray}|. -% -% \medskip -% The environments with |C| at the end of their name, |{pNiceArrayC}|, -% |{bNiceArrayC}|, |{BNiceArrayC}|, |{vNiceArrayC}| and |{VNiceArrayC}| are -% similar to the environment |{NiceArray}| (especially the special letters |L|, -% |C| and |R|) but create an exterior column (on the right of the closing -% delimiter). See p.~\pageref{pNiceArrayC} the section relating to -% |{pNiceArrayC}|. -% -% \medskip -% The environments with |RC|, |{pNiceArrayRC}|, |{bNiceArrayRC}|, -% |{BNiceArrayRC}|, |{vNiceArrayRC}|, |{VNiceArrayRC}| are similar to the -% environment |{NiceArray}| but create an exterior row (above the main matrix) -% and an exterior column. See p.~\pageref{pNiceArrayRC} the section relating to -% |{pNiceArrayRC}|. -% +% |w{...}{...}|, |W{...}{...}|\footnote{However, for the columns of type |w| and +% |W|, the cells are composed in math mode (in the environments of +% \pkg{nicematrix}) whereas in |{array}| of \pkg{array}, they are composed in text mode.}, "|", +% |>{...}|, |<{...}|, |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, +% |m| and |b| should not be used. The environment |{NiceArray}| and its variants +% provide also options to draw exterior rows and columns. See p.~\pageref{NiceArray} +% the section relating to |{NiceArray}| % % % \section{The continuous dotted lines} @@ -234,6 +242,8 @@ version 2005/12/01 or later. % variant of |\ddots| with dots going forward: \smash{$\iddots$}. If |mathdots| % is loaded, the version of |mathdots| is used. It corresponds to the command % |\adots| of \pkg{unicode-math}.} +% \newcounter{fniddots} +% \setcounter{fniddots}{\thefootnote} % % \smallskip % Each of them must be used alone in the cell of the array and it draws a dotted @@ -248,7 +258,7 @@ version 2005/12/01 or later. % \Vdots & a_2 & \Cdots & & a_2 \\ % & \Vdots & \Ddots \\ % \\ -% a_1 & a_2 & & & a_n \\ +% a_1 & a_2 & & & a_n % \end{bNiceMatrix} % \end{BVerbatim} % $\begin{bNiceMatrix} @@ -256,7 +266,7 @@ version 2005/12/01 or later. % \Vdots & a_2 & \Cdots & & a_2 \\ % & \Vdots & \Ddots \\ % \\ -% a_1 & a_2 & & & a_n \\ +% a_1 & a_2 & & & a_n % \end{bNiceMatrix}$ % % \interitem @@ -343,12 +353,13 @@ version 2005/12/01 or later. % 0 & & \Cdots & 0 % \end{bNiceMatrix}$ % -% \bigskip +% \bigskip % There are also other means to change the size of the matrix. Someone might % want to use the optional argument of the command~|\\| for the vertical % dimension and a command~|\hspace*| in a cell for the horizontal % dimension.\footnote{Nevertheless, the best way to fix the width of a column is -% to use the environment |{NiceArray}| with a column of type~|w| (or |W|).} +% to use the environment |{NiceArray}| (or one of its variants) with a column of +% type~|w| or~|W|: see p.~\pageref{width}} % % However, a command~|\hspace*| might interfer with the construction of the % dotted lines. That's why the package \pkg{nicematrix} provides a @@ -474,6 +485,7 @@ version 2005/12/01 or later. % \textbf{There must be no space before the opening bracket (|[|) of the options % of the environment.} % +% % \subsection{The command \textbackslash Hdotsfor} % % Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to @@ -491,14 +503,14 @@ version 2005/12/01 or later. % 1 & 2 & 3 & 4 & 5 \\ % 1 & ~emphase#\Hdotsfor{3}@ & 5 \\ % 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 % \end{pNiceMatrix}$ % \end{BVerbatim} % $\begin{pNiceMatrix} % 1 & 2 & 3 & 4 & 5 \\ % 1 & \Hdotsfor{3} & 5 \\ % 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 % \end{pNiceMatrix}$ % % \bigskip @@ -511,14 +523,14 @@ version 2005/12/01 or later. % 1 & 2 & 3 & 4 & 5 \\ % & ~emphase#\Hdotsfor{3}@ \\ % 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 % \end{pNiceMatrix}$ % \end{BVerbatim} % $\begin{pNiceMatrix} % 1 & 2 & 3 & 4 & 5 \\ % & \Hdotsfor{3} \\ % 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 % \end{pNiceMatrix}$ % % \bigskip @@ -528,7 +540,8 @@ version 2005/12/01 or later. % but this argument is discarded silently. % % Remark: Unlike the command |\hdotsfor| of \pkg{amsmath}, the command -% |\Hdotsfor| is compatible with the extension \pkg{colortbl}. +% |\Hdotsfor| may be used when the extension \pkg{colortbl} is loaded (but you +% might have problem if you use |\rowcolor| on the same row as |\Hdotsfor|). % % \subsection{How to generate the continuous dotted lines transparently} % @@ -545,9 +558,7 @@ version 2005/12/01 or later. % \begin{itemize} % \item The option |renew-dots|\par\nobreak % With this option, the commands |\ldots|, |\cdots|, |\vdots|, |\ddots|, -% |\iddots|\footnote{The command |\iddots| is not a command of LaTeX but is -% defined by the package \pkg{nicematrix}. If |mathdots| is loaded, the version -% of |mathdots| is used.} and |\hdotsfor| are redefined within the environments +% |\iddots|\footnotemark[\thefniddots] and |\hdotsfor| are redefined within the environments % provided by \pkg{nicematrix} and behave like |\Ldots|, |\Cdots|, |\Vdots|, % |\Ddots|, |\Iddots| and |\Hdotsfor|; the command |\dots| (``automatic dots'' % of |amsmath|) is also redefined to behave like |\Ldots|. @@ -598,7 +609,7 @@ version 2005/12/01 or later. % $\begin{pNiceMatrix}[name=~emphase#mymatrix@] % 1 & 2 & 3 \\ % 4 & 5 & 6 \\ -% 7 & 8 & 9 \\ +% 7 & 8 & 9 % \end{pNiceMatrix}$ % \tikz[remember picture,overlay] % \draw ~emphase#(mymatrix-2-2)@ circle (2mm) ; @@ -606,7 +617,7 @@ version 2005/12/01 or later. % $\begin{pNiceMatrix}[name=mymatrix] % 1 & 2 & 3 \\ % 4 & 5 & 6 \\ -% 7 & 8 & 9 \\ +% 7 & 8 & 9 % \end{pNiceMatrix}$ % \tikz[remember picture,overlay] % \draw (mymatrix-2-2) circle (2mm) ; @@ -663,9 +674,8 @@ version 2005/12/01 or later. % The names of the ``large nodes'' are constructed by adding the suffix % ``|-large|'' to the names of the ``normal nodes''. In the following example, % we have underlined the ``large nodes''. We consider that this example is -% self-explanatory.\footnote{In the environments like |{pNiceArrayC}| and -% |{pNiceArrayRC}|, there is not ``large nodes'' created in the exterior row and -% column.} +% self-explanatory.\footnote{There is no ``large nodes'' created in the exterior +% rows and columns (for these rows and columns, cf. p.~\pageref{exterior}).} % % \[\begin{pNiceMatrix}[ % create-extra-nodes, @@ -696,7 +706,9 @@ version 2005/12/01 or later. % ``large nodes'' of the first column and last column. In the following example, % we have used the options |left-margin| and |right-margin|.\footnote{The % options |left-margin| and |right-margin| take dimensions as values but, if no -% value is given, the default value is used, which is |\arraycolsep|.} +% value is given, the default value is used, which is |\arraycolsep|. There is +% also an option |margin| to fix both |left-margin| and |right-margin| to the +% same value.} % \[\begin{pNiceMatrix}[ % create-extra-nodes,left-margin,right-margin, % code-after = {\begin{tikzpicture} @@ -721,10 +733,11 @@ version 2005/12/01 or later. % \medskip % It's also possible to add more space on both side of the array with the % options |extra-left-margin| and |extra-right-margin|. These margins are not -% incorporated in the ``large nodes''. In the following example, we have used -% |extra-left-margin| and |extra-right-margin| with the value $3$~pt. +% incorporated in the ``large nodes''. It's possible to fix both values with the +% option |extra-margin| and, in the following example, we use |extra-margin| +% with the value $3$~pt. % \[\begin{pNiceMatrix}[ -% create-extra-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt, +% create-extra-nodes,margin,extra-margin=3pt, % code-after = {\begin{tikzpicture} % [every node/.style = {blend mode = multiply, % inner sep = -\pgflinewidth/2}, @@ -788,13 +801,13 @@ version 2005/12/01 or later. % $\begin{pNiceMatrix}[~emphase#code-after = {\line {1-1} {3-3}}@] % 0 & 0 & 0 \\ % 0 & & 0 \\ -% 0 & 0 & 0 \\ +% 0 & 0 & 0 % \end{pNiceMatrix}$ % \end{BVerbatim} % $\begin{pNiceMatrix}[code-after = {\line {1-1} {3-3}}] % 0 & 0 & 0 \\ % 0 & & 0 \\ -% 0 & 0 & 0 \\ +% 0 & 0 & 0 % \end{pNiceMatrix}$ % % @@ -828,230 +841,178 @@ version 2005/12/01 or later. % a_1 & ? & \Cdots & ? & ? \\ % 0 & & \Ddots & \Vdots & \Vdots\\ % \Vdots & \Ddots & \Ddots & ? \\ -% 0 & \Cdots & 0 & a_n & ? \\ +% 0 & \Cdots & 0 & a_n & ? % \end{NiceArray}\right]$ % \end{BVerbatim} % $\left[\begin{NiceArray}{CCCC|C} % a_1 & ? & \Cdots & ? & ? \\ % 0 & & \Ddots & \Vdots & \Vdots\\ % \Vdots & \Ddots & \Ddots & ? \\ -% 0 & \Cdots & 0 & a_n & ? \\ +% 0 & \Cdots & 0 & a_n & ? % \end{NiceArray}\right]$ % -% \vspace{1cm} -% An example where we use |{NiceArray}| because we want to use the types |L| and -% |R| for the columns: +% \bigskip +% In fact, there is also variants for the environment |{NiceArray}|: +% |{pNiceArray}|, |{bNiceArray}|, |{BNiceArray}|, |{vNiceArray}| and +% |{VNiceArray}|. +% +% In the following example, we use an environment |{pNiceArray}| (we don't use +% |{pNiceMatrix}| because we want to use the types |L| and |R| +% --- in |{pNiceMatrix}|, all the columns are of type |C|). % % \bigskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\left(\begin{NiceArray}{LCR} +% $\begin{pNiceArray}{LCR} % a_{11} & \Cdots & a_{1n} \\ % a_{21} & & a_{2n} \\ % \Vdots & & \Vdots \\ -% a_{n-1,1} & \Cdots & a_{n-1,n} \\ -% \end{NiceArray}\right)$ +% a_{n-1,1} & \Cdots & a_{n-1,n} +% \end{pNiceArray}$ % \end{BVerbatim} -% $\left(\begin{NiceArray}{LCR} +% $\begin{pNiceArray}{LCR} % a_{11} & \Cdots & a_{1n} \\ % a_{21} & & a_{2n} \\ % \Vdots & & \Vdots \\ -% a_{n-1,1} & \Cdots & a_{n-1,n} \\ -% \end{NiceArray}\right)$ +% a_{n-1,1} & \Cdots & a_{n-1,n} +% \end{pNiceArray}$ % % +% \vspace{1cm} +% With the environment |{NiceArray}| and its the variants, it's possible to +% compose exterior rows and columns with the options |first-row|, |last-row|, +% |first-col| and |last-col|. +% \label{exterior} % +% There is no specification of column to provide for the potential ``first +% column'' (it will automatically be a |R| column) and for the potential ``last +% column'' (it will automatically be a |L| column). +% +% \begin{Verbatim} +% $\begin{pNiceArray}{CCCC}[~emphase#first-row,last-row,first-col,last-col@] +% & C_1 & C_2 & C_3 & C_4 & \\ +% L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +% L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +% L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +% L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ +% & C_1 & C_2 & C_3 & C_4 & +% \end{pNiceArray}$ +% \end{Verbatim} % -% \section{The environment \{pNiceArrayC\} and its variants} -% \label{pNiceArrayC} +% \[\begin{pNiceArray}{CCCC}[first-row,last-row,first-col,last-col] +% & C_1 & C_2 & C_3 & C_4 & \\ +% L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +% L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +% L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +% L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ +% & C_1 & C_2 & C_3 & C_4 & +% \end{pNiceArray}\] % -% The environment |{pNiceArrayC}| composes a matrix with an exterior column. +% \bigskip +% However, there is a particularity for the option |last-row|: when LaTeX +% composes an array (with the TeX command |\halign|) it composes it row by row +% and there is no direct way to know if we are at the last row before the +% composition of that row. That's why \pkg{nicematrix} writes in the |aux| file +% the number of rows of the array in order to use it at the next run. +% Nevertheless, it's possible to give directly the number of rows as the value +% of the key |last-row|. It that way, \pkg{nicematrix} will know the correct +% value by the first compilation. % -% The environment |{pNiceArrayC}| takes a mandatory argument which is the -% preamble of the array. The types of columns available are the same as for the -% environment |{NiceArray}|. \textbf{However, no specification must be given for -% the last column.} It will automatically (and necessarily) be a |L|~column. -% -% A special option, called |code-for-last-col|, specifies tokens that will be -% inserted before each cell of the last column. The option |columns-width| -% doesn't apply to this external column. -% % \bigskip +% It's possible to control the appearance of these rows and columns with options +% |code-for-first-row|, |code-for-last-row|, |code-for-first-col| and +% |code-for-last-col|. These options +% specify tokens that will be inserted before each cell of the corresponding row +% or column. +% % % \begin{Verbatim} -% $\begin{pNiceArrayC}{*6C|C}[nullify-dots,~emphase#code-for-last-col={\scriptstyle}@] -% 1 & 1 & 1 &\Cdots & & 1 & 0 & \\ -% 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ -% 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ -% & & &\Ddots & & & \Vdots & \Vdots \\ -% \Vdots & & &\Ddots & & 0 & \\ -% 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 -% \end{pNiceArrayC}$ +% \NiceMatrixOptions{~emphase#code-for-first-row@ = \color{red}, +% ~emphase#code-for-first-col@ = \color{blue}, +% ~emphase#code-for-last-row@ = \color{green}, +% ~emphase#code-for-last-col@ = \color{magenta}} +% $\begin{pNiceArray}{CC|CC}[first-row,last-row=5,first-col,last-col] +% & C_1 & C_2 & C_3 & C_4 & \\ +% L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +% L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ +% \hline +% L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +% L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ +% & C_1 & C_2 & C_3 & C_4 & +% \end{pNiceArray}$ % \end{Verbatim} -% -% \[\begin{pNiceArrayC}{*6C|C}[nullify-dots,code-for-last-col={\scriptstyle}] -% 1 & 1 & 1 &\Cdots & & 1 & 0 & \\ -% 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ -% 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ -% & & &\Ddots & & & \Vdots & \Vdots \\ -% \Vdots & & &\Ddots & & 0 & \\ -% 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 -% \end{pNiceArrayC}\] -% -% -% \bigskip -% Note that an horizontal line drawn with |\hline| does \emph{not} extend in -% the last column.\par\nobreak % -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{pNiceArrayC} -% a_{11} & a_{12} & a_{13} \\ -% a_{21} & a_{22} & a_{23} \\ -% a_{31} & a_{32} & a_{33} \\ -% ~emphase#\hline@ -% S_1 & S_2 & S_3 -% \end{pNiceArrayC}$ -% \end{BVerbatim} -% $\begin{pNiceArrayC}{CCC} -% a_{11} & a_{12} & a_{13} & L_1 \\ -% a_{21} & a_{22} & a_{23} & L_2 \\ -% a_{31} & a_{32} & a_{33} & L_3 \\ +% \begin{scope} +% \NiceMatrixOptions{code-for-first-row = \color{red}, +% code-for-first-col = \color{blue}, +% code-for-last-row = \color{green}, +% code-for-last-col = \color{magenta}} +% \[\begin{pNiceArray}{CC|CC}[first-row,last-row=5,first-col,last-col] +% & C_1 & \multicolumn1C{C_2} & C_3 & C_4 & \\ +% L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\ +% L_2 & a_{21} & a_{22} & a_{23} & a_{24} & L_2 \\ % \hline -% S_1 & S_2 & S_3 -% \end{pNiceArrayC}$ +% L_3 & a_{31} & a_{32} & a_{33} & a_{34} & L_3 \\ +% L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ +% & C_1 & \multicolumn1C{C_2} & C_3 & C_4 & +% \end{pNiceArray}\] +% \end{scope} +% +% +% \emph{Remarks} +% \begin{itemize} +% \item As shown in the previous example, an horizontal rule (drawn by |\hline|) +% doesn't extend in the exterior columns and a vertical rule (specified by a +% ``\verb+|+'' in the preamble of the array) doesn't extend in the exterior +% rows.\footnote{The latter is not true when the extension \pkg{arydshln} is +% loaded besides \pkg{nicematrix}. In fact, \pkg{nicematrix} and \pkg{arydhsln} +% are not totally compatible because \pkg{arydshln} redefines many internals of +% \pkg{array}.} +% \item The ``first row'' of an environment |{pNiceArray}| has the number $0$, and not +% $1$. Idem for the ``first column''. This number is used for the names of the Tikz +% nodes (the names of these nodes are used, for example, by the command |\line| +% in |code-after|). +% \item Logically, the potential option |columns-width| (described +% p.~\pageref{width}) doesn't apply to the ``first column'' and ``last column''. +% \item For technical reasons, it's not possible to use the option of the command |\\| +% after the ``first row'' or before the ``last row'' (the placement of the +% delimiters would be wrong). +% \end{itemize} +% +% +% % % \bigskip -% In fact, the environment |{pNiceArrayC}| and its variants are based upon a -% more general environment, called |{NiceArrayCwithDelims}|. The first two +% In fact, the environment |{pNiceArray}| and its variants are based upon a +% more general environment, called |{NiceArrayWithDelims}|. The first two % mandatory arguments of this environment are the left and right delimiters used % in the construction of the matrix. It's possible to use -% |{NiceArrayCwithDelims}| if we want to use atypical delimiters. +% |{NiceArrayWithDelims}| if we want to use atypical delimiters. % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{NiceArrayCwithDelims} -% {\downarrow}{\downarrow}{CCC} +% $\begin{~emphase#NiceArrayWithDelims@} +% {\downarrow}{\downarrow}{CCC}[last-col] % 1 & 2 & 3 & L_1 \\ % 4 & 5 & 6 & L_2 \\ % 7 & 8 & 9 & L_3 -% \end{NiceArrayCwithDelims}$ +% \end{~emphase#NiceArrayWithDelims@}$ % \end{BVerbatim} -% $\begin{NiceArrayCwithDelims} -% {\downarrow}{\downarrow}{CCC} +% $\begin{NiceArrayWithDelims} +% {\downarrow}{\downarrow}{CCC}[last-col] % 1 & 2 & 3 & L_1 \\ % 4 & 5 & 6 & L_2 \\ % 7 & 8 & 9 & L_3 -% \end{NiceArrayCwithDelims}$ -% -% -% \section{The environment \{pNiceArrayRC\} and its variants} -% \label{pNiceArrayRC} -% -% The environment |{pNiceArrayRC}| composes a matrix with an exterior row and an -% exterior column. -% -% This environment |{pNiceArrayRC}| takes a mandatory argument which is the -% preamble of the array. As for the environment |{pNiceArrayC}|, no -% specification must be given for the last column (it will automatically be a -% |L| column). -% -% A special option, called |code-for-first-row|, specifies tokens that will be -% inserted before each cell of the first row. -% -% \bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{pNiceArrayRC}{CCC}% (here, % is mandatory) -% [columns-width = auto, -% code-for-first-row = \color{blue}, -% code-for-last-col = \color{blue}] -% C_1 & C_2 & C_3 \\ -% 1 & 2 & 3 & L_1\\ -% 4 & 5 & 6 & L_2\\ -% 7 & 8 & 9 & L_3\\ -% \end{pNiceArrayRC}$ -% \end{BVerbatim} -% $\begin{pNiceArrayRC}{CCC}[columns-width=auto, -% code-for-first-row = \color{blue}, -% code-for-last-col = \color{blue}] -% C_1 & C_2 & C_3 \\ -% 1 & 2 & 3 & L_1 \\ -% 4 & 5 & 6 & L_2 \\ -% 7 & 8 & 9 & L_3 \\ -% \end{pNiceArrayRC}$ -% -% -% \bigskip -% The first row of an environment |{pNiceArrayRC}| has the number $0$, and not -% $1$. This number is used for the names of the Tikz nodes (the names of these -% nodes are used, for example, by the command |\line| in |code-after|). -% -% For technical reasons, it's not possible to use the option of the command |\\| -% after the first row (the placement of the delimiters would be wrong). +% \end{NiceArrayWithDelims}$ % % % -% \bigskip -% If we want to write a linear system, we can use the following code, with a -% preamble "CCC|C":\par\nobreak -% -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{pNiceArrayRC}{~emphase#CCC|C@} -% C_1 & \Cdots & C_n \\ -% a_{11} & \Cdots & a_{1n} & b_1 \\ -% \Vdots & & \Vdots & \Vdots \\ -% a_{n1} & \Cdots & a_{nn} & b_n \\ -% \end{pNiceArrayRC}$ -% \end{BVerbatim} -% $\begin{pNiceArrayRC}{CCC|C} -% C_1 & \Cdots & \multicolumn1C{C_n} \\ -% a_{11} & \Cdots & a_{1n} & b_1 \\ -% \Vdots & & \Vdots & \Vdots \\ -% a_{n1} & \Cdots & a_{nn} & b_n \\ -% \end{pNiceArrayRC}$ -% -% \medskip -% We remark that the vertical rule doesn't extend in the first -% row.\footnote{This is a feature of the version 2.2.1 of \pkg{nicematrix}. Before -% that version, the vrule extended in the first row. We must remark that, if the -% extension \pkg{arydshln} is loaded, the line will extend even if any -% functionnality of \pkg{arydshln} is used in the array (that's because -% \pkg{arydshln} redefine many internals of \pkg{array}).} -% -% -% \bigskip -% In fact, the environment |{pNiceArrayRC}| and its variants are based upon an -% more general environment, called |{NiceArrayRCwithDelims}|. The first two -% mandatory arguments of this environment are the left and right delimiters used -% in the construction of the matrix. It's possible to use -% |{NiceArrayRCwithDelims}| if we want to use atypical delimiters. -% -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{NiceArrayRCwithDelims} -% {\downarrow}{\downarrow}{CCC}[columns-width=auto] -% C_1 & C_2 & C_3 \\ -% 1 & 2 & 3 \\ -% 4 & 5 & 6 \\ -% 7 & 8 & 9 -% \end{NiceArrayRCwithDelims}$ -% \end{BVerbatim} -% $\begin{NiceArrayRCwithDelims} -% {\downarrow}{\downarrow}{CCC}[columns-width=auto] -% C_1 & C_2 & C_3 \\ -% 1 & 2 & 3 \\ -% 4 & 5 & 6 \\ -% 7 & 8 & 9 -% \end{NiceArrayRCwithDelims}$ -% -% % \section{The dotted lines to separate rows or columns} % % % In the environments of the extension \pkg{nicematrix}, it's possible to use % the command |\hdottedline| (provided by \pkg{nicematrix}) which is a -% counterpart of the classical commands |\hline| and |\hdashline| (of -% \pkg{arydshln}). +% counterpart of the classical commands |\hline| and |\hdashline| (the latter is +% a command of\pkg{arydshln}). % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] @@ -1090,31 +1051,33 @@ version 2005/12/01 or later. % % % \bigskip -% These dotted lines do \emph{not} extend in the ``first row'' and the ``last column'' -% of the environments for the environments with such features (\emph{e.g.} |{pNiceArrayRC}|). +% These dotted lines do \emph{not} extend in the potential exterior rows and columns. % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -% $\begin{pNiceArrayRC}{CCC:C}% -% [ code-for-first-row = \color{blue}\scriptstyle, -% code-for-last-col = \color{blue}\scriptstyle ] +% $\begin{pNiceArray}{CCC:C}[ +% first-row,last-col, +% code-for-first-row = \color{blue}\scriptstyle, +% code-for-last-col = \color{blue}\scriptstyle ] % C_1 & C_2 & C_3 & C_4 \\ % 1 & 2 & 3 & 4 & L_1 \\ % 5 & 6 & 7 & 8 & L_2 \\ % 9 & 10 & 11 & 12 & L_3 \\ % \hdottedline % 13 & 14 & 15 & 16 & L_4 -% \end{pNiceArrayRC}$ +% \end{pNiceArray}$ % \end{BVerbatim} -% $\begin{pNiceArrayRC}{CCC:C}[ code-for-first-row = \color{blue}\scriptstyle, -% code-for-last-col = \color{blue}\scriptstyle ] +% $\begin{pNiceArray}{CCC:C}[ +% first-row,last-col, +% code-for-first-row = \color{blue}\scriptstyle, +% code-for-last-col = \color{blue}\scriptstyle ] % C_1 & C_2 & C_3 & C_4 \\ % 1 & 2 & 3 & 4 & L_1 \\ % 5 & 6 & 7 & 8 & L_2 \\ % 9 & 10 & 11 & 12 & L_3 \\ % \hdottedline % 13 & 14 & 15 & 16 & L_4 -% \end{pNiceArrayRC}$ +% \end{pNiceArray}$ % % \bigskip % It's possible to change in \pkg{nicematrix} the letter used to specify a @@ -1145,8 +1108,9 @@ version 2005/12/01 or later. % \section{The width of the columns} % \label{width} % -% In the environments with an explicit preamble (like |{NiceArray}|, |{pNiceArrayC}|, |{pNiceArrayRC}|, etc.), it's -% possible to fix the width of a given column with the standard letters |w| and |W| of the package \pkg{array}. +% In the environments with an explicit preamble (like |{NiceArray}|, +% |{pNiceArray}|, etc.), it's possible to fix the width of a given column with +% the standard letters |w| and |W| of the package \pkg{array}. % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] @@ -1262,55 +1226,53 @@ version 2005/12/01 or later. % \end{NiceMatrixBlock} % % +% % \section{The option hlines} % -% Of course, you can add horizontal rules between rows in the environments of -% \pkg{nicematrix} with the command |\hline|. But you can also specify that all -% horizontal lines must be drawn with the option |hlines|. +% You can add horizontal rules between rows in the environments of +% \pkg{nicematrix} with the usual command |\hline|. But, by convenience, the +% extension \pkg{nicematrix} provides the option |hlines|. With this option, all +% the horizontal rules will be drawn (excepted, of course the rule before the +% potential ``first row'' and the rule after the potential ``last row''). % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] -%$\begin{NiceArray}{|*{4}{C|}}[~emphase#hlines@] -% e & a & b & c \\ -% a & e & c & b \\ -% b & c & e & a \\ -% c & b & a & e +% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +% $\begin{NiceArray}{|*{4}{C|}}[~emphase#hlines@,first-row,first-col] +% & e & a & b & c \\ +% e & e & a & b & c \\ +% a & a & e & c & b \\ +% b & b & c & e & a \\ +% c & c & b & a & e % \end{NiceArray}$ % \end{BVerbatim} -%$\begin{NiceArray}{|*{4}{C|}}[hlines] -% e & a & b & c \\ -% a & e & c & b \\ -% b & c & e & a \\ -% c & b & a & e -% \end{NiceArray}$ -% -% +% \raise-5mm\box\ExampleOne % % \section{Utilisation of the column type S of siunitx} % % If the package \pkg{siunitx} is loaded (before or after \pkg{nicematrix}), % it's possible to use the |S| column type of \pkg{siunitx} in the environments % of \pkg{nicematrix}. The implementation doesn't use explicitly any private -% macro of \pkg{siunitx}. +% macro of \pkg{siunitx}. The |d| columns of \pkg{dcolumn} are not supported by +% \pkg{nicematrix}. % % % \medskip % \begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] -% $\begin{pNiceArrayRC}{~emphase#S@Cwc{1cm}C}[nullify-dots] +% $\begin{pNiceArray}{~emphase#S@CWc{1cm}C}[nullify-dots,first-row] % {C_1} & \Cdots & & C_n \\ % 2.3 & 0 & \Cdots & 0 \\ % 12.4 & \Vdots & & \Vdots \\ % 1.45 \\ % 7.2 & 0 & \Cdots & 0 -% \end{pNiceArrayRC}$ +% \end{pNiceArray}$ % \end{BVerbatim} -% $\begin{pNiceArrayRC}{SCwc{1cm}C}[nullify-dots] +% $\begin{pNiceArray}{SCWc{1cm}C}[nullify-dots,first-row] % {C_1} & \Cdots & & C_n \\ % 2.3 & 0 & \Cdots & 0 \\ % 12.4 & \Vdots & & \Vdots \\ % 1.45 \\ % 7.2 & 0 & \Cdots & 0 -% \end{pNiceArrayRC}$ +% \end{pNiceArray}$ % % % \section{Technical remarks} @@ -1530,8 +1492,25 @@ version 2005/12/01 or later. % \end{pNiceMatrix}$ % % -% +% \subsection{Obsolete environments} +% +% The version 3.0 of \pkg{nicematrix} has introduced the environment +% |{pNiceArray}| (and its variants) with the options |first-row|, |last-row|, +% |first-col| and |last-col|. % +% Consequently the following environments present in previous versions of +% \pkg{nicematrix} are deprecated: +% % +% \begin{itemize} +% \item |{NiceArrayCwithDelims}| ; +% \item |{pNiceArrayC}|, |{bNiceArrayC}|, |{BNiceArrayC}|, |{vNiceArrayC}|, +% |{VNiceArrayC}| ; +% \item |{NiceArrayRCwithDelims}| ; +% \item |{pNiceArrayRC}|, |{bNiceArrayRC}|, |{BNiceArrayRC}|, |{vNiceArrayRC}|, +% |{VNiceArrayRC}|. +% \end{itemize} +% +% They might be deleted in a future version of \pkg{nicematrix}. % % \section{Examples} % @@ -1611,21 +1590,21 @@ version 2005/12/01 or later. % An example with |\multicolumn|:\par\nobreak % \bigskip % \begin{BVerbatim} -% \begin{pNiceMatrix}[nullify-dots] +% \begin{BNiceMatrix}[nullify-dots] % 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ % 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ % \Cdots & & ~emphase#\multicolumn{6}{C}{10 \text{ other rows}}@ & \Cdots \\ % 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 -% \end{pNiceMatrix} +% \end{BNiceMatrix} % \end{BVerbatim} % % \bigskip -% \[\begin{pNiceMatrix}[nullify-dots] +% \[\begin{BNiceMatrix}[nullify-dots] % 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ % 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ % \Cdots & & \multicolumn{6}{C}{10 \text{ other rows}} & \Cdots \\ % 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 -% \end{pNiceMatrix}\] +% \end{BNiceMatrix}\] % % \vspace{2cm} % An example with |\Hdotsfor|:\par\nobreak @@ -1656,34 +1635,58 @@ version 2005/12/01 or later. % \bigskip % \begin{BVerbatim} % \setlength{\extrarowheight}{1mm} -% \[\begin{NiceArray}{|CCCC:CCC|}[columns-width=6mm] +% \[\begin{vNiceArray}{CCCC:CCC}[columns-width=6mm] % a_0 & && &b_0 & & \\ % a_1 &\Ddots&& &b_1 &\Ddots& \\ % \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\ % a_p & &&a_0 & & &b_1 \\ % &\Ddots&&a_1 &b_q & &\Vdots\\ % & &&\Vdots & &\Ddots& \\ -% & &&a_p & & &b_q \\ -% \end{NiceArray}\] +% & &&a_p & & &b_q +% \end{vNiceArray}\] % \end{BVerbatim} % % \bigskip % % \begin{scope} % \setlength{\extrarowheight}{1mm} -% \[\begin{NiceArray}{|CCCC:CCC|}[columns-width=6mm] +% \[\begin{vNiceArray}{CCCC:CCC}[columns-width=6mm] % a_0 & && &b_0 & & \\ % a_1 &\Ddots&& &b_1 &\Ddots& \\ % \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\ % a_p & &&a_0 & & &b_1 \\ % &\Ddots&&a_1 &b_q & &\Vdots\\ % & &&\Vdots & &\Ddots& \\ -% & &&a_p & & &b_q \\ -% \end{NiceArray}\] +% & &&a_p & & &b_q +% \end{vNiceArray}\] % \end{scope} % +% \vspace{2cm} +% An example for a linear system:\par\nobreak +% +% \begin{Verbatim} +% $\begin{pNiceArray}{*6C|C}[nullify-dots,last-col,code-for-last-col={\scriptstyle}] +% 1 & 1 & 1 &\Cdots & & 1 & 0 & \\ +% 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ +% 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ +% & & &\Ddots & & & \Vdots & \Vdots \\ +% \Vdots & & &\Ddots & & 0 & \\ +% 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 +% \end{pNiceArray}$ +% \end{Verbatim} +% +% \[\begin{pNiceArray}{*6C|C}[nullify-dots,last-col,code-for-last-col={\scriptstyle}] +% 1 & 1 & 1 &\Cdots & & 1 & 0 & \\ +% 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\ +% 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\ +% & & &\Ddots & & & \Vdots & \Vdots \\ +% \Vdots & & &\Ddots & & 0 & \\ +% 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 +% \end{pNiceArray}\] +% % % \subsection{Width of the columns} +% % % \medskip % In the following example, we use |{NiceMatrixBlock}| with the option |auto-columns-width| because @@ -1694,12 +1697,12 @@ version 2005/12/01 or later. % ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ % \NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle} % \setlength{\extrarowheight}{1mm} -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \quad $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 2&4&8&16&9&\\ % 3&9&27&81&36&\\ -% 4&16&64&256&100&\\ -% \end{pNiceArrayC}$ +% 4&16&64&256&100& +% \end{pNiceArray}$ % ... % ~emphase#\end{NiceMatrixBlock}@ % \end{BVerbatim} @@ -1711,57 +1714,57 @@ version 2005/12/01 or later. % \NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle} % \setlength{\extrarowheight}{1mm} % -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \enskip $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 2&4&8&16&9&\\ % 3&9&27&81&36&\\ -% 4&16&64&256&100&\\ -% \end{pNiceArrayC}$ +% 4&16&64&256&100& +% \end{pNiceArray}$ % % \medskip % -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \enskip $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 0&2&6&14&7&L_2\gets-2L_1+L_2 \\ % 0&6&24&78&33&L_3\gets-3L_1+L_3 \\ -% 0&12&60&252&96&L_4\gets-4L_1+L_4 \\ -% \end{pNiceArrayC}$ +% 0&12&60&252&96&L_4\gets-4L_1+L_4 +% \end{pNiceArray}$ % % \medskip % -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \enskip $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 0&1&3&7&\frac72&L_2\gets\frac12L_2\\ % 0&3&12&39&\frac{33}2&L_3\gets\frac12L_3 \\ -% 0&1&5&21&8&L_4\gets\frac1{12}L_4 \\ -% \end{pNiceArrayC}$ +% 0&1&5&21&8&L_4\gets\frac1{12}L_4 +% \end{pNiceArray}$ % % \medskip % -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \enskip $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 0&1&3&7&\frac72&\\ % 0&0&3&18&6&L_3 \gets -3L_2+L_3 \\ -% 0&0&-2&-14&-\frac92&L_4 \gets L_2-L_4 \\ -% \end{pNiceArrayC}$ +% 0&0&-2&-14&-\frac92&L_4 \gets L_2-L_4 +% \end{pNiceArray}$ % % \medskip % -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \enskip $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 0&1&3&7&\frac72&\\ % 0&0&1&6&2&L_3 \gets \frac13L_3\\ -% 0&0&-2&-14&-\frac92&\\ -% \end{pNiceArrayC}$ +% 0&0&-2&-14&-\frac92& +% \end{pNiceArray}$ % % \medskip % -% \quad $\begin{pNiceArrayC}{CCCC:C} +% \enskip $\begin{pNiceArray}{CCCC:C}[last-col] % 1&1&1&1&1&\\ % 0&1&3&7&\frac72&\\ % 0&0&1&6&2& \\ -% 0&0&0&-2&-\frac12 & L_4 \gets 2L_3+L_4 \\ -% \end{pNiceArrayC}$ +% 0&0&0&-2&-\frac12 & L_4 \gets 2L_3+L_4 +% \end{pNiceArray}$ % \end{NiceMatrixBlock} % \end{multicols} % @@ -1779,8 +1782,8 @@ version 2005/12/01 or later. % In order to have the continuity of the lines, we have to set |inner sep = -\pgflinewidth/2|. % % \begin{Verbatim} -% $\left(\,\begin{NiceArray}{>{\strut}CCCC}% -% [create-extra-nodes,left-margin,right-margin, +% $\begin{pNiceArray}{>{\strut}CCCC}% +% [create-extra-nodes,margin,extra-margin = 2pt , % code-after = {\begin{tikzpicture} % [~emphase#name suffix = -large@, % every node/.style = {draw, @@ -1794,12 +1797,12 @@ version 2005/12/01 or later. % a_{21} & a_{22} & a_{23} & a_{24} \\ % a_{31} & a_{32} & a_{33} & a_{34} \\ % a_{41} & a_{42} & a_{43} & a_{44} -% \end{NiceArray}\,\right)$ +% \end{pNiceArray}$ % \end{Verbatim} % % -% \[\left(\,\begin{NiceArray}{>{\strut}CCCC}[ -% create-extra-nodes,left-margin,right-margin, +% \[\begin{pNiceArray}{>{\strut}CCCC}[ +% create-extra-nodes,margin,extra-margin = 2pt, % code-after = {\begin{tikzpicture}[name suffix = -large, % every node/.style = {draw, % inner sep = -\pgflinewidth/2}] @@ -1812,34 +1815,20 @@ version 2005/12/01 or later. % a_{21} & a_{22} & a_{23} & a_{24} \\ % a_{31} & a_{32} & a_{33} & a_{34} \\ % a_{41} & a_{42} & a_{43} & a_{44} -% \end{NiceArray}\,\right)\] +% \end{pNiceArray}\] % % % \vspace{1cm} -% The package \pkg{nicematrix} is constructed upon the environment |{array}| and, therefore, it's possible to use -% the package \pkg{colortbl} in the environments of \pkg{nicematrix}. -% -% \medskip -% \begin{BVerbatim}[baseline=c] -% $\begin{bNiceMatrix} -% 0 & \Cdots & 0 \\ -% ~emphase#\rowcolor{red!15}@ 1 & \Cdots & 1 \\ -% 0 & \Cdots & 0 \\ -% \end{bNiceMatrix}$ -% \end{BVerbatim} -% \hspace{2cm} -% $\begin{bNiceMatrix} -% 0 & \Cdots & 0 \\ -% \rowcolor{red!15} 1 & \Cdots & 1 \\ -% 0 & \Cdots & 0 \\ -% \end{bNiceMatrix}$ -% -% \medskip -% The result may be disappointing. We therefore propose another method to highlight a row of the matrix. We -% create a rectangular Tikz node which encompasses the nodes of the second row with the Tikz library \pkg{fit}. This -% Tikz node is filled after the construction of the matrix. In order to see the text \emph{under} this node, we -% have to use transparency with the |blend mode| equal to |multiply|. Warning: some \textsc{pdf} readers are not -% able to render transparency correctly. +% The package \pkg{nicematrix} is constructed upon the environment |{array}| +% and, therefore, it's possible to use the package \pkg{colortbl} in the +% environments of \pkg{nicematrix}. However, it's not always easy to do a fine +% tuning of \pkg{colortbl}. That's why we propose another method to highlight a +% row of the matrix. We create a rectangular Tikz node which encompasses the +% nodes of the second row with the Tikz library \pkg{fit}. This Tikz node is +% filled after the construction of the matrix. In order to see the text +% \emph{under} this node, we have to use transparency with the |blend mode| +% equal to |multiply|. Warning: some \textsc{pdf} readers are not able to render +% transparency correctly. % % \tikzset{highlight/.style={rectangle, % fill=red!15, @@ -1858,14 +1847,14 @@ version 2005/12/01 or later. % $\begin{bNiceMatrix}[~emphase#code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}@] % 0 & \Cdots & 0 \\ % 1 & \Cdots & 1 \\ -% 0 & \Cdots & 0 \\ +% 0 & \Cdots & 0 % \end{bNiceMatrix}$ % \end{Verbatim} % % \[\begin{bNiceMatrix}[code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}] % 0 & \Cdots & 0 \\ % 1 & \Cdots & 1 \\ -% 0 & \Cdots & 0 \\ +% 0 & \Cdots & 0 % \end{bNiceMatrix}\] % % @@ -1895,18 +1884,18 @@ version 2005/12/01 or later. % % \medskip % \begin{Verbatim} -% $\begin{pNiceArrayC}{CCC}[~emphase#name=example@,create-extra-nodes] +% $\begin{pNiceArray}{CCC}[~emphase#name=example@,last-col,create-extra-nodes] % a & a + b & a + b + c & L_1\\ % a & a & a + b & L_2 \\ % a & a & a & L_3 -% \end{pNiceArrayC}$ +% \end{pNiceArray}$ % \end{Verbatim} % -% \[\begin{pNiceArrayC}{CCC} +% \[\begin{pNiceArray}{CCC}[last-col] % a & a + b & a + b + c & L_1\\ % a & a & a + b & L_2 \\ % a & a & a & L_3 -% \end{pNiceArrayC}\] +% \end{pNiceArray}\] % % \bigskip % If we want to highlight each row of this matrix, we can use the previous technique three times. @@ -1939,7 +1928,8 @@ version 2005/12/01 or later. % \medskip % We obtain the following matrix. % -% \[\begin{pNiceArrayC}{CCC}[ +% \[\begin{pNiceArray}{CCC}[ +% last-col, % create-extra-nodes, % code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15, % blend mode = multiply, @@ -1951,7 +1941,7 @@ version 2005/12/01 or later. % a & a + b & a + b + c & L_1\\ % a & a & a + b & L_2 \\ % a & a & a & L_3 -% \end{pNiceArrayC}\] +% \end{pNiceArray}\] % % \medskip % The result may seem disappointing. We can improve it by using the ``medium nodes'' instead of the ``normal nodes''. @@ -1967,7 +1957,8 @@ version 2005/12/01 or later. % \medskip % We obtain the following matrix. % -% \[\begin{pNiceArrayC}{CCC}[ +% \[\begin{pNiceArray}{CCC}[ +% last-col, % create-extra-nodes, % code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15, % blend mode = multiply, @@ -1980,15 +1971,15 @@ version 2005/12/01 or later. % a & a + b & a + b + c & L_1\\ % a & a & a + b & L_2 \\ % a & a & a & L_3 -% \end{pNiceArrayC}\] +% \end{pNiceArray}\] % % % \vspace{1cm} % % In the following example, we use the ``large nodes'' to highlight a zone of the matrix.\par\nobreak % \begin{Verbatim} -% \left(\,\begin{NiceArray}{>{\strut}CCCC}% -% [create-extra-nodes,left-margin,right-margin, +% \begin{pNiceArray}{>{\strut}CCCC}% +% [create-extra-nodes,margin,extra-margin=2pt, % code-after = {\tikz \path [~emphase#name suffix = -large@, % fill = red!15, % blend mode = multiply] @@ -2002,11 +1993,11 @@ version 2005/12/01 or later. % A_{21} & A_{22} & A_{23} & A_{24} \\ % A_{31} & A_{32} & A_{33} & A_{34} \\ % A_{41} & A_{42} & A_{43} & A_{44} -% \end{NiceArray}\,\right) +% \end{pNiceArray} % \end{Verbatim} % -% \[\left(\,\begin{NiceArray}{>{\strut}CCCC}[ -% create-extra-nodes,left-margin,right-margin, +% \[ \begin{pNiceArray}{>{\strut}CCCC}[ +% create-extra-nodes,margin,extra-margin=2pt, % code-after = {\tikz \path [name suffix = -large, % fill = red!15, % blend mode = multiply] @@ -2020,9 +2011,118 @@ version 2005/12/01 or later. % A_{21} & A_{22} & A_{23} & A_{24} \\ % A_{31} & A_{32} & A_{33} & A_{34} \\ % A_{41} & A_{42} & A_{43} & A_{44} -% \end{NiceArray}\,\right)\] +% \end{pNiceArray}\] +% +% +% \subsection{Direct utilisation of the Tikz nodes} +% +% In the following example, we illustrate the mathematical product of two matrices. +% +% \medskip +% The utilisation of |{NiceMatrixBlock}| with the option |auto-columns-width| +% gives the same width for all the columns and, therefore, a perfect alignment +% of the two superposed matrices. +% \begin{Verbatim} +% \begin{NiceMatrixBlock}[auto-columns-width] +% \end{Verbatim} +% +% \begin{Verbatim} +% \NiceMatrixOptions{nullify-dots} +% \end{Verbatim} +% +% The three matrices will be displayed using an environment |{array}| (an +% environment |{tabular}| may also be possible). +% \begin{Verbatim} +% $\begin{array}{cc} +% & +% \end{Verbatim} +% +% The matrix $B$ has a ``first row'' (for $C_j$) and that's why we use the key |first-row|. +% \begin{Verbatim} +% \begin{bNiceArray}{C>{\strut}CCCC}[name=B,first-row] +% & & C_j \\ +% b_{11} & \Cdots & b_{1j} & \Cdots & b_{1n} \\ +% \Vdots & & \Vdots & & \Vdots \\ +% & & b_{kj} \\ +% & & \Vdots \\ +% b_{n1} & \Cdots & b_{nj} & \Cdots & b_{nn} +% \end{bNiceArray} \\ \\ +% \end{Verbatim} +% +% The matrix $A$ has a ``first column'' (for $L_i$) and that's why we use the +% key |first-col|. +% \begin{Verbatim} +% \begin{bNiceArray}{CC>{\strut}CCC}[name=A,first-col] +% & a_{11} & \Cdots & & & a_{nn} \\ +% & \Vdots & & & & \Vdots \\ +% L_i & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} \\ +% & \Vdots & & & & \Vdots \\ +% & a_{n1} & \Cdots & & & a_{nn} \\ +% \end{bNiceArray} +% & +% \end{Verbatim} +% +% In the matrix product, the two dotted lines have an open extremity. +% \begin{Verbatim} +% \begin{bNiceArray}{CC>{\strut}CCC} +% & & & & \\ +% & & \Vdots \\ +% \Cdots & & c_{ij} \\ +% \\ +% \\ +% \end{bNiceArray} +% \end{array}$ +% +% \end{NiceMatrixBlock} +% \end{Verbatim} % +% \begin{Verbatim} +% \begin{tikzpicture}[remember picture, overlay] +% \node [highlight, fit = (A-3-1) (A-3-5) ] {} ; +% \node [highlight, fit = (B-1-3) (B-5-3) ] {} ; +% \draw [color = gray] (A-3-3) to [bend left] (B-3-3) ; +% \end{tikzpicture} +% \end{Verbatim} % +% +% \begin{NiceMatrixBlock}[auto-columns-width] +% \NiceMatrixOptions{nullify-dots} +% $\begin{array}{cc} +% & +% \begin{bNiceArray}{C>{\strut}CCCC}[name=B,first-row] +% & & C_j \\ +% b_{11} & \Cdots & b_{1j} & \Cdots & b_{1n} \\ +% \Vdots & & \Vdots & & \Vdots \\ +% & & b_{kj} \\ +% & & \Vdots \\ +% b_{n1} & \Cdots & b_{nj} & \Cdots & b_{nn} +% \end{bNiceArray} \\ \\ +% \begin{bNiceArray}{CC>{\strut}CCC}[name=A,first-col] +% & a_{11} & \Cdots & & & a_{nn} \\ +% & \Vdots & & & & \Vdots \\ +% L_i & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} \\ +% & \Vdots & & & & \Vdots \\ +% & a_{n1} & \Cdots & & & a_{nn} \\ +% \end{bNiceArray} +% & +% \begin{bNiceArray}{CC>{\strut}CCC} +% & & & & \\ +% & & \Vdots \\ +% \Cdots & & c_{ij} \\ +% \\ +% \\ +% \end{bNiceArray} +% \end{array}$ +% +% \end{NiceMatrixBlock} +% +% \begin{tikzpicture}[remember picture, overlay] +% \node [highlight, fit = (A-3-1) (A-3-5) ] {} ; +% \node [highlight, fit = (B-1-3) (B-5-3) ] {} ; +% \draw [color = gray] (A-3-3) to [bend left] (B-3-3) ; +% \end{tikzpicture} +% +% % \subsection{Block matrices} % % \medskip @@ -2030,8 +2130,8 @@ version 2005/12/01 or later. % drawn with \pkg{arydshln}). % \begin{Verbatim} % \NiceMatrixOptions{letter-for-dotted-lines = V} -% \left(\begin{NiceArray}{CC:CC}% -% [create-extra-nodes, +% \begin{pNiceArray}{CC:CC}[ +% create-extra-nodes, % ~emphase#code-after = { \tikz \node [fit = (1-1-large) (2-2-large), inner sep = 0 pt]@ % ~emphase# {$0_{22}$} ; }@ ] % & & a_{13} & a_{14} \\ @@ -2039,13 +2139,13 @@ version 2005/12/01 or later. % \hdashline % a_{31} & a_{32} & a_{33} & a_{34} \\ % a_{41} & a_{42} & a_{34} & a_{44} -% \end{NiceArray}\right) +% \end{pNiceArray} % \end{Verbatim} % % % \begin{scope} % \NiceMatrixOptions{letter-for-dotted-lines = V} -% \[D = \left(\begin{NiceArray}{CC:CC}[ +% \[D = \begin{pNiceArray}{CC:CC}[ % create-extra-nodes, % code-after = { \tikz \node [fit = (1-1-large) (2-2-large), inner sep = 0 pt] % {$0_{22}$} ; } ] @@ -2054,7 +2154,7 @@ version 2005/12/01 or later. % \hdashline % a_{31} & a_{32} & a_{33} & a_{34} \\ % a_{41} & a_{42} & a_{34} & a_{44} -% \end{NiceArray}\right)\] +% \end{pNiceArray}\] % \end{scope} % % @@ -2064,20 +2164,24 @@ version 2005/12/01 or later. % By default, the package \pkg{nicematrix} doesn't patch any existing code. % % \smallskip -% However, when the option |renew-dots| is used, the commands |\cdots|, |\ldots|, |\dots|, |\vdots|, |\ddots| and -% |\iddots| are redefined in the environments provided by \pkg{nicematrix} as explained previously. In the same way, -% if the option |renew-matrix| is used, the environment |{matrix}| of \pkg{amsmath} is redefined. +% However, when the option |renew-dots| is used, the commands |\cdots|, +% |\ldots|, |\dots|, |\vdots|, |\ddots| and |\iddots| are redefined in the +% environments provided by \pkg{nicematrix} as explained previously. In the same +% way, if the option |renew-matrix| is used, the environment |{matrix}| of +% \pkg{amsmath} is redefined. % % \smallskip % On the other hand, the environment |{array}| is never redefined. % % \smallskip -% Of course, the package \pkg{nicematrix} uses the features of the package \pkg{array}. It tries to be independant of its -% implementation. Unfortunately, it was not possible to be strictly independant: the package \pkg{nicematrix} relies upon the -% fact that the package |{array}| uses |\ialign| to begin the |\halign|. +% Of course, the package \pkg{nicematrix} uses the features of the package +% \pkg{array}. It tries to be independant of its implementation. Unfortunately, +% it was not possible to be strictly independant: the package \pkg{nicematrix} +% relies upon the fact that the package |{array}| uses |\ialign| to begin the |\halign|. % % \smallskip -% The desire to do no modification to existing code leads to complications in the code of this extension. +% The desire to do no modification to existing code leads to complications in +% the code of this extension. % % \subsection{Declaration of the package and extensions loaded} % @@ -2085,6 +2189,9 @@ version 2005/12/01 or later. % They are loaded this way because |\usetikzlibrary| in |expl3| code fails.\footnote{cf. % |tex.stackexchange.com/questions/57424/using-of-usetikzlibrary-in-an-expl3-package-fails|} % +% \begin{macrocode} +%<@@=nm> +% \end{macrocode} % % \begin{macrocode} \RequirePackage{tikz} @@ -2103,8 +2210,9 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% We test if the class option |draft| has been used. In this case, we raise the flag |\c_@@_draft_bool| because we -% won't draw the dotted lines if the option |draft| is used. +% We test if the class option |draft| has been used. In this case, we raise the +% flag |\c_@@_draft_bool| because we won't draw the dotted lines if the option +% |draft| is used. % \begin{macrocode} \bool_new:N \c_@@_draft_bool \DeclareOption { draft } { \bool_set_true:N \c_@@_draft_bool } @@ -2127,18 +2235,11 @@ version 2005/12/01 or later. % % \bigskip % \begin{macrocode} -\cs_new_protected:Nn \@@_error:n { \msg_error:nn { nicematrix } { #1 } } -% \end{macrocode} -% -% \begin{macrocode} -\cs_new_protected:Nn \@@_error:nn { \msg_error:nn { nicematrix } { #1 } { #2 } } -% \end{macrocode} -% -% \begin{macrocode} +\cs_new_protected:Npn \@@_error:n { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \@@_error:nn { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \@@_fatal:n { \msg_fatal:nn { nicematrix } } +\cs_new_protected:Npn \@@_fatal:nn { \msg_fatal:nn { nicematrix } } \cs_new_protected:Npn \@@_msg_new:nn { \msg_new:nnn { nicematrix } } -% \end{macrocode} -% -% \begin{macrocode} \cs_new_protected:Npn \@@_msg_new:nnn { \msg_new:nnnn { nicematrix } } % \end{macrocode} % @@ -2150,7 +2251,9 @@ version 2005/12/01 or later. % % \subsection{Technical definitions} % -% We test whether the current class is \cls{revtex4-1} or \cls{revtex4-2}. +% We test whether the current class is \cls{revtex4-1} or \cls{revtex4-2} +% because these classes redefines |\array| (of \pkg{array}) in a way +% incompatible with our programmation. % \begin{macrocode} \bool_new:N \c_@@_revtex_bool \@ifclassloaded { revtex4-1 } @@ -2160,46 +2263,23 @@ version 2005/12/01 or later. { \bool_set_true:N \c_@@_revtex_bool } { } % \end{macrocode} -% -% % % \begin{macrocode} \@@_msg_new:nn { Draft~mode } { The~compilation~is~in~draft~mode:~the~dotted~lines~won't~be~drawn. } % \end{macrocode} % -% % \begin{macrocode} \bool_if:NT \c_@@_draft_bool { \msg_warning:nn { nicematrix } { Draft~mode } } % \end{macrocode} % -% \medskip -% We create booleans in order to know if some packages are loaded. -% for the package \pkg{siunitx}, the boolean is called -% |\c_@@_siunitx_loaded_bool|.\footnote{It's not possible to use -% |\@ifpackageloaded| in the core of the functions because |\@ifpackageloaded| -% is available only in the preamble.} -% \begin{macrocode} -\AtBeginDocument - { - \clist_map_inline:nn - { - siunitx - } - { - \bool_new:c { c_@@_#1_loaded_bool } - \@ifpackageloaded { #1 } - { \bool_set_true:c { c_@@_#1_loaded_bool } } - { } - } - } -% \end{macrocode} % % \bigskip -% We define a command |\iddots| similar to |\ddots| ($\ddots$) but with dots going forward ($\iddots$). We -% use |\ProvideDocumentCommand| of \pkg{xparse}, and so, if the command |\iddots| has already been defined (for -% example by the package \pkg{mathdots}), we don't define it again. +% We define a command |\iddots| similar to |\ddots| ($\ddots$) but with dots +% going forward ($\iddots$). We use |\ProvideDocumentCommand| of \pkg{xparse}, +% and so, if the command |\iddots| has already been defined (for example by the +% package \pkg{mathdots}), we don't define it again. % % \begin{macrocode} \ProvideDocumentCommand \iddots { } @@ -2220,15 +2300,16 @@ version 2005/12/01 or later. % % % \bigskip -% The following counter will count the environments |{NiceArray}|. The value of this counter will be used to -% prefix the names of the Tikz nodes created in the array. +% The following counter will count the environments |{NiceArray}|. The value of +% this counter will be used to prefix the names of the Tikz nodes created in the +% array. % \begin{macrocode} \int_new:N \g_@@_env_int % \end{macrocode} % % \bigskip -% The dimension |\l_@@_columns_width_dim| will be used when the options specify that all the columns must have the -% same width. +% The dimension |\l_@@_columns_width_dim| will be used when the options specify +% that all the columns must have the same width. % \begin{macrocode} \dim_new:N \l_@@_columns_width_dim % \end{macrocode} @@ -2242,50 +2323,169 @@ version 2005/12/01 or later. \seq_new:N \g_@@_names_seq % \end{macrocode} % + +% \bigskip +% We want to know if we are in an environment of \pkg{nicematrix} because we +% will raise an error if the user tries to use nested environments. +% \begin{macrocode} +\bool_new:N \l_@@_in_env_bool +% \end{macrocode} +% +% % \bigskip -% The integer |\l_@@_nb_first_row_int| is the number of the first row of the -% array. The default value is $1$, but, in the environments like -% |{pNiceArrayRC}|, the value will be~$0$. +% If the user uses |{NiceArray}| (and not another environment relying upon +% |{NiceArrayWithDelims}| like |{pNiceArray}|), we will raise the flag +% |\l_@@_NiceArray_bool|. We have to know that, because, in |{NiceArray}|, we +% won't use a structure with |\left| and |\right| and we will use the option of +% position (|t|, |b| or |c|). % \begin{macrocode} -\int_new:N \l_@@_nb_first_row_int -\int_set:Nn \l_@@_nb_first_row_int 1 +\bool_new:N \l_@@_NiceArray_bool +\bool_new:N \g_@@_NiceArray_bool % \end{macrocode} % +% +% \bigskip +% \begin{macrocode} +\cs_new_protected:Npn \@@_test_if_math_mode: + { + \if_mode_math: \else: + \@@_fatal:n { Outside~math~mode } + \fi: + } +% \end{macrocode} +% +% \bigskip +% \begin{macrocode} +\@@_msg_new:nn { Yet~in~env } + { + Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ + nested.\\ + This~error~is~fatal. + } +% \end{macrocode} +% +% \bigskip +% \begin{macrocode} +\@@_msg_new:nn { Outside~math~mode } + { + The~environment~\{\@currenvir\}~can~be~used~only~in~math~mode~ + (and~not~in~\token_to_str:N \vcenter).\\ + This~error~is~fatal. + } +% \end{macrocode} +% % \bigskip -% The flag |\l_@@_exterior_column_bool| will indicate if we are in an -% environment of the type of |{pNiceArrayC}| or |{pNiceArrayRC}|. It will be -% used for the creation of the ``large nodes''. +% We have to known whether if \pkg{colortbl} is loaded for the redefinition of +% |\everycr|. % \begin{macrocode} -\bool_new:N \l_@@_exterior_column_bool +\bool_new:N \c_@@_colortbl_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { colortbl } + { \bool_set_true:N \c_@@_colortbl_loaded_bool } + { } + } % \end{macrocode} % % \bigskip -% Consider the following code : +% \subsubsection{Variables for the exterior rows and columns} +% +% The keys for the exterior rows and columns are |first-row|, |first-col|, +% |last-row| and |last-col|. However, internally, these keys are not coded in a +% similar way. +% +% \bigskip +% \begin{itemize} +% \item \textbf{First row}\par\nobreak +% The integer |\l_@@_first_row_int| is the number of the first row of the +% array. The default value is $1$, but, if the option |first-row| is used, +% the value will be~$0$. As usual, the global version is for the passage in the +% |\group_insert_after:N|. +% \begin{macrocode} +\int_new:N \l_@@_first_row_int +\int_set:Nn \l_@@_first_row_int 1 +\int_new:N \g_@@_first_row_int +% \end{macrocode} +% +% \medskip +% \item \textbf{First column}\par\nobreak +% The integer |\l_@@_first_col_int| is the number of the first column of the +% array. The default value is $1$, but, if the option |first-col| is used, +% the value will be~$0$. +% \begin{macrocode} +\int_new:N \l_@@_first_col_int +\int_set:Nn \l_@@_first_col_int 1 +\int_new:N \g_@@_first_col_int +% \end{macrocode} +% +% \medskip +% \item \textbf{Last row}\par\nobreak +% The counter |\l_@@_last_row_int| is the number of the eventual ``last row'', +% as specified by the key |last-row|. A value of $-2$ means that there is no +% ``last row''. A value of $-1$ means that there is a ``last row'' but we don't +% know the number of that row (the key |last-row| has been used without value +% and has not still been read in the |aux|). +% \begin{macrocode} +\int_new:N \l_@@_last_row_int +\int_set:Nn \l_@@_last_row_int { -2 } +\int_new:N \g_@@_last_row_int +% \end{macrocode} +% +% \smallskip +% If, in an environment like |{pNiceArray}|, the option |last-row| is used +% without value, we will globally raise the following flag. It will be used to +% know if we have, after the construction of the array, to write in the |aux| +% file the number of the ``last row''.\footnote{We can't use +% |\l_@@_last_row_int| for this usage because, if \pkg{nicematrix} has read its +% value from the |aux| file, the value of the counter won't be $-1$ any longer.} +% \begin{macrocode} +\bool_new:N \l_@@_last_row_without_value_bool +\bool_new:N \g_@@_last_row_without_value_bool +% \end{macrocode} +% +% \medskip +% \item \textbf{Last column}\par\nobreak +% +% For the eventual ``last column'', we have a boolean an not an integer. +% \begin{macrocode} +\bool_new:N \l_@@_last_col_bool +% \end{macrocode} +% +% However, we have also another boolean. Consider the following code: % \begin{center} % \begin{BVerbatim} -% \begin{pNiceArrayC}{CC} -% 1 & 2 +% \begin{pNiceArray}{CC}[last-col] +% 1 & 2 \\ % 3 & 4 -% \end{pNiceArrayC} +% \end{pNiceArray} % \end{BVerbatim} % \end{center} -% In such a code, the last column of the environment |{pNiceArrayC}| is not -% used. We want to be able to detect such a situation. We create a boolean for -% that job. +% In such a code, the ``last column'' specified by the key |last-col| is not +% used. We want to be able to detect such a situation and we create a boolean +% for that job. % \begin{macrocode} -\bool_new:N \g_@@_exterior_column_found_bool +\bool_new:N \g_@@_last_col_found_bool % \end{macrocode} -% This boolean will be raised in the last column of environments like |{pNiceArrayC}|. -% +% This boolean is set to |false| at the end of |\@@_pre_array:|. +% \end{itemize} +% % \bigskip -% We want to known if we are in an environment |{NiceArray}| because we want to -% raise an error if the user tries to use nested environments |{NiceArray}|. +% \subsubsection{The column S of siunitx} +% +% +% We want to know whether the package \pkg{siunitx} is loaded and, if it is +% loaded, we redefine the |S| columns of \pkg{siunitx}. % \begin{macrocode} -\bool_new:N \l_@@_in_NiceArray_bool +\bool_new:N \c_@@_siunitx_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { siunitx } + { \bool_set_true:N \c_@@_siunitx_loaded_bool } + { } + } % \end{macrocode} % -% \subsection{The column S of siunitx} -% +% \medskip % The command |\NC@rewrite@S| is a LaTeX command created by \pkg{siunitx} in % connection with the |S| column. In the code of \pkg{siunitx}, this command is % defined by: @@ -2317,9 +2517,9 @@ version 2005/12/01 or later. % \NC@find % } % \end{Verbatim} -% However, we don't want do use explicitly any private command of \pkg{siunitx}. That's why we -% will extract the name of the two |\__siunitx...| commands by their position in -% the code of |\NC@rewrite@S|. +% However, we don't want do use explicitly any private command of \pkg{siunitx}. +% That's why we will extract the name of the two |\__siunitx...| commands by +% their position in the code of |\NC@rewrite@S|. % % Since the command |\NC@rewrite@S| appends some tokens to the \emph{toks} list % |\@temptokena|, we use the LaTeX command |\NC@rewrite@S| in a group @@ -2329,41 +2529,51 @@ version 2005/12/01 or later. % and, in fact, after the beginning of the document --- because some instructions of % \pkg{siunitx} are executed in a |\AtBeginDocument|). That's why this % extraction will be done only at the first utilisation of an environment of -% \pkg{nicematrix} with the command |\@@_adapt_S_column:|. This command becomes -% globally no-op when used once. +% \pkg{nicematrix} with the command |\@@_adapt_S_column:|. % \begin{macrocode} \cs_set_protected:Npn \@@_adapt_S_column: { +% \end{macrocode} +% In the preamble of the LaTeX document, the boolean |\c_@@_siunitx_loaded_bool| +% won't be known. That's why we test the existence of |\c_@@_siunitx_loaded_bool| +% and not its value.\footnote{Indeed, \pkg{nicematrix} may be used +% in the preamble of the LaTeX document. For example, in this document, we compose a +% matrix in the box |\ExampleOne| before loading \pkg{arydshln} (because +% \pkg{arydshln} is not totally compatible with \pkg{nicematrix}).} +% \begin{macrocode} \bool_if:NT \c_@@_siunitx_loaded_bool - { + { \group_begin: - \@temptokena = { } + \@temptokena = { } % \end{macrocode} % We protect |\NC@find| which is at the end of |\NC@rewrite@S|. % \begin{macrocode} - \cs_set_eq:NN \NC@find \prg_do_nothing: - \NC@rewrite@S { } + \cs_set_eq:NN \NC@find \prg_do_nothing: + \NC@rewrite@S { } % \end{macrocode} % Conversion of the \emph{toks} |\@temptokena| in a token list of \pkg{expl3} -% (the toks are not supported by \pkg{expl3} and that's why we use -% |\tex_the:D|). The conversion is global (|gset|) because we have to exit the group. +% (the toks are not supported by \pkg{expl3} but we can, nevertheless, use the +% option |V| for |\tl_gset:NV|). % \begin{macrocode} - \exp_args:NNo \tl_gset:Nn \g_tmpa_tl { \tex_the:D \@temptokena } + \tl_gset:NV \g_tmpa_tl \@temptokena \group_end: \tl_new:N \c_@@_table_collect_begin_tl \tl_set:Nx \l_tmpa_tl { \tl_item:Nn \g_tmpa_tl 2 } \tl_gset:Nx \c_@@_table_collect_begin_tl { \tl_item:Nn \l_tmpa_tl 1 } \tl_new:N \c_@@_table_print_tl \tl_gset:Nx \c_@@_table_print_tl { \tl_item:Nn \g_tmpa_tl { -1 } } - } % \end{macrocode} -% When, used once, the command |\@@_adapt_S_column:| becomes no-op (globally). +% The token lists |\c_@@_table_collect_begin_tl| and |\c_@@_table_print_tl| contain +% now the two commands of \pkg{siunitx}. +% +% \smallskip +% If the adaptation has been done, the command |\@@_adapt_S_column:| becomes +% no-op (globally). % \begin{macrocode} - \cs_gset_eq:NN \@@_adapt_S_column: \prg_do_nothing: + \cs_gset_eq:NN \@@_adapt_S_column: \prg_do_nothing: + } } % \end{macrocode} -% The token lists |\c_@@_table_collect_begin_tl| and |\c_@@_table_print_tl| contain -% now the two commands of \pkg{siunitx}. % % \bigskip % The command |\@@_renew_NC@rewrite@S:| will be used in each environment of @@ -2385,10 +2595,10 @@ version 2005/12/01 or later. } } % \end{macrocode} -% +% +% % \bigskip % \subsection{The options} -% % % \begin{macrocode} \@@_msg_new:nn { Option~Transparent~suppressed } @@ -2398,7 +2608,7 @@ version 2005/12/01 or later. } \@@_msg_new:nn { Option~RenewMatrix~suppressed } { - The~option~'RenewMatrix~has~been~renamed~'renew-matrix'.\\ + The~option~'RenewMatrix'~has~been~renamed~'renew-matrix'.\\ However,~you~can~go~on~for~this~time. } % \end{macrocode} @@ -2407,9 +2617,9 @@ version 2005/12/01 or later. % The token list |\l_@@_pos_env_str| will contain one of the three values |t|, % |c| or |b| and will indicate the position of the environment as in the option % of the environment |{array}|. For the environment |{pNiceMatrix}|, -% |{pNiceArrayC}|, |{pNiceArrayRC}| and their variants, the value will -% programmatically be fixed to |c|. For the environment |{NiceArray}|, however, -% the three values |t|, |c| and |b| are possible. +% |{pNiceArray}| and their variants, the value will programmatically be fixed to +% |c|. For the environment |{NiceArray}|, however, the three values |t|, |c| and +% |b| are possible. % \begin{macrocode} \str_new:N \l_@@_pos_env_str \str_set:Nn \l_@@_pos_env_str c @@ -2418,9 +2628,8 @@ version 2005/12/01 or later. % \bigskip % The flag |\l_@@_exterior_arraycolsep_bool| corresponds to the option % |exterior-arraycolsep|. If this option is set, a space equal to |\arraycolsep| -% will be put on both sides of an environment |{NiceArray}| (but neither for -% |{NiceMatrix}|, |{pNiceArrayC}|, |{pNiceArrayRC}| and their variants even if -% these environments rely upon |{NiceArray}|). +% will be put on both sides of an environment |{NiceArray}| (as it is done in +% |{array}| of \pkg{array}). % \begin{macrocode} \bool_new:N \l_@@_exterior_arraycolsep_bool % \end{macrocode} @@ -2434,7 +2643,7 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% The flag |\l_@@_hlines_bool| correspond to the option |\hlines|. +% The flag |\l_@@_hlines_bool| corresponds to the option |\hlines|. % \begin{macrocode} \bool_new:N \l_@@_hlines_bool % \end{macrocode} @@ -2453,19 +2662,11 @@ version 2005/12/01 or later. % \bigskip % The following flag will be used when the current options specify that all the % columns of the array must have the same width equal to the largest width of a -% cell of the array (except the cell of the ``exterior column'' of an -% environment of the kind of |{pNiceArrayC}|). +% cell of the array (except the cell of the potential exterior columns). % \begin{macrocode} \bool_new:N \l_@@_auto_columns_width_bool % \end{macrocode} % -% \bigskip -% The token list |\l_@@_code_for_last_col_tl| will contain code inserted at the -% beginning of each cell of the last column in the environment |{pNiceArrayC}| -% (and its variants). It corresponds to the option |code-for-last-col|. -% \begin{macrocode} -\tl_new:N \l_@@_code_for_last_col_tl -% \end{macrocode} % % \bigskip % We don't want to patch any existing code. That's why some code must be @@ -2480,8 +2681,8 @@ version 2005/12/01 or later. % environment: this name can be used to access to the Tikz nodes created in the % array from outside the environment. % \begin{macrocode} -\str_new:N \g_@@_name_str \str_new:N \l_@@_name_str +\str_new:N \g_@@_name_str % \end{macrocode} % % \bigskip @@ -2500,6 +2701,8 @@ version 2005/12/01 or later. \dim_new:N \l_@@_right_margin_dim \dim_new:N \g_@@_left_margin_dim \dim_new:N \g_@@_right_margin_dim +\dim_new:N \g_@@_width_last_col_dim +\dim_new:N \g_@@_width_first_col_dim % \end{macrocode} % % \bigskip @@ -2512,10 +2715,12 @@ version 2005/12/01 or later. \dim_new:N \g_@@_extra_right_margin_dim % \end{macrocode} % -% +% +% +% % \bigskip % First, we define a set of keys ``|NiceMatrix / Global|'' which will be used -% (with the mechanism of |.inherit:n| by other keys of set). +% (with the mechanism of |.inherit:n|) by other sets of keys. % \begin{macrocode} \keys_define:nn { NiceMatrix / Global } { @@ -2539,7 +2744,8 @@ version 2005/12/01 or later. % An option to test whether the extra nodes will be created (these nodes are the % ``medium nodes'' and ``large nodes''). In some circonstancies, the extra nodes % are created automatically, for example when a dotted line has an ``open'' -% extremity. +% extremity.\footnote{In fact, we should not because, if there is a |w|~node, +% the |w|~node is used instead of the ``medium'' node.} % \begin{macrocode} create-extra-nodes .bool_set:N = \l_@@_extra_nodes_bool , create-extra-nodes .default:n = true, @@ -2547,14 +2753,35 @@ version 2005/12/01 or later. left-margin .default:n = \arraycolsep , right-margin .dim_set:N = \l_@@_right_margin_dim , right-margin .default:n = \arraycolsep , + margin .meta:n = { left-margin = #1 , right-margin = #1 } , + margin .default:n = \arraycolsep , extra-left-margin .dim_set:N = \l_@@_extra_left_margin_dim , - extra-right-margin .dim_set:N = \l_@@_extra_right_margin_dim + extra-right-margin .dim_set:N = \l_@@_extra_right_margin_dim , + extra-margin .meta:n = + { extra-left-margin = #1 , extra-right-margin = #1 } , } % \end{macrocode} % % \bigskip -% We define a set of keys used by the environments (and not by the command -% |\NiceMatrixOptions|). +% The following set of keys concerns the options to \emph{customize} the +% exterior columns, that is to say the options |code-for-first-row|, etc. +% \begin{macrocode} +\keys_define:nn { NiceMatrix / Code } + { + code-for-first-col .tl_set:N = \l_@@_code_for_first_col_tl , + code-for-first-col .value_required:n = true , + code-for-last-col .tl_set:N = \l_@@_code_for_last_col_tl , + code-for-last-col .value_required:n = true , + code-for-first-row .tl_set:N = \l_@@_code_for_first_row_tl , + code-for-first-row .value_required:n = true , + code-for-last-row .tl_set:N = \l_@@_code_for_last_row_tl , + code-for-last-row .value_required:n = true , + } +% \end{macrocode} +% +% \bigskip +% 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 } { @@ -2564,10 +2791,11 @@ version 2005/12/01 or later. { \dim_set:Nn \l_@@_columns_width_dim { #1 } } , columns-width .value_required:n = true , name .code:n = - \seq_if_in:NnTF \g_@@_names_seq { #1 } + \str_set:Nn \l_tmpa_str { #1 } + \seq_if_in:NVTF \g_@@_names_seq \l_tmpa_str { \@@_error:nn { Duplicate~name } { #1 } } - { \seq_gput_left:Nn \g_@@_names_seq { #1 } } - \str_set:Nn \l_@@_name_str { #1 } , + { \seq_gput_left:NV \g_@@_names_seq \l_tmpa_str } + \str_set_eq:NN \l_@@_name_str \l_tmpa_str , name .value_required:n = true , code-after .tl_gset:N = \g_@@_code_after_tl , code-after .initial:n = \c_empty_tl , @@ -2576,12 +2804,16 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% We begin the construction of the major sets of keys (used by the differents +% We begin the construction of the major sets of keys (used by the different % user commands and environments). % \begin{macrocode} \keys_define:nn { NiceMatrix } { - NiceMatrixOptions .inherit:n = NiceMatrix / Global , + NiceMatrixOptions .inherit:n = + { + NiceMatrix / Global , + NiceMatrix / Code + } , NiceMatrix .inherit:n = { NiceMatrix / Global , @@ -2590,17 +2822,14 @@ version 2005/12/01 or later. NiceArray .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Env , + NiceMatrix / Code } , - NiceArrayC .inherit:n = - { - NiceMatrix / Global , - NiceMatrix / Env - } , - NiceArrayRC .inherit:n = + pNiceArray .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Env , + NiceMatrix / Code } } % \end{macrocode} @@ -2609,7 +2838,7 @@ version 2005/12/01 or later. % \bigskip % We finalise the definition of the set of keys % ``|NiceMatrix / NiceMatrixOptions|'' with the options specific to -% |\NiceMatrixOptions|. +% |\NiceMatrixOptions|. % \begin{macrocode} \keys_define:nn { NiceMatrix / NiceMatrixOptions } { @@ -2630,22 +2859,6 @@ version 2005/12/01 or later. \bool_set_true:N \l_@@_renew_dots_bool , % \end{macrocode} % -% \bigskip -% The following option is only for the environment |{pNiceArrayC}| and its -% variants. It will contain code inserted at the beginning of each cell of the -% last column.\footnote{In an environment |{pNiceArrayC}|, the last column is -% composed outside the parentheses of the array.} -% \begin{macrocode} - code-for-last-col .tl_set:N = \l_@@_code_for_last_col_tl , - code-for-last-col .value_required:n = true , -% \end{macrocode} -% -% \bigskip -% Idem for the first row in environments like |{pNiceArrayRC}|. -% \begin{macrocode} - code-for-first-row .tl_set:N = \l_@@_code_for_first_row_tl , - code-for-first-row .value_required:n = true , -% \end{macrocode} % % \bigskip % The option |exterior-arraycolsep| will have effect only in |{NiceArray}| for @@ -2680,20 +2893,37 @@ version 2005/12/01 or later. % % \bigskip % By default, the specifier used in the preamble of the array (for example in -% |{pNiceArrayC}| to draw a vertical dotted line between two columns is the +% |{pNiceArray}|) to draw a vertical dotted line between two columns is the % colon ``|:|''. However, it's possible to change this letter with % |letter-for-dotted-lines| and, by the way, the letter ``|:|'' will remain free % for other packages (for example \pkg{arydshln}). % \begin{macrocode} - letter-for-dotted-lines .tl_set:N = \l_@@_letter_for_dotted_lines_str , + letter-for-dotted-lines .code:n = + { + \int_compare:nTF { \tl_count:n { #1 } = \c_one_int } + { \tl_set:Nx \l_@@_letter_for_dotted_lines_str { #1 } } + { \@@_error:n { Bad~value~for~letter~for~dotted~lines } } + } , letter-for-dotted-lines .value_required:n = true , letter-for-dotted-lines .initial:n = \c_colon_str , % \end{macrocode} +% % \bigskip % \begin{macrocode} unknown .code:n = \@@_error:n { Unknown~key~for~NiceMatrixOptions } } % \end{macrocode} % +% +% \bigskip +% \begin{macrocode} +\@@_msg_new:nn { Bad~value~for~letter~for~dotted~lines } + { + The~value~of~key~'\tl_use:N\l_keys_key_tl'~must~be~of~length~1.\\ + If~you~go~on,~it~will~be~ignored. + } +% \end{macrocode} +% +% % \bigskip % \begin{macrocode} \@@_msg_new:nnn { Unknown~key~for~NiceMatrixOptions } @@ -2706,7 +2936,10 @@ version 2005/12/01 or later. { The~available~keys~are~(in~alphabetic~order):~ allow-duplicate-names,~ + code-for-first-col,~ + code-for-first-row,~ code-for-last-col,~ + code-for-last-row,~ exterior-arraycolsep,~ hlines,~ left-margin,~ @@ -2808,6 +3041,11 @@ version 2005/12/01 or later. c .code:n = \str_set:Nn \l_@@_pos_env_str c , t .code:n = \str_set:Nn \l_@@_pos_env_str t , b .code:n = \str_set:Nn \l_@@_pos_env_str b , + first-col .code:n = \int_zero:N \l_@@_first_col_int , + last-col .bool_set:N = \l_@@_last_col_bool , + first-row .code:n = \int_zero:N \l_@@_first_row_int , + last-row .int_set:N = \l_@@_last_row_int , + last-row .default:n = -1 , unknown .code:n = \@@_error:n { Unknown~option~for~NiceArray } } % \end{macrocode} @@ -2825,8 +3063,12 @@ version 2005/12/01 or later. b,~ c,~ code-after,~ - create-extra-nodes,~ + code-for-first-col,~ + code-for-first-row,~ + code-for-last-col,~ + code-for-last-row,~ columns-width,~ + create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ hlines,~ @@ -2839,8 +3081,55 @@ version 2005/12/01 or later. and~t. } % \end{macrocode} -% -% \subsection{The environments \{NiceArray\} and \{NiceMatrix\}} +% +% +% \begin{macrocode} +\keys_define:nn { NiceMatrix / pNiceArray } + { + first-col .code:n = \int_zero:N \l_@@_first_col_int , + last-col .bool_set:N = \l_@@_last_col_bool , + first-row .code:n = \int_zero:N \l_@@_first_row_int , + last-row .int_set:N = \l_@@_last_row_int , + last-row .default:n = -1 , + unknown .code:n = \@@_error:n { Unknown~option~for~pNiceArray } + } +% \end{macrocode} +% +% +% \begin{macrocode} +\@@_msg_new:nnn { Unknown~option~for~pNiceArray } + { + The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ + \{\@currenvir\}. \\ + If~you~go~on,~it~will~be~ignored. \\ + For~a~list~of~the~available~options,~type~H~<return>. + } + { + The~available~options~are~(in~alphabetic~order):~ + code-after,~ + code-for-first-col,~ + code-for-first-row,~ + code-for-last-col,~ + code-for-last-row,~ + columns-width,~ + create-extra-nodes,~ + extra-left-margin,~ + extra-right-margin,~ + first-col,~ + first-row,~ + last-col,~ + last-row,~ + hlines,~ + left-margin,~ + name,~ + nullify-dots,~ + parallelize-diags,~ + renew-dots,~ + and~right-margin. + } +% \end{macrocode} +% +% \subsection{Code common to \{NiceArrayWithDelims\} and \{NiceMatrix\}} % % The pseudo-environment |\@@_Cell:|--|\@@_end_Cell:| will be used to format the % cells of the array. In the code, the affectations are global because this @@ -2851,24 +3140,79 @@ version 2005/12/01 or later. \cs_new_protected:Nn \@@_Cell: { % \end{macrocode} -% We increment |\g_@@_column_int|, which is the counter of the columns. +% We increment |\g_@@_col_int|, which is the counter of the columns. % \begin{macrocode} - \int_gincr:N \g_@@_column_int + \int_gincr:N \g_@@_col_int % \end{macrocode} % Now, we increment the counter of the rows. We don't do this incrementation in % the |\everycr| because some packages, like \pkg{arydshln}, create special rows % in the |\halign| that we don't want to take into account. % \begin{macrocode} - \int_compare:nNnT \g_@@_column_int = 1 { \int_gincr:N \g_@@_row_int } - \int_gset:Nn \g_@@_column_total_int - { \int_max:nn \g_@@_column_total_int \g_@@_column_int } + \int_compare:nNnT \g_@@_col_int = \c_one_int + { + \int_compare:nNnT \l_@@_first_col_int = \c_one_int + \@@_begin_of_row: + } + \int_gset:Nn \g_@@_col_total_int + { \int_max:nn \g_@@_col_total_int \g_@@_col_int } +% \end{macrocode} +% The content of the cell is composed in the box |\l_tmpa_box| because we want +% to compute some dimensions of the box. The |\hbox_set_end:| corresponding to +% this |\hbox_set:Nw| will be in the |\@@_end_Cell:| (and the +% |\c_math_toggle_token| also). +% \begin{macrocode} \hbox_set:Nw \l_tmpa_box \c_math_toggle_token - \int_compare:nNnT \g_@@_row_int = \c_zero_int - \l_@@_code_for_first_row_tl + \int_compare:nNnTF \g_@@_row_int = \c_zero_int + \l_@@_code_for_first_row_tl + { + \int_compare:nNnT \g_@@_row_int = \l_@@_last_row_int + \l_@@_code_for_last_row_tl + } + } +% \end{macrocode} +% +% \interitem +% The following macro |\@@_begin_of_row| is usually used in the cell +% number~$1$ of the array. However, when the key |first-col| is used, +% |\@@_begin_of_row| is executed in the cell number~$0$ of the array. +% \begin{macrocode} +\cs_new_protected:Nn \@@_begin_of_row: + { + \int_gincr:N \g_@@_row_int + \dim_gset_eq:NN \g_@@_dp_ante_last_row_dim \g_@@_dp_last_row_dim + \dim_gzero:N \g_@@_dp_last_row_dim + \dim_gzero:N \g_@@_ht_last_row_dim } % \end{macrocode} % +% +% \interitem +% The following code is used in each cell of the array. It actualises quantities +% that, at the end of the array, will give informations about the vertical +% dimension of the two first rows and the two last rows. +% \begin{macrocode} +\cs_new_protected:Npn \@@_actualization_for_first_and_last_row: + { + \int_compare:nNnT \g_@@_row_int = \c_zero_int + { + \dim_gset:Nn \g_@@_dp_row_zero_dim + { \dim_max:nn \g_@@_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } + \dim_gset:Nn \g_@@_ht_row_zero_dim + { \dim_max:nn \g_@@_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } + } + \int_compare:nNnT \g_@@_row_int = \c_one_int + { + \dim_gset:Nn \g_@@_ht_row_one_dim + { \dim_max:nn \g_@@_ht_row_one_dim { \box_ht:N \l_tmpa_box } } + } + \dim_gset:Nn \g_@@_ht_last_row_dim + { \dim_max:nn \g_@@_ht_last_row_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g_@@_dp_last_row_dim + { \dim_max:nn \g_@@_dp_last_row_dim { \box_dp:N \l_tmpa_box } } + } +% \end{macrocode} +% % \begin{macrocode} \cs_new_protected:Nn \@@_end_Cell: { @@ -2877,27 +3221,17 @@ version 2005/12/01 or later. % \end{macrocode} % % We want to compute in |\l_@@_max_cell_width_dim| the width of the widest cell -% of the array (except the cells of the last column of an environment of the -% kind of |{pNiceArrayC}|). +% of the array (except the cells of the ``first column'' and the ``last +% column''). +% % \begin{macrocode} \dim_gset:Nn \g_@@_max_cell_width_dim { \dim_max:nn \g_@@_max_cell_width_dim { \box_wd:N \l_tmpa_box } } % \end{macrocode} % -% +% The following computations are for the ``first row'' and the ``last row''. % \begin{macrocode} - \int_compare:nNnT \g_@@_row_int = \c_zero_int - { - \dim_gset:Nn \g_@@_max_dp_row_zero_dim - { \dim_max:nn \g_@@_max_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } - \dim_gset:Nn \g_@@_max_ht_row_zero_dim - { \dim_max:nn \g_@@_max_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } - } - \int_compare:nNnT \g_@@_row_int = \c_one_int - { - \dim_gset:Nn \g_@@_max_ht_row_one_dim - { \dim_max:nn \g_@@_max_ht_row_one_dim { \box_ht:N \l_tmpa_box } } - } + \@@_actualization_for_first_and_last_row: % \end{macrocode} % % Now, we can create the Tikz node of the cell. @@ -2914,13 +3248,13 @@ version 2005/12/01 or later. anchor = base , name = nm - \int_use:N \g_@@_env_int - \int_use:N \g_@@_row_int - - \int_use:N \g_@@_column_int , + \int_use:N \g_@@_col_int , alias = \str_if_empty:NF \l_@@_name_str { \l_@@_name_str - \int_use:N \g_@@_row_int - - \int_use:N \g_@@_column_int + \int_use:N \g_@@_col_int } ] \bgroup @@ -2930,86 +3264,18 @@ version 2005/12/01 or later. % \end{macrocode} % % -% \interitem -% The environment |{NiceArray}| is the main environment of the extension -% \pkg{nicematrix}. In order to clarify the explanations, we will first give the -% definition of the environment |{NiceMatrix}|. -% -% Our environment |{NiceMatrix}| must have the same second part as the -% environment |{matrix}| of \pkg{amsmath} (because of the programmation of the -% option |renew-matrix|). Hence, this second part is the following: -% -% \begin{Verbatim} -% \endarray -% \skip_horizontal:n {-\arraycolsep} -% \end{Verbatim} -% -% That's why, in the definition of |{NiceMatrix}|, we must use |\NiceArray| and -% not |\begin{NiceArray}| (and, in the definition of |{NiceArray}|, we will have -% to use |\array|, and not |\begin{array}|: see below). -% -% \medskip -% Here's the definition of |{NiceMatrix}|: -% \begin{macrocode} -\NewDocumentEnvironment { NiceMatrix } { ! O { } } - { - \keys_set:nn { NiceMatrix / NiceMatrix } { #1 } - \str_set:Nn \l_@@_pos_env_str c - \bool_set_false:N \l_@@_exterior_arraycolsep_bool - \NiceArray { * \c@MaxMatrixCols C } - } - { - \endarray - \skip_horizontal:n - { \g_@@_right_margin_dim + \g_@@_extra_right_margin_dim - \arraycolsep } - } -% \end{macrocode} -% -% \interitem -% For the definition of |{NiceArray}| (just below), we have the following -% constraints: -% \begin{itemize} -% \item we must use |\array| in the first part of |{NiceArray}| and, therefore, -% |\endarray| in the second part; -% \item we have to put a |\group_insert_after:N \@@_after_array:| in the first -% part of |{NiceArray}| so that |\@@_draw_lines| will be executed at the end of -% the current environment (either |{NiceArray}| or |{NiceMatrix}|). -% \end{itemize} -% % \begin{macrocode} \cs_generate_variant:Nn \dim_set:Nn { N x } % \end{macrocode} % -% -% \bigskip -% \begin{macrocode} -\@@_msg_new:nn { Yet~in~NiceArray } - { - Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ - nested.~You~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~ - result. - } -% \end{macrocode} -% -% \begin{macrocode} -\@@_msg_new:nn { Outside~math~mode } - { - The~environment~\{\@currenvir\}~can~be~used~only~in~math~mode~ - (and~not~in~\token_to_str:N \vcenter).\_ - If~you~go~on,~you~will~have~other~errors. - } -% \end{macrocode} -% -% -% % \bigskip -% In the environment |{NiceArray}|, we will have to redefine the column types -% |w| and |W|. These definitions are rather long because we have to construct -% the |w|-nodes in these columns. The redefinition of these two column types are -% very close and that's why we use a macro |\@@_renewcolumntype:nn|. The first -% argument is the type of the column (|w| or |W|) and the second argument is a -% code inserted at a special place and which is the only difference between the -% two definitions. +% In the environment |{NiceArrayWithDelims}|, we will have to redefine the +% column types |w| and |W|. These definitions are rather long because we have to +% construct the |w|-nodes in these columns. The redefinition of these two column +% types are very close and that's why we use a macro |\@@_renewcolumntype:nn|. +% The first argument is the type of the column (|w| or |W|) and the second +% argument is a code inserted at a special place and which is the only +% difference between the two definitions. % \begin{macrocode} \cs_new_protected:Nn \@@_renewcolumntype:nn { @@ -3047,8 +3313,8 @@ version 2005/12/01 or later. } % \end{macrocode} % The |w|-node is created using the Tikz library |fit| after construction of the -% nodes |(@@~south~west)| and |(@@~north~east)|. It's not possible to contruct -% by a standard |node| instruction because such a construction give a erroneous +% nodes |(@@~south~west)| and |(@@~north~east)|. It's not possible to construct +% by a standard |node| instruction because such a construction give an erroneous % result with some engines (|XeTeX|, |LuaTeX|) although the result is good with % |pdflatex| (why?). % \begin{macrocode} @@ -3058,13 +3324,13 @@ version 2005/12/01 or later. node~contents = { } , name = nm - \int_use:N \g_@@_env_int - \int_use:N \g_@@_row_int - - \int_use:N \g_@@_column_int - w, + \int_use:N \g_@@_col_int - w, alias = \str_if_empty:NF \l_@@_name_str { \l_@@_name_str - \int_use:N \g_@@_row_int - - \int_use:N \g_@@_column_int - w + \int_use:N \g_@@_col_int - w } , inner~sep = \c_zero_dim , fit = (@@~south~west) (@@~north~east) @@ -3075,62 +3341,134 @@ version 2005/12/01 or later. } % \end{macrocode} % +% +% \interitem +% The argument of the following command |\@@_instruction_of_type:n| defined +% below is the type of the instruction (|Cdots|, |Vdots|, |Ddots|, etc.). This +% command writes in |\g_@@_lines_to_draw_tl| the instruction that will really +% draw the line after the construction of the matrix. +% +% \medskip +% For example, for the following matrix, +% +% \smallskip +% \begin{BVerbatim}[baseline=c,boxwidth=11cm] +% \begin{pNiceMatrix} +% 1 & 2 & 3 & 4 \\ +% 5 & \Cdots & & 6 \\ +% 7 & \Hdotsfor{2} \\ +% \end{pNiceMatrix} +% \end{BVerbatim} +% $\begin{pNiceMatrix} +% 1 & 2 & 3 & 4 \\ +% 5 & \Cdots & & 6 \\ +% 7 & \Hdotsfor{2} \\ +% \end{pNiceMatrix}$ +% +% the content of |\g_@@_lines_to_draw_tl| will be: +% +% \begin{scope} +% \color{gray} +% \verb|\@@_draw_Cdots:nn {2}{2}| +% +% \verb|\@@_draw_Hdotsfor:nnn {3}{2}{2}| +% \end{scope} +% +% +% We begin with a test of the flag |\c_@@_draft_bool| because, if the key +% |draft| is used, the dotted lines are not drawn. % \begin{macrocode} -\cs_new_protected:Npn \@@_test_if_math_mode: - { - \ifmmode \else - \@@_error:n { Outside~math~mode } - \fi +\bool_if:NTF \c_@@_draft_bool + { \cs_set_protected:Npn \@@_instruction_of_type:n #1 { } } + { + \cs_new_protected:Npn \@@_instruction_of_type:n #1 + { + \tl_gput_right:Nx \g_@@_lines_to_draw_tl + { + \use:c { @@ _ draw _ #1 : nn } + { \int_use:N \g_@@_row_int } + { \int_use:N \g_@@_col_int } + } + } } % \end{macrocode} % +% % \bigskip -% First, we test if we are yet in an environment |{NiceArray}| (nested -% environments are forbidden). +% We want to use |\array| of \pkg{array}. However, if the class used is +% \cls{revtex4-1} or \cls{revtex4-2}, we have to do some tuning and use the +% command |\@array@array| instead of |\array| because these classes do a +% redefinition of |\array| incompatible with our use of |\array|. +% % \begin{macrocode} -\NewDocumentEnvironment { NiceArray } { O { } m ! O { } } - { - \@@_adapt_S_column: - \@@_test_if_math_mode: - \bool_if:NT \l_@@_in_NiceArray_bool - { \@@_error:n { Yet~in~NiceArray } } - \bool_set_true:N \l_@@_in_NiceArray_bool +\cs_new_protected:Npn \@@_array: + { + \bool_if:NTF \c_@@_revtex_bool + { + \cs_set_eq:NN \@acoll \@arrayacol + \cs_set_eq:NN \@acolr \@arrayacol + \cs_set_eq:NN \@acol \@arrayacol + \cs_set:Npn \@halignto { } + \@array@array + } + \array % \end{macrocode} -% -% We deactivate Tikz externalization (since we use Tikz pictures with the -% options |overlay| and |remember picture|, there would be errors). +% |\l_@@_pos_env_str| may have the value |t|, |c| or |b|. % \begin{macrocode} - \cs_if_exist:NT \tikz@library@external@loaded - { \tikzset { external / export = false } } - \group_insert_after:N \@@_after_array: - \tl_gclear_new:N \g_@@_lines_to_draw_tl + [ \l_@@_pos_env_str ] + } % \end{macrocode} % -% We increment the counter |\g_@@_env_int| which counts the environments -% |{NiceArray}|. +% +% +% \bigskip +% The following must \emph{not} be protected because it begins with |\noalign|. % \begin{macrocode} - \int_gincr:N \g_@@_env_int - \bool_if:NF \l_@@_block_auto_columns_width_bool - { \dim_gzero_new:N \g_@@_max_cell_width_dim } +\cs_new:Npn \@@_everycr: + { \noalign { \@@_everycr_i: } } % \end{macrocode} % -% For the following variables, maybe we should create it only if we use the -% environment |{pNiceArrayRC}| or its variants. % \begin{macrocode} - \dim_gzero_new:N \g_@@_max_dp_row_zero_dim - \dim_gzero_new:N \g_@@_max_ht_row_zero_dim - \dim_gzero_new:N \g_@@_max_ht_row_one_dim +\cs_new_protected:Npn \@@_everycr_i: + { + \int_gzero:N \g_@@_col_int + \bool_if:NT \l_@@_hlines_bool + { % \end{macrocode} -% +% The counter |\g_@@_row_int| has the value $-1$ only if there is a ``first +% row'' and that we are before that ``first row'', i.e. just before the +% beginning of the array. % \begin{macrocode} - \keys_set:nn { NiceMatrix / NiceArray } { #1 , #3 } + \int_compare:nNnT \g_@@_row_int > { -1 } + { + \int_compare:nNnF \g_@@_row_int = \g_@@_last_row_int + { + \hrule \@height \arrayrulewidth + \skip_vertical:n { - \arrayrulewidth } + } + } + } + } % \end{macrocode} % +% \bigskip +% The following code |\@@_pre_array:| is used in |{NiceArray}| and in +% |{NiceMatrix}|. It contains code that will be executed \emph{before} the +% construction of the array. +% \label{prearray} +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_pre_array: + { +% \end{macrocode} +% % If the user requires all the columns to have a width equal to the widest cell % of the array, we read this length in the file |.aux| (of, course, this is -% possible only on the second run of LaTeX : on the first run, the dimension +% possible only on the second run of LaTeX: on the first run, the dimension % |\l_@@_columns_width_dim| will be set to zero --- and the columns will have -% their natural width). +% their natural width). Remark that, even if the environment has a name (see +% just below) we have to write in the |aux| file the information with the number +% of environment because of |auto-columns-width| of |{NiceMatrixBlock}|. % \begin{macrocode} \bool_if:NT \l_@@_auto_columns_width_bool { @@ -3140,7 +3478,7 @@ version 2005/12/01 or later. { \dim_set:Nx \l_@@_columns_width_dim { \use:c { _@@_max_cell_width _ \int_use:N \g_@@_env_int } } - } + } % \end{macrocode} % If the environment has a name, we read the value of the maximal value of the % columns from |_@@_name_cell_width|{\ttfamily\slshape name} (the value will be @@ -3167,7 +3505,13 @@ version 2005/12/01 or later. \dim_gset_eq:NN \g_@@_left_margin_dim \l_@@_left_margin_dim \dim_gset_eq:NN \g_@@_right_margin_dim \l_@@_right_margin_dim \dim_gset_eq:NN \g_@@_extra_right_margin_dim \l_@@_extra_right_margin_dim + \int_gset_eq:NN \g_@@_last_row_int \l_@@_last_row_int \tl_gset_eq:NN \g_@@_name_str \l_@@_name_str + \int_gset_eq:NN \g_@@_first_row_int \l_@@_first_row_int + \int_gset_eq:NN \g_@@_first_col_int \l_@@_first_col_int + \bool_gset_eq:NN \g_@@_NiceArray_bool \l_@@_NiceArray_bool + \bool_gset_eq:NN \g_@@_last_row_without_value_bool + \l_@@_last_row_without_value_bool % \end{macrocode} % The environment |{array}| uses internally the command |\ialign| and, in % particular, this command |\ialign| sets |\everycr| to |{}|. However, we want @@ -3181,21 +3525,15 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_set:Npn \ialign { - \everycr - { - \noalign + \bool_if:NTF \c_@@_colortbl_loaded_bool + { + \CT@everycr { - \int_gzero:N \g_@@_column_int - \bool_if:NT \l_@@_hlines_bool - { - \int_compare:nNnT \g_@@_row_int > { -1 } - { - \hrule \@height \arrayrulewidth - \skip_vertical:n { - \arrayrulewidth } - } - } - } + \noalign { \global\let\CT@row@color\relax } + \@@_everycr: + } } + { \everycr { \@@_everycr: } } \tabskip = \c_zero_skip \cs_set:Npn \ialign { @@ -3229,20 +3567,91 @@ version 2005/12/01 or later. % \end{macrocode} % % +% \begin{macrocode} + \cs_set_eq:NN \Ldots \@@_Ldots + \cs_set_eq:NN \Cdots \@@_Cdots + \cs_set_eq:NN \Vdots \@@_Vdots + \cs_set_eq:NN \Ddots \@@_Ddots + \cs_set_eq:NN \Iddots \@@_Iddots + \cs_set_eq:NN \hdottedline \@@_hdottedline: + \cs_set_eq:NN \Hspace \@@_Hspace: + \cs_set_eq:NN \Hdotsfor \@@_Hdotsfor: + \cs_set_eq:NN \multicolumn \@@_multicolumn:nnn + \bool_if:NT \l_@@_renew_dots_bool + { + \cs_set_eq:NN \ldots \@@_Ldots + \cs_set_eq:NN \cdots \@@_Cdots + \cs_set_eq:NN \vdots \@@_Vdots + \cs_set_eq:NN \ddots \@@_Ddots + \cs_set_eq:NN \iddots \@@_Iddots + \cs_set_eq:NN \dots \@@_Ldots + \cs_set_eq:NN \hdotsfor \@@_Hdotsfor: + } +% \end{macrocode} +% +% +% The sequence |\g_@@_empty_cells_seq| will contain a list of ``empty'' cells +% (not all the empty cells of the matrix). If we want to indicate that the cell +% in row~$i$ and column~$j$ must be considered as empty, the token list +% ``|i-j|'' will be put in this sequence. +% \begin{macrocode} + \seq_gclear_new:N \g_@@_empty_cells_seq +% \end{macrocode} +% +% The sequence |\g_@@_multicolumn_cells_seq| will contain the list of the cells +% of the array where a command |\multicolumn{|$n$|}{...}{...}| with $n>1$ is +% issued. In |\g_@@_multicolumn_sizes_seq|, the ``sizes'' (that is to say the +% values of $n$) correspondant will be stored. These lists will be used for the +% creation of the ``medium nodes'' (if they are created). +% \begin{macrocode} + \seq_gclear_new:N \g_@@_multicolumn_cells_seq + \seq_gclear_new:N \g_@@_multicolumn_sizes_seq +% \end{macrocode} +% +% +% The counter |\g_@@_row_int| will be used to count the rows of the array (its +% incrementation will be in the first cell of the row). +% \begin{macrocode} + \int_gzero_new:N \g_@@_row_int + \int_gset:Nn \g_@@_row_int { \l_@@_first_row_int - 1 } +% \end{macrocode} +% +% At the end of the environment |{array}|, |\g_@@_row_int| will be the total +% number de rows and |\g_@@_row_total_int| will be the number or rows excepted +% the last row (if |\l_@@_last_row_bool| has been raised with the option +% |last-row|). +% \begin{macrocode} + \int_gzero_new:N \g_@@_row_total_int +% \end{macrocode} +% +% The counter |\g_@@_col_int| will be used to count the columns of the array. +% Since we want to know the total number of columns of the matrix, we also +% create a counter |\g_@@_col_total_int|. These counters are updated in the +% command |\@@_Cell:| executed at the beginning of each cell. +% \begin{macrocode} + \int_gzero_new:N \g_@@_col_int + \int_gzero_new:N \g_@@_col_total_int +% \end{macrocode} +% +% \begin{macrocode} + \cs_set_eq:NN \@ifnextchar \new@ifnextchar +% \end{macrocode} % We nullify the definitions of the column types |w| and |W| before their % redefinition because we want to avoid a warning in the log file for a % redefinition of a column type. We must put |\relax| and not |\prg_do_nothing:|. % \begin{macrocode} \cs_set_eq:NN \NC@find@w \relax \cs_set_eq:NN \NC@find@W \relax -% \end{macrocode} -% -% We redefine the column types |w| and |W| of the package \pkg{array}. -% \begin{macrocode} \@@_renewcolumntype:nn w { } \@@_renewcolumntype:nn W { \cs_set_eq:NN \hss \hfil } + \dim_gzero_new:N \g_@@_dp_row_zero_dim + \dim_gzero_new:N \g_@@_ht_row_zero_dim + \dim_gzero_new:N \g_@@_ht_row_one_dim + \dim_gzero_new:N \g_@@_dp_ante_last_row_dim + \dim_gzero_new:N \g_@@_ht_last_row_dim + \dim_gzero_new:N \g_@@_dp_last_row_dim % \end{macrocode} -% +% % \bigskip % By default, the letter used to specify a dotted line in the preamble of an % environment of \pkg{nicematrix} (for example in |{pNiceArray}|) is the letter @@ -3253,8 +3662,8 @@ version 2005/12/01 or later. % \begin{macrocode} \exp_args:Nx \newcolumntype \l_@@_letter_for_dotted_lines_str { - ! - { + ! + { \skip_horizontal:n { 0.53 pt } \bool_gset_true:N \g_@@_extra_nodes_bool % \end{macrocode} @@ -3279,142 +3688,649 @@ version 2005/12/01 or later. % ``|:|'' encountered during the parsing has already been taken into account in % the |code-after|. % \begin{macrocode} - \int_compare:nNnT \g_@@_column_int > \g_@@_last_vdotted_col_int + \int_compare:nNnT \g_@@_col_int > \g_@@_last_vdotted_col_int { - \int_gset_eq:NN \g_@@_last_vdotted_col_int \g_@@_column_int + \int_gset_eq:NN \g_@@_last_vdotted_col_int \g_@@_col_int \tl_gput_right:Nx \g_@@_code_after_tl % \end{macrocode} % The command |\@@_vdottedline:n| is protected, and, therefore, won't be expanded % before writing on |\g_@@_code_after_tl|. % \begin{macrocode} - { \@@_vdottedline:n { \int_use:N \g_@@_column_int } } + { \@@_vdottedline:n { \int_use:N \g_@@_col_int } } } } - } + } + \int_gzero_new:N \g_@@_last_vdotted_col_int + \bool_if:NT \c_@@_siunitx_loaded_bool \@@_renew_NC@rewrite@S: + \int_gset:Nn \g_@@_last_vdotted_col_int { -1 } + \bool_gset_false:N \g_@@_last_col_found_bool + } % \end{macrocode} % -% -% The commands |\Ldots|, |\Cdots|, etc. will be defined only in the environment -% |{NiceArray}|. +% +% +% \bigskip +% \subsection{The environment \{NiceArrayWithDelims\}} +% % \begin{macrocode} - \cs_set_eq:NN \Ldots \@@_Ldots - \cs_set_eq:NN \Cdots \@@_Cdots - \cs_set_eq:NN \Vdots \@@_Vdots - \cs_set_eq:NN \Ddots \@@_Ddots - \cs_set_eq:NN \Iddots \@@_Iddots - \cs_set_eq:NN \hdottedline \@@_hdottedline: - \cs_set_eq:NN \Hspace \@@_Hspace: - \cs_set_eq:NN \Hdotsfor \@@_Hdotsfor - \cs_set_eq:NN \multicolumn \@@_multicolumn:nnn - \bool_if:NT \l_@@_renew_dots_bool - { - \cs_set_eq:NN \ldots \@@_Ldots - \cs_set_eq:NN \cdots \@@_Cdots - \cs_set_eq:NN \vdots \@@_Vdots - \cs_set_eq:NN \ddots \@@_Ddots - \cs_set_eq:NN \iddots \@@_Iddots - \cs_set_eq:NN \dots \@@_Ldots - \cs_set_eq:NN \hdotsfor \@@_Hdotsfor - } - \bool_if:NT \c_@@_siunitx_loaded_bool \@@_renew_NC@rewrite@S: +\NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } } + { + \@@_adapt_S_column: + \@@_test_if_math_mode: + \bool_if:NT \l_@@_in_env_bool { \@@_fatal:n { Yet~in~env } } + \bool_set_true:N \l_@@_in_env_bool % \end{macrocode} -% % -% The sequence |\g_@@_empty_cells_seq| will contain a list of ``empty'' cells -% (not all the empty cells of the matrix). If we want to indicate that the cell -% in row~$i$ and column~$j$ must be considered as empty, the token list -% ``|i-j|'' will be put in this sequence. +% We deactivate Tikz externalization (since we use Tikz pictures with the +% options |overlay| and |remember picture|, there would be errors). % \begin{macrocode} - \seq_gclear_new:N \g_@@_empty_cells_seq + \cs_if_exist:NT \tikz@library@external@loaded + { \tikzset { external / export = false } } +% \end{macrocode} +% In |{NiceArrayWithDelims}|, it would have been possible to avoid the +% |\group_insert_after:N| and to put |\@@_after_array| in the second +% part of the environment |{NiceArrayWithDelims}|. However, it's not possible to +% do that in |{NiceMatrix}| (because of the option |renew-matrix|) and that's +% why we use this technique in |{NiceArrayWithDelims}| and in |{NiceMatrix}|. +% \begin{macrocode} + \group_insert_after:N \@@_after_array: + \tl_gclear_new:N \g_@@_lines_to_draw_tl % \end{macrocode} % -% The sequence |\g_@@_multicolumn_cells_seq| will contain the list of the cells -% of the array where a command |\multicolumn{|$n$|}{...}{...}| with $n>1$ is -% issued. In |\g_@@_multicolumn_sizes_seq|, the ``sizes'' (that is to say the -% values of $n$) correspondant will be stored. These lists will be used for the -% creation of the ``medium nodes'' (if they are created). +% We increment the counter |\g_@@_env_int| which counts the environments +% of the extension. % \begin{macrocode} - \seq_gclear_new:N \g_@@_multicolumn_cells_seq - \seq_gclear_new:N \g_@@_multicolumn_sizes_seq + \int_gincr:N \g_@@_env_int + \bool_if:NF \l_@@_block_auto_columns_width_bool + { \dim_gzero_new:N \g_@@_max_cell_width_dim } +% \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 counter |\g_@@_row_int| will be used to count the rows of the array (its -% incrementation will be in the first cell of the row). At the end of the -% environment |{array}|, this counter will give the total number of rows of the -% matrix. +% The set of keys is not exactly the same for |{NiceArray}| and for the variants +% of |{NiceArray}| (|{pNiceArray}|, |{bNiceArray}|, etc.) because, for +% |{NiceArray}|, we have the options |t|, |c| and |b|. % \begin{macrocode} - \int_gzero_new:N \g_@@_row_int - \int_gset:Nn \g_@@_row_int { \l_@@_nb_first_row_int - 1 } + \bool_if:NTF \l_@@_NiceArray_bool + { \keys_set:nn { NiceMatrix / NiceArray } } + { \keys_set:nn { NiceMatrix / pNiceArray } } + { #3 , #5 } % \end{macrocode} % -% The counter |\g_@@_column_int| will be used to count the columns of the array. -% Since we want to know the total number of columns of the matrix, we also -% create a counter |\g_@@_column_total_int|. These counters are updated in the -% command |\@@_Cell:| executed at the beginning of each cell. +% A value of $-1$ for the counter |\l_@@_last_row_int| means that the user has +% used the option |last-row| without value, that is to say without specifying +% the number of that last row. In this case, we try to read that value from the +% |aux| file (if it has been written on a previous run). +% % \begin{macrocode} - \int_gzero_new:N \g_@@_column_int - \int_gzero_new:N \g_@@_column_total_int + \int_compare:nNnT \l_@@_last_row_int = { -1 } + { + \bool_set_true:N \l_@@_last_row_without_value_bool +% \end{macrocode} +% A value based the name is more reliable than a value based on the number of +% the environment. +% \begin{macrocode} + \str_if_empty:NTF \g_@@_name_str + { + \cs_if_exist:cT { @@_last_row_ \int_use:N \g_@@_env_int } + { + \int_set:Nn \l_@@_last_row_int + { \use:c { @@_last_row_ \int_use:N \g_@@_env_int } } + } + } + { + \cs_if_exist:cT { @@_last_row_ \g_@@_name_str } + { + \int_set:Nn \l_@@_last_row_int + { \use:c { @@_last_row_ \g_@@_name_str } } + } + } + } % \end{macrocode} % +% The code in |\@@_pre_array:| is common to |{NiceArrayWithDelims}| and |{NiceMatrix}|. % \begin{macrocode} - \int_gzero_new:N \g_@@_last_vdotted_col_int - \int_gset:Nn \g_@@_last_vdotted_col_int { -1 } - \cs_set_eq:NN \@ifnextchar \new@ifnextchar + \@@_pre_array: % \end{macrocode} % -% The extra horizontal spaces on both sides of an environment |{array}| should -% be considered as a bad idea of standard LaTeX. In the environment |{matrix}| -% the package \pkg{amsmath} prefers to suppress these spaces with instructions -% ``|\hskip -\arraycolsep|''. In the same way, we decide to suppress them in -% |{NiceArray}|. However, for better compatibility, we give an option -% |exterior-arraycolsep| to control this feature. +% \medskip +% We compute the width of the two delimiters. % \begin{macrocode} - \bool_if:NF \l_@@_exterior_arraycolsep_bool - { \skip_horizontal:n { - \arraycolsep } } + \dim_zero_new:N \g_@@_left_delim_dim + \dim_zero_new:N \g_@@_right_delim_dim + \bool_if:NTF \l_@@_NiceArray_bool + { + \dim_gset:Nn \g_@@_left_delim_dim { 2 \arraycolsep } + \dim_gset:Nn \g_@@_right_delim_dim { 2 \arraycolsep } + } + { + \group_begin: + \dim_set_eq:NN \nulldelimiterspace \c_zero_dim + \hbox_set:Nn \l_tmpa_box + { + \c_math_toggle_token + \left #1 \vcenter to 1 cm { } \right. + \c_math_toggle_token + + } + \dim_gset:Nn \g_@@_left_delim_dim { \box_wd:N \l_tmpa_box } + \hbox_set:Nn \l_tmpa_box + { + \dim_set_eq:NN \nulldelimiterspace \c_zero_dim + \c_math_toggle_token + \left. \vcenter to 1 cm { } \right #2 + \c_math_toggle_token + } + \dim_gset:Nn \g_@@_right_delim_dim { \box_wd:N \l_tmpa_box } + \group_end: + } % \end{macrocode} % +% \medskip +% The array will be composed in a box (named |\l_@@_the_array_box|) because we +% have to do manipulations concerning the potential exterior rows (such +% construction in a box is not possible for |{NiceMatrix}|). % \begin{macrocode} + \box_clear_new:N \l_@@_the_array_box +% \end{macrocode} +% +% \medskip +% We construct the preamble of the array in |\l_tmpa_tl|. +% \begin{macrocode} + \tl_set:Nn \l_tmpa_tl { #4 } + \int_compare:nNnTF \l_@@_first_col_int = \c_zero_int + { \tl_put_left:NV \l_tmpa_tl \c_@@_preamble_first_col_tl } + { + \bool_if:NT \l_@@_NiceArray_bool + { + \bool_if:NF \l_@@_exterior_arraycolsep_bool + { \tl_put_left:Nn \l_tmpa_tl { @ { } } } + } + } + \bool_if:NTF \l_@@_last_col_bool + { \tl_put_right:NV \l_tmpa_tl \c_@@_preamble_last_col_tl } + { + \bool_if:NT \l_@@_NiceArray_bool + { + \bool_if:NF \l_@@_exterior_arraycolsep_bool + { \tl_put_right:Nn \l_tmpa_tl { @ { } } } + } + } +% \end{macrocode} +% Here is the beginning of the box which will contain the array. The +% |\hbox_set_end:| corresponding to this |\hbox_set:Nw| will be in the second part of +% the environment (and the closing |\c_math_toggle_token| also). +% \begin{macrocode} + \hbox_set:Nw \l_@@_the_array_box \skip_horizontal:n \l_@@_left_margin_dim \skip_horizontal:n \l_@@_extra_left_margin_dim + \c_math_toggle_token +% \end{macrocode} +% Here is the call to |\array| (we have a dedicated macro |\@@_array:| because +% of compatibility with \cls{revtex4-1} and \cls{revtex4-2}). +% \begin{macrocode} + \exp_args:NV \@@_array: \l_tmpa_tl + } +% \end{macrocode} +% +% \bigskip +% We begin the second part of the environment |{NiceArrayWithDelims}|. +% \begin{macrocode} + { + \endarray + \c_math_toggle_token + \skip_horizontal:n \g_@@_right_margin_dim + \skip_horizontal:n \g_@@_extra_right_margin_dim + \hbox_set_end: +% \end{macrocode} +% Now, we compute |\l_tmpa_dim| which is the vertical dimension of the ``first +% row'' above the array (when the key |first-row| is used). +% \begin{macrocode} + \int_compare:nNnTF \l_@@_first_row_int = \c_zero_int + { + \dim_compare:nNnTF + { \g_@@_ht_row_one_dim + \g_@@_dp_row_zero_dim + \lineskiplimit } + > \baselineskip + { + \dim_set:Nn \l_tmpa_dim + { + \g_@@_ht_row_one_dim + \g_@@_dp_row_zero_dim + \lineskip + + \g_@@_ht_row_zero_dim - \g_@@_ht_row_one_dim + } + } + { + \dim_set:Nn \l_tmpa_dim + { \baselineskip + \g_@@_ht_row_zero_dim - \g_@@_ht_row_one_dim } + } + } + { \dim_zero:N \l_tmpa_dim } +% \end{macrocode} +% We compute |\l_tmpb_dim| which is the vertical dimension of the ``last row'' +% below the array (when the key |last-row| is used). A value of $-2$ for +% |\l_@@_last_row_int| means that there is no ``last row''.\footnote{A value of +% $-1$ for |\l_@@_last_row_int| means that there is a ``last row'' but the +% number of that row is unknown (the user have not set the value with the option +% |last row|).} +% \begin{macrocode} + \int_compare:nNnTF \l_@@_last_row_int > { -2 } + { + \dim_compare:nNnTF + { + \g_@@_ht_last_row_dim + \g_@@_dp_ante_last_row_dim + \lineskiplimit + } + > + \baselineskip + { + \dim_set:Nn \l_tmpb_dim + { + \g_@@_ht_last_row_dim + \g_@@_dp_ante_last_row_dim + \lineskip + + \g_@@_dp_last_row_dim - \g_@@_dp_ante_last_row_dim + } + } + { + \dim_set:Nn \l_tmpb_dim + { + \baselineskip + + \g_@@_dp_last_row_dim - \g_@@_dp_ante_last_row_dim + } + } + } + { \dim_zero:N \l_tmpb_dim } % \end{macrocode} % -% -% Eventually, the environment |{NiceArray}| is defined upon the environment -% |{array}|. However, if the class used is \cls{revtex4-1} or \cls{revtex4-2}, -% we have to do some tuning and use the command |\@array@array| instead of -% |\array| because these classes do a redefinition of |\array| incompatible with -% our use of |\array|. +% \bigskip +% Now, we begin the real construction in the output flow of TeX. First, we take +% into account a potential ``first column'' (we remind that this ``first +% column'' has been constructed in an overlapping position and that we have computed +% its width in |\g_@@_width_first_col_dim|: see p.~\pageref{overlap-left}). % \begin{macrocode} - \bool_if:NTF \c_@@_revtex_bool - { - \cs_set_eq:NN \@acoll \@arrayacol - \cs_set_eq:NN \@acolr \@arrayacol - \cs_set_eq:NN \@acol \@arrayacol - \cs_set:Npn \@halignto { } - \@array@array - } - \array + \int_compare:nNnT \g_@@_first_col_int = \c_zero_int + { + \skip_horizontal:n \arraycolsep + \skip_horizontal:n \g_@@_width_first_col_dim + } +% \end{macrocode} +% +% The construction of the real box is different in |{NiceArray}| and in its +% variants (|{pNiceArray}|, etc.) because, in |{NiceArray}|, we have to take +% into account the option of position (|t|, |c| or |b|). We begin with +% |{NiceArray}|. +% \begin{macrocode} + \bool_if:NTF \g_@@_NiceArray_bool + { + \int_compare:nNnT \g_@@_first_row_int = \c_zero_int + { + \str_if_eq:VnTF \l_@@_pos_env_str { t } + { + \box_move_up:nn + { \l_tmpa_dim - \g_@@_ht_row_zero_dim + \g_@@_ht_row_one_dim } + } + } + { + \bool_if:NT \g_@@_last_row_int + { + \str_if_eq:VnT \l_@@_pos_env_str { b } + { + \box_move_down:nn + { + \l_tmpb_dim + - \g_@@_dp_last_row_dim + \g_@@_dp_ante_last_row_dim + } + } + } + } + { \box_use_drop:N \l_@@_the_array_box } + } +% \end{macrocode} +% +% Now, in the case of an environment |{pNiceArray}|, |{bNiceArray}|, etc. +% \begin{macrocode} + { + \hbox_set:Nn \l_tmpa_box + { + \c_math_toggle_token + \left #1 + \vcenter + { % \end{macrocode} -% The token list |\l_@@_pos_env_str|, which is the argument of |\array| (or -% |\@array@array|) will contain one of the values |t|, |c| or |b|. +% We take into account the ``first row'' (we have previously computed its size +% in |\l_tmpa_dim|). % \begin{macrocode} - [ \l_@@_pos_env_str ] { #2 } + \skip_vertical:n { - \l_tmpa_dim } + \hbox:n + { + \skip_horizontal:n { - \arraycolsep } + \box_use_drop:N \l_@@_the_array_box + \skip_horizontal:n { - \arraycolsep } + } +% \end{macrocode} +% We take into account the ``last row'' (we have previously computed its size +% in |\l_tmpb_dim|). +% \begin{macrocode} + \skip_vertical:n { - \l_tmpb_dim } + } + \right #2 + \c_math_toggle_token + } + \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } + \box_set_dp:Nn \l_tmpa_box { \box_dp:N \l_tmpa_box + \l_tmpb_dim } + \box_use_drop:N \l_tmpa_box + } +% \end{macrocode} +% We take into account a potential ``last column'' (this ``last +% column'' has been constructed in an overlapping position and we have computed +% its width in |\g_@@_width_last_col_dim|: see p.~\pageref{overlap-right}). +% \begin{macrocode} + \bool_if:NT \g_@@_last_col_found_bool + { + \skip_horizontal:n \g_@@_width_last_col_dim + \skip_horizontal:n \arraycolsep + } } % \end{macrocode} +% This is the end of the environment |{NiceArrayWithDelims}|. % -% \bigskip +% \interitem +% Here is the preamble for the ``first column'' (if the user uses the key |first-col|) +% \begin{macrocode} +\tl_const:Nn \c_@@_preamble_first_col_tl + { + > + { + \@@_begin_of_row: +% \end{macrocode} +% The contents of the cell is constructed in the box |\l_tmpa_box| because we +% have to compute some dimensions of this box. +% \begin{macrocode} + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token + \l_@@_code_for_first_col_tl + } + l + < + { + \c_math_toggle_token + \hbox_set_end: + \@@_actualization_for_first_and_last_row: +% \end{macrocode} +% We actualise the width of the ``first column'' because we will use this width +% after the construction of the array. +% \begin{macrocode} + \dim_gset:Nn \g_@@_width_first_col_dim + { + \dim_max:nn + \g_@@_width_first_col_dim + { \box_wd:N \l_tmpa_box } + } +% \end{macrocode} +% The content of the cell is inserted in an overlapping position. +% \label{overlap-left} +% \begin{macrocode} + \hbox_overlap_left:n + { + \tikz + [ + remember~picture , + inner~sep = \c_zero_dim , + minimum~width = \c_zero_dim , + baseline + ] + \node + [ + anchor = base , + name = + nm - + \int_use:N \g_@@_env_int - + \int_use:N \g_@@_row_int - + 0 , + alias = + \str_if_empty:NF \l_@@_name_str + { + \l_@@_name_str - + \int_use:N \g_@@_row_int - + 0 + } + ] + { \box_use:N \l_tmpa_box } ; + \skip_horizontal:n + { + \g_@@_left_delim_dim + + \l_@@_left_margin_dim + + \l_@@_extra_left_margin_dim + } + } + \skip_horizontal:n { - 2 \arraycolsep } + } + } +% \end{macrocode} +% +% +% Here is the preamble for the ``last column'' (if the user uses the key |last-col|). +% \begin{macrocode} +\tl_const:Nn \c_@@_preamble_last_col_tl + { + > + { +% \end{macrocode} +% With the flag |\g_@@_last_col_found_bool|, we will know that the ``last +% column'' i s really used. +% \begin{macrocode} + \bool_gset_true:N \g_@@_last_col_found_bool + \int_gincr:N \g_@@_col_int + \int_gset:Nn \g_@@_col_total_int + { \int_max:nn \g_@@_col_total_int \g_@@_col_int } +% \end{macrocode} +% The contents of the cell is constructed in the box |\l_tmpa_box| because we +% have to compute some dimensions of this box. +% \begin{macrocode} + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token + \l_@@_code_for_last_col_tl + } + l + < + { + \c_math_toggle_token + \hbox_set_end: + \@@_actualization_for_first_and_last_row: +% \end{macrocode} +% We actualise the width of the ``last column'' because we will use this width +% after the construction of the array. % \begin{macrocode} - { \endarray - \bool_if:NF \l_@@_exterior_arraycolsep_bool - { \skip_horizontal:n { - \arraycolsep } } - \skip_horizontal:n \g_@@_right_margin_dim - \skip_horizontal:n \g_@@_extra_right_margin_dim + \dim_gset:Nn \g_@@_width_last_col_dim + { + \dim_max:nn + \g_@@_width_last_col_dim + { \box_wd:N \l_tmpa_box } + } + \skip_horizontal:n { - 2 \arraycolsep } +% \end{macrocode} +% The content of the cell is inserted in an overlapping position. +% \label{overlap-right} +% \begin{macrocode} + \hbox_overlap_right:n + { + \skip_horizontal:n + { + \g_@@_right_delim_dim + + \l_@@_right_margin_dim + + \l_@@_extra_right_margin_dim + } + \tikz + [ + remember~picture , + inner~sep = \c_zero_dim , + minimum~width = \c_zero_dim , + baseline + ] + \node + [ + anchor = base , + name = + nm - + \int_use:N \g_@@_env_int - + \int_use:N \g_@@_row_int - + \int_use:N \g_@@_col_int , + alias = + \str_if_empty:NF \l_@@_name_str + { + \l_@@_name_str - + \int_use:N \g_@@_row_int - + \int_use:N \g_@@_col_int + } + ] + { \box_use:N \l_tmpa_box } ; + } + } } % \end{macrocode} % % % \interitem +% The environment |{NiceArray}| is constructed upon the environment +% |{NiceArrayWithDelims}| but, in fact, there is a flag |\l_@@_NiceArray_bool|. +% In |{NiceArrayWithDelims}|, some special code will be executed if this flag is raised. +% \begin{macrocode} +\NewDocumentEnvironment { NiceArray } { } + { + \bool_set_true:N \l_@@_NiceArray_bool +% \end{macrocode} +% We put . and . for the delimiters but, in fact, that doesn't matter because +% these arguments won't be used in |{NiceArrayWithDelims}| (because the flag +% |\l_@@_NiceArray_bool| is raised). +% \begin{macrocode} + \NiceArrayWithDelims . . + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% +% \interitem +% We create the variants of the environment |{NiceArrayWithDelims}|. These +% variants exist since the version 3.0 of \pkg{nicematrix}. +% +% \begin{macrocode} +\NewDocumentEnvironment { pNiceArray } { } + { + \@@_test_if_math_mode: + \NiceArrayWithDelims ( ) + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { bNiceArray } { } + { + \@@_test_if_math_mode: + \NiceArrayWithDelims [ ] + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { BNiceArray } { } + { + \@@_test_if_math_mode: + \NiceArrayWithDelims \{ \} + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { vNiceArray } { } + { + \@@_test_if_math_mode: + \NiceArrayWithDelims | | + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { VNiceArray } { } + { + \@@_test_if_math_mode: + \NiceArrayWithDelims \| \| + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% \bigskip +% \subsection{The environment \{NiceMatrix\} and its variants} +% +% Our environment |{NiceMatrix}| must have the same second part as the +% environment |{matrix}| of \pkg{amsmath} (because of the programmation of the +% option |renew-matrix|). Hence, this second part is the following: +% +% \begin{Verbatim} +% \endarray +% \skip_horizontal:n { - \arraycolsep } +% \end{Verbatim} +% +% That's why in the definition of |{NiceMatrix}|, we have to use |\array| and +% not |\begin{array}|. This command |\array| is in |\@@_array:| (we have written +% this command because of the redefinition of |\array| done in \cls{revtex4-1} +% and \cls{revtex4-2}). +% +% In order to execute code after the array, we use a command +% |\group_insert_after:N|. +% +% \medskip +% Here's the definition of |{NiceMatrix}|: +% \begin{macrocode} +\NewDocumentEnvironment { NiceMatrix } { ! O { } } + { + \@@_test_if_math_mode: + \bool_if:NT \l_@@_in_env_bool { \@@_fatal:n { Yet~in~env } } + \bool_set_true:N \l_@@_in_env_bool +% \end{macrocode} +% We have to deactivate the potential externalisation of Tikz because +% \pkg{nicematrix} uses Tikz with |remember picture|. +% \begin{macrocode} + \cs_if_exist:NT \tikz@library@external@loaded + { \tikzset { external / export = false } } +% \end{macrocode} +% The instruction for actual drawing of the dotted lines must be in a +% |\group_insert_after:N| because the second part of the environment must be the +% same as in |{array}| (for the option |renew-matrix|). +% \begin{macrocode} + \group_insert_after:N \@@_after_array: + \tl_gclear_new:N \g_@@_lines_to_draw_tl + \int_gincr:N \g_@@_env_int + \bool_if:NF \l_@@_block_auto_columns_width_bool + { \dim_gzero_new:N \g_@@_max_cell_width_dim } + \keys_set:nn { NiceMatrix / NiceMatrix } { #1 } +% \end{macrocode} +% The macro |\@@_pre_array:| is defined above (see p.~\pageref{prearray}). It +% is also used in |{NiceArrayWithDelims}|. +% \begin{macrocode} + \@@_pre_array: + \skip_horizontal:n { - \arraycolsep } + \skip_horizontal:n \l_@@_left_margin_dim + \skip_horizontal:n \l_@@_extra_left_margin_dim + \str_set:Nn \l_@@_pos_env_str c + \bool_set_false:N \l_@@_exterior_arraycolsep_bool + \@@_array: { * \c@MaxMatrixCols C } + } + { + \endarray + \skip_horizontal:n { - \arraycolsep } +% \end{macrocode} +% The two following lines are, of course, not in the second part of |{array}|, +% but that doesn't matter because, when |renew-matrix| is used, +% |\g_@@_right_margin_dim| and |\g_@@_extra_right_margin_dim| will be equal to $0$~pt. +% \begin{macrocode} + \skip_horizontal:n \g_@@_right_margin_dim + \skip_horizontal:n \g_@@_extra_right_margin_dim + } +% \end{macrocode} +% +% \interitem % We create the variants of the environment |{NiceMatrix}|. % \begin{macrocode} \NewDocumentEnvironment { pNiceMatrix } { } @@ -3453,7 +4369,7 @@ version 2005/12/01 or later. % \end{macrocode} % % \begin{macrocode} -\NewDocumentEnvironment { VNiceMatrix } {} +\NewDocumentEnvironment { VNiceMatrix } { } { \@@_test_if_math_mode: \left\lVert \begin{NiceMatrix} @@ -3461,8 +4377,11 @@ version 2005/12/01 or later. { \end{NiceMatrix} \right\rVert } % \end{macrocode} % -% \interitem -% For the option \verb|columns-width=auto| (or the option |auto-columns-width| +% +% \bigskip +% \subsection{Automatic width of the cells} +% +% For the option |columns-width=auto| (or the option |auto-columns-width| % of the environment |{NiceMatrixBlock}|), we want to know the maximal width of % the cells of the array (except the cells of the ``exterior'' column of an % environment of the kind of |{pNiceAccayC}|). This length can be known only @@ -3498,7 +4417,9 @@ version 2005/12/01 or later. } % \end{macrocode} % -% \interitem +% \bigskip +% \subsection{How to know whether a cell is ``empty''} +% % The conditionnal |\@@_if_not_empty_cell:nnT| tests whether a cell is empty. The % first two arguments must be LaTeX3 counters for the row and the column of the % considered cell. @@ -3549,57 +4470,13 @@ version 2005/12/01 or later. } % \end{macrocode} % -% \interitem -% The argument of the following command |\@@_instruction_of_type:n| is the type -% of the instruction (|Cdots|, |Vdots|, |Ddots|, etc.). This command writes in -% |\g_@@_lines_to_draw_tl| the instruction that will really draw the line after -% the construction of the matrix. -% -% \medskip -% For example, for the following matrix, -% -% \smallskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% \begin{pNiceMatrix} -% 1 & 2 & 3 & 4 \\ -% 5 & \Cdots & & 6 \\ -% 7 & \Hdotsfor{2} \\ -% \end{pNiceMatrix} -% \end{BVerbatim} -% $\begin{pNiceMatrix} -% 1 & 2 & 3 & 4 \\ -% 5 & \Cdots & & 6 \\ -% 7 & \Hdotsfor{2} \\ -% \end{pNiceMatrix}$ -% -% the content of |\g_@@_lines_to_draw_tl| will be: -% -% \begin{scope} -% \color{gray} -% \verb|\@@_draw_Cdots:nn {2}{2}| -% -% \verb|\@@_draw_Hdotsfor:nnn {3}{2}{2}| -% \end{scope} -% -% \begin{macrocode} -\bool_if:NTF \c_@@_draft_bool - { \cs_set_protected:Npn \@@_instruction_of_type:n #1 { } } - { - \cs_new_protected:Npn \@@_instruction_of_type:n #1 - { - \tl_gput_right:Nx \g_@@_lines_to_draw_tl - { - \exp_not:c { @@ _ draw _ #1 : nn } - { \int_use:N \g_@@_row_int } - { \int_use:N \g_@@_column_int } - } - } - } -% \end{macrocode} -% % % \subsection{After the construction of the array} % +% The macro |\@@_after_array:| is called (via +% |\group_insert_after:N|) in |{NiceArrayWithDelims}| and +% |{NiceMatrix}|. +% % \begin{macrocode} \cs_new_protected:Nn \@@_after_array: { @@ -3613,7 +4490,7 @@ version 2005/12/01 or later. \@@_msg_new:nn { Zero~row } { There~is~a~problem.~Maybe~your~environment~\{\@currenvir\}~is~empty.~ - Maybe~you~have~used~L,~C~and~R~instead~of~l,~c~and~r~in~the~preamble~ + Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~and~R~in~the~preamble~ of~your~environment. \\ If~you~go~on,~the~result~may~be~incorrect. } @@ -3629,17 +4506,52 @@ version 2005/12/01 or later. \cs_if_exist:NT \tikz@library@external@loaded { \tikzset { external / export = false } } % \end{macrocode} -% Now, the definition of the counters |\g_@@_column_int| and -% |\g_@@_column_total_int| change: |\g_@@_column_int| will be the number of -% columns without the exterior column (in an environment like |{pNiceArrayC}|) -% and |\g_@@_column_total_int| will be the number of columns with this exterior -% column. +% Now, the definition of |\g_@@_col_int| and +% |\g_@@_col_total_int| change: |\g_@@_col_int| will be the number of +% columns without the ``last column''; |\g_@@_col_total_int| will be the +% number of columns with this ``last column''.\footnote{We remind that the +% potential ``first column'' has the number~$0$.} +% \begin{macrocode} + \int_gset_eq:NN \g_@@_col_int \g_@@_col_total_int + \bool_if:nT \g_@@_last_col_found_bool { \int_gdecr:N \g_@@_col_int } +% \end{macrocode} +% +% We fix also the value of |\g_@@_row_int| and |\g_@@_row_total_int| with the +% same principle. % \begin{macrocode} - \int_gset_eq:NN \g_@@_column_int \g_@@_column_total_int - \bool_if:nT { \l_@@_exterior_column_bool && \g_@@_exterior_column_found_bool } - { \int_gdecr:N \g_@@_column_int } + \int_gset_eq:NN \g_@@_row_total_int \g_@@_row_int + \int_compare:nNnT \g_@@_last_row_int > { -1 } + { \int_gsub:Nn \g_@@_row_int \c_one_int } % \end{macrocode} % +% In the user has used the option |last-row| without value, we write in the +% |aux| file the number of that last row for the next run. +% \begin{macrocode} + \bool_if:NT \g_@@_last_row_without_value_bool + { + \iow_now:Nn \@mainaux \ExplSyntaxOn + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { @@_last_row_ \int_use:N \g_@@_env_int } + { \int_use:N \g_@@_row_total_int } + } +% \end{macrocode} +% If the environment has a name, we also write a value based on the name +% because it's more reliable than a value based on the number of the +% environment. +% \begin{macrocode} + \str_if_empty:NF \g_@@_name_str + { + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { @@_last_row_ \g_@@_name_str } + { \int_use:N \g_@@_row_total_int } + } + } + \iow_now:Nn \@mainaux \ExplSyntaxOff + } +% \end{macrocode} +% % The sequence |\g_@@_yet_drawn_seq| contains a list of lines which have been % drawn previously in the matrix. We maintain this sequence because we don't % want to draw two overlapping lines. @@ -3727,8 +4639,8 @@ version 2005/12/01 or later. % a & a+b & a+b+c % \end{pNiceMatrix}\] % For a closed extremity, we use the normal node and for a open one, we use the -% ``medium node'' (the medium and large nodes are created with -% |\@@_create_extra_nodes:| if they have not been created yet). +% ``medium node'' or, if it exists, the |w|~node (the medium and large nodes are +% created with |\@@_create_extra_nodes:| if they have not been created yet). % \[ \begin{pNiceMatrix}[create-extra-nodes, % code-after = {\begin{tikzpicture} % \node [highlight, fit={(2-1)}] {} ; @@ -3750,7 +4662,8 @@ version 2005/12/01 or later. % issued; % \item the third argument is the $x$-value of the orientation vector of the % line; -% \item the fourth argument is the $y$-value the orientation vector of the line; +% \item the fourth argument is the $y$-value of the orientation vector of the +% line; % \end{itemize} % % This command computes: @@ -3771,8 +4684,6 @@ version 2005/12/01 or later. \int_set:Nn \l_@@_initial_j_int { #2 } \int_set:Nn \l_@@_final_i_int { #1 } \int_set:Nn \l_@@_final_j_int { #2 } - \bool_set_false:N \l_@@_initial_open_bool - \bool_set_false:N \l_@@_final_open_bool % \end{macrocode} % We will do two loops: one when determinating the initial cell and the other % when determinating the final cell. The boolean |\l_@@_stop_loop_bool| will be @@ -3786,27 +4697,32 @@ version 2005/12/01 or later. % \end{macrocode} % We test if we are still in the matrix. % \begin{macrocode} - \bool_if:nTF - { - \int_compare_p:nNn - \l_@@_final_i_int < { \l_@@_nb_first_row_int - 1 } - || \int_compare_p:nNn \l_@@_final_i_int > \g_@@_row_int - || \int_compare_p:nNn \l_@@_final_j_int < \c_one_int - || \int_compare_p:nNn \l_@@_final_j_int > \g_@@_column_total_int -% \end{macrocode} -% If you arrive in the column |C| of an environment with such columns (like -% |{pNiceArrayC}|), you must consider that we are \emph{outside} the matrix -% except if we are drawing a vertical line (included in the column |C|). -% \begin{macrocode} - || \int_compare_p:nNn \l_@@_final_j_int > \g_@@_column_int - && \int_compare_p:nNn { #4 } > \c_zero_int + \bool_set_false:N \l_@@_final_open_bool + \int_compare:nNnTF \l_@@_final_i_int > \g_@@_row_int + { + \int_compare:nNnT { #3 } = 1 + { \bool_set_true:N \l_@@_final_open_bool } } + { + \int_compare:nNnTF \l_@@_final_j_int < 1 + { + \int_compare:nNnT { #4 } = { -1 } + { \bool_set_true:N \l_@@_final_open_bool } + } + { + \int_compare:nNnT \l_@@_final_j_int > \g_@@_col_int + { + \int_compare:nNnT { #4 } = 1 + { \bool_set_true:N \l_@@_final_open_bool } + } + } + } + \bool_if:NTF \l_@@_final_open_bool % \end{macrocode} % If we are outside the matrix, we have found the extremity of the dotted line % and it's a \emph{open} extremity. % \begin{macrocode} { - \bool_set_true:N \l_@@_final_open_bool % \end{macrocode} % We do a step backwards because we will draw the dotted line upon the last cell % in the matrix (we will use the ``medium node'' of this cell). @@ -3836,18 +4752,28 @@ version 2005/12/01 or later. { \int_sub:Nn \l_@@_initial_i_int { #3 } \int_sub:Nn \l_@@_initial_j_int { #4 } - \bool_if:nTF + \bool_set_false:N \l_@@_initial_open_bool + \int_compare:nNnTF \l_@@_initial_i_int < 1 + { + \int_compare:nNnT { #3 } = 1 + { \bool_set_true:N \l_@@_initial_open_bool } + } { - \int_compare_p:nNn \l_@@_initial_i_int < \l_@@_nb_first_row_int - || - \int_compare_p:nNn \l_@@_initial_i_int > \g_@@_row_int - || - \int_compare_p:nNn \l_@@_initial_j_int < 1 - || - \int_compare_p:nNn \l_@@_initial_j_int > \g_@@_column_total_int + \int_compare:nNnTF \l_@@_initial_j_int < 1 + { + \int_compare:nNnT { #4 } = 1 + { \bool_set_true:N \l_@@_initial_open_bool } + } + { + \int_compare:nNnT \l_@@_initial_j_int > \g_@@_col_int + { + \int_compare:nNnT { #4 } = { -1 } + { \bool_set_true:N \l_@@_initial_open_bool } + } + } } + \bool_if:NTF \l_@@_initial_open_bool { - \bool_set_true:N \l_@@_initial_open_bool \int_add:Nn \l_@@_initial_i_int { #3 } \int_add:Nn \l_@@_initial_j_int { #4 } \bool_set_true:N \l_@@_stop_loop_bool @@ -3860,8 +4786,9 @@ version 2005/12/01 or later. } % \end{macrocode} % If we have at least one open extremity, we create the ``medium nodes'' in the -% matrix (in the case of an open extremity, the dotted line uses the ``medium -% node'' of the last empty cell). We remind that, when used once, the command +% matrix\footnote{We should change this. Indeed, for an open extremity of an +% \emph{horizontal} dotted line, we use the |w|~node, if, it exists, and not the +% ``medium node''.}. We remind that, when used once, the command % |\@@_create_extra_nodes:| becomes no-op in the current TeX group. % \begin{macrocode} \bool_if:nT { \l_@@_initial_open_bool || \l_@@_final_open_bool } @@ -3907,7 +4834,7 @@ version 2005/12/01 or later. % arguments which are |\l_@@_initial_i_int|, |\l_@@_initial_j_int|, % |\l_@@_final_i_int| and |\l_@@_final_j_int|. % -% The two arguments of the command |\@@_retrieve_coords:nn| are the prefix and +% The two arguments of the command |\@@_retrieve_coords:nn| are the suffix and % the anchor that must be used for the two nodes. % % The coordinates are stored in |\g_@@_x_initial_dim|, |\g_@@_y_initial_dim|, @@ -3949,24 +4876,48 @@ version 2005/12/01 or later. % \end{macrocode} % % \medskip -% The command |\@@_actually_draw_Ldots:| actually draws the |Ldots| line using +% The command |\@@_actually_draw_Ldots:| draws the |Ldots| line using % |\l_@@_initial_i_int|, |\l_@@_initial_j_int|, |\l_@@_initial_open_bool|, % |\l_@@_final_i_int|, |\l_@@_final_j_int| and |\l_@@_final_open_bool|. We have % a dedicated command because if is used also by |\Hdotsfor|. % \begin{macrocode} \cs_new_protected:Nn \@@_actually_draw_Ldots: { - \@@_retrieve_coords:xx - { - \bool_if:NTF \l_@@_initial_open_bool - { - medium.base~west } - { .base~east } - } - { - \bool_if:NTF \l_@@_final_open_bool - { - medium.base~east } - { . base~west } - } + \@@_retrieve_coords:xx + { + \bool_if:NTF \l_@@_initial_open_bool + { +% \end{macrocode} +% If a |w| node exists (created when the key |columns-width| is used), we use +% the |w| node for the extremity. +% \begin{macrocode} + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g_@@_env_int + - \int_use:N \l_@@_initial_i_int + - \int_use:N \l_@@_initial_j_int - w + } + { - w.base~west } + { - medium.base~west } + } + { .base~east } + } + { + \bool_if:NTF \l_@@_final_open_bool + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g_@@_env_int + - \int_use:N \l_@@_final_i_int + - \int_use:N \l_@@_final_j_int - w + } + { - w.base~east } + { - medium.base~east } + } + { .base~west } + } \bool_if:NT \l_@@_initial_open_bool { \dim_gset_eq:NN \g_@@_y_initial_dim \g_@@_y_final_dim } \bool_if:NT \l_@@_final_open_bool @@ -3991,13 +4942,33 @@ version 2005/12/01 or later. \@@_retrieve_coords:xx { \bool_if:NTF \l_@@_initial_open_bool - { - medium.mid~west } + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g_@@_env_int + - \int_use:N \l_@@_initial_i_int + - \int_use:N \l_@@_initial_j_int - w + } + { - w.mid~west } + { - medium.mid~west } + } { .mid~east } - } - { + } + { \bool_if:NTF \l_@@_final_open_bool - { - medium.mid~east } - { .mid~west } + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g_@@_env_int + - \int_use:N \l_@@_final_i_int + - \int_use:N \l_@@_final_j_int - w + } + { - w.mid~east } + { - medium.mid~east } + } + { .mid~west } } \bool_if:NT \l_@@_initial_open_bool { \dim_gset_eq:NN \g_@@_y_initial_dim \g_@@_y_final_dim } @@ -4197,7 +5168,8 @@ version 2005/12/01 or later. \fp_to_dim:n { sqrt - ( ( \dim_use:N \g_@@_x_final_dim + ( + ( \dim_use:N \g_@@_x_final_dim - \dim_use:N \g_@@_x_initial_dim ) ^ 2 + @@ -4329,7 +5301,7 @@ version 2005/12/01 or later. \cs_new_protected:Nn \@@_add_to_empty_cells: { \seq_gput_right:Nx \g_@@_empty_cells_seq - { \int_use:N \g_@@_row_int - \int_use:N \g_@@_column_int } + { \int_use:N \g_@@_row_int - \int_use:N \g_@@_col_int } } % \end{macrocode} % @@ -4410,10 +5382,10 @@ version 2005/12/01 or later. \int_compare:nNnT #1 > 1 { \seq_gput_left:Nx \g_@@_multicolumn_cells_seq - { \int_eval:n \g_@@_row_int - \int_use:N \g_@@_column_int } + { \int_eval:n \g_@@_row_int - \int_use:N \g_@@_col_int } \seq_gput_left:Nn \g_@@_multicolumn_sizes_seq { #1 } } - \int_gadd:Nn \g_@@_column_int { #1 - 1 } + \int_gadd:Nn \g_@@_col_int { #1 - 1 } } % \end{macrocode} % @@ -4424,23 +5396,40 @@ version 2005/12/01 or later. % discarded (in |\hdotsfor|, this argument is used for fine tuning of the space % beetween two consecutive dots). Tikz nodes are created for all the cells of % the array, even the implicit cells of the |\Hdotsfor|. +% +% \medskip +% This command must not be protected since it begins with |\multicolumn|. +% \begin{macrocode} +\cs_new:Npn \@@_Hdotsfor: + { + \multicolumn { 1 } { C } { } + \@@_Hdotsfor_i + } +% \end{macrocode} +% +% The command |\@@_Hdotsfor_i| is defined with the tools of \pkg{xparse} because +% it has an optionnal argument. Note that such a command defined by +% |\multicolumn| is protected and that's why we have put the |\multicolumn| +% before (in the definition of |\@@_Hdotsfor:|). % \begin{macrocode} \bool_if:NTF \c_@@_draft_bool { - \NewDocumentCommand \@@_Hdotsfor { O { } m } - { \prg_replicate:nn { #2 - 1 } { & } } + \NewDocumentCommand \@@_Hdotsfor_i { O { } m } + { + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } + } } { - \NewDocumentCommand \@@_Hdotsfor { O { } m } - { - \tl_gput_right:Nx \g_@@_lines_to_draw_tl - { + \NewDocumentCommand \@@_Hdotsfor_i { O { } m } + { + \tl_gput_right:Nx \g_@@_lines_to_draw_tl + { \@@_draw_Hdotsfor:nnn - { \int_use:N \g_@@_row_int } - { \int_use:N \g_@@_column_int } + { \int_use:N \g_@@_row_int } + { \int_use:N \g_@@_col_int } { #2 } } - \prg_replicate:nn { #2 - 1 } { & } + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } % \end{macrocode} @@ -4473,7 +5462,7 @@ version 2005/12/01 or later. \bool_set_true:N \l_@@_initial_open_bool } } - \int_compare:nNnTF { #2 + #3 -1 } = \g_@@_column_int + \int_compare:nNnTF { #2 + #3 -1 } = \g_@@_col_int { \int_set:Nn \l_@@_final_j_int { #2 + #3 - 1 } \bool_set_true:N \l_@@_final_open_bool @@ -4549,15 +5538,17 @@ version 2005/12/01 or later. % % % \medskip -% Some extension, like the extension \pkg{doc}, do a redefinition of the command +% Some extensions, like the extension \pkg{doc}, do a redefinition of the command % |\dotfill| of LaTeX. That's why we define a command |\@@_dotfill:| as we wish. +% We test whether we are in draft mode because, in this case, we don't draw the +% dotted lines. % \begin{macrocode} \bool_if:NTF \c_@@_draft_bool { \cs_set_eq:NN \@@_dotfill: \prg_do_nothing: } { \cs_set:Npn \@@_dotfill: { - \cleaders \hbox_to_wd:nn { .44 em } { \hss .\hss } \hfill + \cleaders \hbox_to_wd:nn { .44 em } { \hss . \hss } \hfill \skip_horizontal:n \c_zero_dim } } @@ -4574,7 +5565,8 @@ version 2005/12/01 or later. { \dim_set:Nv \l_tmpa_dim { @@_width_ \int_use:N \g_@@_env_int } } { \dim_set:Nn \l_tmpa_dim { 5 mm } } \hbox_overlap_right:n - { \hbox_to_wd:nn + { + \hbox_to_wd:nn { \l_tmpa_dim + 2 \arraycolsep - \l_@@_left_margin_dim - \g_@@_right_margin_dim @@ -4660,6 +5652,74 @@ version 2005/12/01 or later. } % \end{macrocode} % +% \bigskip +% \subsection{The vertical rules} +% +% We don't want that a vertical rule drawn by the specifier ``"|"'' extends +% in the eventual ``first row'' and ``last row'' of the array. +% +% The natural way to do that would be to redefine the specifier ``"|"'' +% with |\newcolumntype|: +% \begin{Verbatim}[commandchars=\~\#\+] +% \newcolumntype { | } +% { ! { \int_compare:nNnF \g_@@_row_int = \c_zero_int \vline } } +% \end{Verbatim} +% +% However, this code fails is the user uses "\DefineShortVerb{\|}" of +% \pkg{fancyvrb}. Moreover, it would not be able to deal correctly with two +% consecutive specifiers ``"|"'' (in a preambule like "ccc||ccc"). +% +% That's why we will do a redefinition of the macro |\@arrayrule| of \pkg{array} +% and this redefinition will add |\@@_vline:| instead of |\vline| to the +% preamble. +% +% Here is the definition of |\@@_vline:|. This definition \emph{must} be +% protected because you don't want that macro expanded during the construction of +% the preamble (the tests must be effective in each row and not once when the +% preamble is constructed). +% \begin{macrocode} +\cs_new_protected:Npn \@@_vline: + { + \int_compare:nNnTF \l_@@_first_col_int = \c_zero_int + { + \int_compare:nNnTF \g_@@_col_int = \c_zero_int + { + \int_compare:nNnTF \l_@@_first_row_int = \c_zero_int + { + \int_compare:nNnF \g_@@_row_int = \c_zero_int + { + \int_compare:nNnF \g_@@_row_int = \l_@@_last_row_int \vline + } + } + { + \int_compare:nNnF \g_@@_row_int = \c_zero_int + { + \int_compare:nNnF \g_@@_row_int = \l_@@_last_row_int \vline + } + } + } + { + \int_compare:nNnF \g_@@_row_int = \c_zero_int + { \int_compare:nNnF \g_@@_row_int = \l_@@_last_row_int \vline } + } + } + { + \int_compare:nNnTF \g_@@_col_int = \c_zero_int + { + \int_compare:nNnF \g_@@_row_int = { -1 } + { + \int_compare:nNnF \g_@@_row_int = { \l_@@_last_row_int - 1 } + \vline + } + } + { + \int_compare:nNnF \g_@@_row_int = \c_zero_int + { \int_compare:nNnF \g_@@_row_int = \l_@@_last_row_int \vline } + } + } + } +% \end{macrocode} +% % % % \subsection{The environment \{NiceMatrixBlock\}} @@ -4718,367 +5778,6 @@ version 2005/12/01 or later. } % \end{macrocode} % -% \subsection{The environment \{pNiceArrayC\} and its variants} -% -% The code in this section can be removed without affecting the previous code. -% -% \medskip -% First, we define a set of options for the environment |{pNiceArrayC}| and its -% variants. This set of keys is named |NiceMatrix/NiceArrayC| even though there -% is no environment called |{NiceArrayC}|. -% -% \begin{macrocode} -\keys_define:nn { NiceMatrix / NiceArrayC } - { - code-for-last-col .tl_set:N = \l_@@_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - unknown .code:n = \@@_error:n { Unknown~option~for~NiceArrayC } - } -% \end{macrocode} -% -% \begin{macrocode} -\@@_msg_new:nnn { Unknown~option~for~NiceArrayC } - { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ - \{\@currenvir\}. \\ - If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~<return>. - } - { - The~available~options~are~(in~alphabetic~order):~ - code-after,~ - code-for-last-col,~ - columns-width,~ - create-extra-nodes,~ - extra-left-margin,~ - extra-right-margin,~ - hlines,~ - left-margin,~ - name,~ - nullify-dots,~ - parallelize-diags~ - renew-dots~ - and~right-margin. - } -% \end{macrocode} -% -% \bigskip -% In the environment |{pNiceArrayC}| (and its variants), the last column is -% composed with instructions |\hbox_overlap_right:n| (this instruction may be -% seen as the \pkg{expl3} equivalent of the classical command |\rlap|). After -% the composition of the array, an horizontal skip is inserted to compensate for -% these overlapping boxes. -% -% \medskip -% The command |\@@_NiceArrayC:n| will be used in |{NiceArrayCwithDelims}| but -% also in the environment |{NiceArrayRCwithDelims}|. -% \begin{macrocode} -\cs_new_protected:Nn \@@_NiceArrayC:n - { - \bool_set_true:N \l_@@_exterior_column_bool - \bool_gset_false:N \g_@@_exterior_column_found_bool - \begin { NiceArray } -% \end{macrocode} -% The beginning of the preamble is the argument of the environment -% |{pNiceArrayC}|. -% \begin{macrocode} - { #1 -% \end{macrocode} -% -% However, we add a last column with its own specification. For a cell in this -% last column, the first operation is to store the content of the cell in the -% box |\l_tmpa_box|. This is allowed in \pkg{expl3} with the construction -% |\hbox_set:Nw \l_tmpa_box| ... |\hbox_set_end:|. -% \begin{macrocode} - > - { - \bool_gset_true:N \g_@@_exterior_column_found_bool - \int_gincr:N \g_@@_column_int - \int_gset:Nn \g_@@_column_total_int - { \int_max:nn \g_@@_column_total_int \g_@@_column_int } - \hbox_set:Nw \l_tmpa_box \c_math_toggle_token - \l_@@_code_for_last_col_tl - } - l -% \end{macrocode} -% -% We actualize the value of |\g_@@_width_last_col_dim| which, at the end of the -% array, will contain the maximal width of the cells of the last column (thus, -% it will be equal to the width of the last column). -% \begin{macrocode} - < { \c_math_toggle_token - \hbox_set_end: - \dim_gset:Nn \g_@@_width_last_col_dim - { - \dim_max:nn - \g_@@_width_last_col_dim - { \box_wd:N \l_tmpa_box } - } - \skip_horizontal:n { - 2 \arraycolsep } -% \end{macrocode} -% The content of the cell is inserted in an overlapping position. -% \begin{macrocode} - \hbox_overlap_right:n - { - \skip_horizontal:n - { - 2 \arraycolsep + - \l_@@_right_margin_dim + - \l_@@_extra_right_margin_dim - } - \tikz - [ - remember~picture , - inner~sep = \c_zero_dim , - minimum~width = \c_zero_dim , - baseline - ] - \node - [ - anchor = base , - name = - nm - - \int_use:N \g_@@_env_int - - \int_use:N \g_@@_row_int - - \int_use:N \g_@@_column_int , - alias = - \str_if_empty:NF \l_@@_name_str - { - \l_@@_name_str - - \int_use:N \g_@@_row_int - - \int_use:N \g_@@_column_int - } - ] - { \box_use:N \l_tmpa_box } ; - } - } - } - } -% \end{macrocode} -% -% \bigskip -% The environments of the type of |{pNiceArrayC}| will be constructed over -% |{NiceArrayCwithDelims}|. The first two arguments of this environment are the -% left and the right delimiter. -% \begin{macrocode} -\NewDocumentEnvironment { NiceArrayCwithDelims } { m m O { } m ! O { } } - { - \@@_test_if_math_mode: - \dim_gzero_new:N \g_@@_width_last_col_dim - \keys_set:nn { NiceMatrix / NiceArrayC } { #3 , #5 } - \bool_set_false:N \l_@@_exterior_arraycolsep_bool - \str_set:Nn \l_@@_pos_env_str c - \left #1 - \@@_NiceArrayC:n { #4 } - } - { - \end { NiceArray } - \right #2 - \skip_horizontal:n \g_@@_width_last_col_dim - } -% \end{macrocode} -% -% -% \bigskip -% In the following environments, we don't use the form with |\begin{...}| and -% |\end{...}| because we use |\@currenvir| in the error message for an unknown -% option. -% \begin{macrocode} -\NewDocumentEnvironment { pNiceArrayC } { } - { \NiceArrayCwithDelims ( ) } - { \endNiceArrayCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { vNiceArrayC } { } - { \NiceArrayCwithDelims | | } - { \endNiceArrayCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { VNiceArrayC } { } - { \NiceArrayCwithDelims \| \| } - { \endNiceArrayCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { bNiceArrayC } { } - { \NiceArrayCwithDelims [ ] } - { \endNiceArrayCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { BNiceArrayC } { } - { \NiceArrayCwithDelims \{ \} } - { \endNiceArrayCwithDelims } -% \end{macrocode} -% -% -% \subsection{The environment \{pNiceArrayRC\}} -% -% The code in this section can be removed without affecting the previous code. -% -% -% \bigskip -% \begin{macrocode} -\keys_define:nn { NiceMatrix / NiceArrayRC } - { - code-for-first-row .tl_set:N = \l_@@_code_for_first_row_tl , - code-for-first-row .value_required:n = true , - code-for-last-col .tl_set:N = \l_@@_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - unknown .code:n = \@@_error:n { Unknown~option~for~NiceArrayRC } - } -% \end{macrocode} -% -% \begin{macrocode} -\@@_msg_new:nnn { Unknown~option~for~NiceArrayRC } - { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ - \{ \@currenvir \}. \\ - If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~<return>. - } - { - The~available~options~are~(in~alphabetic~order):~ - code-after,~ - code-for-last-col,~ - code-for-first-row,~ - columns-width,~ - create-extra-nodes,~ - extra-left-margin,~ - extra-right-margin,~ - hlines,~ - left-margin,~ - name,~ - nullify-dots,~ - parallelize-diags,~ - renew-dots~ - and~right-margin. - } -% \end{macrocode} -% -% \bigskip -% The first and the second argument of the environment |{NiceArrayRCwithDelims}| -% are the delimiters which will be used in the array. Usually, the final user -% will not use directly this environment |{NiceArrayRCwithDelims}| because he -% will use one of the variants |{pNiceArrayRC}|, |{vNiceArrayRC}|, etc. -% -% -% \medskip -% We don't want that a vertical rule drawn by this specifier extends in the -% first row of the array (since this first row is for the labels and is -% ``outside'' the matrix). -% -% The natural way to do that would be to redefine the specifier ``"|"'' -% with |\newcolumntype|: -% \begin{Verbatim}[commandchars=\~\#\+] -% \newcolumntype { | } -% { ! { \int_compare:nNnF \g_@@_row_int = \c_zero_int \vline } } -% \end{Verbatim} -% -% However, this code fails is the user uses "\DefineShortVerb{\|}" of -% \pkg{fancyvrb}. Moreover, it would not be able to deal correctly with two -% consecutive specifier ``"|"'' (in a preambule like "ccc||ccc"). -% -% That's why we will do a redefinition of the macro |\@arrayrule| of \pkg{array} -% and this redefinition will add |\@@_vline:| instead of |\vline| to the -% preamble. -% -% Here is the definition of |\@@_vline:|. This definition \emph{must} be -% protected because you don't want that macro expanded during the construction of -% the preamble (the test must be effective in each row and not once when the -% preamble is constructed). -% \begin{macrocode} -\cs_new_protected:Npn \@@_vline: - { - \int_compare:nNnTF \g_@@_column_int = \c_zero_int - { \int_compare:nNnF \g_@@_row_int < \c_zero_int \vline } - { \int_compare:nNnF \g_@@_row_int < \c_one_int \vline } - } -% \end{macrocode} -% -% \bigskip -% \begin{macrocode} -\NewDocumentEnvironment { NiceArrayRCwithDelims } { m m O { } m ! O { } } - { - \@@_test_if_math_mode: - \cs_set_protected:Npn \@arrayrule { \@addtopreamble \@@_vline: } - \int_zero:N \l_@@_nb_first_row_int - \dim_gzero_new:N \g_@@_width_last_col_dim - \keys_set:nn { NiceMatrix / NiceArrayRC } { #3 , #5 } - \bool_set_false:N \l_@@_exterior_arraycolsep_bool - \str_set:Nn \l_@@_pos_env_str c - \box_clear_new:N \l_@@_the_array_box - \hbox_set:Nw \l_@@_the_array_box - \c_math_toggle_token - \@@_NiceArrayC:n { #4 } - } - { - \end { NiceArray } - \c_math_toggle_token - \hbox_set_end: - \dim_set:Nn \l_tmpa_dim - { - ( - \dim_max:nn - { 12 pt } - { \g_@@_max_ht_row_one_dim + \g_@@_max_dp_row_zero_dim } - ) - + \g_@@_max_ht_row_zero_dim - \g_@@_max_ht_row_one_dim - } - \hbox_set:Nn \l_tmpa_box - { - \c_math_toggle_token - \left #1 - \vcenter - { - \skip_vertical:n { - \l_tmpa_dim } - \box_use_drop:N \l_@@_the_array_box - } - \right #2 - \c_math_toggle_token - \skip_horizontal:n \g_@@_width_last_col_dim - } - \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } - \box_use_drop:N \l_tmpa_box - } -% \end{macrocode} -% -% \bigskip -% In the following environments, we don't use the form with |\begin{...}| and -% |\end{...}| because we use |\@currenvir| in the error message for an unknown -% option. -% \begin{macrocode} -\NewDocumentEnvironment { pNiceArrayRC } { } - { \NiceArrayRCwithDelims ( ) } - { \endNiceArrayRCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { bNiceArrayRC } { } - { \NiceArrayRCwithDelims [ ] } - { \endNiceArrayRCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { vNiceArrayRC } { } - { \NiceArrayRCwithDelims | | } - { \endNiceArrayRCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { VNiceArrayRC } { } - { \NiceArrayRCwithDelims \| \| } - { \endNiceArrayRCwithDelims } -% \end{macrocode} -% -% \begin{macrocode} -\NewDocumentEnvironment { BNiceArrayRC } { } - { \NiceArrayRCwithDelims \{ \} } - { \endNiceArrayRCwithDelims } -% \end{macrocode} -% % % \subsection{The extra nodes} % @@ -5092,7 +5791,7 @@ version 2005/12/01 or later. % % \bigskip % For each row $i$, we compute two dimensions -% "l_@@_row_\textsl{i}_min_dim" and \texttt{l_@@_row_\textsl{i}_max_dim}. +% \texttt{l_@@_row_\textsl{i}_min_dim} and \texttt{l_@@_row_\textsl{i}_max_dim}. % The dimension \texttt{l_@@_row_\textsl{i}_min_dim} is the minimal % $y$-value of all the cells of the row~$i$. The dimension % \texttt{l_@@_row_\textsl{i}_max_dim} is the maximal $y$-value of all the cells @@ -5111,14 +5810,14 @@ version 2005/12/01 or later. \cs_new_protected:Nn \@@_create_extra_nodes: { \begin { tikzpicture } [ remember~picture , overlay ] - \int_step_variable:nnnNn \l_@@_nb_first_row_int 1 \g_@@_row_int \@@_i: + \int_step_variable:nnNn \g_@@_first_row_int \g_@@_row_total_int \@@_i: { \dim_zero_new:c { l_@@_row_\@@_i: _min_dim } \dim_set_eq:cN { l_@@_row_\@@_i: _min_dim } \c_max_dim \dim_zero_new:c { l_@@_row_\@@_i: _max_dim } \dim_set:cn { l_@@_row_\@@_i: _max_dim } { - \c_max_dim } } - \int_step_variable:nNn \g_@@_column_total_int \@@_j: + \int_step_variable:nnNn \g_@@_first_col_int \g_@@_col_total_int \@@_j: { \dim_zero_new:c { l_@@_column_\@@_j: _min_dim } \dim_set_eq:cN { l_@@_column_\@@_j: _min_dim } \c_max_dim @@ -5128,9 +5827,10 @@ version 2005/12/01 or later. % \end{macrocode} % We begin the two nested loops over the rows and the columns of the array. % \begin{macrocode} - \int_step_variable:nnNn \l_@@_nb_first_row_int \g_@@_row_int \@@_i: + \int_step_variable:nnNn \g_@@_first_row_int \g_@@_row_total_int \@@_i: { - \int_step_variable:nNn \g_@@_column_total_int \@@_j: + \int_step_variable:nnNn + \g_@@_first_col_int \g_@@_col_total_int \@@_j: % \end{macrocode} % Maybe the cell ($i$-$j$) is an implicit cell (that is to say a cell after % implicit ampersands |&|). In this case, of course, we don't update the @@ -5179,15 +5879,12 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% For ``large nodes'', the eventual ``first row'' and ``last column'' (in -% environments like |{pNiceArrayRC}|) don't interfer. That's why the loop over -% the rows will start at 1 and the loop over the columns will stop at -% $|\g_@@_column_int|$ (and not |\g_@@_column_total_int|).\footnote{We recall -% that |\g_@@_column_total_int| is equal to |\g_@@_column_int| except if there -% is an exterior column. In this case, |\g_@@_column_total_int| is equal to -% |\g_@@_column_int|${}+1$.} +% For ``large nodes'', the exterior rows and columns don't interfer. +% That's why the loop over the rows will start at 1 and the loop over the columns +% will stop at $|\g_@@_col_int|$ (and not |\g_@@_col_total_int|). Idem for the rows. % \begin{macrocode} - \int_set:Nn \l_@@_nb_first_row_int 1 + \int_set:Nn \g_@@_first_row_int 1 + \int_set:Nn \g_@@_first_col_int 1 % \end{macrocode} % We have to change the values of all the dimensions % \texttt{l_@@_row_\textsl{i}_min_dim}, \texttt{l_@@_row_\textsl{i}_max_dim}, @@ -5207,7 +5904,7 @@ version 2005/12/01 or later. \dim_set_eq:cc { l_@@_row _ \int_eval:n { \@@_i: + 1 } _ max _ dim } { l_@@_row_\@@_i: _min_dim } } - \int_step_variable:nNn { \g_@@_column_int - 1 } \@@_j: + \int_step_variable:nNn { \g_@@_col_int - 1 } \@@_j: { \dim_set:cn { l_@@_column _ \@@_j: _ max _ dim } { @@ -5226,7 +5923,7 @@ version 2005/12/01 or later. { l_@@_column _ 1 _ min _ dim } \g_@@_left_margin_dim \dim_add:cn - { l_@@_column _ \int_use:N \g_@@_column_int _ max _ dim } + { l_@@_column _ \int_use:N \g_@@_col_int _ max _ dim } \g_@@_right_margin_dim % \end{macrocode} % Now, we can actually create the ``large nodes''. @@ -5252,9 +5949,9 @@ version 2005/12/01 or later. \dim_gset:Nn \g_tmpa_dim \pgf@x \tikz@parse@node \pgfutil@firstofone ( nm - \int_use:N \g_@@_env_int - 1 - - \int_use:N \g_@@_column_int - large .north~east ) + \int_use:N \g_@@_col_int - large .north~east ) \dim_gset:Nn \g_tmpb_dim \pgf@x - \end { tikzpicture } + \end { tikzpicture } \iow_now:Nn \@mainaux \ExplSyntaxOn \iow_now:Nx \@mainaux { @@ -5278,9 +5975,9 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_new_protected:Nn \@@_create_nodes: { - \int_step_variable:nnNn \l_@@_nb_first_row_int \g_@@_row_int \@@_i: + \int_step_variable:nnNn \g_@@_first_row_int \g_@@_row_total_int \@@_i: { - \int_step_variable:nNn \g_@@_column_total_int \@@_j: + \int_step_variable:nnNn \g_@@_first_col_int \g_@@_col_total_int \@@_j: % \end{macrocode} % We create two ponctual nodes for the extremities of a diagonal of the % rectangular node we want to create. These nodes |(@@~south~west)| and @@ -5293,7 +5990,7 @@ version 2005/12/01 or later. at ( \dim_use:c { l_@@_column_ \@@_j: _min_dim } , \dim_use:c { l_@@_row_ \@@_i: _min_dim } ) ; \coordinate ( @@~north~east ) - at ( \dim_use:c { l_@@_column_ \@@_j: _max_dim }, + at ( \dim_use:c { l_@@_column_ \@@_j: _max_dim } , \dim_use:c { l_@@_row_ \@@_i: _max_dim } ) ; % \end{macrocode} % We can eventually draw the rectangular node for the cell (|\@@_i|-|\@@_j|). @@ -5326,7 +6023,6 @@ version 2005/12/01 or later. } % \end{macrocode} % -% % % \begin{macrocode} \cs_new_protected:Npn \@@_extract_coords: #1 - #2 \q_stop @@ -5374,7 +6070,7 @@ version 2005/12/01 or later. % recommend to use |\NiceMatrixOptions| instead. % % We must process these options after the definition of the environment -% |{NiceMatrix}| because the option |renew-matrix| execute the code +% |{NiceMatrix}| because the option |renew-matrix| executes the code % |\cs_set_eq:NN \env@matrix \NiceMatrix|. % % Of course, the command |\NiceMatrix| must be defined before such an @@ -5429,21 +6125,140 @@ version 2005/12/01 or later. } % \end{macrocode} % +% +% +% \subsection{Obsolete environments} +% +% \begin{macrocode} +\NewDocumentEnvironment { pNiceArrayC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \pNiceArray + } + { \endpNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { bNiceArrayC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \bNiceArray + } + { \endbNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { BNiceArrayC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \BNiceArray + } + { \endBNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { vNiceArrayC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \vNiceArray + } + { \endvNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { VNiceArrayC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \VNiceArray + } + { \endVNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { pNiceArrayRC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \int_set:Nn \l_@@_first_row_int \c_zero_int + \pNiceArray + } + { \endpNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { bNiceArrayRC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \int_set:Nn \l_@@_first_row_int \c_zero_int + \bNiceArray + } + { \endbNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { BNiceArrayRC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \int_set:Nn \l_@@_first_row_int \c_zero_int + \BNiceArray + } + { \endBNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { vNiceArrayRC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \int_set:Nn \l_@@_first_row_int \c_zero_int + \vNiceArray + } + { \endvNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { VNiceArrayRC } { } + { + \bool_set_true:N \l_@@_last_col_bool + \int_set:Nn \l_@@_first_row_int \c_zero_int + \VNiceArray + } + { \endVNiceArray } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { NiceArrayCwithDelims } { } + { + \bool_set_true:N \l_@@_last_col_bool + \NiceArrayWithDelims + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% \begin{macrocode} +\NewDocumentEnvironment { NiceArrayRCwithDelims } { } + { + \bool_set_true:N \l_@@_last_col_bool + \int_set:Nn \l_@@_first_row_int \c_zero_int + \NiceArrayWithDelims + } + { \endNiceArrayWithDelims } +% \end{macrocode} +% +% % % \section{History} % -% \subsection{Changes between versions 1.0 and 1.1} +% \subsection*{Changes between versions 1.0 and 1.1} % % The dotted lines are no longer drawn with Tikz nodes but with Tikz circles % (for efficiency). % % Modification of the code which is now twice faster. % -% \subsection{Changes between versions 1.1 and 1.2} +% \subsection*{Changes between versions 1.1 and 1.2} % % New environment |{NiceArray}| with column types |L|, |C| and |R|. % -% \subsection{Changes between version 1.2 and 1.3} +% \subsection*{Changes between version 1.2 and 1.3} % % New environment |{pNiceArrayC}| and its variants. % @@ -5457,7 +6272,7 @@ version 2005/12/01 or later. % kept). % % -% \subsection{Changes between version 1.3 and 1.4} +% \subsection*{Changes between version 1.3 and 1.4} % % The column types |w| and |W| can now be used in the environments % |{NiceArray}|, |{pNiceArrayC}| and its variants with the same meaning as in @@ -5467,13 +6282,13 @@ version 2005/12/01 or later. % array. % % -% \subsection{Changes between version 1.4 and 2.0} +% \subsection*{Changes between version 1.4 and 2.0} % % The versions 1.0 to 1.4 of \pkg{nicematrix} were focused on the continuous % dotted lines whereas the version 2.0 of \pkg{nicematrix} provides different % features to improve the typesetting of mathematical matrices. % -% \subsection{Changes between version 2.0 and 2.1} +% \subsection*{Changes between version 2.0 and 2.1} % % New implementation of the environment |{pNiceArrayRC}|. With this new % implementation, there is no restriction on the width of the columns. @@ -5483,7 +6298,7 @@ version 2005/12/01 or later. % % Creation of ``medium nodes'' and ``large nodes''. % -% \subsection{Changes between version 2.1 and 2.1.1} +% \subsection*{Changes between version 2.1 and 2.1.1} % % Small corrections: for example, the option |code-for-first-row| is now % available in the command |\NiceMatrixOptions|. @@ -5497,23 +6312,23 @@ version 2005/12/01 or later. % possible to externalize the Tikz elements constructed by \pkg{nicematrix} % because they use the options |overlay| and |remember picture|.} % -% \subsection{Changes between version 2.1 and 2.1.2} +% \subsection*{Changes between version 2.1 and 2.1.2} % Option |draft|: with this option, the dotted lines are not drawn (quicker). % -% \subsection{Changes between version 2.1.2 and 2.1.3} +% \subsection*{Changes between version 2.1.2 and 2.1.3} % % When searching the end of a dotted line from a command like |\Cdots| issued in % the ``main matrix'' (not in the column |C|), the cells in the column |C| are % considered as outside the matrix. That means that it's possible to do the % following matrix with only a |\Cdots| command (and a single |\Vdots|). -% \[\begin{pNiceArrayRC}{wc{5mm}Cwc{5mm}} +% \[\begin{pNiceArrayRC}{Wc{5mm}CWc{5mm}} % & C_j & \\ % \mbox{\Large $0$} & \Vdots & \mbox{\Large $0$} \\ % & \strut a & \Cdots & L_i \\ % \mbox{\Large $0$} & & \mbox{\Large $0$} \\ % \end{pNiceArrayRC}\] % -% \subsection{Changes between version 2.1.3 and 2.1.4} +% \subsection*{Changes between version 2.1.3 and 2.1.4} % % Replacement of some options |O { }| in commands and environments defined with % \pkg{xparse} by |! O { }| (because a recent version of \pkg{xparse} introduced @@ -5522,13 +6337,13 @@ version 2005/12/01 or later. % % See |https://www.texdev.net/2018/04/21/xparse-optional-arguments-at-the-end| % -% \subsection{Changes between version 2.1.4 and 2.1.5} +% \subsection*{Changes between version 2.1.4 and 2.1.5} % % Compatibility with the classes \cls{revtex4-1} and \cls{revtex4-2}. % % Option |allow-duplicate-names|. % -% \subsection{Changes between version 2.1.5 and 2.2} +% \subsection*{Changes between version 2.1.5 and 2.2} % % Possibility to draw horizontal dotted lines to separate rows with the command % |\hdottedline| (similar to the classical command |\hline| and the command @@ -5538,14 +6353,14 @@ version 2005/12/01 or later. % specifier ``|:|'' in the preamble (similar to the classical specifier % ``"|"'' and the specifier ``|:|'' of \pkg{arydshln}). % -% \subsection{Changes between version 2.2 and 2.2.1} +% \subsection*{Changes between version 2.2 and 2.2.1} % % Improvment of the vertical dotted lines drawn by the specifier ``:'' in the % preamble. % % Modification of the position of the dotted lines drawn by |\hdottedline|. % -% \subsection{Changes between version 2.2.1 and 2.3} +% \subsection*{Changes between version 2.2.1 and 2.3} % % Compatibility with the column type |S| of \pkg{siunitx}. % @@ -5554,6 +6369,18 @@ version 2005/12/01 or later. % A warning is issued when the |draft| mode is used. In this case, the dotted % lines are not drawn. % +% +% \subsection*{Changes between version 2.2.1 and 2.3} +% +% Modification of |\Hdotsfor|. Now |\Hdotsfor| erases the |\vlines| (of ``"|"'') +% as |\hdotsfor| does. +% +% \subsection*{Changes between version 2.3 and 3.0} +% +% Composition of exterior rows and columns of the four sides of the matrix (and +% not only on two sides) with the options |first-row|, |last-row|, |first-col| +% and |last-col|. +% % \PrintIndex % % \tableofcontents diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index a1e3830d1cf..a8c8baaf489 100644 --- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty +++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty @@ -18,8 +18,8 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{2.3} -\def\myfiledate{2019/07/18} +\def\myfileversion{3.0} +\def\myfiledate{2019/08/15} \RequirePackage{tikz} \usetikzlibrary{fit} \RequirePackage{expl3}[2019/02/15] @@ -36,8 +36,10 @@ \RequirePackage { array } \RequirePackage { amsmath } \RequirePackage { xparse } [ 2018-10-17 ] -\cs_new_protected:Nn \__nm_error:n { \msg_error:nn { nicematrix } { #1 } } -\cs_new_protected:Nn \__nm_error:nn { \msg_error:nn { nicematrix } { #1 } { #2 } } +\cs_new_protected:Npn \__nm_error:n { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \__nm_error:nn { \msg_error:nn { nicematrix } } +\cs_new_protected:Npn \__nm_fatal:n { \msg_fatal:nn { nicematrix } } +\cs_new_protected:Npn \__nm_fatal:nn { \msg_fatal:nn { nicematrix } } \cs_new_protected:Npn \__nm_msg_new:nn { \msg_new:nnn { nicematrix } } \cs_new_protected:Npn \__nm_msg_new:nnn { \msg_new:nnnn { nicematrix } } \cs_new_protected:Npn \__nm_msg_redirect_name:nn @@ -53,19 +55,6 @@ { The~compilation~is~in~draft~mode:~the~dotted~lines~won't~be~drawn. } \bool_if:NT \c__nm_draft_bool { \msg_warning:nn { nicematrix } { Draft~mode } } -\AtBeginDocument - { - \clist_map_inline:nn - { - siunitx - } - { - \bool_new:c { c__nm_#1_loaded_bool } - \@ifpackageloaded { #1 } - { \bool_set_true:c { c__nm_#1_loaded_bool } } - { } - } - } \ProvideDocumentCommand \iddots { } { \mathinner @@ -81,28 +70,72 @@ \int_new:N \g__nm_env_int \dim_new:N \l__nm_columns_width_dim \seq_new:N \g__nm_names_seq -\int_new:N \l__nm_nb_first_row_int -\int_set:Nn \l__nm_nb_first_row_int 1 -\bool_new:N \l__nm_exterior_column_bool -\bool_new:N \g__nm_exterior_column_found_bool -\bool_new:N \l__nm_in_NiceArray_bool + +\bool_new:N \l__nm_in_env_bool +\bool_new:N \l__nm_NiceArray_bool +\bool_new:N \g__nm_NiceArray_bool +\cs_new_protected:Npn \__nm_test_if_math_mode: + { + \if_mode_math: \else: + \__nm_fatal:n { Outside~math~mode } + \fi: + } +\__nm_msg_new:nn { Yet~in~env } + { + Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ + nested.\\ + This~error~is~fatal. + } +\__nm_msg_new:nn { Outside~math~mode } + { + The~environment~\{\@currenvir\}~can~be~used~only~in~math~mode~ + (and~not~in~\token_to_str:N \vcenter).\\ + This~error~is~fatal. + } +\bool_new:N \c__nm_colortbl_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { colortbl } + { \bool_set_true:N \c__nm_colortbl_loaded_bool } + { } + } +\int_new:N \l__nm_first_row_int +\int_set:Nn \l__nm_first_row_int 1 +\int_new:N \g__nm_first_row_int +\int_new:N \l__nm_first_col_int +\int_set:Nn \l__nm_first_col_int 1 +\int_new:N \g__nm_first_col_int +\int_new:N \l__nm_last_row_int +\int_set:Nn \l__nm_last_row_int { -2 } +\int_new:N \g__nm_last_row_int +\bool_new:N \l__nm_last_row_without_value_bool +\bool_new:N \g__nm_last_row_without_value_bool +\bool_new:N \l__nm_last_col_bool +\bool_new:N \g__nm_last_col_found_bool +\bool_new:N \c__nm_siunitx_loaded_bool +\AtBeginDocument + { + \@ifpackageloaded { siunitx } + { \bool_set_true:N \c__nm_siunitx_loaded_bool } + { } + } \cs_set_protected:Npn \__nm_adapt_S_column: { \bool_if:NT \c__nm_siunitx_loaded_bool { \group_begin: - \@temptokena = { } - \cs_set_eq:NN \NC@find \prg_do_nothing: - \NC@rewrite@S { } - \exp_args:NNo \tl_gset:Nn \g_tmpa_tl { \tex_the:D \@temptokena } + \@temptokena = { } + \cs_set_eq:NN \NC@find \prg_do_nothing: + \NC@rewrite@S { } + \tl_gset:NV \g_tmpa_tl \@temptokena \group_end: \tl_new:N \c__nm_table_collect_begin_tl \tl_set:Nx \l_tmpa_tl { \tl_item:Nn \g_tmpa_tl 2 } \tl_gset:Nx \c__nm_table_collect_begin_tl { \tl_item:Nn \l_tmpa_tl 1 } \tl_new:N \c__nm_table_print_tl \tl_gset:Nx \c__nm_table_print_tl { \tl_item:Nn \g_tmpa_tl { -1 } } + \cs_gset_eq:NN \__nm_adapt_S_column: \prg_do_nothing: } - \cs_gset_eq:NN \__nm_adapt_S_column: \prg_do_nothing: } \cs_new_protected:Npn \__nm_renew_NC@rewrite@S: { @@ -125,7 +158,7 @@ } \__nm_msg_new:nn { Option~RenewMatrix~suppressed } { - The~option~'RenewMatrix~has~been~renamed~'renew-matrix'.\\ + The~option~'RenewMatrix'~has~been~renamed~'renew-matrix'.\\ However,~you~can~go~on~for~this~time. } \str_new:N \l__nm_pos_env_str @@ -136,15 +169,16 @@ \bool_new:N \l__nm_hlines_bool \bool_new:N \l__nm_nullify_dots_bool \bool_new:N \l__nm_auto_columns_width_bool -\tl_new:N \l__nm_code_for_last_col_tl -\str_new:N \g__nm_name_str \str_new:N \l__nm_name_str +\str_new:N \g__nm_name_str \bool_new:N \l__nm_extra_nodes_bool \bool_new:N \g__nm_extra_nodes_bool \dim_new:N \l__nm_left_margin_dim \dim_new:N \l__nm_right_margin_dim \dim_new:N \g__nm_left_margin_dim \dim_new:N \g__nm_right_margin_dim +\dim_new:N \g__nm_width_last_col_dim +\dim_new:N \g__nm_width_first_col_dim \dim_new:N \l__nm_extra_left_margin_dim \dim_new:N \l__nm_extra_right_margin_dim \dim_new:N \g__nm_extra_right_margin_dim @@ -163,8 +197,23 @@ left-margin .default:n = \arraycolsep , right-margin .dim_set:N = \l__nm_right_margin_dim , right-margin .default:n = \arraycolsep , + margin .meta:n = { left-margin = #1 , right-margin = #1 } , + margin .default:n = \arraycolsep , extra-left-margin .dim_set:N = \l__nm_extra_left_margin_dim , - extra-right-margin .dim_set:N = \l__nm_extra_right_margin_dim + extra-right-margin .dim_set:N = \l__nm_extra_right_margin_dim , + extra-margin .meta:n = + { extra-left-margin = #1 , extra-right-margin = #1 } , + } +\keys_define:nn { NiceMatrix / Code } + { + code-for-first-col .tl_set:N = \l__nm_code_for_first_col_tl , + code-for-first-col .value_required:n = true , + code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , + code-for-last-col .value_required:n = true , + code-for-first-row .tl_set:N = \l__nm_code_for_first_row_tl , + code-for-first-row .value_required:n = true , + code-for-last-row .tl_set:N = \l__nm_code_for_last_row_tl , + code-for-last-row .value_required:n = true , } \keys_define:nn { NiceMatrix / Env } { @@ -174,10 +223,11 @@ { \dim_set:Nn \l__nm_columns_width_dim { #1 } } , columns-width .value_required:n = true , name .code:n = - \seq_if_in:NnTF \g__nm_names_seq { #1 } + \str_set:Nn \l_tmpa_str { #1 } + \seq_if_in:NVTF \g__nm_names_seq \l_tmpa_str { \__nm_error:nn { Duplicate~name } { #1 } } - { \seq_gput_left:Nn \g__nm_names_seq { #1 } } - \str_set:Nn \l__nm_name_str { #1 } , + { \seq_gput_left:NV \g__nm_names_seq \l_tmpa_str } + \str_set_eq:NN \l__nm_name_str \l_tmpa_str , name .value_required:n = true , code-after .tl_gset:N = \g__nm_code_after_tl , code-after .initial:n = \c_empty_tl , @@ -185,26 +235,27 @@ } \keys_define:nn { NiceMatrix } { - NiceMatrixOptions .inherit:n = NiceMatrix / Global , - NiceMatrix .inherit:n = + NiceMatrixOptions .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Code } , - NiceArray .inherit:n = + NiceMatrix .inherit:n = { NiceMatrix / Global , NiceMatrix / Env } , - NiceArrayC .inherit:n = + NiceArray .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env - } , - NiceArrayRC .inherit:n = + NiceMatrix / Env , + NiceMatrix / Code + } , + pNiceArray .inherit:n = { NiceMatrix / Global , - NiceMatrix / Env + NiceMatrix / Env , + NiceMatrix / Code } } \keys_define:nn { NiceMatrix / NiceMatrixOptions } @@ -218,10 +269,6 @@ Transparent .code:n = \__nm_error:n { Option~Transparent~suppressed } \__nm_renew_matrix: \bool_set_true:N \l__nm_renew_dots_bool , - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - code-for-first-row .tl_set:N = \l__nm_code_for_first_row_tl , - code-for-first-row .value_required:n = true , exterior-arraycolsep .bool_set:N = \l__nm_exterior_arraycolsep_bool , exterior-arraycolsep .default:n = true , columns-width .code:n = @@ -231,10 +278,20 @@ allow-duplicate-names .code:n = \__nm_msg_redirect_name:nn { Duplicate~name } { none } , allow-duplicate-names .value_forbidden:n = true , - letter-for-dotted-lines .tl_set:N = \l__nm_letter_for_dotted_lines_str , + letter-for-dotted-lines .code:n = + { + \int_compare:nTF { \tl_count:n { #1 } = \c_one_int } + { \tl_set:Nx \l__nm_letter_for_dotted_lines_str { #1 } } + { \__nm_error:n { Bad~value~for~letter~for~dotted~lines } } + } , letter-for-dotted-lines .value_required:n = true , letter-for-dotted-lines .initial:n = \c_colon_str , unknown .code:n = \__nm_error:n { Unknown~key~for~NiceMatrixOptions } } +\__nm_msg_new:nn { Bad~value~for~letter~for~dotted~lines } + { + The~value~of~key~'\tl_use:N\l_keys_key_tl'~must~be~of~length~1.\\ + If~you~go~on,~it~will~be~ignored. + } \__nm_msg_new:nnn { Unknown~key~for~NiceMatrixOptions } { The~key~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~command~ @@ -245,7 +302,10 @@ { The~available~keys~are~(in~alphabetic~order):~ allow-duplicate-names,~ + code-for-first-col,~ + code-for-first-row,~ code-for-last-col,~ + code-for-last-row,~ exterior-arraycolsep,~ hlines,~ left-margin,~ @@ -307,6 +367,11 @@ c .code:n = \str_set:Nn \l__nm_pos_env_str c , t .code:n = \str_set:Nn \l__nm_pos_env_str t , b .code:n = \str_set:Nn \l__nm_pos_env_str b , + first-col .code:n = \int_zero:N \l__nm_first_col_int , + last-col .bool_set:N = \l__nm_last_col_bool , + first-row .code:n = \int_zero:N \l__nm_first_row_int , + last-row .int_set:N = \l__nm_last_row_int , + last-row .default:n = -1 , unknown .code:n = \__nm_error:n { Unknown~option~for~NiceArray } } \__nm_msg_new:nnn { Unknown~option~for~NiceArray } @@ -321,8 +386,12 @@ b,~ c,~ code-after,~ - create-extra-nodes,~ + code-for-first-col,~ + code-for-first-row,~ + code-for-last-col,~ + code-for-last-row,~ columns-width,~ + create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ hlines,~ @@ -334,35 +403,97 @@ right-margin,~ and~t. } +\keys_define:nn { NiceMatrix / pNiceArray } + { + first-col .code:n = \int_zero:N \l__nm_first_col_int , + last-col .bool_set:N = \l__nm_last_col_bool , + first-row .code:n = \int_zero:N \l__nm_first_row_int , + last-row .int_set:N = \l__nm_last_row_int , + last-row .default:n = -1 , + unknown .code:n = \__nm_error:n { Unknown~option~for~pNiceArray } + } +\__nm_msg_new:nnn { Unknown~option~for~pNiceArray } + { + The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ + \{\@currenvir\}. \\ + If~you~go~on,~it~will~be~ignored. \\ + For~a~list~of~the~available~options,~type~H~<return>. + } + { + The~available~options~are~(in~alphabetic~order):~ + code-after,~ + code-for-first-col,~ + code-for-first-row,~ + code-for-last-col,~ + code-for-last-row,~ + columns-width,~ + create-extra-nodes,~ + extra-left-margin,~ + extra-right-margin,~ + first-col,~ + first-row,~ + last-col,~ + last-row,~ + hlines,~ + left-margin,~ + name,~ + nullify-dots,~ + parallelize-diags,~ + renew-dots,~ + and~right-margin. + } \cs_new_protected:Nn \__nm_Cell: { - \int_gincr:N \g__nm_column_int - \int_compare:nNnT \g__nm_column_int = 1 { \int_gincr:N \g__nm_row_int } - \int_gset:Nn \g__nm_column_total_int - { \int_max:nn \g__nm_column_total_int \g__nm_column_int } + \int_gincr:N \g__nm_col_int + \int_compare:nNnT \g__nm_col_int = \c_one_int + { + \int_compare:nNnT \l__nm_first_col_int = \c_one_int + \__nm_begin_of_row: + } + \int_gset:Nn \g__nm_col_total_int + { \int_max:nn \g__nm_col_total_int \g__nm_col_int } \hbox_set:Nw \l_tmpa_box \c_math_toggle_token - \int_compare:nNnT \g__nm_row_int = \c_zero_int + \int_compare:nNnTF \g__nm_row_int = \c_zero_int \l__nm_code_for_first_row_tl + { + \int_compare:nNnT \g__nm_row_int = \l__nm_last_row_int + \l__nm_code_for_last_row_tl + } } -\cs_new_protected:Nn \__nm_end_Cell: +\cs_new_protected:Nn \__nm_begin_of_row: + { + \int_gincr:N \g__nm_row_int + \dim_gset_eq:NN \g__nm_dp_ante_last_row_dim \g__nm_dp_last_row_dim + \dim_gzero:N \g__nm_dp_last_row_dim + \dim_gzero:N \g__nm_ht_last_row_dim + } +\cs_new_protected:Npn \__nm_actualization_for_first_and_last_row: { - \c_math_toggle_token - \hbox_set_end: - \dim_gset:Nn \g__nm_max_cell_width_dim - { \dim_max:nn \g__nm_max_cell_width_dim { \box_wd:N \l_tmpa_box } } \int_compare:nNnT \g__nm_row_int = \c_zero_int { - \dim_gset:Nn \g__nm_max_dp_row_zero_dim - { \dim_max:nn \g__nm_max_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } - \dim_gset:Nn \g__nm_max_ht_row_zero_dim - { \dim_max:nn \g__nm_max_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_dp_row_zero_dim + { \dim_max:nn \g__nm_dp_row_zero_dim { \box_dp:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_ht_row_zero_dim + { \dim_max:nn \g__nm_ht_row_zero_dim { \box_ht:N \l_tmpa_box } } } \int_compare:nNnT \g__nm_row_int = \c_one_int { - \dim_gset:Nn \g__nm_max_ht_row_one_dim - { \dim_max:nn \g__nm_max_ht_row_one_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_ht_row_one_dim + { \dim_max:nn \g__nm_ht_row_one_dim { \box_ht:N \l_tmpa_box } } } + \dim_gset:Nn \g__nm_ht_last_row_dim + { \dim_max:nn \g__nm_ht_last_row_dim { \box_ht:N \l_tmpa_box } } + \dim_gset:Nn \g__nm_dp_last_row_dim + { \dim_max:nn \g__nm_dp_last_row_dim { \box_dp:N \l_tmpa_box } } + } +\cs_new_protected:Nn \__nm_end_Cell: + { + \c_math_toggle_token + \hbox_set_end: + \dim_gset:Nn \g__nm_max_cell_width_dim + { \dim_max:nn \g__nm_max_cell_width_dim { \box_wd:N \l_tmpa_box } } + \__nm_actualization_for_first_and_last_row: \tikz [ remember~picture , @@ -375,44 +506,20 @@ anchor = base , name = nm - \int_use:N \g__nm_env_int - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int , + \int_use:N \g__nm_col_int , alias = \str_if_empty:NF \l__nm_name_str { \l__nm_name_str - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int + \int_use:N \g__nm_col_int } ] \bgroup \box_use:N \l_tmpa_box \egroup ; } -\NewDocumentEnvironment { NiceMatrix } { ! O { } } - { - \keys_set:nn { NiceMatrix / NiceMatrix } { #1 } - \str_set:Nn \l__nm_pos_env_str c - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \NiceArray { * \c@MaxMatrixCols C } - } - { - \endarray - \skip_horizontal:n - { \g__nm_right_margin_dim + \g__nm_extra_right_margin_dim - \arraycolsep } - } \cs_generate_variant:Nn \dim_set:Nn { N x } -\__nm_msg_new:nn { Yet~in~NiceArray } - { - Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~ - nested.~You~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~ - result. - } -\__nm_msg_new:nn { Outside~math~mode } - { - The~environment~\{\@currenvir\}~can~be~used~only~in~math~mode~ - (and~not~in~\token_to_str:N \vcenter).\_ - If~you~go~on,~you~will~have~other~errors. - } \cs_new_protected:Nn \__nm_renewcolumntype:nn { \newcolumntype #1 [ 2 ] @@ -453,13 +560,13 @@ node~contents = { } , name = nm - \int_use:N \g__nm_env_int - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int - w, + \int_use:N \g__nm_col_int - w, alias = \str_if_empty:NF \l__nm_name_str { \l__nm_name_str - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int - w + \int_use:N \g__nm_col_int - w } , inner~sep = \c_zero_dim , fit = (__nm~south~west) (__nm~north~east) @@ -468,30 +575,51 @@ } } } -\cs_new_protected:Npn \__nm_test_if_math_mode: +\bool_if:NTF \c__nm_draft_bool + { \cs_set_protected:Npn \__nm_instruction_of_type:n #1 { } } + { + \cs_new_protected:Npn \__nm_instruction_of_type:n #1 + { + \tl_gput_right:Nx \g__nm_lines_to_draw_tl + { + \use:c { __nm _ draw _ #1 : nn } + { \int_use:N \g__nm_row_int } + { \int_use:N \g__nm_col_int } + } + } + } +\cs_new_protected:Npn \__nm_array: { - \ifmmode \else - \__nm_error:n { Outside~math~mode } - \fi + \bool_if:NTF \c__nm_revtex_bool + { + \cs_set_eq:NN \@acoll \@arrayacol + \cs_set_eq:NN \@acolr \@arrayacol + \cs_set_eq:NN \@acol \@arrayacol + \cs_set:Npn \@halignto { } + \@array@array + } + \array + [ \l__nm_pos_env_str ] } -\NewDocumentEnvironment { NiceArray } { O { } m ! O { } } +\cs_new:Npn \__nm_everycr: + { \noalign { \__nm_everycr_i: } } +\cs_new_protected:Npn \__nm_everycr_i: + { + \int_gzero:N \g__nm_col_int + \bool_if:NT \l__nm_hlines_bool + { + \int_compare:nNnT \g__nm_row_int > { -1 } + { + \int_compare:nNnF \g__nm_row_int = \g__nm_last_row_int + { + \hrule \@height \arrayrulewidth + \skip_vertical:n { - \arrayrulewidth } + } + } + } + } +\cs_new_protected:Npn \__nm_pre_array: { - \__nm_adapt_S_column: - \__nm_test_if_math_mode: - \bool_if:NT \l__nm_in_NiceArray_bool - { \__nm_error:n { Yet~in~NiceArray } } - \bool_set_true:N \l__nm_in_NiceArray_bool - \cs_if_exist:NT \tikz@library@external@loaded - { \tikzset { external / export = false } } - \group_insert_after:N \__nm_after_array: - \tl_gclear_new:N \g__nm_lines_to_draw_tl - \int_gincr:N \g__nm_env_int - \bool_if:NF \l__nm_block_auto_columns_width_bool - { \dim_gzero_new:N \g__nm_max_cell_width_dim } - \dim_gzero_new:N \g__nm_max_dp_row_zero_dim - \dim_gzero_new:N \g__nm_max_ht_row_zero_dim - \dim_gzero_new:N \g__nm_max_ht_row_one_dim - \keys_set:nn { NiceMatrix / NiceArray } { #1 , #3 } \bool_if:NT \l__nm_auto_columns_width_bool { \group_insert_after:N \__nm_write_max_cell_width: @@ -514,24 +642,24 @@ \dim_gset_eq:NN \g__nm_left_margin_dim \l__nm_left_margin_dim \dim_gset_eq:NN \g__nm_right_margin_dim \l__nm_right_margin_dim \dim_gset_eq:NN \g__nm_extra_right_margin_dim \l__nm_extra_right_margin_dim + \int_gset_eq:NN \g__nm_last_row_int \l__nm_last_row_int \tl_gset_eq:NN \g__nm_name_str \l__nm_name_str + \int_gset_eq:NN \g__nm_first_row_int \l__nm_first_row_int + \int_gset_eq:NN \g__nm_first_col_int \l__nm_first_col_int + \bool_gset_eq:NN \g__nm_NiceArray_bool \l__nm_NiceArray_bool + \bool_gset_eq:NN \g__nm_last_row_without_value_bool + \l__nm_last_row_without_value_bool \cs_set:Npn \ialign { - \everycr + \bool_if:NTF \c__nm_colortbl_loaded_bool { - \noalign + \CT@everycr { - \int_gzero:N \g__nm_column_int - \bool_if:NT \l__nm_hlines_bool - { - \int_compare:nNnT \g__nm_row_int > { -1 } - { - \hrule \@height \arrayrulewidth - \skip_vertical:n { - \arrayrulewidth } - } - } + \noalign { \global\let\CT@row@color\relax } + \__nm_everycr: } } + { \everycr { \__nm_everycr: } } \tabskip = \c_zero_skip \cs_set:Npn \ialign { @@ -552,24 +680,6 @@ \newcolumntype C { w c { \dim_use:N \l__nm_columns_width_dim } } \newcolumntype R { w r { \dim_use:N \l__nm_columns_width_dim } } } - \cs_set_eq:NN \NC@find@w \relax - \cs_set_eq:NN \NC@find@W \relax - \__nm_renewcolumntype:nn w { } - \__nm_renewcolumntype:nn W { \cs_set_eq:NN \hss \hfil } - \exp_args:Nx \newcolumntype \l__nm_letter_for_dotted_lines_str - { - ! - { - \skip_horizontal:n { 0.53 pt } - \bool_gset_true:N \g__nm_extra_nodes_bool - \int_compare:nNnT \g__nm_column_int > \g__nm_last_vdotted_col_int - { - \int_gset_eq:NN \g__nm_last_vdotted_col_int \g__nm_column_int - \tl_gput_right:Nx \g__nm_code_after_tl - { \__nm_vdottedline:n { \int_use:N \g__nm_column_int } } - } - } - } \cs_set_eq:NN \Ldots \__nm_Ldots \cs_set_eq:NN \Cdots \__nm_Cdots \cs_set_eq:NN \Vdots \__nm_Vdots @@ -577,7 +687,7 @@ \cs_set_eq:NN \Iddots \__nm_Iddots \cs_set_eq:NN \hdottedline \__nm_hdottedline: \cs_set_eq:NN \Hspace \__nm_Hspace: - \cs_set_eq:NN \Hdotsfor \__nm_Hdotsfor + \cs_set_eq:NN \Hdotsfor \__nm_Hdotsfor: \cs_set_eq:NN \multicolumn \__nm_multicolumn:nnn \bool_if:NT \l__nm_renew_dots_bool { @@ -587,39 +697,424 @@ \cs_set_eq:NN \ddots \__nm_Ddots \cs_set_eq:NN \iddots \__nm_Iddots \cs_set_eq:NN \dots \__nm_Ldots - \cs_set_eq:NN \hdotsfor \__nm_Hdotsfor + \cs_set_eq:NN \hdotsfor \__nm_Hdotsfor: } - \bool_if:NT \c__nm_siunitx_loaded_bool \__nm_renew_NC@rewrite@S: \seq_gclear_new:N \g__nm_empty_cells_seq \seq_gclear_new:N \g__nm_multicolumn_cells_seq \seq_gclear_new:N \g__nm_multicolumn_sizes_seq \int_gzero_new:N \g__nm_row_int - \int_gset:Nn \g__nm_row_int { \l__nm_nb_first_row_int - 1 } - \int_gzero_new:N \g__nm_column_int - \int_gzero_new:N \g__nm_column_total_int + \int_gset:Nn \g__nm_row_int { \l__nm_first_row_int - 1 } + \int_gzero_new:N \g__nm_row_total_int + \int_gzero_new:N \g__nm_col_int + \int_gzero_new:N \g__nm_col_total_int + \cs_set_eq:NN \@ifnextchar \new@ifnextchar + \cs_set_eq:NN \NC@find@w \relax + \cs_set_eq:NN \NC@find@W \relax + \__nm_renewcolumntype:nn w { } + \__nm_renewcolumntype:nn W { \cs_set_eq:NN \hss \hfil } + \dim_gzero_new:N \g__nm_dp_row_zero_dim + \dim_gzero_new:N \g__nm_ht_row_zero_dim + \dim_gzero_new:N \g__nm_ht_row_one_dim + \dim_gzero_new:N \g__nm_dp_ante_last_row_dim + \dim_gzero_new:N \g__nm_ht_last_row_dim + \dim_gzero_new:N \g__nm_dp_last_row_dim + \exp_args:Nx \newcolumntype \l__nm_letter_for_dotted_lines_str + { + ! + { + \skip_horizontal:n { 0.53 pt } + \bool_gset_true:N \g__nm_extra_nodes_bool + \int_compare:nNnT \g__nm_col_int > \g__nm_last_vdotted_col_int + { + \int_gset_eq:NN \g__nm_last_vdotted_col_int \g__nm_col_int + \tl_gput_right:Nx \g__nm_code_after_tl + { \__nm_vdottedline:n { \int_use:N \g__nm_col_int } } + } + } + } \int_gzero_new:N \g__nm_last_vdotted_col_int + \bool_if:NT \c__nm_siunitx_loaded_bool \__nm_renew_NC@rewrite@S: \int_gset:Nn \g__nm_last_vdotted_col_int { -1 } - \cs_set_eq:NN \@ifnextchar \new@ifnextchar - \bool_if:NF \l__nm_exterior_arraycolsep_bool - { \skip_horizontal:n { - \arraycolsep } } + \bool_gset_false:N \g__nm_last_col_found_bool + } +\NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } } + { + \__nm_adapt_S_column: + \__nm_test_if_math_mode: + \bool_if:NT \l__nm_in_env_bool { \__nm_fatal:n { Yet~in~env } } + \bool_set_true:N \l__nm_in_env_bool + \cs_if_exist:NT \tikz@library@external@loaded + { \tikzset { external / export = false } } + \group_insert_after:N \__nm_after_array: + \tl_gclear_new:N \g__nm_lines_to_draw_tl + \int_gincr:N \g__nm_env_int + \bool_if:NF \l__nm_block_auto_columns_width_bool + { \dim_gzero_new:N \g__nm_max_cell_width_dim } + \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nm_vline: } + \bool_if:NTF \l__nm_NiceArray_bool + { \keys_set:nn { NiceMatrix / NiceArray } } + { \keys_set:nn { NiceMatrix / pNiceArray } } + { #3 , #5 } + \int_compare:nNnT \l__nm_last_row_int = { -1 } + { + \bool_set_true:N \l__nm_last_row_without_value_bool + \str_if_empty:NTF \g__nm_name_str + { + \cs_if_exist:cT { __nm_last_row_ \int_use:N \g__nm_env_int } + { + \int_set:Nn \l__nm_last_row_int + { \use:c { __nm_last_row_ \int_use:N \g__nm_env_int } } + } + } + { + \cs_if_exist:cT { __nm_last_row_ \g__nm_name_str } + { + \int_set:Nn \l__nm_last_row_int + { \use:c { __nm_last_row_ \g__nm_name_str } } + } + } + } + \__nm_pre_array: + \dim_zero_new:N \g__nm_left_delim_dim + \dim_zero_new:N \g__nm_right_delim_dim + \bool_if:NTF \l__nm_NiceArray_bool + { + \dim_gset:Nn \g__nm_left_delim_dim { 2 \arraycolsep } + \dim_gset:Nn \g__nm_right_delim_dim { 2 \arraycolsep } + } + { + \group_begin: + \dim_set_eq:NN \nulldelimiterspace \c_zero_dim + \hbox_set:Nn \l_tmpa_box + { + \c_math_toggle_token + \left #1 \vcenter to 1 cm { } \right. + \c_math_toggle_token + + } + \dim_gset:Nn \g__nm_left_delim_dim { \box_wd:N \l_tmpa_box } + \hbox_set:Nn \l_tmpa_box + { + \dim_set_eq:NN \nulldelimiterspace \c_zero_dim + \c_math_toggle_token + \left. \vcenter to 1 cm { } \right #2 + \c_math_toggle_token + } + \dim_gset:Nn \g__nm_right_delim_dim { \box_wd:N \l_tmpa_box } + \group_end: + } + \box_clear_new:N \l__nm_the_array_box + \tl_set:Nn \l_tmpa_tl { #4 } + \int_compare:nNnTF \l__nm_first_col_int = \c_zero_int + { \tl_put_left:NV \l_tmpa_tl \c__nm_preamble_first_col_tl } + { + \bool_if:NT \l__nm_NiceArray_bool + { + \bool_if:NF \l__nm_exterior_arraycolsep_bool + { \tl_put_left:Nn \l_tmpa_tl { @ { } } } + } + } + \bool_if:NTF \l__nm_last_col_bool + { \tl_put_right:NV \l_tmpa_tl \c__nm_preamble_last_col_tl } + { + \bool_if:NT \l__nm_NiceArray_bool + { + \bool_if:NF \l__nm_exterior_arraycolsep_bool + { \tl_put_right:Nn \l_tmpa_tl { @ { } } } + } + } + \hbox_set:Nw \l__nm_the_array_box \skip_horizontal:n \l__nm_left_margin_dim \skip_horizontal:n \l__nm_extra_left_margin_dim - \bool_if:NTF \c__nm_revtex_bool - { - \cs_set_eq:NN \@acoll \@arrayacol - \cs_set_eq:NN \@acolr \@arrayacol - \cs_set_eq:NN \@acol \@arrayacol - \cs_set:Npn \@halignto { } - \@array@array - } - \array - [ \l__nm_pos_env_str ] { #2 } + \c_math_toggle_token + \exp_args:NV \__nm_array: \l_tmpa_tl + } + { + \endarray + \c_math_toggle_token + \skip_horizontal:n \g__nm_right_margin_dim + \skip_horizontal:n \g__nm_extra_right_margin_dim + \hbox_set_end: + \int_compare:nNnTF \l__nm_first_row_int = \c_zero_int + { + \dim_compare:nNnTF + { \g__nm_ht_row_one_dim + \g__nm_dp_row_zero_dim + \lineskiplimit } + > \baselineskip + { + \dim_set:Nn \l_tmpa_dim + { + \g__nm_ht_row_one_dim + \g__nm_dp_row_zero_dim + \lineskip + + \g__nm_ht_row_zero_dim - \g__nm_ht_row_one_dim + } + } + { + \dim_set:Nn \l_tmpa_dim + { \baselineskip + \g__nm_ht_row_zero_dim - \g__nm_ht_row_one_dim } + } + } + { \dim_zero:N \l_tmpa_dim } + \int_compare:nNnTF \l__nm_last_row_int > { -2 } + { + \dim_compare:nNnTF + { + \g__nm_ht_last_row_dim + \g__nm_dp_ante_last_row_dim + \lineskiplimit + } + > + \baselineskip + { + \dim_set:Nn \l_tmpb_dim + { + \g__nm_ht_last_row_dim + \g__nm_dp_ante_last_row_dim + \lineskip + + \g__nm_dp_last_row_dim - \g__nm_dp_ante_last_row_dim + } + } + { + \dim_set:Nn \l_tmpb_dim + { + \baselineskip + + \g__nm_dp_last_row_dim - \g__nm_dp_ante_last_row_dim + } + } + } + { \dim_zero:N \l_tmpb_dim } + \int_compare:nNnT \g__nm_first_col_int = \c_zero_int + { + \skip_horizontal:n \arraycolsep + \skip_horizontal:n \g__nm_width_first_col_dim + } + \bool_if:NTF \g__nm_NiceArray_bool + { + \int_compare:nNnT \g__nm_first_row_int = \c_zero_int + { + \str_if_eq:VnTF \l__nm_pos_env_str { t } + { + \box_move_up:nn + { \l_tmpa_dim - \g__nm_ht_row_zero_dim + \g__nm_ht_row_one_dim } + } + } + { + \bool_if:NT \g__nm_last_row_int + { + \str_if_eq:VnT \l__nm_pos_env_str { b } + { + \box_move_down:nn + { + \l_tmpb_dim + - \g__nm_dp_last_row_dim + \g__nm_dp_ante_last_row_dim + } + } + } + } + { \box_use_drop:N \l__nm_the_array_box } + } + { + \hbox_set:Nn \l_tmpa_box + { + \c_math_toggle_token + \left #1 + \vcenter + { + \skip_vertical:n { - \l_tmpa_dim } + \hbox:n + { + \skip_horizontal:n { - \arraycolsep } + \box_use_drop:N \l__nm_the_array_box + \skip_horizontal:n { - \arraycolsep } + } + \skip_vertical:n { - \l_tmpb_dim } + } + \right #2 + \c_math_toggle_token + } + \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } + \box_set_dp:Nn \l_tmpa_box { \box_dp:N \l_tmpa_box + \l_tmpb_dim } + \box_use_drop:N \l_tmpa_box + } + \bool_if:NT \g__nm_last_col_found_bool + { + \skip_horizontal:n \g__nm_width_last_col_dim + \skip_horizontal:n \arraycolsep + } + } +\tl_const:Nn \c__nm_preamble_first_col_tl + { + > + { + \__nm_begin_of_row: + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token + \l__nm_code_for_first_col_tl + } + l + < + { + \c_math_toggle_token + \hbox_set_end: + \__nm_actualization_for_first_and_last_row: + \dim_gset:Nn \g__nm_width_first_col_dim + { + \dim_max:nn + \g__nm_width_first_col_dim + { \box_wd:N \l_tmpa_box } + } + \hbox_overlap_left:n + { + \tikz + [ + remember~picture , + inner~sep = \c_zero_dim , + minimum~width = \c_zero_dim , + baseline + ] + \node + [ + anchor = base , + name = + nm - + \int_use:N \g__nm_env_int - + \int_use:N \g__nm_row_int - + 0 , + alias = + \str_if_empty:NF \l__nm_name_str + { + \l__nm_name_str - + \int_use:N \g__nm_row_int - + 0 + } + ] + { \box_use:N \l_tmpa_box } ; + \skip_horizontal:n + { + \g__nm_left_delim_dim + + \l__nm_left_margin_dim + + \l__nm_extra_left_margin_dim + } + } + \skip_horizontal:n { - 2 \arraycolsep } + } + } +\tl_const:Nn \c__nm_preamble_last_col_tl + { + > + { + \bool_gset_true:N \g__nm_last_col_found_bool + \int_gincr:N \g__nm_col_int + \int_gset:Nn \g__nm_col_total_int + { \int_max:nn \g__nm_col_total_int \g__nm_col_int } + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token + \l__nm_code_for_last_col_tl + } + l + < + { + \c_math_toggle_token + \hbox_set_end: + \__nm_actualization_for_first_and_last_row: + \dim_gset:Nn \g__nm_width_last_col_dim + { + \dim_max:nn + \g__nm_width_last_col_dim + { \box_wd:N \l_tmpa_box } + } + \skip_horizontal:n { - 2 \arraycolsep } + \hbox_overlap_right:n + { + \skip_horizontal:n + { + \g__nm_right_delim_dim + + \l__nm_right_margin_dim + + \l__nm_extra_right_margin_dim + } + \tikz + [ + remember~picture , + inner~sep = \c_zero_dim , + minimum~width = \c_zero_dim , + baseline + ] + \node + [ + anchor = base , + name = + nm - + \int_use:N \g__nm_env_int - + \int_use:N \g__nm_row_int - + \int_use:N \g__nm_col_int , + alias = + \str_if_empty:NF \l__nm_name_str + { + \l__nm_name_str - + \int_use:N \g__nm_row_int - + \int_use:N \g__nm_col_int + } + ] + { \box_use:N \l_tmpa_box } ; + } + } + } +\NewDocumentEnvironment { NiceArray } { } + { + \bool_set_true:N \l__nm_NiceArray_bool + \NiceArrayWithDelims . . + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { pNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims ( ) } - { \endarray - \bool_if:NF \l__nm_exterior_arraycolsep_bool - { \skip_horizontal:n { - \arraycolsep } } - \skip_horizontal:n \g__nm_right_margin_dim - \skip_horizontal:n \g__nm_extra_right_margin_dim + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { bNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims [ ] + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { BNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims \{ \} + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { vNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims | | + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { VNiceArray } { } + { + \__nm_test_if_math_mode: + \NiceArrayWithDelims \| \| + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { NiceMatrix } { ! O { } } + { + \__nm_test_if_math_mode: + \bool_if:NT \l__nm_in_env_bool { \__nm_fatal:n { Yet~in~env } } + \bool_set_true:N \l__nm_in_env_bool + \cs_if_exist:NT \tikz@library@external@loaded + { \tikzset { external / export = false } } + \group_insert_after:N \__nm_after_array: + \tl_gclear_new:N \g__nm_lines_to_draw_tl + \int_gincr:N \g__nm_env_int + \bool_if:NF \l__nm_block_auto_columns_width_bool + { \dim_gzero_new:N \g__nm_max_cell_width_dim } + \keys_set:nn { NiceMatrix / NiceMatrix } { #1 } + \__nm_pre_array: + \skip_horizontal:n { - \arraycolsep } + \skip_horizontal:n \l__nm_left_margin_dim + \skip_horizontal:n \l__nm_extra_left_margin_dim + \str_set:Nn \l__nm_pos_env_str c + \bool_set_false:N \l__nm_exterior_arraycolsep_bool + \__nm_array: { * \c@MaxMatrixCols C } + } + { + \endarray + \skip_horizontal:n { - \arraycolsep } + \skip_horizontal:n \g__nm_right_margin_dim + \skip_horizontal:n \g__nm_extra_right_margin_dim } \NewDocumentEnvironment { pNiceMatrix } { } { @@ -645,7 +1140,7 @@ \left\lvert \begin{NiceMatrix} } { \end{NiceMatrix} \right\rvert } -\NewDocumentEnvironment { VNiceMatrix } {} +\NewDocumentEnvironment { VNiceMatrix } { } { \__nm_test_if_math_mode: \left\lVert \begin{NiceMatrix} @@ -696,19 +1191,6 @@ } } } -\bool_if:NTF \c__nm_draft_bool - { \cs_set_protected:Npn \__nm_instruction_of_type:n #1 { } } - { - \cs_new_protected:Npn \__nm_instruction_of_type:n #1 - { - \tl_gput_right:Nx \g__nm_lines_to_draw_tl - { - \exp_not:c { __nm _ draw _ #1 : nn } - { \int_use:N \g__nm_row_int } - { \int_use:N \g__nm_column_int } - } - } - } \cs_new_protected:Nn \__nm_after_array: { \int_compare:nNnTF \g__nm_row_int > \c_zero_int @@ -718,7 +1200,7 @@ \__nm_msg_new:nn { Zero~row } { There~is~a~problem.~Maybe~your~environment~\{\@currenvir\}~is~empty.~ - Maybe~you~have~used~L,~C~and~R~instead~of~l,~c~and~r~in~the~preamble~ + Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~and~R~in~the~preamble~ of~your~environment. \\ If~you~go~on,~the~result~may~be~incorrect. } @@ -727,9 +1209,29 @@ \group_begin: \cs_if_exist:NT \tikz@library@external@loaded { \tikzset { external / export = false } } - \int_gset_eq:NN \g__nm_column_int \g__nm_column_total_int - \bool_if:nT { \l__nm_exterior_column_bool && \g__nm_exterior_column_found_bool } - { \int_gdecr:N \g__nm_column_int } + \int_gset_eq:NN \g__nm_col_int \g__nm_col_total_int + \bool_if:nT \g__nm_last_col_found_bool { \int_gdecr:N \g__nm_col_int } + \int_gset_eq:NN \g__nm_row_total_int \g__nm_row_int + \int_compare:nNnT \g__nm_last_row_int > { -1 } + { \int_gsub:Nn \g__nm_row_int \c_one_int } + \bool_if:NT \g__nm_last_row_without_value_bool + { + \iow_now:Nn \@mainaux \ExplSyntaxOn + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { __nm_last_row_ \int_use:N \g__nm_env_int } + { \int_use:N \g__nm_row_total_int } + } + \str_if_empty:NF \g__nm_name_str + { + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { __nm_last_row_ \g__nm_name_str } + { \int_use:N \g__nm_row_total_int } + } + } + \iow_now:Nn \@mainaux \ExplSyntaxOff + } \seq_gclear_new:N \g__nm_yet_drawn_seq \bool_if:NT \l__nm_parallelize_diags_bool { @@ -772,25 +1274,33 @@ \int_set:Nn \l__nm_initial_j_int { #2 } \int_set:Nn \l__nm_final_i_int { #1 } \int_set:Nn \l__nm_final_j_int { #2 } - \bool_set_false:N \l__nm_initial_open_bool - \bool_set_false:N \l__nm_final_open_bool \bool_set_false:N \l__nm_stop_loop_bool \bool_do_until:Nn \l__nm_stop_loop_bool { \int_add:Nn \l__nm_final_i_int { #3 } \int_add:Nn \l__nm_final_j_int { #4 } - \bool_if:nTF + \bool_set_false:N \l__nm_final_open_bool + \int_compare:nNnTF \l__nm_final_i_int > \g__nm_row_int { - \int_compare_p:nNn - \l__nm_final_i_int < { \l__nm_nb_first_row_int - 1 } - || \int_compare_p:nNn \l__nm_final_i_int > \g__nm_row_int - || \int_compare_p:nNn \l__nm_final_j_int < \c_one_int - || \int_compare_p:nNn \l__nm_final_j_int > \g__nm_column_total_int - || \int_compare_p:nNn \l__nm_final_j_int > \g__nm_column_int - && \int_compare_p:nNn { #4 } > \c_zero_int + \int_compare:nNnT { #3 } = 1 + { \bool_set_true:N \l__nm_final_open_bool } } { - \bool_set_true:N \l__nm_final_open_bool + \int_compare:nNnTF \l__nm_final_j_int < 1 + { + \int_compare:nNnT { #4 } = { -1 } + { \bool_set_true:N \l__nm_final_open_bool } + } + { + \int_compare:nNnT \l__nm_final_j_int > \g__nm_col_int + { + \int_compare:nNnT { #4 } = 1 + { \bool_set_true:N \l__nm_final_open_bool } + } + } + } + \bool_if:NTF \l__nm_final_open_bool + { \int_sub:Nn \l__nm_final_i_int { #3 } \int_sub:Nn \l__nm_final_j_int { #4 } \bool_set_true:N \l__nm_stop_loop_bool @@ -805,18 +1315,28 @@ { \int_sub:Nn \l__nm_initial_i_int { #3 } \int_sub:Nn \l__nm_initial_j_int { #4 } - \bool_if:nTF + \bool_set_false:N \l__nm_initial_open_bool + \int_compare:nNnTF \l__nm_initial_i_int < 1 { - \int_compare_p:nNn \l__nm_initial_i_int < \l__nm_nb_first_row_int - || - \int_compare_p:nNn \l__nm_initial_i_int > \g__nm_row_int - || - \int_compare_p:nNn \l__nm_initial_j_int < 1 - || - \int_compare_p:nNn \l__nm_initial_j_int > \g__nm_column_total_int + \int_compare:nNnT { #3 } = 1 + { \bool_set_true:N \l__nm_initial_open_bool } } { - \bool_set_true:N \l__nm_initial_open_bool + \int_compare:nNnTF \l__nm_initial_j_int < 1 + { + \int_compare:nNnT { #4 } = 1 + { \bool_set_true:N \l__nm_initial_open_bool } + } + { + \int_compare:nNnT \l__nm_initial_j_int > \g__nm_col_int + { + \int_compare:nNnT { #4 } = { -1 } + { \bool_set_true:N \l__nm_initial_open_bool } + } + } + } + \bool_if:NTF \l__nm_initial_open_bool + { \int_add:Nn \l__nm_initial_i_int { #3 } \int_add:Nn \l__nm_initial_j_int { #4 } \bool_set_true:N \l__nm_stop_loop_bool @@ -875,17 +1395,37 @@ } \cs_new_protected:Nn \__nm_actually_draw_Ldots: { - \__nm_retrieve_coords:xx - { - \bool_if:NTF \l__nm_initial_open_bool - { - medium.base~west } - { .base~east } - } - { - \bool_if:NTF \l__nm_final_open_bool - { - medium.base~east } - { . base~west } - } + \__nm_retrieve_coords:xx + { + \bool_if:NTF \l__nm_initial_open_bool + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_initial_i_int + - \int_use:N \l__nm_initial_j_int - w + } + { - w.base~west } + { - medium.base~west } + } + { .base~east } + } + { + \bool_if:NTF \l__nm_final_open_bool + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_final_i_int + - \int_use:N \l__nm_final_j_int - w + } + { - w.base~east } + { - medium.base~east } + } + { .base~west } + } \bool_if:NT \l__nm_initial_open_bool { \dim_gset_eq:NN \g__nm_y_initial_dim \g__nm_y_final_dim } \bool_if:NT \l__nm_final_open_bool @@ -902,13 +1442,33 @@ \__nm_retrieve_coords:xx { \bool_if:NTF \l__nm_initial_open_bool - { - medium.mid~west } + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_initial_i_int + - \int_use:N \l__nm_initial_j_int - w + } + { - w.mid~west } + { - medium.mid~west } + } { .mid~east } } { \bool_if:NTF \l__nm_final_open_bool - { - medium.mid~east } - { .mid~west } + { + \cs_if_exist:cTF + { + pgf@sh@ns@nm + - \int_use:N \g__nm_env_int + - \int_use:N \l__nm_final_i_int + - \int_use:N \l__nm_final_j_int - w + } + { - w.mid~east } + { - medium.mid~east } + } + { .mid~west } } \bool_if:NT \l__nm_initial_open_bool { \dim_gset_eq:NN \g__nm_y_initial_dim \g__nm_y_final_dim } @@ -1042,7 +1602,8 @@ \fp_to_dim:n { sqrt - ( ( \dim_use:N \g__nm_x_final_dim + ( + ( \dim_use:N \g__nm_x_final_dim - \dim_use:N \g__nm_x_initial_dim ) ^ 2 + @@ -1129,7 +1690,7 @@ \cs_new_protected:Nn \__nm_add_to_empty_cells: { \seq_gput_right:Nx \g__nm_empty_cells_seq - { \int_use:N \g__nm_row_int - \int_use:N \g__nm_column_int } + { \int_use:N \g__nm_row_int - \int_use:N \g__nm_col_int } } \NewDocumentCommand \__nm_Ldots { s } { @@ -1173,27 +1734,34 @@ \int_compare:nNnT #1 > 1 { \seq_gput_left:Nx \g__nm_multicolumn_cells_seq - { \int_eval:n \g__nm_row_int - \int_use:N \g__nm_column_int } + { \int_eval:n \g__nm_row_int - \int_use:N \g__nm_col_int } \seq_gput_left:Nn \g__nm_multicolumn_sizes_seq { #1 } } - \int_gadd:Nn \g__nm_column_int { #1 - 1 } + \int_gadd:Nn \g__nm_col_int { #1 - 1 } + } +\cs_new:Npn \__nm_Hdotsfor: + { + \multicolumn { 1 } { C } { } + \__nm_Hdotsfor_i } \bool_if:NTF \c__nm_draft_bool { - \NewDocumentCommand \__nm_Hdotsfor { O { } m } - { \prg_replicate:nn { #2 - 1 } { & } } + \NewDocumentCommand \__nm_Hdotsfor_i { O { } m } + { + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } + } } { - \NewDocumentCommand \__nm_Hdotsfor { O { } m } + \NewDocumentCommand \__nm_Hdotsfor_i { O { } m } { \tl_gput_right:Nx \g__nm_lines_to_draw_tl { \__nm_draw_Hdotsfor:nnn { \int_use:N \g__nm_row_int } - { \int_use:N \g__nm_column_int } + { \int_use:N \g__nm_col_int } { #2 } } - \prg_replicate:nn { #2 - 1 } { & } + \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } } } } \cs_new_protected:Nn \__nm_draw_Hdotsfor:nnn @@ -1216,7 +1784,7 @@ \bool_set_true:N \l__nm_initial_open_bool } } - \int_compare:nNnTF { #2 + #3 -1 } = \g__nm_column_int + \int_compare:nNnTF { #2 + #3 -1 } = \g__nm_col_int { \int_set:Nn \l__nm_final_j_int { #2 + #3 - 1 } \bool_set_true:N \l__nm_final_open_bool @@ -1259,7 +1827,7 @@ { \cs_set:Npn \__nm_dotfill: { - \cleaders \hbox_to_wd:nn { .44 em } { \hss .\hss } \hfill + \cleaders \hbox_to_wd:nn { .44 em } { \hss . \hss } \hfill \skip_horizontal:n \c_zero_dim } } @@ -1272,7 +1840,8 @@ { \dim_set:Nv \l_tmpa_dim { __nm_width_ \int_use:N \g__nm_env_int } } { \dim_set:Nn \l_tmpa_dim { 5 mm } } \hbox_overlap_right:n - { \hbox_to_wd:nn + { + \hbox_to_wd:nn { \l_tmpa_dim + 2 \arraycolsep - \l__nm_left_margin_dim - \g__nm_right_margin_dim @@ -1329,6 +1898,46 @@ first~position~of~the~preamble~of~the~environment~\{\@currenvir\}. \\ If~you~go~on,~this~dotted~line~will~be~ignored. } +\cs_new_protected:Npn \__nm_vline: + { + \int_compare:nNnTF \l__nm_first_col_int = \c_zero_int + { + \int_compare:nNnTF \g__nm_col_int = \c_zero_int + { + \int_compare:nNnTF \l__nm_first_row_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline + } + } + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline + } + } + } + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline } + } + } + { + \int_compare:nNnTF \g__nm_col_int = \c_zero_int + { + \int_compare:nNnF \g__nm_row_int = { -1 } + { + \int_compare:nNnF \g__nm_row_int = { \l__nm_last_row_int - 1 } + \vline + } + } + { + \int_compare:nNnF \g__nm_row_int = \c_zero_int + { \int_compare:nNnF \g__nm_row_int = \l__nm_last_row_int \vline } + } + } + } \bool_new:N \l__nm_block_auto_columns_width_bool \keys_define:nn { NiceMatrix / NiceMatrixBlock } { @@ -1360,244 +1969,29 @@ \iow_now:Nn \@mainaux \ExplSyntaxOff } } -\keys_define:nn { NiceMatrix / NiceArrayC } - { - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - unknown .code:n = \__nm_error:n { Unknown~option~for~NiceArrayC } - } -\__nm_msg_new:nnn { Unknown~option~for~NiceArrayC } - { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ - \{\@currenvir\}. \\ - If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~<return>. - } - { - The~available~options~are~(in~alphabetic~order):~ - code-after,~ - code-for-last-col,~ - columns-width,~ - create-extra-nodes,~ - extra-left-margin,~ - extra-right-margin,~ - hlines,~ - left-margin,~ - name,~ - nullify-dots,~ - parallelize-diags~ - renew-dots~ - and~right-margin. - } -\cs_new_protected:Nn \__nm_NiceArrayC:n - { - \bool_set_true:N \l__nm_exterior_column_bool - \bool_gset_false:N \g__nm_exterior_column_found_bool - \begin { NiceArray } - { #1 - > - { - \bool_gset_true:N \g__nm_exterior_column_found_bool - \int_gincr:N \g__nm_column_int - \int_gset:Nn \g__nm_column_total_int - { \int_max:nn \g__nm_column_total_int \g__nm_column_int } - \hbox_set:Nw \l_tmpa_box \c_math_toggle_token - \l__nm_code_for_last_col_tl - } - l - < { \c_math_toggle_token - \hbox_set_end: - \dim_gset:Nn \g__nm_width_last_col_dim - { - \dim_max:nn - \g__nm_width_last_col_dim - { \box_wd:N \l_tmpa_box } - } - \skip_horizontal:n { - 2 \arraycolsep } - \hbox_overlap_right:n - { - \skip_horizontal:n - { - 2 \arraycolsep + - \l__nm_right_margin_dim + - \l__nm_extra_right_margin_dim - } - \tikz - [ - remember~picture , - inner~sep = \c_zero_dim , - minimum~width = \c_zero_dim , - baseline - ] - \node - [ - anchor = base , - name = - nm - - \int_use:N \g__nm_env_int - - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int , - alias = - \str_if_empty:NF \l__nm_name_str - { - \l__nm_name_str - - \int_use:N \g__nm_row_int - - \int_use:N \g__nm_column_int - } - ] - { \box_use:N \l_tmpa_box } ; - } - } - } - } -\NewDocumentEnvironment { NiceArrayCwithDelims } { m m O { } m ! O { } } - { - \__nm_test_if_math_mode: - \dim_gzero_new:N \g__nm_width_last_col_dim - \keys_set:nn { NiceMatrix / NiceArrayC } { #3 , #5 } - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \str_set:Nn \l__nm_pos_env_str c - \left #1 - \__nm_NiceArrayC:n { #4 } - } - { - \end { NiceArray } - \right #2 - \skip_horizontal:n \g__nm_width_last_col_dim - } -\NewDocumentEnvironment { pNiceArrayC } { } - { \NiceArrayCwithDelims ( ) } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { vNiceArrayC } { } - { \NiceArrayCwithDelims | | } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { VNiceArrayC } { } - { \NiceArrayCwithDelims \| \| } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { bNiceArrayC } { } - { \NiceArrayCwithDelims [ ] } - { \endNiceArrayCwithDelims } -\NewDocumentEnvironment { BNiceArrayC } { } - { \NiceArrayCwithDelims \{ \} } - { \endNiceArrayCwithDelims } -\keys_define:nn { NiceMatrix / NiceArrayRC } - { - code-for-first-row .tl_set:N = \l__nm_code_for_first_row_tl , - code-for-first-row .value_required:n = true , - code-for-last-col .tl_set:N = \l__nm_code_for_last_col_tl , - code-for-last-col .value_required:n = true , - unknown .code:n = \__nm_error:n { Unknown~option~for~NiceArrayRC } - } -\__nm_msg_new:nnn { Unknown~option~for~NiceArrayRC } - { - The~option~'\tl_use:N\l_keys_key_tl'~is~unknown~for~the~environment~ - \{ \@currenvir \}. \\ - If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~<return>. - } - { - The~available~options~are~(in~alphabetic~order):~ - code-after,~ - code-for-last-col,~ - code-for-first-row,~ - columns-width,~ - create-extra-nodes,~ - extra-left-margin,~ - extra-right-margin,~ - hlines,~ - left-margin,~ - name,~ - nullify-dots,~ - parallelize-diags,~ - renew-dots~ - and~right-margin. - } -\cs_new_protected:Npn \__nm_vline: - { - \int_compare:nNnTF \g__nm_column_int = \c_zero_int - { \int_compare:nNnF \g__nm_row_int < \c_zero_int \vline } - { \int_compare:nNnF \g__nm_row_int < \c_one_int \vline } - } -\NewDocumentEnvironment { NiceArrayRCwithDelims } { m m O { } m ! O { } } - { - \__nm_test_if_math_mode: - \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nm_vline: } - \int_zero:N \l__nm_nb_first_row_int - \dim_gzero_new:N \g__nm_width_last_col_dim - \keys_set:nn { NiceMatrix / NiceArrayRC } { #3 , #5 } - \bool_set_false:N \l__nm_exterior_arraycolsep_bool - \str_set:Nn \l__nm_pos_env_str c - \box_clear_new:N \l__nm_the_array_box - \hbox_set:Nw \l__nm_the_array_box - \c_math_toggle_token - \__nm_NiceArrayC:n { #4 } - } - { - \end { NiceArray } - \c_math_toggle_token - \hbox_set_end: - \dim_set:Nn \l_tmpa_dim - { - ( - \dim_max:nn - { 12 pt } - { \g__nm_max_ht_row_one_dim + \g__nm_max_dp_row_zero_dim } - ) - + \g__nm_max_ht_row_zero_dim - \g__nm_max_ht_row_one_dim - } - \hbox_set:Nn \l_tmpa_box - { - \c_math_toggle_token - \left #1 - \vcenter - { - \skip_vertical:n { - \l_tmpa_dim } - \box_use_drop:N \l__nm_the_array_box - } - \right #2 - \c_math_toggle_token - \skip_horizontal:n \g__nm_width_last_col_dim - } - \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim } - \box_use_drop:N \l_tmpa_box - } -\NewDocumentEnvironment { pNiceArrayRC } { } - { \NiceArrayRCwithDelims ( ) } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { bNiceArrayRC } { } - { \NiceArrayRCwithDelims [ ] } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { vNiceArrayRC } { } - { \NiceArrayRCwithDelims | | } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { VNiceArrayRC } { } - { \NiceArrayRCwithDelims \| \| } - { \endNiceArrayRCwithDelims } -\NewDocumentEnvironment { BNiceArrayRC } { } - { \NiceArrayRCwithDelims \{ \} } - { \endNiceArrayRCwithDelims } \cs_generate_variant:Nn \dim_min:nn { v n } \cs_generate_variant:Nn \dim_max:nn { v n } \cs_new_protected:Nn \__nm_create_extra_nodes: { \begin { tikzpicture } [ remember~picture , overlay ] - \int_step_variable:nnnNn \l__nm_nb_first_row_int 1 \g__nm_row_int \__nm_i: + \int_step_variable:nnNn \g__nm_first_row_int \g__nm_row_total_int \__nm_i: { \dim_zero_new:c { l__nm_row_\__nm_i: _min_dim } \dim_set_eq:cN { l__nm_row_\__nm_i: _min_dim } \c_max_dim \dim_zero_new:c { l__nm_row_\__nm_i: _max_dim } \dim_set:cn { l__nm_row_\__nm_i: _max_dim } { - \c_max_dim } } - \int_step_variable:nNn \g__nm_column_total_int \__nm_j: + \int_step_variable:nnNn \g__nm_first_col_int \g__nm_col_total_int \__nm_j: { \dim_zero_new:c { l__nm_column_\__nm_j: _min_dim } \dim_set_eq:cN { l__nm_column_\__nm_j: _min_dim } \c_max_dim \dim_zero_new:c { l__nm_column_\__nm_j: _max_dim } \dim_set:cn { l__nm_column_\__nm_j: _max_dim } { - \c_max_dim } } - \int_step_variable:nnNn \l__nm_nb_first_row_int \g__nm_row_int \__nm_i: + \int_step_variable:nnNn \g__nm_first_row_int \g__nm_row_total_int \__nm_i: { - \int_step_variable:nNn \g__nm_column_total_int \__nm_j: + \int_step_variable:nnNn + \g__nm_first_col_int \g__nm_col_total_int \__nm_j: { \cs_if_exist:cT { pgf@sh@ns@nm - \int_use:N \g__nm_env_int - \__nm_i: - \__nm_j: } { @@ -1625,7 +2019,8 @@ } \tikzset { name~suffix = -medium } \__nm_create_nodes: - \int_set:Nn \l__nm_nb_first_row_int 1 + \int_set:Nn \g__nm_first_row_int 1 + \int_set:Nn \g__nm_first_col_int 1 \int_step_variable:nNn { \g__nm_row_int - 1 } \__nm_i: { \dim_set:cn { l__nm_row _ \__nm_i: _ min _ dim } @@ -1639,7 +2034,7 @@ \dim_set_eq:cc { l__nm_row _ \int_eval:n { \__nm_i: + 1 } _ max _ dim } { l__nm_row_\__nm_i: _min_dim } } - \int_step_variable:nNn { \g__nm_column_int - 1 } \__nm_j: + \int_step_variable:nNn { \g__nm_col_int - 1 } \__nm_j: { \dim_set:cn { l__nm_column _ \__nm_j: _ max _ dim } { @@ -1658,7 +2053,7 @@ { l__nm_column _ 1 _ min _ dim } \g__nm_left_margin_dim \dim_add:cn - { l__nm_column _ \int_use:N \g__nm_column_int _ max _ dim } + { l__nm_column _ \int_use:N \g__nm_col_int _ max _ dim } \g__nm_right_margin_dim \tikzset { name~suffix = -large } \__nm_create_nodes: @@ -1670,9 +2065,9 @@ \dim_gset:Nn \g_tmpa_dim \pgf@x \tikz@parse@node \pgfutil@firstofone ( nm - \int_use:N \g__nm_env_int - 1 - - \int_use:N \g__nm_column_int - large .north~east ) + \int_use:N \g__nm_col_int - large .north~east ) \dim_gset:Nn \g_tmpb_dim \pgf@x - \end { tikzpicture } + \end { tikzpicture } \iow_now:Nn \@mainaux \ExplSyntaxOn \iow_now:Nx \@mainaux { @@ -1683,15 +2078,15 @@ } \cs_new_protected:Nn \__nm_create_nodes: { - \int_step_variable:nnNn \l__nm_nb_first_row_int \g__nm_row_int \__nm_i: + \int_step_variable:nnNn \g__nm_first_row_int \g__nm_row_total_int \__nm_i: { - \int_step_variable:nNn \g__nm_column_total_int \__nm_j: + \int_step_variable:nnNn \g__nm_first_col_int \g__nm_col_total_int \__nm_j: { \coordinate ( __nm~south~west ) at ( \dim_use:c { l__nm_column_ \__nm_j: _min_dim } , \dim_use:c { l__nm_row_ \__nm_i: _min_dim } ) ; \coordinate ( __nm~north~east ) - at ( \dim_use:c { l__nm_column_ \__nm_j: _max_dim }, + at ( \dim_use:c { l__nm_column_ \__nm_j: _max_dim } , \dim_use:c { l__nm_row_ \__nm_i: _max_dim } ) ; \node [ @@ -1770,6 +2165,84 @@ { \BNiceMatrix } { \endBNiceMatrix } } +\NewDocumentEnvironment { pNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \pNiceArray + } + { \endpNiceArray } +\NewDocumentEnvironment { bNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \bNiceArray + } + { \endbNiceArray } +\NewDocumentEnvironment { BNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \BNiceArray + } + { \endBNiceArray } +\NewDocumentEnvironment { vNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \vNiceArray + } + { \endvNiceArray } +\NewDocumentEnvironment { VNiceArrayC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \VNiceArray + } + { \endVNiceArray } +\NewDocumentEnvironment { pNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \pNiceArray + } + { \endpNiceArray } +\NewDocumentEnvironment { bNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \bNiceArray + } + { \endbNiceArray } +\NewDocumentEnvironment { BNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \BNiceArray + } + { \endBNiceArray } +\NewDocumentEnvironment { vNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \vNiceArray + } + { \endvNiceArray } +\NewDocumentEnvironment { VNiceArrayRC } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \VNiceArray + } + { \endVNiceArray } +\NewDocumentEnvironment { NiceArrayCwithDelims } { } + { + \bool_set_true:N \l__nm_last_col_bool + \NiceArrayWithDelims + } + { \endNiceArrayWithDelims } +\NewDocumentEnvironment { NiceArrayRCwithDelims } { } + { + \bool_set_true:N \l__nm_last_col_bool + \int_set:Nn \l__nm_first_row_int \c_zero_int + \NiceArrayWithDelims + } + { \endNiceArrayWithDelims } \endinput %% %% End of file `nicematrix.sty'. |