JuliaPlots / MakieTeX.jl

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

Switch to poppler pipeline #25

Closed asinghvi17 closed 2 years ago

asinghvi17 commented 2 years ago

Currently, there are two issues with this:

Screen Shot 2022-05-06 at 5 40 52 PM

Otherwise, it works and is probably faster than the current master.

greimel commented 2 years ago
  • weird gray border at the edge of any LTeX

Did you check what happens after processing the pdf in Makie?

To me it seems that all pdfs have a gray frame when opening on macos. After importing to inkscape that frame is gone.

asinghvi17 commented 2 years ago

Hmm, good point - will have to test that. As I recall it did not.

asinghvi17 commented 2 years ago

Looks like there are rotation issues in the PNG backend, which is really strange, and image rendering isn't working at all. I'm not comfortable merging this without figuring the PNG issues out, but if anyone wants to use it only for PDFs, feel free.

With CairoMakie (rendered direct from surface)

corrupted_axis.pdf

corrupted_axis

SVG looks bad here but fine on my Mac, somehow.

With GLMakie (rendered to image and plotted), it doesn't show up at all:

Screen Shot 2022-05-14 at 4 24 49 PM
asinghvi17 commented 2 years ago

OK, I still have some boundingbox issues but otherwise it looks fine. See the following images:

smooth-maps corrupted_axis logo

As of https://github.com/JuliaPlots/MakieTeX.jl/pull/25/commits/5d0c7f86d432b861998f5a3a127bb6cc4bad2a23, I was rendering directly from Poppler on cairo_draw. However: Poppler apparently forgets about the page at some point, so I am now trying to add a Glib object reference to CachedTeX. If that doesn't work, then I'll switch back to Cairo surfaces.

asinghvi17 commented 2 years ago

This should now be ready for anyone who wants to try it! The external API is essentially the same, with two new features.

Also, text! has been overridden for TeXDocument as well, so you can directly plot text / tikz using those.

asinghvi17 commented 2 years ago

As a stopgap, I brute-forced the Poppler issue by reloading the pdf at each CairoMakie render.

asinghvi17 commented 2 years ago

@greimel, thanks for the suggestion of tectonic! It seems to work pretty well as a fallback, and it does basic TikZ as well! I think that with this, we can successfully call MakieTeX platform-independent! With the text hijacking, I can do this:

fig = Figure()
l1 = Label(
    fig[1, 1], L"A \emph{convex} function $f \in C$ is \textcolor{blue}{denoted} as \tikz{\draw[line width=1pt, >->] (0, -2pt) arc (-180:0:8pt);}";
    tellwidth = false, tellheight = true
)
ax1 = Axis(
    fig[2, 1];
    xtickformat = x -> latexstring.("a_{" .* string.(x) .* "}"),
    ylabel = L"\displaystyle \Phi(\vec x) = f(\vec x) + g(V)",
    ylabelpadding = 15
)
heatmap!(ax1, Makie.peaks())
fig

hello copy

Two problems: note the large whitespace gap on the left (caused, I think, by a bad boundingbox in teximg) and the weird x tick labels. The x tick label issue is just because of asynchronous updates, which I am not entirely sure how to handle.

Essentially, the ticks just take too long to render; because of that, there is some asynchronicity between the positions and the markers. I would have to implement a pipeline such that the cached tex and positions go together - maybe by forcing the user to pass Vector{Tuple{CachedTeX, Point3f}}?

asinghvi17 commented 2 years ago

Theming is fully integrated!

julia> fig = with_theme(theme_dark()) do
                           fig = Figure(fontsize = 12, resolution = (300, 300))
                           ax = Axis(
                               fig[1,1];
                               xlabel = LaTeXString("time (\$t\$) in arbitrary units"),
                               ylabel = LaTeXString("here we go fellas"),
                               title  = LaTeXString(raw"A \emph{convex} function $f \in C$ is \textcolor{red}{denoted} as \tikz{\draw[line width=1pt, >->] (0, -2pt) arc (-180:0:8pt);}"),
                               xtickformat = x -> latexstring.("a_{" .* string.(x) .* "}"),
                               xlabelpadding = 12,
                               ylabelpadding = 12,
                           )
                           # plot to the axis
                           heatmap!(ax, Makie.peaks(); colormap = :inferno)
                           fig
                       end

iTerm2 PJyE1B