PGFPlotsX.jl icon indicating copy to clipboard operation
PGFPlotsX.jl copied to clipboard

Variables in nested options

Open BeastyBlacksmith opened this issue 6 years ago • 8 comments

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?

BeastyBlacksmith avatar Nov 13 '19 13:11 BeastyBlacksmith

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:

  1. expose the API for constructing options, eg by defining a direct push! method, and a constructor from an iterable,
  2. make the @pgf macro process interpolation ($c)

We should do (1) in any case IMO, (2) would be a nice sugar in addition.

tpapp avatar Nov 13 '19 14:11 tpapp

that wouldn't allow me to pass colors as a RGB type though, am I right?

BeastyBlacksmith avatar Nov 13 '19 14:11 BeastyBlacksmith

no, use color = ... for that. that needs no extra tricks.

tpapp avatar Nov 13 '19 15:11 tpapp

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 )

BeastyBlacksmith avatar Nov 13 '19 15:11 BeastyBlacksmith

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))

tpapp avatar Nov 13 '19 15:11 tpapp

We could do like BenchmarkTools and implement interpolation in the macro.

KristofferC avatar Nov 13 '19 15:11 KristofferC

I see, that would be useful to construct things like

using PGFPlotsX
opt = :mark
PGFPlotsX.@pgf { $opt = "*" }

BeastyBlacksmith avatar Nov 14 '19 07:11 BeastyBlacksmith

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.

tpapp avatar Nov 15 '19 07:11 tpapp