I have the following code
\documentclass[10pt, a4paper]{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\ExplSyntaxOn
\NewDocumentCommand \WhenNotMeasuring { } { \legacy_if:nF {measuring@} }
\makeatother
\ExplSyntaxOff
\let\adding\relax
\pgfkeys{
/adding/.code=\ifx\adding\relax
\edef\adding{#1}%
\else
\edef\adding{\adding, #1}%
\fi
}
\begin{document}
\begin{align*}
\begin{bNiceMatrix}[name=mymatrix]
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{bNiceMatrix}
\WhenNotMeasuring{
\begin{tikzpicture}[remember picture,overlay]
\pgfkeys{/adding={2-3/3-3/2}}
\foreach \x/\y/\z in \adding{
\draw[->] (mymatrix-\x) ++(.75em,0) -- ++(.75em,0) node [anchor=west]{\tiny x\z} |- ($ (mymatrix-\y) + (0.75em,0) $);
}
%\foreach \x/\y in {\pgfkeysvalueof{/mult}}
%\draw (\x) ++(.75em,0) node [anchor=west]{\tiny \y};
%\foreach \x/\y in {\pgfkeysvalueof{\swap}}
%\draw (\x) -- ++(3ex,0) |- (\y);
\end{tikzpicture}
}
\end{align*}
\end{document}
But now if I move the \pgfkeys{/adding={2-3/3-3/2}} to the nicematrix env e.g.
\begin{bNiceMatrix}[name=mymatrix]
1 & 2 & 3 \\
4 & 5 & 6 \\ \pgfkeys{/adding={1-3/2-3/2}}
7 & 8 & 9 \\
\end{bNiceMatrix}
The arrow isn't drawn anymore.
Any Ideas why and how to solve it?
EDIT:
\documentclass[10pt, a4paper]{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\ExplSyntaxOn
\NewDocumentCommand \WhenNotMeasuring { } { \legacy_if:nF {measuring@} }
\makeatother
\ExplSyntaxOff
\makeatletter
\pgfkeys{
/adding/.code=\ifx\tikz@atticus@adding\relax
\xdef\tikz@atticus@adding{#1}%
\else
\xdef\tikz@atticus@adding{\tikz@atticus@adding, #1}%
\fi,/tikz/.cd,
reset Gauss/.code=\global\let\tikz@atticus@adding\relax,
reset Gauss,
get list/.code=\edef#1{\tikz@atticus@adding},
get list/.default=\adding,
}
\makeatother
\newenvironment{gaussMatrix}%
{
\begin{pNiceMatrix}[name=mymatrix]
}%
{
\end{pNiceMatrix}
\WhenNotMeasuring{
\begin{tikzpicture}[remember picture,overlay,get list=\adding]
\foreach \x/\y/\z in \adding
\draw[->] (mymatrix-\x) ++(.75em,0) -- ++(.75em,0) node [anchor=west]{\tiny x\z} |- ($ (mymatrix-\y) + (0.75em,0) $);
\tikzset{reset Gauss}% <-important
\end{tikzpicture}
}
}
\begin{document}
\begin{align*}
\begin{gaussMatrix}
1 & 1 & 1 & 1 & 1 \\
2 & 2 & 2 & 2 & 2 \\
3 & 3 & 3 & 3 & 3 \\
\end{gaussMatrix}
\end{align*}
\end{document}

/I thought it would be in the root "directory"? Any way to make it global? – atticus Jun 05 '20 at 20:40\adding. As a matter of fact, pgf keys are always local (unless you do something like\globaldefs1, which you absolutely should not). This has nothing to do with the hierarchy in pgf trees. – Jun 05 '20 at 20:42