diff --git a/Project.toml b/Project.toml index b3f69d8f..0d718087 100644 --- a/Project.toml +++ b/Project.toml @@ -31,6 +31,7 @@ Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] @@ -52,6 +53,7 @@ Requires = "1" Scratch = "1" Showoff = "0.3.1, 1.0" StatsBase = "0.32 - 0.33" +UnicodeFun = "0.4" UnicodePlots = "2.4" julia = "1.5" diff --git a/src/Plots.jl b/src/Plots.jl index b1fe9125..d11ef67a 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -29,9 +29,10 @@ import RecipesBase: plot, plot!, animate, is_explicit using Base.Meta @reexport using PlotUtils @reexport using PlotThemes -import Showoff +import UnicodeFun import StatsBase import Downloads +import Showoff import JSON using Requires diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index d3f5835d..afb5d530 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -70,7 +70,7 @@ function _inspectdr_add_annotations(plot, x, y, val::PlotText) color = _inspectdr_mapcolor(val.font.color), ) ann = InspectDR.atext( - val.str, + texmath2unicode(val.str), x = x, y = y, font = fnt, @@ -384,9 +384,9 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) _inspectdr_setticks(sp, plot, strip, xaxis, yaxis) a = plot.annotation - a.title = sp[:title] - a.xlabel = xaxis[:guide] - a.ylabels = [yaxis[:guide]] + a.title = texmath2unicode(sp[:title]) + a.xlabel = texmath2unicode(xaxis[:guide]) + a.ylabels = [texmath2unicode(yaxis[:guide])] #Modify base layout of new object: l = plot.layout.defaults = deepcopy(InspectDR.defaults.plotlayout) diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 448cebdf..0c4d6dc1 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -42,9 +42,9 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend}) kw = ( compact = true, - title = sp[:title], - xlabel = xaxis[:guide], - ylabel = yaxis[:guide], + title = texmath2unicode(sp[:title]), + xlabel = texmath2unicode(xaxis[:guide]), + ylabel = texmath2unicode(yaxis[:guide]), xscale = xaxis[:scale], yscale = yaxis[:scale], border = isijulia() ? :ascii : :solid, @@ -63,7 +63,7 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend}) o, x, y, - val.str; + texmath2unicode(val.str); color = up_color(val.font.color), halign = val.font.halign, valign = val.font.valign, diff --git a/src/utils.jl b/src/utils.jl index 43fc98f1..f2cff665 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1221,6 +1221,7 @@ function mesh3d_triangles(x, y, z, cns::Tuple{Array,Array,Array}) end return X, Y, Z end + function mesh3d_triangles(x, y, z, cns::AbstractVector{NTuple{3,Int}}) X = zeros(eltype(x), 4length(cns)) Y = zeros(eltype(y), 4length(cns)) @@ -1251,3 +1252,5 @@ const _attrsymbolcache = Dict{Symbol,Dict{Symbol,Symbol}}() get_attr_symbol(letter::Symbol, keyword::String) = get_attr_symbol(letter, Symbol(keyword)) get_attr_symbol(letter::Symbol, keyword::Symbol) = _attrsymbolcache[letter][keyword] + +texmath2unicode(s::AbstractString, pat=r"\$([^$]+)\$") = replace(s, pat => m->UnicodeFun.to_latex(m[2:(length(m)-1)])) diff --git a/test/runtests.jl b/test/runtests.jl index a69099bb..9f3c4113 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -199,6 +199,11 @@ end @test Plots.process_clims(nothing) == Plots.process_clims(missing) == Plots.process_clims(:auto) + + @test (==)( + Plots.texmath2unicode(raw"Equation $y = \alpha \cdot x + \beta$ and eqn $y = \sin(x)^2$"), + raw"Equation y = α ⋅ x + β and eqn y = sin(x)²" + ) end @testset "Backends" begin