Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables in nested options #182

Open
BeastyBlacksmith opened this issue Nov 13, 2019 · 8 comments
Open

Variables in nested options #182

BeastyBlacksmith opened this issue Nov 13, 2019 · 8 comments

Comments

@BeastyBlacksmith
Copy link
Contributor

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?

@tpapp
Copy link
Collaborator

tpapp commented Nov 13, 2019

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.

@BeastyBlacksmith
Copy link
Contributor Author

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

@tpapp
Copy link
Collaborator

tpapp commented Nov 13, 2019

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

@BeastyBlacksmith
Copy link
Contributor Author

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 )

tpapp added a commit that referenced this issue Nov 13, 2019
Addesses #182, **NEEDS DOCS**.
@tpapp
Copy link
Collaborator

tpapp commented Nov 13, 2019

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

@KristofferC
Copy link
Owner

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

@BeastyBlacksmith
Copy link
Contributor Author

I see, that would be useful to construct things like

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

@tpapp
Copy link
Collaborator

tpapp commented Nov 15, 2019

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.

KristofferC pushed a commit that referenced this issue Nov 24, 2019
BeastyBlacksmith pushed a commit to BeastyBlacksmith/PGFPlotsX.jl that referenced this issue Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants