JuliaPlots / MakieTeX.jl

TeX integration in Makie
MIT License
86 stars 12 forks source link

`LTeX` in `Legend` #26

Closed greimel closed 2 years ago

greimel commented 2 years ago

In the README you say you can have LaTeX in the legend. Would you mind adding code for the example, just to get an idea of how hacky it is?

asinghvi17 commented 2 years ago

The code is at https://gist.github.com/asinghvi17/53f09388954e8ad7728b85ecf62a20cf (it was adapted from some code written a couple of years ago, and still a little disjointed) but basically the principle was:


 ltexs = LTeX.(
     Ref(fig), [
         L"dv = 0", L"v", "Trajectories", "Trajectory from \$(v_0, w_0)\$",
         L"dw = 0", L"w", "Initial point"
     ];
     halign = :left,
 )
 translate!.(getproperty.(ltexs, :blockscene), 0, 0, 100)

 grid_indices = vcat(CartesianIndex.(1, 2:2:8), CartesianIndex.(2, 2:2:6))

 for (ind, ltex) in zip(grid_indices, ltexs)
     leg.grid[1, 1][ind[1], ind[2]] = ltex
 end
asinghvi17 commented 2 years ago

P.S. The legend should be initialized with empty strings.

asinghvi17 commented 2 years ago

I am pretty time squeezed now but will probably end up doing #27 and #29 at some point. With these, I'll be able to extend Makie's atomic text! to the tex-image recipe, which means you could just pass a CachedTeX or TeXDocument to the legend constructor, or possibly even axis ticks and labels!

asinghvi17 commented 2 years ago

On current master (will tag a version today or tomorrow), you only have to supply LaTeXStrings to the legend (or TeXDocuments or CachedTeX) in place of ordinary Strings.