I have some macros \foo
that expand to |[some style]| the content
, and I’d like to be able to do: execute at empty cell={\foo}
(I can already do \foo
inside a matrix). But it seems like execute at empty cell
does not allow this syntax. Any idea how to make this work?
Importantly: I want BOTH syntax to work since I might also use normal syntax), so sayed differently, I want to find a command \createNode
such that execute at empty cell={\createNode{\node[red]{A};}}
works and execute at empty cell={\createNode{|[red]|A}}
works as well.
\documentclass[options]{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
For now I do:
\begin{tikzpicture}
\matrix [matrix of math nodes,
execute at empty cell={\node[red]{A};
}]
{
8 & & |[green]| B \\
& 5 & \\
4 & & 2 \\
};
\end{tikzpicture}
And I would like this to work (the reason being that I internally call existing macros that expand to this):
\begin{tikzpicture}
\matrix [matrix of math nodes,
%% This ----------------v
execute at empty cell={|[red]| A}
]
{
8 & & |[green]| B \\
& 5 & \\
4 & & 2 \\
};
\end{tikzpicture}
\end{document}
EDIT
Thanks for the answer, sadly it does not work for both, it is broken now for \node
:
replace empty cell with={\node[red]{A};}
instead, I get an error saying that node is not defined.
I also tried to replace this code with directly:
execute at empty cell={
\tikz@lib@matrix@start@cell
|[red]| A%
\tikz@lib@matrix@end@cell
}
but it is not working (error ERROR: Argument of \tikz@next has an extra }.
). Any idea why?
Then, I tried it on my real world example, but it does not work as all normal nodes at least are removed. I use something like this, but without success, does it ring a bell?
/tikz/replace empty cell with/.code={%
\def\tikz@at@emptycell{%
\tikz@lib@matrix@start@cell
#1%
\tikz@lib@matrix@end@cell
}%
},
/tikz/replace empty cell with={%
% /tikz/execute at empty cell={%
% We want to check if there is a
\ifcsname zxExecuteAtCell-\tikzcdmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn\endcsname%
\csname zxExecuteAtCell-\tikzcdmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn\endcsname%
\else%
\ifdefined\zxCustomExecuteAtEmptyCell\zxCustomExecuteAtEmptyCell%
\else%
\coordinate[
% yshift=axis_height, % We already do that elsewhere
name=\tikzmatrixname
-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn];
\fi%
\fi%
},
|
out, for example. If you had to, you could also pass it to a custom key which passed it on toexecute at empty cells
, though I imagine that would be needlessly circuitous.|
programmatically. That is, you take whatever the current internals spits out, parse it and remove the|
delimiters, then pass it to the key. Alternatively, you pass what it spits out to a key which removes them and passes it to the existing key. But the ans below is far neater.\node
will not give a default name to the nodes based on the position in the matrix, which is really important for my application. (or maybe I can manually specify it, but then it gets quite ugly)\createnode{}
to parse the argument as a regular expression and substitute as necessary. If the expression has constraints as a result of your internal manipulations, make use of them. You'll need at least minimal predictability e.g. no|
except the two would help a lot - then you can just remove them, remove the unneeded\node
and add\node
as you want.