summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/nicematrix
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-02-26 23:16:50 +0000
committerKarl Berry <karl@freefriends.org>2018-02-26 23:16:50 +0000
commit50ac47bcadbdf7f9fda1f19d5e1eae599006bfa5 (patch)
tree0d783c06eaaf66a84ae14558989b2dcde3c00dae /Master/texmf-dist/source/latex/nicematrix
parent468ba45a95f1adb9c950eae06fbabace68c4b561 (diff)
nicematrix (27feb18)
git-svn-id: svn://tug.org/texlive/trunk@46747 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/nicematrix')
-rw-r--r--Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx235
1 files changed, 136 insertions, 99 deletions
diff --git a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx
index bead31a579d..bfb21ac8785 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{1.0}
-\def\myfiledate{2018/02/13}
+\def\myfileversion{1.1}
+\def\myfiledate{2018/02/26}
%
%
%<*batchfile>
@@ -26,7 +26,7 @@
\usedir{tex/latex/nicematrix}
\preamble
-Copyright (C) 2017 by F. Pantigny
+Copyright (C) 2018 by F. Pantigny
-----------------------------------
This file may be distributed and/or modified under the
@@ -46,20 +46,15 @@ version 2005/12/01 or later.
%
%<@@=nm>
%<*driver>
-\documentclass{l3doc} % load fancyvrb, amsmath, array, color, etc.
+\documentclass[dvipsnames]{l3doc}% dvipsnames is for xcolor (loaded by Tikz, loaded by nicematrix)
\VerbatimFootnotes
\usepackage{xltxtra}
-\usepackage{lmodern}
\usepackage{geometry}
-\usepackage[dvipsnames]{xcolor} % color is already loaded with l3doc (?)
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
-\usepackage{mathtools}
-\usepackage{amsfonts}
-\usepackage{stmaryrd}
\usepackage{nicematrix}
\NewDocumentEnvironment {scope} {} {} {}
\def\interitem{\vskip 7mm plus 2 mm minus 3mm}
-\def\emphase#1{{\color{RoyalPurple}#1}}
+\def\emphase{\bgroup\color{RoyalPurple}\let\next=}
\fvset{commandchars=\~\#\@,formatcom={\color{gray}}}
\parindent 0pt
\DisableCrossrefs
@@ -83,8 +78,7 @@ version 2005/12/01 or later.
%
% This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by the classical workflow
% |latex|-|dvips|-|ps2pdf| (or Adobe Distiller). Two compilations may be necessary. This package requires the
-% packages \pkg{expl3}, \pkg{l3keys2e}, \pkg{xparse}, \pkg{array}, \pkg{mathtools} and \pkg{tikz}. The Tikz
-% libraries \pkg{calc} and \pkg{math} are also required.
+% packages \pkg{expl3}, \pkg{l3keys2e}, \pkg{xparse}, \pkg{array}, \pkg{mathtools} and \pkg{tikz}.
%
% \medskip
% The package \pkg{nicematrix} aims to draw beautiful matrices in a way almost transparent for the user.
@@ -141,7 +135,9 @@ version 2005/12/01 or later.
% Inside these environments, five new commands are defined: |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots| and |\Iddots|.
% These commands are intended to be used in place of |\dots|, |\cdots|, |\vdots|, |\ddots| and
% |\iddots|.\footnote{The command |\iddots|, defined in \pkg{nicematrix}, is a variant of
-% |\ddots| with dots going forward: \smash{$\iddots$}. If |mathdots| is loaded, the version of |mathdots| is used.}
+% |\ddots| with dots going forward: \smash{$\iddots$}. If the command |\iddots| is already defined (for example if
+% \pkg{mathdots} is loaded), the previous definition is not overwritten. Note that the package \pkg{yhmath} provides a
+% command |\adots| similar to |\iddots|.}
%
% \smallskip
% Each of them must be used alone in the cell of the array and it draws a dotted line between the first non-empty
@@ -207,7 +203,7 @@ version 2005/12/01 or later.
%
% However, useless computations are performed by TeX before detecting that both instructions would eventually yield
% the same dotted line. That's why the package \pkg{nicematrix} provides starred versions of |\Ldots|, |\Cdots|,
-% etc.: |\Ldots*|, |\Cdots*|, etc.. These versions are simply equivalent to |\hphantom{\ldots}|,
+% etc.: |\Ldots*|, |\Cdots*|, etc. These versions are simply equivalent to |\hphantom{\ldots}|,
% |\hphantom{\cdots}|, etc. The user should use these starred versions whenever a classical version has already
% been used for the same dotted line.\par\nobreak
% \bigskip
@@ -484,9 +480,11 @@ version 2005/12/01 or later.
% \vskip1cm
% \subsection{The ``empty'' cells}
%
-% An instruction like |\Ldots|, |\Cdots|, etc. tries to determine the first non-empty cell on both sides. However,
-% a 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.
+% An instruction like |\Ldots|, |\Cdots|, etc. tries to determine the first non-empty cell on both
+% sides\footnote{If \pkg{nicematrix} can't find theses cells, an error |Imposible instruction| is raised. Nevertheless,
+% with the option |Silent|, these instructions are discarded silently.}. However, a 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.
%
% \interitem
% For \pkg{nicematrix}, the precise rules are as follow.
@@ -608,18 +606,8 @@ version 2005/12/01 or later.
%
% \subsection{Declaration of the package and extensions loaded}
%
-%
-% First, Tikz and the Tikz libraries \pkg{calc} and \pkg{math} are loaded before the |\ProvidesExplPackage|. They
-% are loaded this way because |\usetikzlibrary| in |expl3| code fails.\footnote{cf.
-% |tex.stackexchange.com/questions/57424/using-of-usetikzlibrary-in-an-expl3-package-fails|}
-%
-% \begin{macrocode}
-\RequirePackage{tikz}
-\usetikzlibrary{calc,math}
-% \end{macrocode}
-%
% \bigskip
-% Then, we can give the traditionnal declaration of a package written with |expl3|:
+% We give the traditionnal declaration of a package written with |expl3|:
% \begin{macrocode}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
@@ -632,10 +620,11 @@ version 2005/12/01 or later.
% The command for the treatment of the options of |\usepackage| is at the end of this package for technical reasons.
%
% \bigskip
-% We load \pkg{array} and \pkg{mathtools} (\pkg{mathtools} may be considered as the successor of \pkg{amsmath}).
+% We load \pkg{array} and \pkg{mathtools} (\pkg{mathtools} may be considered as the successor of \pkg{amsmath}) and \pkg{tikz}.
% \begin{macrocode}
\RequirePackage{array}
\RequirePackage{mathtools}
+\RequirePackage{tikz}
% \end{macrocode}
%
% \bigskip
@@ -649,19 +638,19 @@ version 2005/12/01 or later.
% \subsection{Technical definitions}
%
% First, we define a command |\iddots| similar to |\ddots| ($\ddots$) but with dots going forward ($\iddots$). We
-% use |\ProvideDocumentCommand|, and so, if the command |\iddots| has already been defined (for example by the
-% package \pkg{mathdots}), we don't define it again.
+% use |\ProvideDocumentCommand| of \pkg{xparse}, and so, if the command |\iddots| has already been defined (for
+% example by the package \pkg{mathdots}), we don't define it again.
%
% \begin{macrocode}
\ProvideDocumentCommand \iddots {}
{\mathinner{\mkern 1mu
- \raise 1pt \hbox{.}
+ \raise \p@ \hbox{.}
\mkern 2mu
- \raise 4pt\hbox{.}
+ \raise 4\p@ \hbox{.}
\mkern 2mu
- \raise7pt \vbox{\kern 7pt
- \hbox{.}}
- \mkern1mu}}
+ \raise 7\p@ \vbox{\kern 7pt
+ \hbox{.}}
+ \mkern 1mu}}
% \end{macrocode}
%
% This definition is a variant of the standard definition of |\ddots|.
@@ -742,10 +731,20 @@ version 2005/12/01 or later.
% classical |{matrix}| and |\ldots|, |\vdots|, etc.). This option is set by default.
% \begin{macrocode}
NullifyDots .bool_set:N = \l_@@_nullify_dots_bool ,
- NullifyDots .default:n = true}
+ NullifyDots .default:n = true,
% \end{macrocode}
%
% \bigskip
+% With the option |Silent|, no error is generated for the impossible instructions. This option can be useful when
+% adapting an existing code.
+% \begin{macrocode}
+ Silent .code:n = {\msg_redirect_name:nnn {nicematrix}
+ {Impossible~instruction}
+ {none}} ,
+ Silent .value_forbidden:n = true}
+% \end{macrocode}
+%
+% \bigskip
% |\NiceMatrixOptions| is the command of the \pkg{nicematrix} package to fix options at the document level. The
% scope of these specification is the current TeX group.
% \begin{macrocode}
@@ -929,10 +928,9 @@ version 2005/12/01 or later.
% If the cell is a implicit cell (that is after the symbol |\\| of end of row), the cell must, of course, be
% considered as empty. It's easy to check wether we are in this situation considering the correspondant Tikz node.
% \begin{macrocode}
- {\cs_if_exist:cTF {pgf@sh@ns@nm-
- \int_use:N \g_@@_env_int-
- \int_use:N #1-
- \int_use:N #2}
+ {\cs_if_exist:cTF {pgf@sh@ns@nm-\int_use:N \g_@@_env_int-
+ \int_use:N #1-
+ \int_use:N #2}
% \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
@@ -944,26 +942,24 @@ version 2005/12/01 or later.
% \end{macrocode}
% In the general case, we consider the width of the Tikz node corresponding to the cell. In order to compute this
% width, we have to extract the coordinate of the west and east anchors of the node. This extraction needs a
-% command |\tikz| but, in fact, nothing is drawn.
-% \begin{macrocode}
- {\tikz[remember~picture]
- \path let \p1 = (nm-
- \int_use:N \g_@@_env_int-
- \int_use:N #1-
- \int_use:N #2.east),
- \p2 = (nm-
- \int_use:N \g_@@_env_int-
- \int_use:N #1-
- \int_use:N #2.west)
- in \pgfextra {\dim_gset:Nn \g_tmpa_dim {\x1}
- \dim_gset:Nn \g_tmpb_dim {\x2}} ;
-% \end{macrocode}
-% We compute in |\g_tmpa_dim| the width of the Tikz node.
-% \begin{macrocode}
- \dim_gsub:Nn \g_tmpa_dim \g_tmpb_dim
- \dim_compare:nNnTF {\dim_abs:n \g_tmpa_dim} < {0.5 pt}
+% command environment |{pgfpicture}| but, in fact, nothing is drawn.
+% \begin{macrocode}
+ {\begin{pgfpicture}
+% \end{macrocode}
+% We store the name of the node corresponding to the cell in |\l_tmpa_tl|.
+% \begin{macrocode}
+ \tl_set:Nx \l_tmpa_tl {nm-\int_use:N \g_@@_env_int-
+ \int_use:N #1-
+ \int_use:N #2}
+ \pgfpointanchor \l_tmpa_tl {east}
+ \dim_gset:Nn \g_tmpa_dim \pgf@x
+ \pgfpointanchor \l_tmpa_tl {west}
+ \dim_gset:Nn \g_tmpb_dim \pgf@x
+ \end{pgfpicture}
+ \dim_compare:nNnTF {\dim_abs:n {\g_tmpb_dim-\g_tmpa_dim}} < {0.5 pt}
{\prg_return_false:}
- {\prg_return_true:}}}
+ {\prg_return_true:}
+ }}
{\prg_return_false:}
}
% \end{macrocode}
@@ -1229,44 +1225,46 @@ version 2005/12/01 or later.
% |\l_@@_final_i_int| and |\l_@@_final_j_int|.
%
% The two arguments of the command |\@@_retrieve_coords:nn| are the anchors that must be used for the two nodes.
-% These anchors must be given with the point (e.g.: |.north|, |.south|, etc.).
%
% The coordinates are stored in |\g_@@_x_initial_dim|, |\g_@@_y_initial_dim|, |\g_@@_x_final_dim|,
-% |\g_@@_y_final_dim|. These variables are global for technical reasons: we have to do an affectation in a Tikz
-% picture.
+% |\g_@@_y_final_dim|. These variables are global for technical reasons: we have to do an affectation in an
+% environment |{pgfpicture}|.
% \begin{macrocode}
\cs_new_protected:Nn \@@_retrieve_coords:nn
- {\tikz[remember~picture]
- \path let \p1 = (nm-\int_use:N \g_@@_env_int-
- \int_use:N \l_@@_initial_i_int-
- \int_use:N \l_@@_initial_j_int #1),
- \p2 = (nm-\int_use:N \g_@@_env_int-
- \int_use:N \l_@@_final_i_int-
- \int_use:N \l_@@_final_j_int #2)
- in \pgfextra {\dim_gset:Nn \g_@@_x_initial_dim {\x1}
- \dim_gset:Nn \g_@@_y_initial_dim {\y1}
- \dim_gset:Nn \g_@@_x_final_dim {\x2}
- \dim_gset:Nn \g_@@_y_final_dim {\y2}} ; }
+ {\begin{tikzpicture}[remember~picture]
+ \tikz@parse@node\pgfutil@firstofone
+ (nm-\int_use:N \g_@@_env_int-
+ \int_use:N \l_@@_initial_i_int-
+ \int_use:N \l_@@_initial_j_int.#1)
+ \dim_gset:Nn \g_@@_x_initial_dim \pgf@x
+ \dim_gset:Nn \g_@@_y_initial_dim \pgf@y
+ \tikz@parse@node\pgfutil@firstofone
+ (nm-\int_use:N \g_@@_env_int-
+ \int_use:N \l_@@_final_i_int-
+ \int_use:N \l_@@_final_j_int.#2)
+ \dim_gset:Nn \g_@@_x_final_dim \pgf@x
+ \dim_gset:Nn \g_@@_y_final_dim \pgf@y
+ \end{tikzpicture} }
% \end{macrocode}
%
% \interitem
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_ldots_line:
- {\@@_retrieve_coords:nn {.south~east} {.south~west}
+ {\@@_retrieve_coords:nn {south~east} {south~west}
\@@_draw_tikz_line:}
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_cdots_line:
- {\@@_retrieve_coords:nn {.mid~east} {.mid~west}
+ {\@@_retrieve_coords:nn {mid~east} {mid~west}
\@@_draw_tikz_line:}
% \end{macrocode}
%
% \bigskip
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_vdots_line:
- {\@@_retrieve_coords:nn {.south} {.north}
+ {\@@_retrieve_coords:nn {south} {north}
\@@_draw_tikz_line:}
% \end{macrocode}
%
@@ -1276,7 +1274,7 @@ version 2005/12/01 or later.
% one.
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_ddots_line:
- {\@@_retrieve_coords:nn {.south~east} {.north~west}
+ {\@@_retrieve_coords:nn {south~east} {north~west}
% \end{macrocode}
% We have retrieved the coordinates in the usual way (they are stored in |\g_@@_x_initial_dim|, etc.).
% If the parallelization of the diagonals is set, we will have (maybe) to adjust the fourth coordinate.
@@ -1311,7 +1309,7 @@ version 2005/12/01 or later.
% We draw the |\Iddots| diagonals in the same way.
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_iddots_line:
- {\_@@_retrieve_coords:nn {.south~west} {.north~east}
+ {\@@_retrieve_coords:nn {south~west} {north~east}
\bool_if:NT \l_@@_parallelize_diags_bool
{\int_incr:N \l_@@_iddots_int
\int_compare:nNnTF \l_@@_iddots_int = 1
@@ -1330,28 +1328,58 @@ version 2005/12/01 or later.
% The command |\@@_draw_tikz_line:| draws the line using four implicit arguments:
%
% \quad |\g_@@_x_initial_dim|, |\g_@@_y_initial_dim|, |\g_@@_x_final_dim| and |\g_@@_y_final_dim|.
-
-% These variables are global for technical reasons: we have to do affectations in an instruction |\tikz|.
+% These variables are global for technical reasons: their first affectation was in an instruction |\tikz|.
%
% \begin{macrocode}
\cs_new_protected:Nn \@@_draw_tikz_line:
- {\begin{tikzpicture}[overlay]
- \tikzmath{
- coordinate~\a , \b ;
- real~\l, \x, \d ;
- integer~\n ;
- \a = (\g_@@_x_initial_dim, \g_@@_y_initial_dim) ;
- \b = (\g_@@_x_final_dim, \g_@@_y_final_dim) ;
- \l = veclen(\bx-\ax,\by-\ay) ;
- \n = (\l - 0.54em)/(0.45em) ;
- \x = (\l - \n*0.45em)/(2*\l) ;
- \d = 0.45em / \l ;
- if~\n>0
- then~{ for~\k in~{0,...,\n}
- { {\node at ($(\a)!\x+\k*\d!(\b)$) {.} ; } ; } ;
- } ;
- }
- \end{tikzpicture}}
+ {
+% \end{macrocode}
+% The dimension |\l_@@_l_dim| is the length $\ell$ of the line to draw. We use the floating point reals of
+% \pkg{expl3} to compute this length.
+% \begin{macrocode}
+ \dim_zero_new:N \l_@@_l_dim
+ \dim_set:Nn \l_@@_l_dim
+ { \fp_to_dim:n
+ { sqrt( ( \dim_use:N \g_@@_x_final_dim
+ -\dim_use:N \g_@@_x_initial_dim) ^2
+ +( \dim_use:N \g_@@_y_final_dim
+ -\dim_use:N \g_@@_y_initial_dim) ^2 )}
+ }
+% \end{macrocode}
+% The integer |\l_tmpa_int| is the number of dots of the dotted line.
+% \begin{macrocode}
+ \int_set:Nn \l_tmpa_int {\dim_ratio:nn {\l_@@_l_dim - 0.54em}
+ {0.45em}}
+% \end{macrocode}
+% The dimensions |\l_tmpa_dim| and |\l_tmpb_dim| are the coordinates of the vector between two dots in the
+% dotted line.
+% \begin{macrocode}
+ \dim_set:Nn \l_tmpa_dim { (\g_@@_x_final_dim - \g_@@_x_initial_dim)
+ * \dim_ratio:nn {0.45em} \l_@@_l_dim}
+ \dim_set:Nn \l_tmpb_dim { (\g_@@_y_final_dim - \g_@@_y_initial_dim)
+ * \dim_ratio:nn {0.45em} \l_@@_l_dim}
+% \end{macrocode}
+% In the loop over the dots (|\int_step_inline:nnnn|), the dimensions |\g_@@_x_initial_dim| and
+% |\g_@@_y_initial_dim| will be used for the coordinates of the dots.
+% \begin{macrocode}
+ \dim_gadd:Nn \g_@@_x_initial_dim
+ { (\g_@@_x_final_dim - \g_@@_x_initial_dim)
+ * \dim_ratio:nn {\l_@@_l_dim - 0.45 em * \l_tmpa_int}
+ {\l_@@_l_dim * 2}}
+ \dim_gadd:Nn \g_@@_y_initial_dim
+ { (\g_@@_y_final_dim - \g_@@_y_initial_dim)
+ * \dim_ratio:nn {\l_@@_l_dim - 0.45 em * \l_tmpa_int}
+ {\l_@@_l_dim * 2}}
+ \begin{tikzpicture}[overlay]
+ \int_step_inline:nnnn 0 1 \l_tmpa_int
+ { \pgfpathcircle{\pgfpoint{\g_@@_x_initial_dim}
+ {\g_@@_y_initial_dim}}
+ {0.53pt}
+ \pgfusepath{fill}
+ \dim_gadd:Nn \g_@@_x_initial_dim \l_tmpa_dim
+ \dim_gadd:Nn \g_@@_y_initial_dim \l_tmpb_dim }
+ \end{tikzpicture}
+}
% \end{macrocode}
%
% \bigskip
@@ -1480,8 +1508,17 @@ version 2005/12/01 or later.
probably~be~wrong.}
% \end{macrocode}
%
-% \endinput
%
+% \section{History}
+%
+% \subsection{Changes between versions 1.0 and 1.1}
+%
+% Option |Silent| (with this option, the impossible instructions are discarded silently).
+%
+% The dotted lines are no longer drawn with Tikz nodes but with Tikz circles (for efficiency).
+%
+% Modification of the code which is now twice faster.
+% \endinput
% Local Variables:
% TeX-fold-mode: nil
% End: