Variables in nested options
The following does not use the escaped value of c:
c = "red"
PGFPlotsX.@pgf PGFPlotsX.Plot(
{
mark = "*",
mark_options = { c },
},
PGFPlotsX.Coordinates(1:3,2:4))
It reports
! Package pgfkeys Error: I do not know the key '/tikz/c' and I am going to igno
re it. Perhaps you misspelled it.
Is there an alternative way to do this?
We did not expose that API yet, so currently a workaround would be some variant of
using PGFPlotsX
Plot(PGFPlotsX.dictify(["mark" => "*", c]), PGFPlotsX.Coordinates(1:3,2:4))
I can see two solutions to this:
- expose the API for constructing options, eg by defining a direct
push!method, and a constructor from an iterable, - make the
@pgfmacro process interpolation ($c)
We should do (1) in any case IMO, (2) would be a nice sugar in addition.
that wouldn't allow me to pass colors as a RGB type though, am I right?
no, use color = ... for that. that needs no extra tricks.
I mean something like
c = RGB(1.0,0.0,0.0)
PGFPlotsX.@pgf PGFPlotsX.Plot(
{
mark = "*",
"mark options" = "{ color = $c }",
},
PGFPlotsX.Coordinates(1:3,2:4))
( I try to get the markers in a different color than the line )
You don't need a string, so you don't need to interpolate:
using PGFPlotsX, Colors
c = RGB(1.0,0.0,0.0)
PGFPlotsX.@pgf PGFPlotsX.Plot(
{
mark = "*",
"mark options" = { color = c },
},
PGFPlotsX.Coordinates(1:3,2:4))
We could do like BenchmarkTools and implement interpolation in the macro.
I see, that would be useful to construct things like
using PGFPlotsX
opt = :mark
PGFPlotsX.@pgf { $opt = "*" }
That would be nice.
However, thinking about this, most of the standalone options one would want to interpolate are shortcuts, eg red is color = red, for which we have convenient syntax.