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