MakieOrg / MakieTeX.jl

TeX integration in Makie
http://makieorg.github.io/MakieTeX.jl/
MIT License
92 stars 13 forks source link

TeXParseError: unexpected error while parsing #39

Closed ederag closed 2 weeks ago

ederag commented 2 years ago

It looks like MathTeXEngine is used instead of MakieTeX, in recent Makie versions (visible in the summary head), and julia-1.7.3.

It happens both with code that used to work about a month ago, and with the README.md example:

REPL session ```julia-repl julia pkg> activate --temp (jl_F8E2SV) pkg> add Makie [ee78f7c6] + Makie v0.17.8 (jl_F8E2SV) pkg> add MakieTeX [6d554a22] + MakieTeX v0.2.3 (jl_F8E2SV) pkg> add CairoMakie [13f3f980] + CairoMakie v0.8.8 julia> using Makie, MakieTeX julia> using CairoMakie # or whichever other backend julia> fig = Figure() julia> 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 ) julia> ax1 = Axis( fig[2, 1]; xtickformat = x -> latexstring.("a_{" .* string.(x) .* "}"), ytickformat = x -> latexstring.(string.(x)), ylabel = L"\displaystyle \Phi(\vec x) = f(\vec x) + g(V)", ) ERROR: TeXParseError: unexpected error while parsing at position 14 (string index 14) \displaystyle \Phi(\vec x) = f(\vec x) + g(V) ^ Stack before [1] TeXExpr :expr Stacktrace: [1] texparse(data::String; showdebug::Bool) @ MathTeXEngine ~/.julia/packages/MathTeXEngine/rSv9C/src/parser/parser.jl:285 [2] texparse @ ~/.julia/packages/MathTeXEngine/rSv9C/src/parser/parser.jl:271 [inlined] [3] _broadcast_getindex_evalf @ ./broadcast.jl:670 [inlined] [4] _broadcast_getindex @ ./broadcast.jl:643 [inlined] [5] _getindex @ ./broadcast.jl:666 [inlined] [6] _broadcast_getindex @ ./broadcast.jl:642 [inlined] [7] getindex @ ./broadcast.jl:597 [inlined] [8] copy @ ./broadcast.jl:899 [inlined] [9] materialize @ ./broadcast.jl:860 [inlined] [10] generate_tex_elements(str::LaTeXString, font_family::MathTeXEngine.FontFamily) @ MathTeXEngine ~/.julia/packages/MathTeXEngine/rSv9C/src/engine/layout.jl:304 [11] generate_tex_elements @ ~/.julia/packages/MathTeXEngine/rSv9C/src/engine/layout.jl:298 [inlined] [12] texelems_and_glyph_collection(str::LaTeXString, fontscale_px::Float32, halign::Symbol, valign::Symbol, rotation::Quaternionf, color::ColorTypes.RGBA{Float32}, strokecolor::ColorTypes.RGBA{Float32}, strokewidth::Int64, word_wrap_width::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:156 [13] _get_glyphcollection_and_linesegments(latexstring::LaTeXString, index::Int64, ts::Float32, f::FreeTypeAbstraction.FTFont, al::Tuple{Symbol, Symbol}, rot::Quaternionf, jus::MakieCore.Automatic, lh::Float64, col::ColorTypes.RGBA{Float32}, scol::ColorTypes.RGBA{Float32}, swi::Int64, www::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:73 [14] #_#83 @ ./operators.jl:1085 [inlined] [15] ComposedFunction @ ./operators.jl:1085 [inlined] [16] macro expansion @ ~/.julia/packages/Makie/bwZTV/src/utilities/utilities.jl:199 [inlined] [17] broadcast_foreach(::ComposedFunction{Makie.var"#push_args#1801"{Vector{Int64}, Vector{ColorTypes.RGBA{Float32}}, Vector{Float32}, Vector{Point{2, Float32}}, Vector{Makie.GlyphCollection}}, typeof(Makie._get_glyphcollection_and_linesegments)}, ::LaTeXString, ::UnitRange{Int64}, ::Float32, ::FreeTypeAbstraction.FTFont, ::Tuple{Symbol, Symbol}, ::Quaternionf, ::MakieCore.Automatic, ::Float64, ::ColorTypes.RGBA{Float32}, ::ColorTypes.RGBA{Float32}, ::Int64, ::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/utilities/utilities.jl:185 [18] (::Makie.var"#1797#1800"{Base.RefValue{Vector{Int64}}, Observable{Vector{ColorTypes.RGBA{Float32}}}, Observable{Vector{Float32}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Makie.GlyphCollection}}})(str::LaTeXString, ts::Float64, f::FreeTypeAbstraction.FTFont, al::Tuple{Symbol, Symbol}, rot::Float32, jus::MakieCore.Automatic, lh::Float64, col::ColorTypes.RGBA{Float32}, scol::Tuple{Symbol, Float64}, swi::Int64, www::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:34 [19] (::Observables.var"#callback#13"{Makie.var"#1797#1800"{Base.RefValue{Vector{Int64}}, Observable{Vector{ColorTypes.RGBA{Float32}}}, Observable{Vector{Float32}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Makie.GlyphCollection}}}, NTuple{11, Observable{Any}}})(x::Any) @ Observables ~/.julia/packages/Observables/ynr7h/src/Observables.jl:339 [20] #invokelatest#2 @ ./essentials.jl:716 [inlined] [21] invokelatest @ ./essentials.jl:714 [inlined] [22] notify(observable::Observables.AbstractObservable) @ Observables ~/.julia/packages/Observables/ynr7h/src/Observables.jl:143 [23] plot!(plot::MakieCore.Text{Tuple{Vector{Point{2, Float32}}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:53 [24] plot!(scene::Scene, P::Type{MakieCore.Text{Tuple{Point{2, Float32}}}}, attributes::Attributes, input::Tuple{Observable{Point{2, Float32}}}, args::Observable{Tuple{Vector{Point{2, Float32}}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:402 [25] plot!(scene::Scene, P::Type{MakieCore.Text}, attributes::Attributes, args::Observable{Point{2, Float32}}; kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:320 [26] plot! @ ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:288 [inlined] [27] #plot!#132 @ ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:271 [inlined] [28] text!(::Scene, ::Vararg{Any}; attributes::Base.Pairs{Symbol, Any, NTuple{9, Symbol}, NamedTuple{(:text, :textsize, :color, :visible, :align, :rotation, :font, :markerspace, :inspectable), Tuple{Observable{Any}, Observable{Any}, Observable{Any}, Observable{Any}, Observable{Tuple{Symbol, Symbol}}, Observable{Float32}, Observable{Any}, Symbol, Bool}}}) @ MakieCore ~/.julia/packages/MakieCore/YlbA1/src/recipes.jl:38 [29] Makie.LineAxis(parent::Scene, attrs::Attributes) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/lineaxis.jl:367 [30] #LineAxis#1151 @ ~/.julia/packages/Makie/bwZTV/src/makielayout/lineaxis.jl:3 [inlined] [31] initialize_block!(ax::Axis; palette::Nothing) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks/axis.jl:330 [32] initialize_block! @ ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks/axis.jl:170 [inlined] [33] _block(::Type{Axis}, ::Figure; bbox::Nothing, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:xtickformat, :ytickformat, :ylabel), Tuple{var"#1#3", var"#2#4", LaTeXString}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks.jl:393 [34] _block(::Type{Axis}, ::GridPosition; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:xtickformat, :ytickformat, :ylabel), Tuple{var"#1#3", var"#2#4", LaTeXString}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks.jl:284 [35] #_#999 @ ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks.jl:269 [inlined] [36] top-level scope @ REPL[9]:1 caused by: TeXParseError: unsupported command \displaystyle at position 14 (string index 14) \displaystyle \Phi(\vec x) = f(\vec x) + g(V) ^ Stack before [1] TeXExpr :expr Stacktrace: [1] _end_command_builder!(stack::DataStructures.Stack{Any}, p::Int64, data::String) @ MathTeXEngine ~/.julia/packages/MathTeXEngine/rSv9C/src/parser/parser.jl:233 [2] macro expansion @ ~/.julia/packages/MathTeXEngine/rSv9C/src/parser/parser.jl:256 [inlined] [3] macro expansion @ ~/.julia/packages/Automa/1KOLQ/src/codegen.jl:149 [inlined] [4] texparse(data::String; showdebug::Bool) @ MathTeXEngine ~/.julia/packages/MathTeXEngine/rSv9C/src/parser/parser.jl:283 [5] texparse @ ~/.julia/packages/MathTeXEngine/rSv9C/src/parser/parser.jl:271 [inlined] [6] _broadcast_getindex_evalf @ ./broadcast.jl:670 [inlined] [7] _broadcast_getindex @ ./broadcast.jl:643 [inlined] [8] _getindex @ ./broadcast.jl:666 [inlined] [9] _broadcast_getindex @ ./broadcast.jl:642 [inlined] [10] getindex @ ./broadcast.jl:597 [inlined] [11] copy @ ./broadcast.jl:899 [inlined] [12] materialize @ ./broadcast.jl:860 [inlined] [13] generate_tex_elements(str::LaTeXString, font_family::MathTeXEngine.FontFamily) @ MathTeXEngine ~/.julia/packages/MathTeXEngine/rSv9C/src/engine/layout.jl:304 [14] generate_tex_elements @ ~/.julia/packages/MathTeXEngine/rSv9C/src/engine/layout.jl:298 [inlined] [15] texelems_and_glyph_collection(str::LaTeXString, fontscale_px::Float32, halign::Symbol, valign::Symbol, rotation::Quaternionf, color::ColorTypes.RGBA{Float32}, strokecolor::ColorTypes.RGBA{Float32}, strokewidth::Int64, word_wrap_width::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:156 [16] _get_glyphcollection_and_linesegments(latexstring::LaTeXString, index::Int64, ts::Float32, f::FreeTypeAbstraction.FTFont, al::Tuple{Symbol, Symbol}, rot::Quaternionf, jus::MakieCore.Automatic, lh::Float64, col::ColorTypes.RGBA{Float32}, scol::ColorTypes.RGBA{Float32}, swi::Int64, www::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:73 [17] #_#83 @ ./operators.jl:1085 [inlined] [18] ComposedFunction @ ./operators.jl:1085 [inlined] [19] macro expansion @ ~/.julia/packages/Makie/bwZTV/src/utilities/utilities.jl:199 [inlined] [20] broadcast_foreach(::ComposedFunction{Makie.var"#push_args#1801"{Vector{Int64}, Vector{ColorTypes.RGBA{Float32}}, Vector{Float32}, Vector{Point{2, Float32}}, Vector{Makie.GlyphCollection}}, typeof(Makie._get_glyphcollection_and_linesegments)}, ::LaTeXString, ::UnitRange{Int64}, ::Float32, ::FreeTypeAbstraction.FTFont, ::Tuple{Symbol, Symbol}, ::Quaternionf, ::MakieCore.Automatic, ::Float64, ::ColorTypes.RGBA{Float32}, ::ColorTypes.RGBA{Float32}, ::Int64, ::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/utilities/utilities.jl:185 [21] (::Makie.var"#1797#1800"{Base.RefValue{Vector{Int64}}, Observable{Vector{ColorTypes.RGBA{Float32}}}, Observable{Vector{Float32}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Makie.GlyphCollection}}})(str::LaTeXString, ts::Float64, f::FreeTypeAbstraction.FTFont, al::Tuple{Symbol, Symbol}, rot::Float32, jus::MakieCore.Automatic, lh::Float64, col::ColorTypes.RGBA{Float32}, scol::Tuple{Symbol, Float64}, swi::Int64, www::Int64) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:34 [22] (::Observables.var"#callback#13"{Makie.var"#1797#1800"{Base.RefValue{Vector{Int64}}, Observable{Vector{ColorTypes.RGBA{Float32}}}, Observable{Vector{Float32}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Makie.GlyphCollection}}}, NTuple{11, Observable{Any}}})(x::Any) @ Observables ~/.julia/packages/Observables/ynr7h/src/Observables.jl:339 [23] #invokelatest#2 @ ./essentials.jl:716 [inlined] [24] invokelatest @ ./essentials.jl:714 [inlined] [25] notify(observable::Observables.AbstractObservable) @ Observables ~/.julia/packages/Observables/ynr7h/src/Observables.jl:143 [26] plot!(plot::MakieCore.Text{Tuple{Vector{Point{2, Float32}}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/basic_recipes/text.jl:53 [27] plot!(scene::Scene, P::Type{MakieCore.Text{Tuple{Point{2, Float32}}}}, attributes::Attributes, input::Tuple{Observable{Point{2, Float32}}}, args::Observable{Tuple{Vector{Point{2, Float32}}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:402 [28] plot!(scene::Scene, P::Type{MakieCore.Text}, attributes::Attributes, args::Observable{Point{2, Float32}}; kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:320 [29] plot! @ ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:288 [inlined] [30] #plot!#132 @ ~/.julia/packages/Makie/bwZTV/src/interfaces.jl:271 [inlined] [31] text!(::Scene, ::Vararg{Any}; attributes::Base.Pairs{Symbol, Any, NTuple{9, Symbol}, NamedTuple{(:text, :textsize, :color, :visible, :align, :rotation, :font, :markerspace, :inspectable), Tuple{Observable{Any}, Observable{Any}, Observable{Any}, Observable{Any}, Observable{Tuple{Symbol, Symbol}}, Observable{Float32}, Observable{Any}, Symbol, Bool}}}) @ MakieCore ~/.julia/packages/MakieCore/YlbA1/src/recipes.jl:38 [32] Makie.LineAxis(parent::Scene, attrs::Attributes) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/lineaxis.jl:367 [33] #LineAxis#1151 @ ~/.julia/packages/Makie/bwZTV/src/makielayout/lineaxis.jl:3 [inlined] [34] initialize_block!(ax::Axis; palette::Nothing) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks/axis.jl:330 [35] initialize_block! @ ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks/axis.jl:170 [inlined] [36] _block(::Type{Axis}, ::Figure; bbox::Nothing, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:xtickformat, :ytickformat, :ylabel), Tuple{var"#1#3", var"#2#4", LaTeXString}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks.jl:393 [37] _block(::Type{Axis}, ::GridPosition; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:xtickformat, :ytickformat, :ylabel), Tuple{var"#1#3", var"#2#4", LaTeXString}}}) @ Makie ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks.jl:284 [38] #_#999 @ ~/.julia/packages/Makie/bwZTV/src/makielayout/blocks.jl:269 [inlined] [39] top-level scope @ REPL[9]:1 ```
asinghvi17 commented 2 years ago

Interesting, thanks for the report - I haven't used MakieTeX in a couple weeks. I can probably patch this tomorrow, since it should just be a matter of adjusting the method signatures which are available.

asinghvi17 commented 2 years ago

Ugh...this is somewhat harder than I thought, and will require some refactors in Makie itself.

Basically, the text dispatches got changed, and everything now goes through text!(positions...; text = AbstractString[...]), which is not actually possible to dispatch on in plot!. So, I'll have to modify that method in Makie.

Currently, I'm thinking of doing two things to make it more flexible overall, and allow MakieTeX to keep functioning:

  1. Allow arbitrary types to be passed to the final text call (this will allow us to use Pango layouts as well, in time)
  2. Delete and replot the text plot whenever the type passed in to it changes. This may be a little fragile, but it does make text extremely flexible.
Mark2000 commented 1 year ago

Is this package still being maintained? Would love to use it, but this issue seems to break it completely.

BeastyBlacksmith commented 1 year ago

I'd say anything that stayed here and not moved to MakieOrg is unmaintained.

@SimonDanisch these can be archived, no?

SimonDanisch commented 1 year ago

I guess MakieTeX is in the twilight zone of not being actively maintained enough to get moved to MakieOrg (a.k.a it's not working), but it's definitely of value, so hopefully maintenance will be picked up again at some point... Of course, if it noises up JuliaPlots, we can move it back to @asinghvi17, or some other org ;)