From 0770d0964f61096883b1a75524e16c31da08b9a4 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 19 Jul 2019 20:42:46 +0000 Subject: nicematrix (19jul19) git-svn-id: svn://tug.org/texlive/trunk@51680 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/latex/nicematrix/nicematrix-french.pdf | Bin 0 -> 286330 bytes .../doc/latex/nicematrix/nicematrix-french.tex | 2036 ++++++++++++++++++++ .../texmf-dist/doc/latex/nicematrix/nicematrix.pdf | Bin 422728 -> 559454 bytes .../source/latex/nicematrix/nicematrix.dtx | 904 +++++---- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 453 +++-- 5 files changed, 2883 insertions(+), 510 deletions(-) create mode 100644 Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf create mode 100644 Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf new file mode 100644 index 00000000000..8ea0c2f6433 Binary files /dev/null and b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf differ diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex new file mode 100644 index 00000000000..b3dbc988161 --- /dev/null +++ b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex @@ -0,0 +1,2036 @@ +\documentclass[dvipsnames]{article}% dvipsnames is for xcolor (loaded by Tikz, loaded by nicematrix) +\usepackage{xltxtra} +\usepackage[french]{babel} + +\usepackage{geometry} +\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}} + +\usepackage{amsmath} +\usepackage{color} +\usepackage{colortbl} +\usepackage{array} +\usepackage{arydshln} +\usepackage{verbatim} + + +\usepackage{nicematrix} +\usepackage{siunitx} + +\usepackage{fancyvrb} +\fvset{commandchars=\~\#\@,formatcom={\color{gray}}} + +\usepackage{titlesec} +\titlespacing*{\section}{0pt}{6.5ex plus 1ex minus .2ex}{4.3ex plus .2ex} +\titlespacing*{\subsection}{0pt}{4.5ex plus 1ex minus .2ex}{2ex plus .2ex} + +\usepackage{multicol} +\setlength{\columnseprule}{0.4pt} + +\def\interitem{\vskip 7mm plus 2 mm minus 3mm} +\def\emphase{\bgroup\color{RoyalPurple}\let\next=} + +\usepackage{footnote} + +\usepackage[hyperfootnotes = false]{hyperref} + + +\NewDocumentEnvironment {scope} {} {} {} + +\NewDocumentCommand {\pkg} {m} {\textsf{#1}} +\NewDocumentCommand {\cls} {m} {\textsf{#1}} + +\setlength{\parindent}{0pt} + + +\begin{document} + +\VerbatimFootnotes + +\title{L'extension \pkg{nicematrix}\thanks{Ce document correspond à la version~\myfileversion\space of \pkg{nicematrix}, +en date du~\myfiledate.}} \author{F. Pantigny \\ \texttt{fpantigny@wanadoo.fr}} + + +\maketitle + +\begin{abstract} +L'extension LaTeX \pkg{nicematrix} fournit de nouveaux environnements +similaires aux environnements classiques \verb|{array}| et \verb|{matrix}| mais avec des +fonctionnalités supplémentaires. Parmi ces fonctionnalités figurent la +possibilité de fixer la largeur des colonnes et de tracer des traits en +pointillés continus entre les cases du tableau. +\end{abstract} + +\vspace{1cm} +\section{Présentation} + +Cette extension peut être utilisée avec \verb|xelatex|, \verb|lualatex| et \verb|pdflatex| mais +aussi avec le cheminement classique \verb|latex|-\verb|dvips|-\verb|ps2pdf| (ou Adobe +Distiller). Deux ou trois compilations successives peuvent être nécessaires. +Cette extension nécessite et charge les extensions \pkg{expl3}, \pkg{l3keys2e}, +\pkg{xparse}, \pkg{array}, \pkg{amsmath} et \pkg{tikz} . Elle charge aussi la +bibliothèque Tikz \pkg{fit}. + + + +\medskip +\begin{savenotes} +\begin{minipage}{0.6\linewidth} +Cette extension fournit quelques outils supplémentaires pour dessiner des +matrices (au sens mathématique). Les principales caractéristiques sont les +suivantes : + +\textbullet\ lignes en pointillés continues\footnote{Si l'option de classe +\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\ 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}$ + + + + +\medskip +Une commande\verb|\NiceMatrixOptions| est fournie pour régler les options (la +portée des options fixées par cette commande est le groupe TeX courant). + + +\bigskip +\textbf{Un exemple d'utilisation pour les lignes en pointillés continues} + +\medskip +\begin{minipage}{10cm} +Considérons par exemple le code suivant qui utilise un environnement +\verb|{pmatrix}| de l'extension \pkg{amsmath}. + +\smallskip +\begin{BVerbatim} +$A = \begin{pmatrix} +1 & \cdots & \cdots & 1 \\ +0 & \ddots & & \vdots \\ +\vdots & \ddots & \ddots & \vdots \\ +0 & \cdots & 0 & 1 +\end{pmatrix}$ +\end{BVerbatim} + +\smallskip +Ce code compose la matrice $A$ représentée à droite. +\end{minipage}\hspace{1cm} +$A = \begin{pmatrix} +1 &\cdots &\cdots &1 \\ +0 &\ddots & &\vdots \\ +\vdots &\ddots &\ddots &\vdots \\ +0 &\cdots &0 &1 +\end{pmatrix}$ + + + + +\bigskip +\begin{scope} +\NiceMatrixOptions{transparent} +\begin{minipage}{10cm} +Maintenant, si nous utilisons l'extension \pkg{nicematrix} avec l'option +\verb|transparent|, le même code va donner le résultat ci-contre à droite. +\end{minipage}\hspace{1cm} +$A = \begin{pmatrix} +1 & \cdots & \cdots & 1 \\ +0 & \ddots & & \vdots \\ +\vdots & \ddots & \ddots & \vdots \\ +0 & \cdots & 0 & 1 +\end{pmatrix}$ +\end{scope} + + + + +\section{Les environnements de cette extension} + +L'extension \pkg{nicematrix} définit les nouveaux environnements suivants : + +\medskip +\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\} \\ +\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 +\pkg{amsmath} : \verb|{matrix}|, \verb|{pmatrix}|, \verb|{bmatrix}|, \verb|{Bmatrix}|, \verb|{vmatrix}| et +\verb|{Vmatrix}|. + + +\medskip +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|<{...}|, +\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}|. + + + +\section{Les lignes en pointillés continues} + +À l'intérieur des environnements de l'extension \pkg{nicematrix}, de nouvelles commandes sont définies : +\verb|\Ldots|, \verb|\Cdots|, \verb|\Vdots|, \verb|\Ddots|, and \verb|\Iddots|. Ces commandes sont conçues pour +être utilisées à la place de \verb|\dots|, \verb|\cdots|, \verb|\vdots|, \verb|\ddots| et \verb|\iddots|.\footnote{La + 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}.} + +\smallskip +Chacune de ces commandes doit être utilisée seule dans la case du tableau et elle trace une ligne en pointillés +entre les premières cases non vides\footnote{La définition précise de ce qui est considéré comme une «case + vide» est donnée plus loin (cf. p.~\pageref{empty-cells}).} situées de part et d'autre de la case courante. +Bien entendu, pour \verb|\Ldots| et \verb|\Cdots|, c'est une ligne horizontale ; pour \verb|\Vdots|, c'est une +ligne verticale et pour \verb|\Ddots| et \verb|\Iddots|, ce sont des lignes diagonales.\par\nobreak\bigskip + +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +a_1 & \Cdots & & & a_1 \\ +\Vdots & a_2 & \Cdots & & a_2 \\ + & \Vdots & \Ddots \\ +\\ +a_1 & a_2 & & & a_n \\ +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +a_1 & \Cdots & & & a_1 \\ +\Vdots & a_2 & \Cdots & & a_2 \\ + & \Vdots & \Ddots \\ +\\ +a_1 & a_2 & & & a_n \\ +\end{bNiceMatrix}$ + +\interitem +Pour représenter la matrice nulle, on peut choisir d'utiliser le codage +suivant :\par\nobreak \bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & 0 \\ +\Vdots & & \Vdots \\ +0 & \Cdots & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & 0 \\ +\Vdots & & \Vdots \\ +0 & \Cdots & 0 +\end{bNiceMatrix}$ + +\bigskip +On peut néanmoins souhaiter une matrice plus grande. Habituellement, dans un +tel cas, les utilisateurs de LaTeX ajoutent une nouvelle ligne et une nouvelle +colonne. Il est possible d'utiliser la même méthode avec \pkg{nicematrix} +:\par\nobreak \bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & \Cdots & 0 \\ +\Vdots & & & \Vdots \\ +\Vdots & & & \Vdots \\ +0 & \Cdots & \Cdots & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & \Cdots & 0 \\ +\Vdots & & & \Vdots \\ +\Vdots & & & \Vdots \\ +0 & \Cdots & \Cdots & 0 +\end{bNiceMatrix}$ + +\bigskip +Dans la première colonne de cet exemple, il y a deux instructions \verb|\Vdots| mais +une seule ligne en pointillés sera tracée (il n'y a pas d'objets qui se +superposent dans le fichier \textsc{pdf} résultant\footnote{Et il n'est pas +possible de tracer une ligne \verb|\Ldots| et une ligne \verb|\Cdots| entre les mêmes cases.}). + +Néanmoins, des calculs inutiles sont effectués par TeX avant qu'il ne détecte +que les deux instructions définissent la même ligne en pointillés. C'est +pourquoi l'extension \pkg{nicematrix} fournit des versions étoilées de +\verb|\Ldots|, \verb|\Cdots|, etc. : \verb|\Ldots*|, \verb|\Cdots*|, etc. Ces versions sont +simplement équivalentes à \verb|\hphantom{\ldots}|, \verb|\hphantom{\cdots}|, etc. +L'utilisateur devrait utiliser des versions étoilées à chaque fois qu'une +version classique (sans étoile) a déjà été utilisée pour la même ligne en pointillés.\par\nobreak + +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & ~emphase#\Cdots*@ & 0 \\ +\Vdots & & & \Vdots \\ +~emphase#\Vdots*@ & & & ~emphase#\Vdots*@ \\ +0 & \Cdots & ~emphase#\Cdots*@ & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & & 0 \\ +\Vdots & & & \\ + & & & \Vdots \\ +0 & & \Cdots & 0 +\end{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 +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & & 0 \\ +\Vdots & & & \\ + & & & \Vdots \\ +0 & & \Cdots & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & & 0 \\ +\Vdots & & & \\ + & & & \Vdots \\ +0 & & \Cdots & 0 +\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 +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & ~emphase#\Hspace*{1cm}@ & 0 \\ +\Vdots & & & \Vdots \\~emphase#[1cm]@ +0 & \Cdots & & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & \Hspace*{1cm} & 0 \\ +\Vdots & & & \Vdots \\[1cm] +0 & \Cdots & & 0 +\end{bNiceMatrix}$ + +\subsection{L'option nullify-dots} + +Considérons la matrice suivante qui a été composée classiquement avec l'environnement +\verb|{pmatrix}| de \pkg{amsmath}.\par\nobreak + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8cm] +$A = \begin{pmatrix} +a_0 & b \\ +a_1 & \\ +a_2 & \\ +a_3 & \\ +a_4 & \\ +a_5 & b +\end{pmatrix}$ +\end{BVerbatim} +$A = \begin{pmatrix} +a_0 & b \\ +a_1 & \\ +a_2 & \\ +a_3 & \\ +a_4 & \\ +a_5 & b +\end{pmatrix}$ + + +\bigskip +Si nous ajoutons des instructions \verb|\vdots| dans la seconde colonne, la +géométrie de la matrice est modifiée.\par\nobreak +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8cm] +$B = \begin{pmatrix} +a_0 & b \\ +a_1 & \vdots \\ +a_2 & \vdots \\ +a_3 & \vdots \\ +a_4 & \vdots \\ +a_5 & b +\end{pmatrix}$ +\end{BVerbatim} +$B = \begin{pmatrix} +a_0 & b \\ +a_1 & \vdots \\ +a_2 & \vdots \\ +a_3 & \vdots \\ +a_4 & \vdots \\ +a_5 & b +\end{pmatrix}$ + +\bigskip +Par défaut, avec \pkg{nicematrix}, si nous remplaçons \verb|{pmatrix}| par \verb|{pNiceMatrix}| et \verb|\vdots| par +\verb|\Vdots| (or \verb|\Vdots*| pour la rapidité de compilation), la géométrie de la matrice n'est pas +changée.\par\nobreak +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8cm] +$C = \begin{pNiceMatrix} +a_0 & b \\ +a_1 & \Vdots \\ +a_2 & \Vdots* \\ +a_3 & \Vdots* \\ +a_4 & \Vdots* \\ +a_5 & b +\end{pNiceMatrix}$ +\end{BVerbatim} +$C = \begin{pNiceMatrix} +a_0 & b \\ +a_1 & \Vdots \\ +a_2 & \Vdots* \\ +a_3 & \Vdots* \\ +a_4 & \Vdots* \\ +a_5 & b +\end{pNiceMatrix}$ + +\bigskip +On pourrait toutefois préférer la géométrie de la première matrice $A$ et +vouloir avoir la même géométrie avec une ligne en pointillés continue dans la +seconde colonne. C'est possible en utilisant l'option \verb|nullify-dots| (et une +seule instruction \verb|\Vdots| suffit).\par\nobreak +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8cm] +$D = \begin{pNiceMatrix}[~emphase#nullify-dots@] +a_0 & b \\ +a_1 & \Vdots \\ +a_2 & \\ +a_3 & \\ +a_4 & \\ +a_5 & b +\end{pNiceMatrix}$ +\end{BVerbatim} +$D = \begin{pNiceMatrix}[nullify-dots] +a_0 & b \\ +a_1 & \Vdots \\ +a_2 & \\ +a_3 & \\ +a_4 & \\ +a_5 & b +\end{pNiceMatrix}$ + +\medskip +L'option \verb|nullify-dots| «smashe» les instructions \verb|\Ldots| (et ses variantes) +verticalement mais aussi horizontalement. + +\medskip +{\bfseries Il doit n'y avoir aucun espace devant le crochet ouvrant (\verb|[|) des +options de l'environnement.} + +\subsection{La commande \textbackslash Hdotsfor} + +Certaines personnes utilisent habituellement la commande \verb|\hdotsfor| de +l'extension \pkg{amsmath} pour tracer des lignes en pointillés horizontales +dans une matrice. Dans les environnements de \pkg{nicematrix}, il convient +d'utiliser \verb|\Hdotsfor| à la place pour avoir les lignes en pointillés +similaires à toutes celles tracées par l'extension \pkg{nicematrix}. + +Comme avec les autres commandes de \pkg{nicematrix} (comme \verb|\Cdots|, \verb|\Ldots|, \verb|\Vdots|, etc.), la ligne +en pointillés tracée par \verb|\Hdotsfor| s'étend jusqu'au contenu des cases de part et d'autre. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=7cm] +$\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +1 & ~emphase#\Hdotsfor{3}@ & 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 \\ +\end{pNiceMatrix}$ + +\bigskip +Néanmoins, si ces cases sont vides, la ligne en pointillés s'étend seulement dans les cases spécifiées par +l'argument de \verb|\Hdotsfor| (par conception). + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=7cm] +$\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ + & ~emphase#\Hdotsfor{3}@ \\ +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 \\ +\end{pNiceMatrix}$ + +\bigskip +La commande \verb|\hdotsfor| de \pkg{amsmath} prend un argument optionnel (entre +crochets) qui est utilisé pour un réglage fin de l'espace entre deux points +consécutifs. Par homogénéité, \verb|\Hdotsfor| prend aussi un argument optionnel +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}. + +\subsection{Comment créer les lignes en pointillés de manière transparente} + +L'extension \pkg{nicematrix} fournit une option appelée \verb|transparent| qui permet d'utiliser du code existant +de manière transparente dans les environnements \verb|{matrix}|. Cette option peut être passée en option du +\verb|\usepackage| ou bien être fixée avec la commande \verb|\NiceMatrixOptions|. + +En fait, cette option est un alias pour la conjonction de deux options : \verb|renew-dots| et \verb|renew-matrix|. + +\smallskip + +\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|. + +\item L'option \verb|renew-matrix|\par\nobreak +Avec cette option, l'environnement \verb|{matrix}| est redéfini et +se comporte comme \verb|{NiceMatrix}| et il en est de même pour les cinq variantes. +\end{itemize} + +\bigskip +Par conséquent, avec l'option \verb|transparent|, un code classique donne directement le résultat fourni par +\pkg{nicematrix}.\par\nobreak +\bigskip +\begin{scope} +\NiceMatrixOptions{transparent} +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +~emphase#\NiceMatrixOptions{transparent}@ +\begin{pmatrix} +1 & \cdots & \cdots & 1 \\ +0 & \ddots & & \vdots \\ +\vdots & \ddots & \ddots & \vdots \\ +0 & \cdots & 0 & 1 +\end{pmatrix} +\end{BVerbatim} +$\begin{pmatrix} +1 & \cdots & \cdots & 1 \\ +0 & \ddots & & \vdots \\ +\vdots & \ddots & \ddots & \vdots \\ +0 & \cdots & 0 & 1 +\end{pmatrix}$ +\end{scope} + + + + +\section{Les nœuds Tikz créés par l'extension nicematrix} + +L'extension \pkg{nicematrix} crée un nœud Tikz pour chaque case du tableau considéré. Ces nœuds sont utilisés +pour tracer les lignes en pointillés entre les cases du tableau. Toutefois, l'utilisateur peut utiliser +directement ces nœuds. On commence par donner un nom au tableau (avec l'option \verb|name|). Cela étant fait, les +nœuds sont accessibles à travers les noms «\textsl{nom}-$i$-$j$» où \textsl{nom} est le nom donné au tableau et $i$ +et $j$ les numéros de ligne et de colonne de la case considérée. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +$\begin{pNiceMatrix}[name=~emphase#ma-matrice@] +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 \\ +\end{pNiceMatrix}$ +\tikz[remember picture,overlay] + \draw ~emphase#(ma-matrice-2-2)@ circle (2mm) ; +\end{BVerbatim} +$\begin{pNiceMatrix}[name=ma-matrice] +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 \\ +\end{pNiceMatrix}$ +\tikz[remember picture,overlay] + \draw (ma-matrice-2-2) circle (2mm) ; + +\medskip +Ne pas oublier les options \verb|remember picture| et \verb|overlay|. + +\bigskip +Dans l'exemple suivant, nous avons surligné toutes les cases de la matrice. +\begin{scope} +\tikzset{every node/.style = {fill = red!15, inner sep = 0pt}} +\[\begin{pNiceMatrix} +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] +\end{scope} + + +\bigskip +En fait, l'extension \pkg{nicematrix} peut créer des nœuds supplémentaires (\emph{extra nodes} en anglais). Ces +nouveaux nœuds sont créés si l'option \verb|create-extra-nodes| est utilisée. Il y a deux séries de nœuds +supplémentaires : les «nœuds moyens» (\emph{medium nodes} en anglais) et les «nœuds larges» (\emph{large nodes} en +anglais). + +\medskip +Les noms des «nœuds moyens» s'obtiennent en ajoutant le suffixe «\verb|-medium|» au nom des nœuds normaux. Dans +l'exemple suivant, on a surligné tous les «nœuds moyens». Nous considérons que cet exemple se suffit à lui-même +comme définition de ces nœuds. +\[\begin{pNiceMatrix}[ + create-extra-nodes, + code-after = {\begin{tikzpicture} + [every node/.style = {fill = red!15, + blend mode = multiply, + inner sep = -\pgflinewidth/2}, + name suffix = -medium] + \node [fit = (1-1)] {} ; + \node [fit = (1-2)] {} ; + \node [fit = (1-3)] {} ; + \node [fit = (2-1)] {} ; + \node [fit = (2-2)] {} ; + \node [fit = (2-3)] {} ; + \node [fit = (3-1)] {} ; + \node [fit = (3-2)] {} ; + \node [fit = (3-3)] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] + + +\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.} + +\[\begin{pNiceMatrix}[ + create-extra-nodes, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = -\pgflinewidth/2}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] + + +\medskip +Les «nœuds larges» de la première colonne et de la dernière colonne peuvent apparaître trop petits pour certains +usages. C'est pourquoi il est possible d'utiliser les options \verb|left-margin| et \verb|right-margin| pour +ajouter de l'espace des deux côtés du tableau et aussi de l'espace dans les «nœuds larges» de la première colonne et +de la dernière colonne. Dans l'exemple suivant, nous avons utilisé les options \verb|left-margin| et \verb|right-margin|. +\footnote{Les options \verb|left-margin| et \verb|right-margin| prennent des dimensions comme valeurs mais, si + aucune valeur n'est donnée, c'est la valeur par défaut qui est utilisée et elle est égale à \verb|\arraycolsep|.} +\[\begin{pNiceMatrix}[ + create-extra-nodes,left-margin,right-margin, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = -\pgflinewidth/2}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +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 +\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}[ + create-extra-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = -\pgflinewidth/2}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] + +\medskip +Dans le cas présent, si on veut un contrôle sur la hauteur des rangées, on peut ajouter un \verb|\strut| dans +chaque rangée du tableau. +\[\begin{pNiceMatrix}[ + create-extra-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = -\pgflinewidth/2}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +\strut a & a + b & a + b + c \\ +\strut a & a & a + b \\ +\strut a & a & a +\end{pNiceMatrix}\] + +\bigskip +On explique plus loin comment surligner les nœuds créés par Tikz (cf. p. \pageref{highlight}). + +\section{Le code-after} + +L'option \verb|code-after| peut être utilisée pour indiquer du code qui sera exécuté après la construction de la +matrice (et donc, en particulier, après la construction de tous les nœuds). + +Dans le \verb|code-after|, les nœuds Tikz doivent être désignés sous la forme $i$-$j$ (sans le préfixe +correspondant au nom de l'environnement). + +De plus, une commande spéciale, nommée \verb|\line| est disponible pour tracer directement des lignes en pointillés +entre les nœuds). + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=12cm] +$\begin{pNiceMatrix}[~emphase#code-after = {\line {1-1} {3-3}}@] +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 \\ +\end{pNiceMatrix}$ + + +\section{L'environnement \{NiceArray\}} +\label{NiceArray} + +L'environnement \verb|{NiceArray}| est similaire à l'environnement \verb|{array}|. Comme pour \verb|{array}|, +l'argument obligatoire est le préambule du tableau. Néanmoins, pour des raisons techniques, l'utilisateur doit +utiliser les lettres \verb|L|, \verb|C| et \verb|R|\footnote{Les types de colonnes \verb|L|, \verb|C| et \verb|R| + sont définis localement à l'intérieur de \verb|{NiceArray}| avec la commande \verb|\newcolumntype| de + \pkg{array}. Cette définition masque une éventuelle définition précédente. En fait, les types de colonnes + \verb|w| and \verb|W| sont également redéfinis.} au lieu de \verb|l|, \verb|c| et \verb|r|. + +Il est possible d'utiliser les constructions \verb|w{...}{...}|, \verb|W{...}{...}|, \verb+|+, \verb|>{...}|, +\verb|<{...}|, \verb|@{...}|, \verb|!{...}| et \verb|*{n}{...}| mais les lettres \verb|p|, \verb|m| et \verb|b| ne +doivent pas être employées.\footnote{Dans une commande \verb|\multicolumn|, on doit également utiliser les lettres + \verb|L|, \verb|C| et + \verb|R|.} + +\medskip +L'environnement \verb|{NiceArray}| accepte les options classiques \verb|t|, \verb|c| et \verb|b| de \verb|{array}| +mais aussi d'autres options définies par \pkg{nicematrix} (\verb|renew-dots|, \verb|columns-width|, etc.). + + +\vspace{1cm} +Un exemple avec un système linéaire (on a besoin de \verb|{NiceArray}| pour le trait vertical): + +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\left[\begin{NiceArray}{CCCC|C} +a_1 & ? & \Cdots & ? & ? \\ +0 & & \Ddots & \Vdots & \Vdots\\ +\Vdots & \Ddots & \Ddots & ? \\ +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 & ? \\ +\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| : + +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\left(\begin{NiceArray}{LCR} +a_{11} & \Cdots & a_{1n} \\ +a_{21} & & a_{2n} \\ +\Vdots & & \Vdots \\ +a_{n-1,1} & \Cdots & a_{n-1,n} \\ +\end{NiceArray}\right)$ +\end{BVerbatim} +$\left(\begin{NiceArray}{LCR} +a_{11} & \Cdots & a_{1n} \\ +a_{21} & & a_{2n} \\ +\Vdots & & \Vdots \\ +a_{n-1,1} & \Cdots & a_{n-1,n} \\ +\end{NiceArray}\right)$ + + + + +\section{L'environnement \{pNiceArrayC\} et ses variantes} +\label{pNiceArrayC} + +L'environnement \verb|{pNiceArrayC}| compose une matrice avec une colonne extérieure. + +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|. + +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. + +\bigskip + +\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}$ +\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 +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}$ + + + +\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 +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. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +$\begin{NiceArrayCwithDelims} + {\downarrow}{\downarrow}{CCC} +1 & 2 & 3 & L_1 \\ +4 & 5 & 6 & L_2 \\ +7 & 8 & 9 & L_3 +\end{NiceArrayCwithDelims}$ +\end{BVerbatim} +$\begin{NiceArrayCwithDelims} + {\downarrow}{\downarrow}{CCC} +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}$ + + + + +\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}). + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +~emphase#\hdottedline@ +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{pNiceMatrix} +\end{BVerbatim} +$\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +\hdottedline +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{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|:|». + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +\left(\begin{NiceArray}{CCCC~emphase#:@C} +1 & 2 & 3 & 4 & 5 \\ +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{NiceArray}\right) +\end{BVerbatim} +$\left(\begin{NiceArray}{CCCC:C} +1 & 2 & 3 & 4 & 5 \\ +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{NiceArray}\right)$ + + +\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}|). + +\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 ] +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{BVerbatim} +$\begin{pNiceArrayRC}{CCC:C}[ 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}$ + +\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}. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +\NiceMatrixOptions{letter-for-dotted-lines = V} +\left(\begin{NiceArray}{~emphase#C|C:CVC@} +1 & 2 & 3 & 4 \\ +5 & 6 & 7 & 8 \\ +9 & 10 & 11 & 12 +\end{NiceArray}\right) +\end{BVerbatim} +\begin{scope} +\NiceMatrixOptions{letter-for-dotted-lines = V} +$\left(\begin{NiceArray}{C|C:CVC} +1 & 2 & 3 & 4 \\ +5 & 6 & 7 & 8 \\ +9 & 10 & 11 & 12 +\end{NiceArray}\right)$ +\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}. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\left(\begin{NiceArray}{~emphase#wc{1cm}@CC} +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{NiceArray}\right)$ +\end{BVerbatim} +$\left(\begin{NiceArray}{wc{1cm}CC} +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{NiceArray}\right)$ + + +\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}). + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{pNiceMatrix}[~emphase#columns-width = 1cm@] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{pNiceMatrix}$ +\end{BVerbatim} +$\begin{pNiceMatrix}[columns-width = 1cm] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{pNiceMatrix}$ + +\medskip +Noter que l'espace inséré entre deux colonnes (égal à 2 \verb|\arraycolsep|) n'est pas supprimé (il est évidemment +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 + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{pNiceMatrix}[~emphase#columns-width = auto@] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{pNiceMatrix}$ +\end{BVerbatim} +$\begin{pNiceMatrix}[columns-width = auto] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{pNiceMatrix}$ + +\bigskip +Il est possible de fixer la largeur de toutes les colonnes de toutes les matrices dans une certaine portion de +document avec la commande \verb|\NiceMatrixOptions|.\par\nobreak +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +~emphase#\NiceMatrixOptions{columns-width=10mm}@ +$\begin{pNiceMatrix} +a & b \\ c & d \\ +\end{pNiceMatrix} += +\begin{pNiceMatrix} +1 & 1245 \\ 345 & 2 \\ +\end{pNiceMatrix}$ +\end{BVerbatim} +\begin{scope} +\NiceMatrixOptions{columns-width=10mm} +$\begin{pNiceMatrix} +a & b \\ +c & d \\ +\end{pNiceMatrix} += +\begin{pNiceMatrix} +1 & 1245 \\ +345 & 2 \\ +\end{pNiceMatrix}$ +\end{scope} + + +\bigskip +Mais il est aussi possible de fixer une zone dans laquelle toutes les matrices auront leurs colonnes de la même +largeur, égale à la largeur de la case la plus large de toutes les matrices de la zone. Cette construction +utilise l'environnement \verb|{NiceMatrixBlock}| avec l'option \verb|auto-columns-width|.\footnote{Pour le moment, + c'est le seul usage de l'environnement \verb|{NiceMatrixBlock}| mais il pourrait y en avoir davantage dans le futur.} + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ +$\begin{pNiceMatrix} +a & b \\ c & d \\ +\end{pNiceMatrix} += +\begin{pNiceMatrix} +1 & 1245 \\ 345 & 2 \\ +\end{pNiceMatrix}$ +~emphase#\end{NiceMatrixBlock}@ +\end{BVerbatim} +\begin{NiceMatrixBlock}[auto-columns-width] +$\begin{pNiceMatrix} +a & b \\ c & d \\ +\end{pNiceMatrix} += +\begin{pNiceMatrix} +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|. + + +\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 +\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}$ + + +\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}. + +\medskip +\begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] +$\begin{pNiceArrayRC}{~emphase#S@Cwc{1cm}C}[nullify-dots] +{C_1} & \Cdots & & C_n \\ +2.3 & 0 & \Cdots & 0 \\ +12.4 & \Vdots & & \Vdots \\ +1.45 \\ +7.2 & 0 & \Cdots & 0 +\end{pNiceArrayRC}$ +\end{BVerbatim} +$\begin{pNiceArrayRC}{SCwc{1cm}C}[nullify-dots] +{C_1} & \Cdots & & C_n \\ +2.3 & 0 & \Cdots & 0 \\ +12.4 & \Vdots & & \Vdots \\ +1.45 \\ +7.2 & 0 & \Cdots & 0 +\end{pNiceArrayRC}$ + + +\section{Remarques techniques} + +\subsection{Lignes diagonales} + +Par défaut, toutes les lignes diagonales\footnote{On parle des lignes créées par \verb|\Ddots| et non des lignes + créées par une commande \verb|\line| dans le \verb|code-after|.} d'un même tableau sont «parallélisées». Cela signifie que la première +diagonale est tracée et que, ensuite, les autres lignes sont tracées parallèlement à la première (par rotation +autour de l'extrémité la plus à gauche de la ligne). C'est pourquoi la position des instructions \verb|\Ddots| dans +un tableau peut avoir un effet marqué sur le résultat final. + +\medskip +Dans les exemples suivants, la première instruction \verb|\Ddots| est marquée en couleur : + +\medskip +\begin{scope} +\begin{minipage}{9.5cm} +Exemple avec parallélisation (comportement par défaut): +\begin{Verbatim} +$A = \begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +a+b & ~emphase#\Ddots@~ & & \Vdots \\ +\Vdots & \Ddots & & \\ +a+b & \Cdots & a+b & 1 +\end{pNiceMatrix}$ +\end{Verbatim} +\end{minipage} +$A = \begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +a+b & \Ddots & & \Vdots \\ +\Vdots & \Ddots & & \\ +a+b & \Cdots & a+b & 1 +\end{pNiceMatrix}$ + +\bigskip +\NiceMatrixOptions{parallelize-diags=true}% +\begin{minipage}{9.5cm} +\begin{Verbatim} +$A = \begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +a+b & & & \Vdots \\ +\Vdots & ~emphase#\Ddots@~ & \Ddots & \\ +a+b & \Cdots & a+b & 1 +\end{pNiceMatrix}$ +\end{Verbatim} +\end{minipage} +$A = \begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +a+b & & & \Vdots \\ +\Vdots & \Ddots & \Ddots & \\ +a+b & \Cdots & a+b & 1 +\end{pNiceMatrix}$ + +\bigskip +Il est possible de désactiver la parallélisation avec l'option +\verb|parallelize-diags| mise à \verb|false|: \par\nobreak + +\medskip +\NiceMatrixOptions{parallelize-diags=false}% +\begin{minipage}{9.5cm} +Le même exemple sans parallélisation : +\end{minipage} +$A = \begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +a+b & \Ddots & & \Vdots \\ +\Vdots & \Ddots & & \\ +a+b & \Cdots & a+b & 1 +\end{pNiceMatrix}$ + + +\end{scope} + +\subsection{Les cases «vides»} + +\label{empty-cells} +Une instruction comme +\verb|\Ldots|, \verb|\Cdots|, etc. essaye de déterminer la première case vide de part et d'autre de la case +considérée. Néanmoins, une case vide n'est pas nécessairement sans contenu dans le codage TeX (c'est-à-dire sans +aucun token entre les deux esperluettes~\verb|&|). En effet, une case dont le contenu est \verb|\hspace*{1cm}| peut +être considérée comme vide. + +\interitem +Pour \pkg{nicematrix}, les règles précises sont les suivantes : + +\begin{itemize} +\item Une case implicite est vide. Par exemple, dans la matrice suivante + +\begin{Verbatim} +\begin{pmatrix} +a & b \\ +c \\ +\end{pmatrix} +\end{Verbatim} + +la dernière case (deuxième rangée et deuxième colonne) est vide. + +\medskip +\item Chaque case avec un rendu par TeX de largeur inférieure à 0.5~pt est vide. + +\medskip +\item Une case qui contient une commande \verb|\Ldots|, \verb|\Cdots|, \verb|\Vdots|, \verb|\Ddots| +ou \verb|\Iddots| (ou une des versions étoilées) est vide. On rappelle que ces commandes doivent être employées seules +dans une case. + + +\medskip +\item Une case avec une commande \verb|\Hspace| (ou \verb|\Hspace*|) est vide. Cette commande +\verb|\Hspace| est une commande définie par l'extension \pkg{nicematrix} avec la même signification +que \verb|\hspace| excepté que la case où cette commande est utilisée est considérée comme vide. +Cette commande peut être utilisée pour fixer la largeur des colonnes sans interférer avec le tracé des lignes en +pointillés par \pkg{nicematrix}. + +\end{itemize} + + +\subsection{L'option exterior-arraycolsep} + +L'environnement \verb|{array}| insère un espace horizontal égal à \verb|\arraycolsep| +avant et après chaque colonne. En particulier, il y a un espace égal à +\verb|\arraycolsep| avant et après le tableau. Cette caractéristique de l'environnement \verb|{array}| +n'était probablement pas une bonne idée.\footnote{Dans la documentation de +\verb|{amsmath}|, on peut lire : {\itshape The extra space of \verb|\arraycolsep| that +\pkg{array} adds on each side is a waste so we remove it [in \verb|{matrix}|] +(perhaps we should instead remove it from array in general, but that's a +harder task).} Il est possible de supprimer les espaces pour un environnement \verb|{array}| donné par une +construction du type \verb|\begin{array}{@{}ccccc@{}}|.} + +L'environnement \verb|{matrix}| et ses variantes (\verb|{pmatrix}|, \verb|{vmatrix}|, etc.) +de \pkg{amsmath} prefèrent supprimer ces espaces avec des instructions explicites +\verb|\hskip -\arraycolsep| et \verb|{NiceArray}| agit de même. + +Néanmoins, l'utilisateur peut changer ce comportement avec l'option +\verb|exterior-arraycolsep| de la commande \verb|\NiceMatrixOptions|. Avec cette option, +\verb|{NiceArray}| va insérer le même espacement horizontal que \verb|{array}|. + +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|. + + +\subsection{L'option de classe draft} + +L'extension \pkg{nicematrix} est relativement lente pour tracer les lignes en pointillés +(créées par \verb|\Cdots|, \verb|\Ldots|, \verb|\Ddots|, etc. mais aussi par le spécificateur +«\verb|:|»).\footnote{La principale raison est que nous voulons des lignes + en pointillés avec des points ronds et non carrés. Pour atteindre ce + but, il a fallu construire notre propre système de lignes en pointillés.} + + +C'est pourquoi, avec l'option de classe \verb|draft|, les lignes en pointillés ne sont pas tracées, +pour accélérer la compilation. + + +\subsection{Un problème technique ave l'argument de \textbackslash\textbackslash} + + +Pour des raisons techniques, si vous utilisez l'argument optionnel de la commande \verb|\\|, +l'espace vertical sera aussi ajouté au nœud («normal») correspondant à la case précédente. + + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] + \begin{pNiceMatrix} + a & \frac AB \\~emphase#[2mm]@ + b & c + \end{pNiceMatrix} +\end{BVerbatim} +$\begin{pNiceMatrix}[ + code-after = {\tikz \node [inner sep = 0pt, + fill = red!15, + blend mode = multiply, + fit = (1-2) ] {} ; } ] +a & \frac AB \\[2mm] +b & c +\end{pNiceMatrix}$ + +\bigskip +Il y a deux solutions pour résoudre ce problème. La première solution est d'utiliser une commande TeX pour insérer + l'espace entre les deux rangées. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] + \begin{pNiceMatrix} + a & \frac AB \\ + ~emphase#\noalign{\kern2mm}@ + b & c + \end{pNiceMatrix} +\end{BVerbatim} +$\begin{pNiceMatrix}[ + code-after = {\tikz \node [inner sep = 0pt, + fill = red!15, + blend mode = multiply, + fit = (1-2) ] {} ; } ] +a & \frac AB \\ +\noalign{\kern2mm} +b & c +\end{pNiceMatrix}$ + + +\bigskip +L'autre solution est d'utiliser la commande \verb|\multicolumn| dans la case précédente : + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] + \begin{pNiceMatrix} + a & ~emphase#\multicolumn1C{\frac AB}@ \\[2mm] + b & c + \end{pNiceMatrix} +\end{BVerbatim} +$\begin{pNiceMatrix}[ + code-after = {\tikz \node [inner sep = 0pt, + fill = red!15, + blend mode = multiply, + fit = (1-2) ] {} ; } ] +a & \multicolumn1C{\frac AB} \\[2mm] +b & c +\end{pNiceMatrix}$ + + + +\section{Exemples} + +\subsection{Lignes en pointillés} + +\medskip +Une matrice tridiagonale : + +\bigskip +\begin{BVerbatim}[baseline=c] +$\begin{pNiceMatrix}[nullify-dots] +a & b & 0 & & \Cdots & 0 \\ +b & a & b & \Ddots & & \Vdots \\ +0 & b & a & \Ddots & & \\ + & \Ddots & \Ddots & \Ddots & & 0 \\ +\Vdots & & & & & b \\ +0 & \Cdots & & 0 & b & a +\end{pNiceMatrix}$ +\end{BVerbatim} +\hspace{1.5cm} +$\begin{pNiceMatrix}[nullify-dots] +a & b & 0 & & \Cdots & 0 \\ +b & a & b & \Ddots & & \Vdots \\ +0 & b & a & \Ddots & & \\ + & \Ddots & \Ddots & \Ddots & & 0 \\ +\Vdots & & & & & b \\ +0 & \Cdots & & 0 & b & a +\end{pNiceMatrix}$ + +\vspace{2cm} + +Une matrice de permutation : + +\bigskip +\begin{BVerbatim}[baseline=c] +$\begin{pNiceMatrix} +0 & 1 & 0 & & \Cdots & 0 \\ +\Vdots & & & \Ddots & & \Vdots \\ + & & & \Ddots & & \\ + & & & \Ddots & & 0 \\ +0 & 0 & & & & 1 \\ +1 & 0 & & \Cdots & & 0 +\end{pNiceMatrix}$ +\end{BVerbatim} +\hspace{2.5cm} +$\begin{pNiceMatrix} +0 & 1 & 0 & & \Cdots & 0 \\ +\Vdots & & & \Ddots & & \Vdots \\ + & & & \Ddots & & \\ + & & & \Ddots & & 0 \\ +0 & 0 & & & & 1 \\ +1 & 0 & & \Cdots & & 0 +\end{pNiceMatrix}$ + +\vspace{2cm} + +Un exemple avec \verb|\Iddots|: \par\nobreak +\bigskip +\begin{BVerbatim}[baseline=c] +$\begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +\Vdots & & & 0 \\ + & ~emphase#\Iddots@ & ~emphase#\Iddots@ & \Vdots \\ +1 & 0 & \Cdots & 0 +\end{pNiceMatrix}$ +\end{BVerbatim} +\hspace{4cm} +$\begin{pNiceMatrix} +1 & \Cdots & & 1 \\ +\Vdots & & & 0 \\ + & \Iddots & \Iddots & \Vdots \\ +1 & 0 & \Cdots & 0 +\end{pNiceMatrix}$ + + +\vspace{2cm} +Un exemple avec \verb|\multicolumn|:\par\nobreak +\bigskip +\begin{BVerbatim} +\begin{pNiceMatrix}[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{BVerbatim} + +\bigskip +\[\begin{pNiceMatrix}[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}\] + +\vspace{2cm} +Un exemple avec \verb|\Hdotsfor|:\par\nobreak +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +\begin{pNiceMatrix}[nullify-dots] +0 & 1 & 1 & 1 & 1 & 0 \\ +0 & 1 & 1 & 1 & 1 & 0 \\ +\Vdots & ~emphase#\Hdotsfor{4}@ & \Vdots \\ + & ~emphase#\Hdotsfor{4}@ & \\ + & ~emphase#\Hdotsfor{4}@ & \\ + & ~emphase#\Hdotsfor{4}@ & \\ +0 & 1 & 1 & 1 & 1 & 0 +\end{pNiceMatrix} +\end{BVerbatim} +$\begin{pNiceMatrix}[nullify-dots] +0 & 1 & 1 & 1 & 1 & 0 \\ +0 & 1 & 1 & 1 & 1 & 0 \\ +\Vdots & \Hdotsfor{4} & \Vdots \\ + & \Hdotsfor{4} & \\ + & \Hdotsfor{4} & \\ + & \Hdotsfor{4} & \\ +0 & 1 & 1 & 1 & 1 & 0 +\end{pNiceMatrix}$ + +\vspace{2cm} +Un exemple pour le résultant de deux polynômes : +\par\nobreak +\bigskip +\begin{BVerbatim} +\setlength{\extrarowheight}{1mm} +\[\begin{NiceArray}{|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}\] +\end{BVerbatim} + +\bigskip + +\begin{scope} +\setlength{\extrarowheight}{1mm} +\[\begin{NiceArray}{|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}\] +\end{scope} + + +\subsection{Largeur des colonnes} + +\medskip +Dans l'exemple suivant, nous utilisons +\verb|{NiceMatrixBlock}| avec l'option \verb|auto-columns-width| parce que +nous voulons la même largeur (automatique) pour toutes les colonnes. + +\bigskip +\begin{BVerbatim} +~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ +\NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle} +\setlength{\extrarowheight}{1mm} +\quad $\begin{pNiceArrayC}{CCCC:C} +1&1&1&1&1&\\ +2&4&8&16&9&\\ +3&9&27&81&36&\\ +4&16&64&256&100&\\ +\end{pNiceArrayC}$ +... +~emphase#\end{NiceMatrixBlock}@ +\end{BVerbatim} + +\bigskip + +\begin{multicols}{2} +\begin{NiceMatrixBlock}[auto-columns-width] +\NiceMatrixOptions{code-for-last-col = \color{blue}\scriptstyle} +\setlength{\extrarowheight}{1mm} + +\quad $\begin{pNiceArrayC}{CCCC:C} +1&1&1&1&1&\\ +2&4&8&16&9&\\ +3&9&27&81&36&\\ +4&16&64&256&100&\\ +\end{pNiceArrayC}$ + +\medskip + +\quad $\begin{pNiceArrayC}{CCCC:C} +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}$ + +\medskip + +\quad $\begin{pNiceArrayC}{CCCC:C} +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}$ + +\medskip + +\quad $\begin{pNiceArrayC}{CCCC:C} +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}$ + +\medskip + +\quad $\begin{pNiceArrayC}{CCCC:C} +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}$ + +\medskip + +\quad $\begin{pNiceArrayC}{CCCC:C} +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}$ +\end{NiceMatrixBlock} +\end{multicols} + + + + +\subsection{Comment surligner les cases} + +\label{highlight} + +\medskip +Pour mettre en évidence une case, il est possible de «dessiner» l'un des nœuds (le «nœud normal», le «nœud +moyen» ou le «nœud large»). Dans l'exemple suivant, on utilise les «nœuds larges» de la diagonale de la matrice +(avec la clé de Tikz «\verb|name suffix|», il est facile d'utiliser les «nœuds larges»). Pour avoir la continuité +des lignes, on doit fixer \verb|inner sep = -\pgflinewidth/2|. + +\begin{Verbatim} +$\left(\,\begin{NiceArray}{>{\strut}CCCC}% + [create-extra-nodes,left-margin,right-margin, + code-after = {\begin{tikzpicture} + [~emphase#name suffix = -large@, + every node/.style = {draw, + ~emphase#inner sep = -\pgflinewidth/2@}] + \node [fit = (1-1)] {} ; + \node [fit = (2-2)] {} ; + \node [fit = (3-3)] {} ; + \node [fit = (4-4)] {} ; + \end{tikzpicture}}] +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{Verbatim} + + +\[\left(\,\begin{NiceArray}{>{\strut}CCCC}[ + create-extra-nodes,left-margin,right-margin, + code-after = {\begin{tikzpicture}[name suffix = -large, + every node/.style = {draw, + inner sep = -\pgflinewidth/2}] + \node [fit = (1-1)] {} ; + \node [fit = (2-2)] {} ; + \node [fit = (3-3)] {} ; + \node [fit = (4-4)] {} ; + \end{tikzpicture}}] +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)\] + + +\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. + + +\tikzset{highlight/.style={rectangle, + fill=red!15, + blend mode = multiply, + rounded corners = 0.5 mm, + inner sep=1pt}} + +\medskip +\begin{Verbatim} +\tikzset{highlight/.style={rectangle, + fill=red!15, + ~emphase#blend mode = multiply@, + rounded corners = 0.5 mm, + inner sep=1pt}} + +$\begin{bNiceMatrix}[~emphase#code-after = {\tikz \node[highlight, fit = (2-1) (2-3)] {} ;}@] +0 & \Cdots & 0 \\ +1 & \Cdots & 1 \\ +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 \\ +\end{bNiceMatrix}\] + + +\bigskip +Ce code échoue avec +\verb|latex|-\verb|dvips|-\verb|ps2pdf| parce que Tikz pour \verb|dvips|, pour le moment, ne prend pas en charge +les \emph{blend modes}. Néanmoins, le code suivant, dans le préambule du document LaTeX, devrait activer les \emph{blend modes} +pour ce mode de compilation. + + +\begin{scope} \small +\verb|\ExplSyntaxOn| + +\verb|\makeatletter| + +\verb|\tl_set:Nn \l_tmpa_tl {pgfsys-dvips.def}| + +\verb|\tl_if_eq:NNT \l_tmpa_tl \pgfsysdriver| + +\verb| {\cs_set:Npn\pgfsys@blend@mode#1{\special{ps:~/\tl_upper_case:n #1~.setblendmode}}}| + +\verb|\makeatother| + +\verb|\ExplSyntaxOff| +\end{scope} + +\vspace{1cm} +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\\ +a & a & a + b & L_2 \\ +a & a & a & L_3 +\end{pNiceArrayC}$ +\end{Verbatim} + +\[\begin{pNiceArrayC}{CCC} +a & a + b & a + b + c & L_1\\ +a & a & a + b & L_2 \\ +a & a & a & L_3 +\end{pNiceArrayC}\] + +\bigskip +Si on veut surligner chaque rangée de la matrice, on peut utiliser la technique précédente trois fois. + +\begin{Verbatim} +\tikzset{mes-options/.style={remember picture, + overlay, + name prefix = exemple-, + every node/.style = {fill = red!15, + blend mode = multiply, + inner sep = 0pt}}} +\end{Verbatim} + + +\tikzset{mes-options/.style={remember picture, + overlay, + name prefix = exemple-, + every node/.style = {fill = red!15, + blend mode = multiply, + inner sep = 0pt}}} + + +\begin{Verbatim} +\begin{tikzpicture}[mes-options] +\node [fit = (1-1) (1-3)] {} ; +\node [fit = (2-1) (2-3)] {} ; +\node [fit = (3-1) (3-3)] {} ; +\end{tikzpicture} +\end{Verbatim} + +\medskip +On obtient la matrice suivante. + +\[\begin{pNiceArrayC}{CCC}[ + create-extra-nodes, + code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15, + blend mode = multiply, + inner sep = 0pt}] + \node [fit = (1-1) (1-3)] {} ; + \node [fit = (2-1) (2-3)] {} ; + \node [fit = (3-1) (3-3)] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c & L_1\\ +a & a & a + b & L_2 \\ +a & a & a & L_3 +\end{pNiceArrayC}\] + +\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». + +\begin{Verbatim} +\begin{tikzpicture}[mes-options, ~emphase#name suffix = -medium@] +\node [fit = (1-1) (1-3)] {} ; +\node [fit = (2-1) (2-3)] {} ; +\node [fit = (3-1) (3-3)] {} ; +\end{tikzpicture} +\end{Verbatim} + +\medskip +On obtient la matrice suivante. + +\[\begin{pNiceArrayC}{CCC}[ + create-extra-nodes, + code-after = {\begin{tikzpicture}[every node/.style = {fill = red!15, + blend mode = multiply, + inner sep = 0pt}, + name suffix = -medium] + \node [fit = (1-1) (1-3)] {} ; + \node [fit = (2-1) (2-3)] {} ; + \node [fit = (3-1) (3-3)] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c & L_1\\ +a & a & a + b & L_2 \\ +a & a & a & L_3 +\end{pNiceArrayC}\] + + +\vspace{1cm} + +Dans l'exemple suivant, on utilise les «nœuds larges» pour surligner une zone de la matrice.\par\nobreak +\begin{Verbatim} +\left(\,\begin{NiceArray}{>{\strut}CCCC}% + [create-extra-nodes,left-margin,right-margin, + code-after = {\tikz \path [~emphase#name suffix = -large@, + fill = red!15, + blend mode = multiply] + (1-1.north west) + |- (2-2.north west) + |- (3-3.north west) + |- (4-4.north west) + |- (4-4.south east) + |- (1-1.north west) ; } ] +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{Verbatim} + +\[\left(\,\begin{NiceArray}{>{\strut}CCCC}[ + create-extra-nodes,left-margin,right-margin, + code-after = {\tikz \path [name suffix = -large, + fill = red!15, + blend mode = multiply] + (1-1.north west) + |- (2-2.north west) + |- (3-3.north west) + |- (4-4.north west) + |- (4-4.south east) + |- (1-1.north west) ; } ] +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)\] + + +\subsection{Matrices par blocs} + +\medskip +Dans l'exemple suivant, on utilise les «nœuds larges» pour construire une matrice par blocs (les lignes en tiretés +ont été tracées avec \pkg{arydshln}). +\begin{Verbatim} +\NiceMatrixOptions{letter-for-dotted-lines = V} +\left(\begin{NiceArray}{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} \\ + & & a_{23} & a_{24} \\ +\hdashline +a_{31} & a_{32} & a_{33} & a_{34} \\ +a_{41} & a_{42} & a_{34} & a_{44} +\end{NiceArray}\right) +\end{Verbatim} + + +\begin{scope} +\NiceMatrixOptions{letter-for-dotted-lines = V} +\[D = \left(\begin{NiceArray}{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} \\ + & & a_{23} & a_{24} \\ +\hdashline +a_{31} & a_{32} & a_{33} & a_{34} \\ +a_{41} & a_{42} & a_{34} & a_{44} +\end{NiceArray}\right)\] +\end{scope} + + +\end{document} diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf index d93901c70fe..c52a61126fd 100644 Binary files a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf and b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf differ diff --git a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx index 095ec34bfdc..90140a6ec28 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.2.1} -\def\myfiledate{2019/07/02} +\def\myfileversion{2.3} +\def\myfiledate{2019/07/18} % % %<*batchfile> @@ -49,8 +49,9 @@ version 2005/12/01 or later. \documentclass[dvipsnames]{l3doc}% dvipsnames is for xcolor (loaded by Tikz, loaded by nicematrix) \VerbatimFootnotes \usepackage{xltxtra} -\usepackage{geometry} +\usepackage[xetex]{geometry} \geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}} +\usepackage{siunitx} \usepackage{nicematrix} \NewDocumentEnvironment {scope} {} {} {} \def\interitem{\vskip 7mm plus 2 mm minus 3mm} @@ -66,7 +67,7 @@ version 2005/12/01 or later. \usepackage{footnotehyper} \parindent 0pt -\DisableCrossrefs +\EnableCrossrefs \begin{document} \DocInput{nicematrix.dtx} \end{document} @@ -112,8 +113,7 @@ version 2005/12/01 or later. % \end{minipage} % \end{savenotes} % \hspace{1.4cm} -% $\vcenter{ -% \begin{bNiceArrayRC}{CCCC}[code-for-last-col=\color{blue}\scriptstyle, +% $\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 \\ @@ -122,7 +122,7 @@ version 2005/12/01 or later. % \Vdots & \Vdots & \Ddots & \Vdots & \Vdots \\ % a_{n1} & a_{n2} & \Cdots & a_{nn} & L_n % \end{bNiceArrayRC} -% }$ +% $ % % \medskip % A command |\NiceMatrixOptions| is provided to fix the options (the scope of @@ -204,7 +204,7 @@ 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 -% \verb|w{...}{...}|, \verb|W{...}{...}|, \verb+|+, |>{...}|, |<{...}|, +% |w{...}{...}|, |W{...}{...}|, "|", |>{...}|, |<{...}|, % |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, |m| and |b| should not % be used. See p.~\pageref{NiceArray} the section relating to |{NiceArray}|. % @@ -371,7 +371,7 @@ version 2005/12/01 or later. % \subsection{The option nullify-dots} % % Consider the following matrix composed classicaly with the environment -% |{pmatrix}|.\par\nobreak +% |{pmatrix}| of \pkg{amsmath}.\par\nobreak % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=8cm] @@ -474,7 +474,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 Hdotsfor} +% \subsection{The command \textbackslash Hdotsfor} % % Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to % draw horizontal dotted lines in a matrix. In the environments of @@ -769,7 +769,7 @@ version 2005/12/01 or later. % \end{pNiceMatrix}\] % % \bigskip -% We explain below how to fill the nodes created by \pkg{nicematrix}. +% We explain below how to fill the nodes created by \pkg{nicematrix} (cf. p. \pageref{highlight}). % % \section{The code-after} % @@ -808,10 +808,10 @@ version 2005/12/01 or later. % |{NiceArray}| with |\newcolumntype| of \pkg{array}. This definition overrides % an eventual previous definition. In fact, the column types |w| and |W| are % also redefined.} instead of |l|, |c| and |r|. It's possible -% to use the constructions \verb|w{...}{...}|, \verb|W{...}{...}|, \verb+|+, -% |>{...}|, |<{...}|, |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, -% |m| and |b| should not be used.\footnote{In a command |\multicolumn|, one -% should also use the letters |L|, |C|, |R|.} +% to use the constructions |w{...}{...}|, |W{...}{...}|, "|", |>{...}|, +% |<{...}|, |@{...}|, |!{...}| and |*{n}{...}| but the letters |p|, |m| and |b| +% should not be used.\footnote{In a command |\multicolumn|, one should also use +% the letters |L|, |C|, |R|.} % % \medskip % The environment |{NiceArray}| accepts the classical options |t|, |c| and |b| @@ -899,6 +899,28 @@ version 2005/12/01 or later. % % % \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 \\ +% \hline +% S_1 & S_2 & S_3 +% \end{pNiceArrayC}$ +% +% \bigskip % In fact, the environment |{pNiceArrayC}| and its variants are based upon a % more general environment, called |{NiceArrayCwithDelims}|. The first two % mandatory arguments of this environment are the left and right delimiters used @@ -966,35 +988,11 @@ version 2005/12/01 or later. % 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). % -% \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}$ % % % \bigskip % If we want to write a linear system, we can use the following code, with a -% preamble \verb+CCC|C+: +% preamble "CCC|C":\par\nobreak % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=11cm] @@ -1006,65 +1004,54 @@ version 2005/12/01 or later. % \end{pNiceArrayRC}$ % \end{BVerbatim} % $\begin{pNiceArrayRC}{CCC|C} -% C_1 & \Cdots & C_n \\ +% 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 -% The resultat may seem disappointing. It's possible to suppress the vertical -% rule in the first row with the command |\multicolumn| in order to -% ``reconstruct'' the cell. +% 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 -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{pNiceArrayRC}{CCC|C} -% C_1 & \Cdots & ~emphase#\multicolumn{1}{C}{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 & \multicolumn{1}{C}{C_n} \\ -% a_{11} & \Cdots & a_{1n} & b_1 \\ -% \Vdots & & \Vdots & \Vdots \\ -% a_{n1} & \Cdots & a_{nn} & b_n -% \end{pNiceArrayRC}$ -% % \bigskip -% On the other side, we may remark that an horizontal line (with |\hline| or -% |\hdashline| of \pkg{arydshln}) doesn't extend in the ``exterior column'' of -% an environment like |{pNiceArrayC}| or |{pNiceArrayRC}|. +% 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{pNiceArrayC}{CCC} -% a_{11} & \Cdots & a_{1n} & L_1 \\ -% \Vdots & & \Vdots & \Vdots \\ -% a_{n1} & \Cdots & a_{nn} & L_n \\ -% ~emphase#\hdashline@ -% S_1 & \Cdots & S_n \\ -% \end{pNiceArrayC}$ +% $\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{pNiceArrayC}{CCC} -% a_{11} & \Cdots & a_{1n} & L_1 \\ -% \Vdots & & \Vdots & \Vdots \\ -% a_{n1} & \Cdots & a_{nn} & L_n \\ -% \hdashline -% S_1 & \Cdots & S_n \\ -% \end{pNiceArrayC}$ -% +% $\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| which is a counterpart of the classical commands -% |\hline| and |\hdashline| (of \pkg{arydshln}). +% the command |\hdottedline| (provided by \pkg{nicematrix}) which is a +% counterpart of the classical commands |\hline| and |\hdashline| (of +% \pkg{arydshln}). % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] @@ -1196,7 +1183,8 @@ version 2005/12/01 or later. % % \medskip % Note that the space inserted between two columns (equal to 2 |\arraycolsep|) -% is not suppressed. +% is not suppressed (of course, it's possible to suppress this space by setting +% |\arraycolsep| equal to $0$~pt). % % \bigskip % It's possible to give the value |auto| to the option |columns-width|: all the @@ -1274,8 +1262,57 @@ 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|. +% +% \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 +% \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}$ +% +% +% +% \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}. % +% +% \medskip +% \begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] +% $\begin{pNiceArrayRC}{~emphase#S@Cwc{1cm}C}[nullify-dots] +% {C_1} & \Cdots & & C_n \\ +% 2.3 & 0 & \Cdots & 0 \\ +% 12.4 & \Vdots & & \Vdots \\ +% 1.45 \\ +% 7.2 & 0 & \Cdots & 0 +% \end{pNiceArrayRC}$ +% \end{BVerbatim} +% $\begin{pNiceArrayRC}{SCwc{1cm}C}[nullify-dots] +% {C_1} & \Cdots & & C_n \\ +% 2.3 & 0 & \Cdots & 0 \\ +% 12.4 & \Vdots & & \Vdots \\ +% 1.45 \\ +% 7.2 & 0 & \Cdots & 0 +% \end{pNiceArrayRC}$ +% +% % \section{Technical remarks} % % \subsection{Diagonal lines} @@ -1353,7 +1390,7 @@ version 2005/12/01 or later. % % \label{empty-cells} % An instruction like |\Ldots|, |\Cdots|, etc. tries to determine the first -% non-empty cells on both sides. However, a empty cell is not necessarily a cell +% non-empty cells on both sides. However, an empty cell is not necessarily a cell % with no TeX content (that is to say a cell with no token between the two % ampersands~|&|). Indeed, a cell with contents |\hspace*{1cm}| may be % considered as empty. @@ -1493,29 +1530,6 @@ version 2005/12/01 or later. % \end{pNiceMatrix}$ % % -% \subsection{Compatibility with the extension dcolumn} -% -% \label{dcolumn} -% If we want to make \pkg{nicematrix} compatible with \pkg{dcolumn}, it's -% necessary to patch the commands |\DC@endcentre| and |\DC@endright| as follow. -% -% \bigskip -% -% \begin{scope} -% \fvset{commandchars=\~\#\+} -% \begin{Verbatim} -% \def\DC@endcentre{$\egroup -% \ifdim \wd\z@>\wd\tw@ -% \setbox\tw@=\hbox to\wd\z@{\unhbox\tw@\hfill}% -% \else -% \setbox\z@=\hbox to\wd\tw@{\hfill\unhbox\z@}\fi -% ~emphase#\@@_Cell:+\box\z@\box\tw@ ~emphase#\@@_end_Cell:+} -% \end{Verbatim} -% -% \begin{Verbatim} -% \def\DC@endright{$\hfil\egroup ~emphase#\@@_Cell:+\box\z@\box\tw@ ~emphase#\@@_end_Cell:+} -% \end{Verbatim} -% \end{scope} % % % @@ -1754,11 +1768,15 @@ version 2005/12/01 or later. % % \subsection{How to highlight cells of the matrix} % +% \label{highlight} % \medskip -% In order to highlight a cell of a matrix, it's possible to ``draw'' one of the correspond nodes (the ``normal -% node'', the ``medium node'' or the ``large node''). In the following example, we use the ``large nodes'' of the -% diagonal of the matrix (with the Tikz key ``|name suffix|'', it's easy to use the ``large nodes''). In order to -% have the continuity of the lines, we have to set |inner sep = -\pgflinewidth/2|. +% In order to highlight a cell of a matrix, it's possible to ``draw'' one of the +% correspondant nodes (the ``normal node'', the ``medium node'' or the ``large +% node''). In the following example, we use the ``large nodes'' of the diagonal +% of the matrix (with the Tikz key ``|name suffix|'', it's easy to use the +% ``large nodes''). +% +% In order to have the continuity of the lines, we have to set |inner sep = -\pgflinewidth/2|. % % \begin{Verbatim} % $\left(\,\begin{NiceArray}{>{\strut}CCCC}% @@ -2043,8 +2061,7 @@ version 2005/12/01 or later. % % \section{Implementation} % -% By default, the package \pkg{nicematrix} doesn't patch any existing code.\footnote{If we want \pkg{nicematrix} -% compatible with \pkg{dcolumn}, we have to patch \pkg{dcolumn}: cf. p.~\pageref{dcolumn}.} +% 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 @@ -2095,6 +2112,8 @@ version 2005/12/01 or later. \ProcessOptions \relax % \end{macrocode} % +% +% % The command for the treatment of the options of |\usepackage| is at the end of % this package for technical reasons. % @@ -2106,6 +2125,29 @@ version 2005/12/01 or later. \RequirePackage { xparse } [ 2018-10-17 ] % \end{macrocode} % +% \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 \@@_msg_new:nn { \msg_new:nnn { nicematrix } } +% \end{macrocode} +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_msg_new:nnn { \msg_new:nnnn { nicematrix } } +% \end{macrocode} +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_msg_redirect_name:nn + { \msg_redirect_name:nnn { nicematrix } } +% \end{macrocode} +% +% % \subsection{Technical definitions} % % We test whether the current class is \cls{revtex4-1} or \cls{revtex4-2}. @@ -2119,30 +2161,43 @@ version 2005/12/01 or later. { } % \end{macrocode} % -% -% \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 } } +\@@_msg_new:nn { Draft~mode } + { The~compilation~is~in~draft~mode:~the~dotted~lines~won't~be~drawn. } % \end{macrocode} % -% \begin{macrocode} -\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 } } +\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} -\cs_new_protected:Npn \@@_msg_redirect_name:nn - { \msg_redirect_name:nnn { nicematrix } } +\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 -% First, we define a command |\iddots| similar to |\ddots| ($\ddots$) but with dots going forward ($\iddots$). We +% 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. % @@ -2150,12 +2205,13 @@ version 2005/12/01 or later. \ProvideDocumentCommand \iddots { } { \mathinner - { \mkern 1 mu - \raise \p@ \hbox { . } + { + \mkern 1 mu + \raise \p@ \hbox:n { . } \mkern 2 mu - \raise 4 \p@ \hbox { . } + \raise 4 \p@ \hbox:n { . } \mkern 2 mu - \raise 7 \p@ \vbox { \kern 7 pt \hbox { . } } \mkern 1 mu + \raise 7 \p@ \vbox { \kern 7 pt \hbox:n { . } } \mkern 1 mu } } % \end{macrocode} @@ -2228,25 +2284,126 @@ version 2005/12/01 or later. \bool_new:N \l_@@_in_NiceArray_bool % \end{macrocode} % +% \subsection{The column S of siunitx} +% +% 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: +% \begin{Verbatim}[commandchars=\~\!\+, formatcom = \small] +% \renewcommand*{\NC@rewrite@S}[1][] +% { +% \@temptokena \exp_after:wN +% { +% \tex_the:D \@temptokena +% > { \__siunitx_table_collect_begin: S {#1} } +% c +% < { \__siunitx_table_print: } +% } +% \NC@find +% } +% \end{Verbatim} +% We want to patch this command (in the environments of \pkg{nicematrix}) in +% order to have: +% \begin{Verbatim}[commandchars=\~\!\+, formatcom = \small] +% \renewcommand*{\NC@rewrite@S}[1][] +% { +% \@temptokena \exp_after:wN +% { +% \tex_the:D \@temptokena +% > { ~emphase!\@@_Cell:+ \__siunitx_table_collect_begin: S {#1} } +% c +% < { \__siunitx_table_print: ~emphase!\@@_end_Cell:+ } +% } +% \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|. +% +% 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 +% (|\group_begin:|--|\group_end:|) and we extract the two command names which +% are in the toks |\@temptokena|. However, this extraction can be done only +% when \pkg{siunitx} is loaded (and it may be loaded after \pkg{nicematrix}) +% 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. +% \begin{macrocode} +\cs_set_protected:Npn \@@_adapt_S_column: + { + \bool_if:NT \c_@@_siunitx_loaded_bool + { + \group_begin: + \@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 { } +% \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. +% \begin{macrocode} + \exp_args:NNo \tl_gset:Nn \g_tmpa_tl { \tex_the:D \@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). +% \begin{macrocode} + \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 -% A list of names of environments of the extension \pkg{nicematrix} which have a -% preamble as argument. This list is used to parameter some erros messages. +% The command |\@@_renew_NC@rewrite@S:| will be used in each environment of +% \pkg{nicematrix} in order to ``rewrite'' the |S| column in each environment +% (only if the boolean |\c_@@_siunitx_loaded_bool| is raised, of course). +% \begin{macrocode} +\cs_new_protected:Npn \@@_renew_NC@rewrite@S: + { + \renewcommand*{\NC@rewrite@S}[1][] + { + \@temptokena \exp_after:wN + { + \tex_the:D \@temptokena + > { \@@_Cell: \c_@@_table_collect_begin_tl S {##1} } + c + < { \c_@@_table_print_tl \@@_end_Cell: } + } + \NC@find + } + } +% \end{macrocode} +% +% \bigskip +% \subsection{The options} % +% % \begin{macrocode} -\seq_new:N \c_@@_env_with_preamble_seq -\seq_set_from_clist:Nn \c_@@_env_with_preamble_seq +\@@_msg_new:nn { Option~Transparent~suppressed } + { + The~option~'Transparent'~has~been~renamed~'transparent'.\\ + However,~you~can~go~on~for~this~time. + } +\@@_msg_new:nn { Option~RenewMatrix~suppressed } { - NiceArray , NiceArrayCwithDelims , pNiceArrayC , vNiceArrayC , VNiceArrayC , - bNiceArrayC , BNiceArrayC , NiceArrayRCwithDelims , pNiceArrayRC , - vNiceArrayRC , VNiceArrayRC , bNiceArrayRC , BNiceArrayRC + The~option~'RenewMatrix~has~been~renamed~'renew-matrix'.\\ + However,~you~can~go~on~for~this~time. } % \end{macrocode} % % -% \bigskip -% \subsection{The options} -% % 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}|, @@ -2277,6 +2434,12 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip +% The flag |\l_@@_hlines_bool| correspond to the option |\hlines|. +% \begin{macrocode} +\bool_new:N \l_@@_hlines_bool +% \end{macrocode} +% +% \bigskip % The flag |\l_@@_nullify_dots_bool| corresponds to the option |nullify-dots|. % When the flag is down, the instructions like |\vdots| are inserted within a % |\hphantom| (and so the constructed matrix has exactly the same size as a @@ -2356,6 +2519,7 @@ version 2005/12/01 or later. % \begin{macrocode} \keys_define:nn { NiceMatrix / Global } { + hlines .bool_set:N = \l_@@_hlines_bool , parallelize-diags .bool_set:N = \l_@@_parallelize_diags_bool , parallelize-diags .default:n = true , % \end{macrocode} @@ -2457,10 +2621,13 @@ version 2005/12/01 or later. % \begin{macrocode} renew-matrix .code:n = \@@_renew_matrix: , renew-matrix .value_forbidden:n = true , - RenewMatrix .meta:n = renew-matrix , + RenewMatrix .code:n = \@@_error:n { Option~RenewMatrix~suppressed } + \@@_renew_matrix: , transparent .meta:n = { renew-dots , renew-matrix } , transparent .value_forbidden:n = true, - Transparent .meta:n = transparent, + Transparent .code:n = \@@_error:n { Option~Transparent~suppressed } + \@@_renew_matrix: + \bool_set_true:N \l_@@_renew_dots_bool , % \end{macrocode} % % \bigskip @@ -2541,6 +2708,7 @@ version 2005/12/01 or later. allow-duplicate-names,~ code-for-last-col,~ exterior-arraycolsep,~ + hlines,~ left-margin,~ letter-for-dotted-lines,~ nullify-dots,~ @@ -2594,6 +2762,7 @@ version 2005/12/01 or later. create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -2660,6 +2829,7 @@ version 2005/12/01 or later. columns-width,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -2692,7 +2862,8 @@ version 2005/12/01 or later. \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 } - \hbox_set:Nw \l_tmpa_box $ % $ + \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 } @@ -2700,7 +2871,8 @@ version 2005/12/01 or later. % % \begin{macrocode} \cs_new_protected:Nn \@@_end_Cell: - { $ % $ + { + \c_math_toggle_token \hbox_set_end: % \end{macrocode} % @@ -2819,55 +2991,16 @@ version 2005/12/01 or later. } % \end{macrocode} % -% -% \bigskip -% The command |\@@_define_dots:| will be used in the environment |{NiceArray}| -% to define the commands |\Ldots|, |\Cdots|, etc. % \begin{macrocode} -\cs_new_protected:Npn \@@_define_dots: - { - \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 - \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 - } +\@@_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 -% With |\@@_define_dots_to_nil:|, the commands like |\Ldots|, |\Cdots|, are -% defined, but with no effect. This command will be used if the class option -% |draft| is used. -% \begin{macrocode} -\cs_new_protected:Npn \@@_define_dots_to_nil: - { - \cs_set_eq:NN \Ldots \prg_do_nothing: - \cs_set_eq:NN \Cdots \prg_do_nothing: - \cs_set_eq:NN \Vdots \prg_do_nothing: - \cs_set_eq:NN \Ddots \prg_do_nothing: - \cs_set_eq:NN \Iddots \prg_do_nothing: - \bool_if:NT \l_@@_renew_dots_bool - { - \cs_set_eq:NN \ldots \prg_do_nothing: - \cs_set_eq:NN \cdots \prg_do_nothing: - \cs_set_eq:NN \vdots \prg_do_nothing: - \cs_set_eq:NN \ddots \prg_do_nothing: - \cs_set_eq:NN \iddots \prg_do_nothing: - \cs_set_eq:NN \dots \prg_do_nothing: - \cs_set_eq:NN \hdotsfor \@@_Hdotsfor - } - } -% \end{macrocode} % % \bigskip % In the environment |{NiceArray}|, we will have to redefine the column types @@ -2897,7 +3030,8 @@ version 2005/12/01 or later. \box_move_down:nn \l_tmpa_dim { \vbox:n - { \hbox_to_wd:nn { \box_wd:N \l_tmpb_box } + { + \hbox_to_wd:nn { \box_wd:N \l_tmpb_box } { \hfil \tikz [ remember~picture , overlay ] @@ -2941,14 +3075,26 @@ version 2005/12/01 or later. } % \end{macrocode} % +% \begin{macrocode} +\cs_new_protected:Npn \@@_test_if_math_mode: + { + \ifmmode \else + \@@_error:n { Outside~math~mode } + \fi + } +% \end{macrocode} +% % \bigskip % First, we test if we are yet in an environment |{NiceArray}| (nested % environments are forbidden). % \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 % \end{macrocode} % % We deactivate Tikz externalization (since we use Tikz pictures with the @@ -2956,7 +3102,6 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_if_exist:NT \tikz@library@external@loaded { \tikzset { external / export = false } } - \bool_set_true:N \l_@@_in_NiceArray_bool \group_insert_after:N \@@_after_array: \tl_gclear_new:N \g_@@_lines_to_draw_tl % \end{macrocode} @@ -2991,7 +3136,7 @@ version 2005/12/01 or later. { \group_insert_after:N \@@_write_max_cell_width: \cs_if_free:cTF { _@@_max_cell_width_ \int_use:N \g_@@_env_int } - { \dim_set:Nn \l_@@_columns_width_dim \c_zero_dim } + { \dim_zero:N \l_@@_columns_width_dim } { \dim_set:Nx \l_@@_columns_width_dim { \use:c { _@@_max_cell_width _ \int_use:N \g_@@_env_int } } @@ -3036,7 +3181,21 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_set:Npn \ialign { - \everycr { \noalign { \int_gzero:N \g_@@_column_int } } + \everycr + { + \noalign + { + \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 } + } + } + } + } \tabskip = \c_zero_skip \cs_set:Npn \ialign { @@ -3124,30 +3283,40 @@ version 2005/12/01 or later. { \int_gset_eq:NN \g_@@_last_vdotted_col_int \g_@@_column_int \tl_gput_right:Nx \g_@@_code_after_tl - { - \exp_not:N \@@_vdottedline:n - \exp_not:N { - \int_use:N \g_@@_column_int - \exp_not:N } - } +% \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 } } } } } % \end{macrocode} % -% % % The commands |\Ldots|, |\Cdots|, etc. will be defined only in the environment -% |{NiceArray}|. If the class option |draft| is used, these commands will be -% defined to be no-op (the dotted lines are not drawn). +% |{NiceArray}|. % \begin{macrocode} - \bool_if:NTF \c_@@_draft_bool - \@@_define_dots_to_nil: - \@@_define_dots: + \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: % \end{macrocode} % % @@ -3206,7 +3375,8 @@ version 2005/12/01 or later. % \end{macrocode} % % \begin{macrocode} - \skip_horizontal:n { \l_@@_left_margin_dim + \l_@@_extra_left_margin_dim } + \skip_horizontal:n \l_@@_left_margin_dim + \skip_horizontal:n \l_@@_extra_left_margin_dim % \end{macrocode} % % @@ -3238,8 +3408,8 @@ version 2005/12/01 or later. { \endarray \bool_if:NF \l_@@_exterior_arraycolsep_bool { \skip_horizontal:n { - \arraycolsep } } - \skip_horizontal:n - { \g_@@_right_margin_dim + \g_@@_extra_right_margin_dim } + \skip_horizontal:n \g_@@_right_margin_dim + \skip_horizontal:n \g_@@_extra_right_margin_dim } % \end{macrocode} % @@ -3248,31 +3418,46 @@ version 2005/12/01 or later. % We create the variants of the environment |{NiceMatrix}|. % \begin{macrocode} \NewDocumentEnvironment { pNiceMatrix } { } - { \left( \begin{NiceMatrix} } + { + \@@_test_if_math_mode: + \left( \begin{NiceMatrix} + } { \end{NiceMatrix} \right) } % \end{macrocode} % % \begin{macrocode} \NewDocumentEnvironment { bNiceMatrix } { } - { \left[ \begin{NiceMatrix} } + { + \@@_test_if_math_mode: + \left[ \begin{NiceMatrix} + } { \end{NiceMatrix} \right] } % \end{macrocode} % % \begin{macrocode} \NewDocumentEnvironment { BNiceMatrix } { } - { \left\{ \begin{NiceMatrix} } + { + \@@_test_if_math_mode: + \left\{ \begin{NiceMatrix} + } { \end{NiceMatrix} \right\} } % \end{macrocode} % % \begin{macrocode} \NewDocumentEnvironment { vNiceMatrix } { } - { \left\lvert \begin{NiceMatrix} } + { + \@@_test_if_math_mode: + \left\lvert \begin{NiceMatrix} + } { \end{NiceMatrix} \right\rvert } % \end{macrocode} % % \begin{macrocode} \NewDocumentEnvironment { VNiceMatrix } {} - { \left\lVert \begin{NiceMatrix} } + { + \@@_test_if_math_mode: + \left\lVert \begin{NiceMatrix} + } { \end{NiceMatrix} \right\rVert } % \end{macrocode} % @@ -3300,10 +3485,13 @@ version 2005/12/01 or later. % If the environment has a name, we also create an alias named % |\@@_max_cell_width_|{\ttfamily\slshape name}. % \begin{macrocode} - \iow_now:Nx \@mainaux + \str_if_empty:NF \g_@@_name_str { - \cs_gset:cpn { @@_max_cell_width_ \g_@@_name_str } - { \dim_use:N \g_@@_max_cell_width_dim } + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { @@_max_cell_width_ \g_@@_name_str } + { \dim_use:N \g_@@_max_cell_width_dim } + } } \iow_now:Nn \@mainaux \ExplSyntaxOff } @@ -3328,7 +3516,7 @@ version 2005/12/01 or later. % \end{macrocode} % We manage a list of ``empty cells'' called |\g_@@_empty_cells_seq|. In fact, % this list is not a list of all the empty cells of the array but only those -% explicitely declared empty for some reason. It's easy to check if the current +% explicitly declared empty for some reason. It's easy to check if the current % cell is in this list. % \begin{macrocode} { @@ -3352,8 +3540,8 @@ version 2005/12/01 or later. \pgfpointanchor \l_tmpa_tl { west } \dim_gset:Nn \g_tmpb_dim \pgf@x \end { pgfpicture } - \dim_compare:nTF - { \dim_abs:n { \g_tmpb_dim - \g_tmpa_dim } < 0.5 pt } + \dim_compare:nNnTF + { \dim_abs:n { \g_tmpb_dim - \g_tmpa_dim } } < { 0.5 pt } \prg_return_false: \prg_return_true: } @@ -3394,14 +3582,18 @@ version 2005/12/01 or later. % \end{scope} % % \begin{macrocode} -\cs_new_protected:Nn \@@_instruction_of_type:n - { - \tl_gput_right:Nx \g_@@_lines_to_draw_tl +\bool_if:NTF \c_@@_draft_bool + { \cs_set_protected:Npn \@@_instruction_of_type:n #1 { } } + { + \cs_new_protected:Npn \@@_instruction_of_type:n #1 { - \exp_not:c { @@ _ draw _ #1 : nn } - { \int_use:N \g_@@_row_int } - { \int_use:N \g_@@_column_int } - } + \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} % @@ -3411,7 +3603,7 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_new_protected:Nn \@@_after_array: { - \int_compare:nNnTF \g_@@_row_int > 0 + \int_compare:nNnTF \g_@@_row_int > \c_zero_int \@@_after_array_i: { \@@_error:n { Zero~row } } } @@ -3420,8 +3612,9 @@ version 2005/12/01 or later. % \begin{macrocode} \@@_msg_new:nn { Zero~row } { - There~is~a~problem.~Maybe~your~environment~is~empty.~Maybe~you~have~used~L,~ - ~C~and~R~instead~of~l,~c~and~r~in~the~preamble~of~your~environment.\\ + 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~ + of~your~environment. \\ If~you~go~on,~the~result~may~be~incorrect. } % \end{macrocode} @@ -3679,7 +3872,7 @@ version 2005/12/01 or later. % \interitem % If the dotted line to draw is in the list of the previously drawn lines % (|\g_@@_yet_drawn_seq|), we don't draw (so, we won't have overlapping lines in -% the \textsc{pdf}). The token list |\l_tmpa_tl| is the $4$-uplet characteristic +% the \textsc{pdf}). The token list |\l_tmpa_tl| is the $4$-list characteristic % of the line. % \begin{macrocode} \prg_set_conditional:Npnn \@@_if_yet_drawn: { F } @@ -4211,7 +4404,7 @@ version 2005/12/01 or later. % the following command |\@@_multicolumn:nnn|. % \begin{macrocode} \cs_set_eq:NN \@@_old_multicolumn \multicolumn -\cs_new:Nn \@@_multicolumn:nnn +\cs_new:Npn \@@_multicolumn:nnn #1 #2 #3 { \@@_old_multicolumn { #1 } { #2 } { #3 } \int_compare:nNnT #1 > 1 @@ -4232,16 +4425,23 @@ version 2005/12/01 or later. % beetween two consecutive dots). Tikz nodes are created for all the cells of % the array, even the implicit cells of the |\Hdotsfor|. % \begin{macrocode} -\NewDocumentCommand \@@_Hdotsfor { O { } m } - { - \tl_gput_right:Nx \g_@@_lines_to_draw_tl +\bool_if:NTF \c_@@_draft_bool + { + \NewDocumentCommand \@@_Hdotsfor { O { } m } + { \prg_replicate:nn { #2 - 1 } { & } } + } + { + \NewDocumentCommand \@@_Hdotsfor { O { } m } { - \exp_not:N \@@_draw_Hdotsfor:nnn - { \int_use:N \g_@@_row_int } - { \int_use:N \g_@@_column_int } - { #2 } - } - \prg_replicate:nn { #2 - 1 } { & } + \tl_gput_right:Nx \g_@@_lines_to_draw_tl + { + \@@_draw_Hdotsfor:nnn + { \int_use:N \g_@@_row_int } + { \int_use:N \g_@@_column_int } + { #2 } + } + \prg_replicate:nn { #2 - 1 } { & } + } } % \end{macrocode} % @@ -4347,23 +4547,25 @@ version 2005/12/01 or later. \cs_generate_variant:Nn \dim_set:Nn { N v } % \end{macrocode} % -% \medskip -% The command |\@@_hdottedline:| (which is linked to |\hdottedline| in the -% environment |{NiceArray}|) begins with a |\noalign| which contains a -% vertical skip which is part of the construction of the ``false row''. % % \medskip -% Some extension, like the extension \pkg{doc} do a redefinition of the command +% Some extension, 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. % \begin{macrocode} -\cs_set:Npn \@@_dotfill: - { \cleaders \hbox_to_wd:nn {.44em} {\hss .\hss } \hfill \kern \c_zero_dim } +\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 + \skip_horizontal:n \c_zero_dim + } + } % \end{macrocode} % - % This command must \emph{not} be protected because it starts with |\noalign|. % \begin{macrocode} -\cs_new:Nn \@@_hdottedline: +\cs_new:Npn \@@_hdottedline: { \noalign { @@ -4385,23 +4587,6 @@ version 2005/12/01 or later. % % % -% \begin{macrocode} -\@@_msg_new:nn { Use~of~hdottedline~in~first~position } - { - You~can't~use~the~command~\token_to_str:N\hdottedline\ in~the~first~row~ - of~the~environment~\{\@currenvir\}.~But~maybe~you~have~used~l,~c~and~r~ - instead~of~L,~C,~R~in~the~preamble~of~the~array.\\ - If~you~go~on,~this~dotted~line~will~be~ignored. - } -\@@_msg_new:nn { Use~of~hdottedline~in~first~position~bis } - { - You~can't~use~the~command~\token_to_str:N\hdottedline\ in~the~first~row~ - of~the~environment~\{\@currenvir\}. \\ - If~you~go~on,~this~dotted~line~will~be~ignored. - } -% \end{macrocode} -% -% % \bigskip % \begin{macrocode} \cs_new_protected:Nn \@@_vdottedline:n @@ -4567,6 +4752,7 @@ version 2005/12/01 or later. create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -4610,7 +4796,7 @@ version 2005/12/01 or later. \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 $ % $ + \hbox_set:Nw \l_tmpa_box \c_math_toggle_token \l_@@_code_for_last_col_tl } l @@ -4620,7 +4806,7 @@ version 2005/12/01 or later. % 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 { @@ -4676,7 +4862,8 @@ version 2005/12/01 or later. % 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 @@ -4761,6 +4948,7 @@ version 2005/12/01 or later. create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -4770,15 +4958,52 @@ version 2005/12/01 or later. } % \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 } @@ -4786,25 +5011,25 @@ version 2005/12/01 or later. \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 } + { 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 { @@ -4812,7 +5037,7 @@ version 2005/12/01 or later. \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 } @@ -4867,7 +5092,7 @@ version 2005/12/01 or later. % % \bigskip % For each row $i$, we compute two dimensions -% \texttt{l_@@_row_\textsl{i}_min_dim} and \texttt{l_@@_row_\textsl{i}_max_dim}. +% "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 @@ -4886,33 +5111,33 @@ 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:nnnNn \l_@@_nb_first_row_int 1 \g_@@_row_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 } + \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:nNn \g_@@_column_total_int \@@_j: { - \dim_zero_new:c { l_@@_column_\@@_j _min_dim } - \dim_set_eq:cN { l_@@_column_\@@_j _min_dim } \c_max_dim - \dim_zero_new:c { l_@@_column_\@@_j _max_dim } - \dim_set:cn { l_@@_column_\@@_j _max_dim } { - \c_max_dim } + \dim_zero_new:c { l_@@_column_\@@_j: _min_dim } + \dim_set_eq:cN { l_@@_column_\@@_j: _min_dim } \c_max_dim + \dim_zero_new:c { l_@@_column_\@@_j: _max_dim } + \dim_set:cn { l_@@_column_\@@_j: _max_dim } { - \c_max_dim } } % \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 \l_@@_nb_first_row_int \g_@@_row_int \@@_i: { - \int_step_variable:nNn \g_@@_column_total_int \@@_j + \int_step_variable:nNn \g_@@_column_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 % dimensions we want to compute. % \begin{macrocode} { \cs_if_exist:cT - { pgf@sh@ns@nm - \int_use:N \g_@@_env_int - \@@_i- \@@_j } + { pgf@sh@ns@nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: } % \end{macrocode} % We retrieve the coordinates of the anchor |south west| of the (normal) node of % the cell ($i$-$j$). They will be stored in |\pgf@x| and |\pgf@y|. @@ -4920,26 +5145,26 @@ version 2005/12/01 or later. { \tikz@parse@node \pgfutil@firstofone ( nm - \int_use:N \g_@@_env_int - - \@@_i - \@@_j .south~west ) - \dim_set:cn { l_@@_row_\@@_i _min_dim} - { \dim_min:vn { l_@@_row _ \@@_i _min_dim } \pgf@y } - \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i - \@@_j } + - \@@_i: - \@@_j: .south~west ) + \dim_set:cn { l_@@_row_\@@_i: _min_dim} + { \dim_min:vn { l_@@_row _ \@@_i: _min_dim } \pgf@y } + \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i: - \@@_j: } { - \dim_set:cn { l_@@_column _ \@@_j _ min_dim} - { \dim_min:vn { l_@@_column _ \@@_j _min_dim } \pgf@x } + \dim_set:cn { l_@@_column _ \@@_j: _min_dim} + { \dim_min:vn { l_@@_column _ \@@_j: _min_dim } \pgf@x } } % \end{macrocode} % We retrieve the coordinates of the anchor |north east| of the (normal) node of % the cell ($i$-$j$). They will be stored in |\pgf@x| and |\pgf@y|. % \begin{macrocode} \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g_@@_env_int - \@@_i - \@@_j .north~east ) - \dim_set:cn { l_@@_row _ \@@_i _ max_dim } - { \dim_max:vn { l_@@_row _ \@@_i _ max_dim } \pgf@y } - \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i - \@@_j } + ( nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: .north~east ) + \dim_set:cn { l_@@_row _ \@@_i: _ max_dim } + { \dim_max:vn { l_@@_row _ \@@_i: _ max_dim } \pgf@y } + \seq_if_in:NxF \g_@@_multicolumn_cells_seq { \@@_i: - \@@_j: } { - \dim_set:cn { l_@@_column _ \@@_j _ max_dim } - { \dim_max:vn { l_@@_column _ \@@_j _max_dim } \pgf@x } + \dim_set:cn { l_@@_column _ \@@_j: _ max_dim } + { \dim_max:vn { l_@@_column _ \@@_j: _max_dim } \pgf@x } } } } @@ -4969,33 +5194,33 @@ version 2005/12/01 or later. % \texttt{l_@@_column_\textsl{j}_min_dim} and % \texttt{l_@@_column_\textsl{j}_max_dim}. % \begin{macrocode} - \int_step_variable:nNn { \g_@@_row_int - 1 } \@@_i + \int_step_variable:nNn { \g_@@_row_int - 1 } \@@_i: { - \dim_set:cn { l_@@_row _ \@@_i _ min _ dim } + \dim_set:cn { l_@@_row _ \@@_i: _ min _ dim } { ( - \dim_use:c { l_@@_row _ \@@_i _ min _ dim } + - \dim_use:c { l_@@_row _ \int_eval:n { \@@_i + 1 } _ max _ dim } + \dim_use:c { l_@@_row _ \@@_i: _ min _ dim } + + \dim_use:c { l_@@_row _ \int_eval:n { \@@_i: + 1 } _ max _ dim } ) / 2 } - \dim_set_eq:cc { l_@@_row _ \int_eval:n { \@@_i + 1 } _ max _ dim } - { l_@@_row_\@@_i _min_dim } + \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_@@_column_int - 1 } \@@_j: { - \dim_set:cn { l_@@_column _ \@@_j _ max _ dim } + \dim_set:cn { l_@@_column _ \@@_j: _ max _ dim } { ( \dim_use:c - { l_@@_column _ \@@_j _ max _ dim } + + { l_@@_column _ \@@_j: _ max _ dim } + \dim_use:c - { l_@@_column _ \int_eval:n { \@@_j + 1 } _ min _ dim } + { l_@@_column _ \int_eval:n { \@@_j: + 1 } _ min _ dim } ) / 2 } - \dim_set_eq:cc { l_@@_column _ \int_eval:n { \@@_j + 1 } _ min _ dim } - { l_@@_column _ \@@_j _ max _ dim } + \dim_set_eq:cc { l_@@_column _ \int_eval:n { \@@_j: + 1 } _ min _ dim } + { l_@@_column _ \@@_j: _ max _ dim } } \dim_sub:cn { l_@@_column _ 1 _ min _ dim } @@ -5015,7 +5240,7 @@ version 2005/12/01 or later. % When used once, the command |\@@_create_extra_nodes:| must become no-op (in % the current TeX group). That's why we put a nullification of the command. % \begin{macrocode} - \cs_set:Nn \@@_create_extra_nodes: { } + \cs_set:Npn \@@_create_extra_nodes: { } % \end{macrocode} % % \medskip @@ -5053,9 +5278,9 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_new_protected:Nn \@@_create_nodes: { - \int_step_variable:nnnNn \l_@@_nb_first_row_int 1 \g_@@_row_int \@@_i + \int_step_variable:nnNn \l_@@_nb_first_row_int \g_@@_row_int \@@_i: { - \int_step_variable:nnnNn 1 1 \g_@@_column_total_int \@@_j + \int_step_variable:nNn \g_@@_column_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 @@ -5065,11 +5290,11 @@ version 2005/12/01 or later. % \begin{macrocode} { \coordinate ( @@~south~west ) - at ( \dim_use:c { l_@@_column_ \@@_j _min_dim } , - \dim_use:c { l_@@_row_ \@@_i _min_dim } ) ; + 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 }, - \dim_use:c { l_@@_row_ \@@_i _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|). % This node is created with the Tikz library \pkg{fit}. Don't forget that the @@ -5080,10 +5305,10 @@ version 2005/12/01 or later. node~contents = { } , fit = ( @@~south~west ) ( @@~north~east ) , inner~sep = \c_zero_dim , - name = nm - \int_use:N \g_@@_env_int - \@@_i - \@@_j , + name = nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: , alias = \str_if_empty:NF \g_@@_name_str - { \g_@@_name_str - \@@_i - \@@_j } + { \g_@@_name_str - \@@_i: - \@@_j: } ] ; } @@ -5106,8 +5331,8 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_new_protected:Npn \@@_extract_coords: #1 - #2 \q_stop { - \cs_set:Npn \@@_i { #1 } - \cs_set:Npn \@@_j { #2 } + \cs_set:Npn \@@_i: { #1 } + \cs_set:Npn \@@_j: { #2 } } % \end{macrocode} % @@ -5121,22 +5346,22 @@ version 2005/12/01 or later. \@@_extract_coords: #1 \q_stop \coordinate ( @@~south~west ) at ( - \dim_use:c { l_@@_column _ \@@_j _ min _ dim } , - \dim_use:c { l_@@_row _ \@@_i _ min _ dim } + \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 _ \int_eval:n { \@@_j + #2 - 1 } _ max _ dim} , - \dim_use:c { l_@@_row _ \@@_i _ max _ dim } + \dim_use:c { l_@@_column _ \int_eval:n { \@@_j: + #2 - 1 } _ max _ dim} , + \dim_use:c { l_@@_row _ \@@_i: _ max _ dim } ) ; \node [ node~contents = { } , fit = ( @@~south~west ) ( @@~north~east ) , inner~sep = \c_zero_dim , - name = nm - \int_use:N \g_@@_env_int - \@@_i - \@@_j , + name = nm - \int_use:N \g_@@_env_int - \@@_i: - \@@_j: , alias = - \str_if_empty:NF \g_@@_name_str { \g_@@_name_str - \@@_i - \@@_j } + \str_if_empty:NF \g_@@_name_str { \g_@@_name_str - \@@_i: - \@@_j: } ] ; } @@ -5155,10 +5380,11 @@ version 2005/12/01 or later. % Of course, the command |\NiceMatrix| must be defined before such an % instruction is executed. % \begin{macrocode} -\ProcessKeysOptions {NiceMatrix} +\ProcessKeysOptions { NiceMatrix } % \end{macrocode} % -% \subsection{Code for \texttt{seq_mapthread_function:NNN}} +% +% \subsection{Code for \textbackslash seq_mapthread_function:NNN} % % In |\@@_create_nodes:| (used twice in |\@@_create_extra_nodes:| to create the % ``medium nodes'' and ``large nodes''), we want to use @@ -5310,7 +5536,7 @@ version 2005/12/01 or later. % % Possibility to draw vertical dotted lines to separate columns with the % specifier ``|:|'' in the preamble (similar to the classical specifier -% ``\verb+|+'' and the specifier ``|:|'' of \pkg{arydshln}). +% ``"|"'' and the specifier ``|:|'' of \pkg{arydshln}). % % \subsection{Changes between version 2.2 and 2.2.1} % @@ -5319,6 +5545,18 @@ version 2005/12/01 or later. % % Modification of the position of the dotted lines drawn by |\hdottedline|. % +% \subsection{Changes between version 2.2.1 and 2.3} +% +% Compatibility with the column type |S| of \pkg{siunitx}. +% +% Option |hlines|. +% +% A warning is issued when the |draft| mode is used. In this case, the dotted +% lines are not drawn. +% +% \PrintIndex +% +% \tableofcontents % \endinput % Local Variables: % TeX-fold-mode: nil diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index 86dc6b39765..a1e3830d1cf 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.2.1} -\def\myfiledate{2019/07/02} +\def\myfileversion{2.3} +\def\myfiledate{2019/07/18} \RequirePackage{tikz} \usetikzlibrary{fit} \RequirePackage{expl3}[2019/02/15] @@ -36,6 +36,12 @@ \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_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 + { \msg_redirect_name:nnn { nicematrix } } \bool_new:N \c__nm_revtex_bool \@ifclassloaded { revtex4-1 } { \bool_set_true:N \c__nm_revtex_bool } @@ -43,21 +49,33 @@ \@ifclassloaded { revtex4-2 } { \bool_set_true:N \c__nm_revtex_bool } { } -\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_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 - { \msg_redirect_name:nnn { nicematrix } } +\__nm_msg_new:nn { Draft~mode } + { 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 - { \mkern 1 mu - \raise \p@ \hbox { . } + { + \mkern 1 mu + \raise \p@ \hbox:n { . } \mkern 2 mu - \raise 4 \p@ \hbox { . } + \raise 4 \p@ \hbox:n { . } \mkern 2 mu - \raise 7 \p@ \vbox { \kern 7 pt \hbox { . } } \mkern 1 mu + \raise 7 \p@ \vbox { \kern 7 pt \hbox:n { . } } \mkern 1 mu } } \int_new:N \g__nm_env_int @@ -68,18 +86,54 @@ \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 -\seq_new:N \c__nm_env_with_preamble_seq -\seq_set_from_clist:Nn \c__nm_env_with_preamble_seq +\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 } + \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_new_protected:Npn \__nm_renew_NC@rewrite@S: + { + \renewcommand*{\NC@rewrite@S}[1][] + { + \@temptokena \exp_after:wN + { + \tex_the:D \@temptokena + > { \__nm_Cell: \c__nm_table_collect_begin_tl S {##1} } + c + < { \c__nm_table_print_tl \__nm_end_Cell: } + } + \NC@find + } + } +\__nm_msg_new:nn { Option~Transparent~suppressed } { - NiceArray , NiceArrayCwithDelims , pNiceArrayC , vNiceArrayC , VNiceArrayC , - bNiceArrayC , BNiceArrayC , NiceArrayRCwithDelims , pNiceArrayRC , - vNiceArrayRC , VNiceArrayRC , bNiceArrayRC , BNiceArrayRC + The~option~'Transparent'~has~been~renamed~'transparent'.\\ + However,~you~can~go~on~for~this~time. + } +\__nm_msg_new:nn { Option~RenewMatrix~suppressed } + { + The~option~'RenewMatrix~has~been~renamed~'renew-matrix'.\\ + However,~you~can~go~on~for~this~time. } \str_new:N \l__nm_pos_env_str \str_set:Nn \l__nm_pos_env_str c \bool_new:N \l__nm_exterior_arraycolsep_bool \bool_new:N \l__nm_parallelize_diags_bool \bool_set_true:N \l__nm_parallelize_diags_bool +\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 @@ -96,6 +150,7 @@ \dim_new:N \g__nm_extra_right_margin_dim \keys_define:nn { NiceMatrix / Global } { + hlines .bool_set:N = \l__nm_hlines_bool , parallelize-diags .bool_set:N = \l__nm_parallelize_diags_bool , parallelize-diags .default:n = true , renew-dots .bool_set:N = \l__nm_renew_dots_bool , @@ -156,10 +211,13 @@ { renew-matrix .code:n = \__nm_renew_matrix: , renew-matrix .value_forbidden:n = true , - RenewMatrix .meta:n = renew-matrix , + RenewMatrix .code:n = \__nm_error:n { Option~RenewMatrix~suppressed } + \__nm_renew_matrix: , transparent .meta:n = { renew-dots , renew-matrix } , transparent .value_forbidden:n = true, - Transparent .meta:n = transparent, + 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 , @@ -189,6 +247,7 @@ allow-duplicate-names,~ code-for-last-col,~ exterior-arraycolsep,~ + hlines,~ left-margin,~ letter-for-dotted-lines,~ nullify-dots,~ @@ -221,6 +280,7 @@ create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -265,6 +325,7 @@ columns-width,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -279,12 +340,14 @@ \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 } - \hbox_set:Nw \l_tmpa_box $ % $ + \hbox_set:Nw \l_tmpa_box + \c_math_toggle_token \int_compare:nNnT \g__nm_row_int = \c_zero_int \l__nm_code_for_first_row_tl } \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 } } @@ -344,41 +407,11 @@ nested.~You~can~go~on,~but,~maybe,~you~will~have~errors~or~an~incorrect~ result. } -\cs_new_protected:Npn \__nm_define_dots: +\__nm_msg_new:nn { Outside~math~mode } { - \cs_set_eq:NN \Ldots \__nm_Ldots - \cs_set_eq:NN \Cdots \__nm_Cdots - \cs_set_eq:NN \Vdots \__nm_Vdots - \cs_set_eq:NN \Ddots \__nm_Ddots - \cs_set_eq:NN \Iddots \__nm_Iddots - \bool_if:NT \l__nm_renew_dots_bool - { - \cs_set_eq:NN \ldots \__nm_Ldots - \cs_set_eq:NN \cdots \__nm_Cdots - \cs_set_eq:NN \vdots \__nm_Vdots - \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_new_protected:Npn \__nm_define_dots_to_nil: - { - \cs_set_eq:NN \Ldots \prg_do_nothing: - \cs_set_eq:NN \Cdots \prg_do_nothing: - \cs_set_eq:NN \Vdots \prg_do_nothing: - \cs_set_eq:NN \Ddots \prg_do_nothing: - \cs_set_eq:NN \Iddots \prg_do_nothing: - \bool_if:NT \l__nm_renew_dots_bool - { - \cs_set_eq:NN \ldots \prg_do_nothing: - \cs_set_eq:NN \cdots \prg_do_nothing: - \cs_set_eq:NN \vdots \prg_do_nothing: - \cs_set_eq:NN \ddots \prg_do_nothing: - \cs_set_eq:NN \iddots \prg_do_nothing: - \cs_set_eq:NN \dots \prg_do_nothing: - \cs_set_eq:NN \hdotsfor \__nm_Hdotsfor - } + 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 { @@ -399,7 +432,8 @@ \box_move_down:nn \l_tmpa_dim { \vbox:n - { \hbox_to_wd:nn { \box_wd:N \l_tmpb_box } + { + \hbox_to_wd:nn { \box_wd:N \l_tmpb_box } { \hfil \tikz [ remember~picture , overlay ] @@ -434,13 +468,21 @@ } } } +\cs_new_protected:Npn \__nm_test_if_math_mode: + { + \ifmmode \else + \__nm_error:n { Outside~math~mode } + \fi + } \NewDocumentEnvironment { NiceArray } { O { } m ! O { } } { + \__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 } } - \bool_set_true:N \l__nm_in_NiceArray_bool \group_insert_after:N \__nm_after_array: \tl_gclear_new:N \g__nm_lines_to_draw_tl \int_gincr:N \g__nm_env_int @@ -454,7 +496,7 @@ { \group_insert_after:N \__nm_write_max_cell_width: \cs_if_free:cTF { __nm_max_cell_width_ \int_use:N \g__nm_env_int } - { \dim_set:Nn \l__nm_columns_width_dim \c_zero_dim } + { \dim_zero:N \l__nm_columns_width_dim } { \dim_set:Nx \l__nm_columns_width_dim { \use:c { __nm_max_cell_width _ \int_use:N \g__nm_env_int } } @@ -475,7 +517,21 @@ \tl_gset_eq:NN \g__nm_name_str \l__nm_name_str \cs_set:Npn \ialign { - \everycr { \noalign { \int_gzero:N \g__nm_column_int } } + \everycr + { + \noalign + { + \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 } + } + } + } + } \tabskip = \c_zero_skip \cs_set:Npn \ialign { @@ -510,22 +566,30 @@ { \int_gset_eq:NN \g__nm_last_vdotted_col_int \g__nm_column_int \tl_gput_right:Nx \g__nm_code_after_tl - { - \exp_not:N \__nm_vdottedline:n - \exp_not:N { - \int_use:N \g__nm_column_int - \exp_not:N } - } + { \__nm_vdottedline:n { \int_use:N \g__nm_column_int } } } } } - \bool_if:NTF \c__nm_draft_bool - \__nm_define_dots_to_nil: - \__nm_define_dots: + \cs_set_eq:NN \Ldots \__nm_Ldots + \cs_set_eq:NN \Cdots \__nm_Cdots + \cs_set_eq:NN \Vdots \__nm_Vdots + \cs_set_eq:NN \Ddots \__nm_Ddots + \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 \multicolumn \__nm_multicolumn:nnn + \bool_if:NT \l__nm_renew_dots_bool + { + \cs_set_eq:NN \ldots \__nm_Ldots + \cs_set_eq:NN \cdots \__nm_Cdots + \cs_set_eq:NN \vdots \__nm_Vdots + \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 + } + \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 @@ -538,7 +602,8 @@ \cs_set_eq:NN \@ifnextchar \new@ifnextchar \bool_if:NF \l__nm_exterior_arraycolsep_bool { \skip_horizontal:n { - \arraycolsep } } - \skip_horizontal:n { \l__nm_left_margin_dim + \l__nm_extra_left_margin_dim } + \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 @@ -553,23 +618,38 @@ { \endarray \bool_if:NF \l__nm_exterior_arraycolsep_bool { \skip_horizontal:n { - \arraycolsep } } - \skip_horizontal:n - { \g__nm_right_margin_dim + \g__nm_extra_right_margin_dim } + \skip_horizontal:n \g__nm_right_margin_dim + \skip_horizontal:n \g__nm_extra_right_margin_dim } \NewDocumentEnvironment { pNiceMatrix } { } - { \left( \begin{NiceMatrix} } + { + \__nm_test_if_math_mode: + \left( \begin{NiceMatrix} + } { \end{NiceMatrix} \right) } \NewDocumentEnvironment { bNiceMatrix } { } - { \left[ \begin{NiceMatrix} } + { + \__nm_test_if_math_mode: + \left[ \begin{NiceMatrix} + } { \end{NiceMatrix} \right] } \NewDocumentEnvironment { BNiceMatrix } { } - { \left\{ \begin{NiceMatrix} } + { + \__nm_test_if_math_mode: + \left\{ \begin{NiceMatrix} + } { \end{NiceMatrix} \right\} } \NewDocumentEnvironment { vNiceMatrix } { } - { \left\lvert \begin{NiceMatrix} } + { + \__nm_test_if_math_mode: + \left\lvert \begin{NiceMatrix} + } { \end{NiceMatrix} \right\rvert } \NewDocumentEnvironment { VNiceMatrix } {} - { \left\lVert \begin{NiceMatrix} } + { + \__nm_test_if_math_mode: + \left\lVert \begin{NiceMatrix} + } { \end{NiceMatrix} \right\rVert } \cs_new_protected:Nn \__nm_write_max_cell_width: { @@ -581,10 +661,13 @@ \cs_gset:cpn { __nm_max_cell_width_ \int_use:N \g__nm_env_int } { \dim_use:N \g__nm_max_cell_width_dim } } - \iow_now:Nx \@mainaux + \str_if_empty:NF \g__nm_name_str { - \cs_gset:cpn { __nm_max_cell_width_ \g__nm_name_str } - { \dim_use:N \g__nm_max_cell_width_dim } + \iow_now:Nx \@mainaux + { + \cs_gset:cpn { __nm_max_cell_width_ \g__nm_name_str } + { \dim_use:N \g__nm_max_cell_width_dim } + } } \iow_now:Nn \@mainaux \ExplSyntaxOff } @@ -606,32 +689,37 @@ \pgfpointanchor \l_tmpa_tl { west } \dim_gset:Nn \g_tmpb_dim \pgf@x \end { pgfpicture } - \dim_compare:nTF - { \dim_abs:n { \g_tmpb_dim - \g_tmpa_dim } < 0.5 pt } + \dim_compare:nNnTF + { \dim_abs:n { \g_tmpb_dim - \g_tmpa_dim } } < { 0.5 pt } \prg_return_false: \prg_return_true: } } } -\cs_new_protected:Nn \__nm_instruction_of_type:n +\bool_if:NTF \c__nm_draft_bool + { \cs_set_protected:Npn \__nm_instruction_of_type:n #1 { } } { - \tl_gput_right:Nx \g__nm_lines_to_draw_tl + \cs_new_protected:Npn \__nm_instruction_of_type:n #1 { - \exp_not:c { __nm _ draw _ #1 : nn } - { \int_use:N \g__nm_row_int } - { \int_use:N \g__nm_column_int } + \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 > 0 + \int_compare:nNnTF \g__nm_row_int > \c_zero_int \__nm_after_array_i: { \__nm_error:n { Zero~row } } } \__nm_msg_new:nn { Zero~row } { - There~is~a~problem.~Maybe~your~environment~is~empty.~Maybe~you~have~used~L,~ - ~C~and~R~instead~of~l,~c~and~r~in~the~preamble~of~your~environment.\\ + 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~ + of~your~environment. \\ If~you~go~on,~the~result~may~be~incorrect. } \cs_new_protected:Nn \__nm_after_array_i: @@ -1079,7 +1167,7 @@ \hspace } \cs_set_eq:NN \__nm_old_multicolumn \multicolumn -\cs_new:Nn \__nm_multicolumn:nnn +\cs_new:Npn \__nm_multicolumn:nnn #1 #2 #3 { \__nm_old_multicolumn { #1 } { #2 } { #3 } \int_compare:nNnT #1 > 1 @@ -1090,16 +1178,23 @@ } \int_gadd:Nn \g__nm_column_int { #1 - 1 } } -\NewDocumentCommand \__nm_Hdotsfor { O { } m } +\bool_if:NTF \c__nm_draft_bool + { + \NewDocumentCommand \__nm_Hdotsfor { O { } m } + { \prg_replicate:nn { #2 - 1 } { & } } + } { - \tl_gput_right:Nx \g__nm_lines_to_draw_tl + \NewDocumentCommand \__nm_Hdotsfor { O { } m } { - \exp_not:N \__nm_draw_Hdotsfor:nnn - { \int_use:N \g__nm_row_int } - { \int_use:N \g__nm_column_int } - { #2 } + \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 } + { #2 } + } + \prg_replicate:nn { #2 - 1 } { & } } - \prg_replicate:nn { #2 - 1 } { & } } \cs_new_protected:Nn \__nm_draw_Hdotsfor:nnn { @@ -1159,10 +1254,16 @@ \__nm_draw_tikz_line: } \cs_generate_variant:Nn \dim_set:Nn { N v } -\cs_set:Npn \__nm_dotfill: - { \cleaders \hbox_to_wd:nn {.44em} {\hss .\hss } \hfill \kern \c_zero_dim } - -\cs_new:Nn \__nm_hdottedline: +\bool_if:NTF \c__nm_draft_bool + { \cs_set_eq:NN \__nm_dotfill: \prg_do_nothing: } + { + \cs_set:Npn \__nm_dotfill: + { + \cleaders \hbox_to_wd:nn { .44 em } { \hss .\hss } \hfill + \skip_horizontal:n \c_zero_dim + } + } +\cs_new:Npn \__nm_hdottedline: { \noalign { @@ -1180,19 +1281,6 @@ } } } -\__nm_msg_new:nn { Use~of~hdottedline~in~first~position } - { - You~can't~use~the~command~\token_to_str:N\hdottedline\ in~the~first~row~ - of~the~environment~\{\@currenvir\}.~But~maybe~you~have~used~l,~c~and~r~ - instead~of~L,~C,~R~in~the~preamble~of~the~array.\\ - If~you~go~on,~this~dotted~line~will~be~ignored. - } -\__nm_msg_new:nn { Use~of~hdottedline~in~first~position~bis } - { - You~can't~use~the~command~\token_to_str:N\hdottedline\ in~the~first~row~ - of~the~environment~\{\@currenvir\}. \\ - If~you~go~on,~this~dotted~line~will~be~ignored. - } \cs_new_protected:Nn \__nm_vdottedline:n { \int_compare:nNnTF #1 = \c_zero_int @@ -1293,6 +1381,7 @@ create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -1312,11 +1401,11 @@ \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 $ % $ + \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 { @@ -1363,6 +1452,7 @@ } \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 @@ -1414,6 +1504,7 @@ create-extra-nodes,~ extra-left-margin,~ extra-right-margin,~ + hlines,~ left-margin,~ name,~ nullify-dots,~ @@ -1421,8 +1512,16 @@ 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 } @@ -1430,25 +1529,25 @@ \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 } + { 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 { @@ -1456,7 +1555,7 @@ \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 } @@ -1482,44 +1581,44 @@ \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:nnnNn \l__nm_nb_first_row_int 1 \g__nm_row_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 } + \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:nNn \g__nm_column_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 } + \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 \l__nm_nb_first_row_int \g__nm_row_int \__nm_i: { - \int_step_variable:nNn \g__nm_column_total_int \__nm_j + \int_step_variable:nNn \g__nm_column_total_int \__nm_j: { \cs_if_exist:cT - { pgf@sh@ns@nm - \int_use:N \g__nm_env_int - \__nm_i- \__nm_j } + { pgf@sh@ns@nm - \int_use:N \g__nm_env_int - \__nm_i: - \__nm_j: } { \tikz@parse@node \pgfutil@firstofone ( nm - \int_use:N \g__nm_env_int - - \__nm_i - \__nm_j .south~west ) - \dim_set:cn { l__nm_row_\__nm_i _min_dim} - { \dim_min:vn { l__nm_row _ \__nm_i _min_dim } \pgf@y } - \seq_if_in:NxF \g__nm_multicolumn_cells_seq { \__nm_i - \__nm_j } + - \__nm_i: - \__nm_j: .south~west ) + \dim_set:cn { l__nm_row_\__nm_i: _min_dim} + { \dim_min:vn { l__nm_row _ \__nm_i: _min_dim } \pgf@y } + \seq_if_in:NxF \g__nm_multicolumn_cells_seq { \__nm_i: - \__nm_j: } { - \dim_set:cn { l__nm_column _ \__nm_j _ min_dim} - { \dim_min:vn { l__nm_column _ \__nm_j _min_dim } \pgf@x } + \dim_set:cn { l__nm_column _ \__nm_j: _min_dim} + { \dim_min:vn { l__nm_column _ \__nm_j: _min_dim } \pgf@x } } \tikz@parse@node \pgfutil@firstofone - ( nm - \int_use:N \g__nm_env_int - \__nm_i - \__nm_j .north~east ) - \dim_set:cn { l__nm_row _ \__nm_i _ max_dim } - { \dim_max:vn { l__nm_row _ \__nm_i _ max_dim } \pgf@y } - \seq_if_in:NxF \g__nm_multicolumn_cells_seq { \__nm_i - \__nm_j } + ( nm - \int_use:N \g__nm_env_int - \__nm_i: - \__nm_j: .north~east ) + \dim_set:cn { l__nm_row _ \__nm_i: _ max_dim } + { \dim_max:vn { l__nm_row _ \__nm_i: _ max_dim } \pgf@y } + \seq_if_in:NxF \g__nm_multicolumn_cells_seq { \__nm_i: - \__nm_j: } { - \dim_set:cn { l__nm_column _ \__nm_j _ max_dim } - { \dim_max:vn { l__nm_column _ \__nm_j _max_dim } \pgf@x } + \dim_set:cn { l__nm_column _ \__nm_j: _ max_dim } + { \dim_max:vn { l__nm_column _ \__nm_j: _max_dim } \pgf@x } } } } @@ -1527,33 +1626,33 @@ \tikzset { name~suffix = -medium } \__nm_create_nodes: \int_set:Nn \l__nm_nb_first_row_int 1 - \int_step_variable:nNn { \g__nm_row_int - 1 } \__nm_i + \int_step_variable:nNn { \g__nm_row_int - 1 } \__nm_i: { - \dim_set:cn { l__nm_row _ \__nm_i _ min _ dim } + \dim_set:cn { l__nm_row _ \__nm_i: _ min _ dim } { ( - \dim_use:c { l__nm_row _ \__nm_i _ min _ dim } + - \dim_use:c { l__nm_row _ \int_eval:n { \__nm_i + 1 } _ max _ dim } + \dim_use:c { l__nm_row _ \__nm_i: _ min _ dim } + + \dim_use:c { l__nm_row _ \int_eval:n { \__nm_i: + 1 } _ max _ dim } ) / 2 } - \dim_set_eq:cc { l__nm_row _ \int_eval:n { \__nm_i + 1 } _ max _ dim } - { l__nm_row_\__nm_i _min_dim } + \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_column_int - 1 } \__nm_j: { - \dim_set:cn { l__nm_column _ \__nm_j _ max _ dim } + \dim_set:cn { l__nm_column _ \__nm_j: _ max _ dim } { ( \dim_use:c - { l__nm_column _ \__nm_j _ max _ dim } + + { l__nm_column _ \__nm_j: _ max _ dim } + \dim_use:c - { l__nm_column _ \int_eval:n { \__nm_j + 1 } _ min _ dim } + { l__nm_column _ \int_eval:n { \__nm_j: + 1 } _ min _ dim } ) / 2 } - \dim_set_eq:cc { l__nm_column _ \int_eval:n { \__nm_j + 1 } _ min _ dim } - { l__nm_column _ \__nm_j _ max _ dim } + \dim_set_eq:cc { l__nm_column _ \int_eval:n { \__nm_j: + 1 } _ min _ dim } + { l__nm_column _ \__nm_j: _ max _ dim } } \dim_sub:cn { l__nm_column _ 1 _ min _ dim } @@ -1564,7 +1663,7 @@ \tikzset { name~suffix = -large } \__nm_create_nodes: \end{tikzpicture} - \cs_set:Nn \__nm_create_extra_nodes: { } + \cs_set:Npn \__nm_create_extra_nodes: { } \begin { tikzpicture } [ remember~picture , overlay ] \tikz@parse@node \pgfutil@firstofone ( nm - \int_use:N \g__nm_env_int - 1 - 1 - large .north~west ) @@ -1584,25 +1683,25 @@ } \cs_new_protected:Nn \__nm_create_nodes: { - \int_step_variable:nnnNn \l__nm_nb_first_row_int 1 \g__nm_row_int \__nm_i + \int_step_variable:nnNn \l__nm_nb_first_row_int \g__nm_row_int \__nm_i: { - \int_step_variable:nnnNn 1 1 \g__nm_column_total_int \__nm_j + \int_step_variable:nNn \g__nm_column_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 } ) ; + 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 }, - \dim_use:c { l__nm_row_ \__nm_i _max_dim } ) ; + at ( \dim_use:c { l__nm_column_ \__nm_j: _max_dim }, + \dim_use:c { l__nm_row_ \__nm_i: _max_dim } ) ; \node [ node~contents = { } , fit = ( __nm~south~west ) ( __nm~north~east ) , inner~sep = \c_zero_dim , - name = nm - \int_use:N \g__nm_env_int - \__nm_i - \__nm_j , + name = nm - \int_use:N \g__nm_env_int - \__nm_i: - \__nm_j: , alias = \str_if_empty:NF \g__nm_name_str - { \g__nm_name_str - \__nm_i - \__nm_j } + { \g__nm_name_str - \__nm_i: - \__nm_j: } ] ; } @@ -1614,34 +1713,34 @@ } \cs_new_protected:Npn \__nm_extract_coords: #1 - #2 \q_stop { - \cs_set:Npn \__nm_i { #1 } - \cs_set:Npn \__nm_j { #2 } + \cs_set:Npn \__nm_i: { #1 } + \cs_set:Npn \__nm_j: { #2 } } \cs_new_protected:Nn \__nm_node_for_multicolumn:nn { \__nm_extract_coords: #1 \q_stop \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 } + \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 _ \int_eval:n { \__nm_j + #2 - 1 } _ max _ dim} , - \dim_use:c { l__nm_row _ \__nm_i _ max _ dim } + \dim_use:c { l__nm_column _ \int_eval:n { \__nm_j: + #2 - 1 } _ max _ dim} , + \dim_use:c { l__nm_row _ \__nm_i: _ max _ dim } ) ; \node [ node~contents = { } , fit = ( __nm~south~west ) ( __nm~north~east ) , inner~sep = \c_zero_dim , - name = nm - \int_use:N \g__nm_env_int - \__nm_i - \__nm_j , + name = nm - \int_use:N \g__nm_env_int - \__nm_i: - \__nm_j: , alias = - \str_if_empty:NF \g__nm_name_str { \g__nm_name_str - \__nm_i - \__nm_j } + \str_if_empty:NF \g__nm_name_str { \g__nm_name_str - \__nm_i: - \__nm_j: } ] ; } -\ProcessKeysOptions {NiceMatrix} +\ProcessKeysOptions { NiceMatrix } \cs_new:Npn \__nm_seq_mapthread_function:NNN #1 #2 #3 { \group_begin: -- cgit v1.2.3