diff --git a/Project.toml b/Project.toml index a578907..5fe2b45 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MakieTeX" uuid = "6d554a22-29e7-47bd-aee5-0c5f06619414" authors = ["Anshul Singhvi"] -version = "0.2.0" +version = "0.2.1" [deps] Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" diff --git a/src/recipe.jl b/src/recipe.jl index 9f840fb..e9b95a2 100644 --- a/src/recipe.jl +++ b/src/recipe.jl @@ -36,11 +36,11 @@ function offset_from_align(align::Tuple{Symbol, Symbol}, wh)::Vec2f y = -h / 2 if halign == :left - x -= w/2 + x += w/2 elseif halign == :center x -= 0 elseif halign == :right - x += w/2 + x -= w/2 end if valign == :top @@ -114,12 +114,13 @@ function draw_tex(scene::Scene, screen::CairoMakie.CairoScreen, cachedtex::Cache # First, find the desired position of the marker with respect to the alignment halign, valign = align + pos = position pos = if halign == :left - position .- (scale[1], 0) + pos # (scale[1], 0) elseif halign == :center - position .- (scale[1] / 2, 0) + pos .- (scale[1] / 2, 0) elseif halign == :right - position + pos .- (scale[1], 0) end pos = if valign == :top @@ -155,9 +156,9 @@ function draw_tex(scene::Scene, screen::CairoMakie.CairoScreen, cachedtex::Cache scale[1] / w, scale[2] / h ) - # the rendereing pipeline - # first is the "unsafe" Poppler pipeline, with better results in PDF - # but worse in PNG, especially when rotated. + # the rendering pipeline + # first is the "safe" Poppler pipeline, with better results in PDF + # and PNG, especially when rotated. if !(RENDER_EXTRASAFE[]) # retrieve a new Poppler document pointer document = update_pointer!(cachedtex) @@ -175,7 +176,7 @@ function draw_tex(scene::Scene, screen::CairoMakie.CairoScreen, cachedtex::Cache (Ptr{Cvoid}, Ptr{Cvoid}), page, ctx.ptr ) - else # "safer" Cairo pipeline, also somewhat faster. + else # "extra-safe" Cairo pipeline, also somewhat faster. # render the cached CairoSurface to the screen. # bad with PNG output though. Cairo.set_source(ctx, cachedtex.surf, 0, 0) diff --git a/src/text_override.jl b/src/text_override.jl index b7249b7..66603de 100644 --- a/src/text_override.jl +++ b/src/text_override.jl @@ -5,11 +5,25 @@ # and spreads them out! function to_plottable_cachedtex(lstr, font, textsize, lineheight, color) # $(usemain && raw"\usepackage{fontspec}") + packages = [ + # math stuff + "amsmath", "amssymb", "amsfonts", "esint", + # color management + "xcolor", + ] + # smart detect tikz to decrease load time + if occursin("tikz", lstr) + push!(packages, "tikz") + end + + package_load_str = raw"\usepackage{" * join(packages, ", ") * raw"}" + + preamble = """ \\usepackage{lmodern} \\usepackage[T1]{fontenc} - \\usepackage{amsmath, amssymb, amsfonts, xcolor, tikz} + $(package_load_str) \\definecolor{maincolor}{HTML}{$(Makie.Colors.hex(RGBf(color)))} \\DeclareMathSizes{$(textsize)}{$(textsize + .5)}{$(textsize*7/12)}{$(textsize*7/12)} """ @@ -46,7 +60,7 @@ end function Makie.plot!(t::Makie.Text{<: Tuple{<:AbstractVector{<:CachedTeX}}}) - teximgcollection!( + teximg!( t, t[1]; space = t.space, position=t.position, align = t.align, rotations = lift(to_array, t.rotation), visible = t.visible, @@ -120,7 +134,7 @@ function Makie.plot!(t::Makie.Text{<: Tuple{<: AbstractVector{<: LaTeXString}}}) end - +# Define bounding box methods for all extended plot types function Makie.boundingbox(x::Makie.Text{<:Tuple{<:CachedTeX}}) Makie.boundingbox( @@ -161,3 +175,8 @@ function Makie.boundingbox(x::Makie.Text{<:Tuple{<:AbstractArray{<:Union{LaTeXSt x.align[] ) end + +# Re-direct and allow our methods to pick these up +function Makie.boundingbox(x::Makie.Text{<:Tuple{<:AbstractArray{<: Tuple{<:T, <:Point}}}}) where T <: AbstractString + return Makie.boundingbox(x.plots[1]) +end