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

Vector syntax not working within options? #284

Open
kimauth opened this issue Oct 3, 2021 · 4 comments
Open

Vector syntax not working within options? #284

kimauth opened this issue Oct 3, 2021 · 4 comments

Comments

@kimauth
Copy link

kimauth commented Oct 3, 2021

Does the vector syntax not work within a set of options or am I just missing how to do this right?

This is what I would like to obtain:

using PGFPlotsX

node_options = @pgf {circle, # and some other options I want to set
                    pin=raw"[pin edge = {out=-70,in=110,semithick,}, color={rgb,1:red,0.0052;green,0.0982;blue,0.3498}] below right:{my_text}"}

# prints as
[circle, pin={[pin edge = {out=-70,in=110,semithick,}, color={rgb,1:red,0.0052;green,0.0982;blue,0.3498}] below right:{my_text}}]

But, within the options of pin I don't want to hardcode the color. So I can do:

using ColorSchemes
blue = ColorSchemes.batlow[0.0]
pin_options = @pgf {pin_edge = {out=-70,in=110, semithick,}, color = blue}
pin = [pin_options, raw"below right:{my_text}"]

and so far, print_tex(pin) does what I want to get:

[pin edge={out={-70}, in={110}, semithick}, color={rgb,1:red,0.0052;green,0.0982;blue,0.3498}] below right:{my_text}

However, using pin within another set of options prints Julia types instead

node_options = @pgf {circle, pin = pin}

# prints as
[circle, pin={PGFPlotsX.Options(OrderedCollections.OrderedDict{Any, Any}("pin_edge" => PGFPlotsX.Options(OrderedCollections.OrderedDict{Any, Any}("out" => -70, "in" => 110, "semithick" => nothing), true), "color" => RGB{Float64}(0.005193,0.098238,0.349842)), true),below right:{my_text}}]
@KristofferC
Copy link
Owner

KristofferC commented Oct 3, 2021

It is possible

print_opt(io::IO, v::AbstractVector) = print(io, join(v, ","))
should be changed to also call print_tex on the vs.

I just tried something like

@eval PGFPlotsX begin
    print_opt(io::IO, v::AbstractVector) = print(io, join((print_tex(String, x) for x in v), ","))
end

and I get

julia> node_options
[circle, pin={[pin edge={out={-70}, in={110}, semithick}, color={rgb,1:red,0.0052;green,0.0982;blue,0.3498}] ,below right:{my_text}
}]

I haven't thought anything deep about this though.

@kimauth
Copy link
Author

kimauth commented Oct 3, 2021

It's almost good, but it prints a comma behind the square brackets which tikz doesn't understand. I guess this is sort of special syntax though, as it's options for tikz and not for pgf.

For the sake of completeness, here is something that actually shows a picture (and does work with the first node_options, but not if there is the additional comma):

axis_opts = @pgf {width = "8cm", "axis equal", xmin= -2., xmax=10, ymin = -2., ymax=9., axis_lines="none",}
Axis(axis_opts, [raw"\node", node_options, " at ", Coordinate(0.0, 0.0), "{};"],)

@tpapp
Copy link
Collaborator

tpapp commented Oct 4, 2021

Note that this is TikZ code, not pgfplots. In the manual we suggest that \node commands are just constructed as strings and passed as is.

I sympathize with

don't want to hardcode the color

but I would recommend constructing the string from something like

col = colorant"firebrick3"
sprint(PGFPlotsX.print_opt, col)

which is currently not officially part of the API but should remain supported.

Generally, quite a few building blocks of the package are useful outside pgfplots, and maybe we should make an effort to clean up and export them to emit LaTeX code for general purposes.

@tpapp
Copy link
Collaborator

tpapp commented Apr 27, 2022

Maybe we should just expose (but not necessarily export) print_opt and print_options as API, and mention them in the manual. They are probably the best solution for composing raw LaTeX directly with the translations this package implements.

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