KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Support for raw"..." strings inside at-pgf {...}. #247

Closed fredrikekre closed 3 years ago

fredrikekre commented 3 years ago

This doesn't add support for raw"..." when used as a key, e.g. @pgf {raw"a" = b}, but I couldn't not find any examples of keys where you might want that in the example gallery. However, it is a pretty small change to support that too, e.g.

diff --git a/src/options.jl b/src/options.jl
index 109e0a2..d701c17 100644
--- a/src/options.jl
+++ b/src/options.jl
@@ -68,6 +68,9 @@ function prockey(key)
     elseif @capture(key, @raw_str(str_))
         return :($(string(str)) => nothing)
     elseif @capture(key, (a_ : b_) | (a_ => b_) | (a_ = b_))
+        if @capture(a, @raw_str(str_))
+            a = str
+        end
         return :($(string(a))=>$b)
     elseif @capture(key, g_...)
         return :($MergeEntry($g))

Thoughts?

tpapp commented 3 years ago

I am confused: it looks to me that this does add support for raw"..." as a key. Isn't that the intention?

Practically, I don't think this came up before since one usually doesn't need \ and $ in pgfplots keys, so plain vanilla strings are fine. Is there an example where you needed this?

fredrikekre commented 3 years ago

I am confused: it looks to me that this does add support for raw"..." as a key. Isn't that the intention?

I mean that it doesn't add support for @pgf { raw"hello" = "world" }, only @pgf { raw"hello = world" }.

Practically, I don't think this came up before since one usually doesn't need \ and $ in pgfplots keys, so plain vanilla strings are fine. Is there an example where you needed this?

Right, what triggered this PR was actually a misread from me where I thought someting should go in options [] but should be outside. However, I sometiemes find it convenient to just copy-paste stuff and have it work. A trivial example would be something like @pgf {raw"xlabel=$x$"}. Obviously this could be written as @pgf {xlabel=raw"$x$"}, but for multiword keys it would be @pgf {"two word key" = raw"$x$"} and then we might as well just support @pgf {raw"two word key = $x$"} and you don't have to worry about splitting the entry yourself.

KristofferC commented 3 years ago

Since we pass through String literals I think it makes sense to pass through raw strings as well.