Open tobiasBora opened 9 months ago
It seems your usage example was pasted twice.
Thanks, sorry, this is fixed. So for now it seems that the simpler is to do /zx/boxes/.code={\scantokens{\pgfkeysalso{/zx/every box/.append style={#1}}}},
, I don't know if it is the recommended way to proceed or if we could provide a better solution.
Haven't looked at it in detail yet, but I can already guarantee that \scantokens
is not the correct solution.
I think what is going on here is a fundamental misunderstanding of how nested declarations are processed in TeX.
The #1
in fill=#1
will refer to the first argument of style node aux
and not to the first argument of the nested test
. For that you have to escape it using ##1
. That is the intended behavior. I don't see how a hypothetical .append estyle
handler would help here.
Try swapping fill=#1
and fill=##1
in the following example to see it:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
style node aux/.style={},%
style node/.code = {%
\pgfkeysalso{style node aux/.append style={#1}}%
},
}
\tikzset{
style node={
test/.style={fill=#1},
test=red,
},
style node={rounded corners},
}
\begin{tikzpicture}
\node[style node aux] at (0,0) {Hello};
\node[style node aux=blue] at (3,0) {Hello};
\end{tikzpicture}
\end{document}
Oh sure, the issue is that I do not want to escape it since it is the duty of my users to double the number of hashes. One reason is that the user does not know where the style is defined, and how many layers of escape they should use, and it is easy to forget the escaping and get weird result (as your example shows).
In one project for instance I use nested styles (as I can’t find a clean way to import styles, cf my other issue) and it might be the case that the user needs to escape it 2 or even 3 times (i.e. needs 2^3 = 8 hashes) in extreme cases… and nobody wants to write \helloNode{inner style={my style/.style={fill=########1},}}
, not only because it is ugly, but also because it is error prone (forgetting to double the hashes might not even produce an error, instead weird values will just be inserted).
The .append estyle
comes from a suggestion proposed here that can solve the problem if I want to replace the style with estyle
, but cannot append a style to it.
Another potential solution would be to be able to define an equivalent of .style
that takes no argument at all (most of the time I do not need any argument), and therefore would not require escaping.
Brief outline of the proposed feature
If I define a style and a command like this (following the usual convention in tikz to define a style and a code to edit the style):
Then the user needs to double the number of hashes:
I asked here an elegant solution to avoid that issue, and people mentioned that it is possible to do:
but this replaces the style while I’d like to append stuff to the style. But I can't find an equivalent of
.append estyle
. Would it be possible to provide an elegant solution to this issue?Usage example