Skip to content

Commit 0b615f0

Browse files
KristianHolmehenrik-wolfffreyer
authored
Fix rendering of LaTeXString when using bracket (#5536)
* Fix bracket text to support LaTeXStrings The text type annotation was forcing LaTeXString to convert to String, which caused LaTeX expressions like L"u(x) = \sin(x)" to render as literal text with dollar signs instead of mathematical notation. Changed text_pos type from Tuple{String, Point2f} to Tuple{Union{String, LaTeXStrings.LaTeXString}, Point2f} * Add bracket plot tests with LaTeXString support Adds new test file test/plots/bracket.jl containing tests to verify that LaTeX strings are properly preserved in bracket text, including: - Regular strings still work - LaTeXStrings are preserved as LaTeXString type - Mixed vectors preserve individual element types * Update changelog * import LaTeXStrings in test * import LaTeXStrings from Makie * include RichText Co-authored-by: Henrik Wolf <49985053+henrik-wolf@users.noreply.github.com> * check child text plot for string type and test for rich text * update bracket reftest to use LaTeXString and RichText * correct placement of changelog entry after merge --------- Co-authored-by: Henrik Wolf <49985053+henrik-wolf@users.noreply.github.com> Co-authored-by: Frederic Freyer <frederic481994@hotmail.de>
1 parent 97ccdb6 commit 0b615f0

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Fixed `bracket` not supporting `LaTeXString` text, which would render with dollar signs instead of mathematical notation [#5536](https://github.com/MakieOrg/Makie.jl/pull/5536)
56
- Added text glow to CairoMakie [#5542](https://github.com/MakieOrg/Makie.jl/pull/5542)
67
- Allow to set low or high bound of the colorrange and let the other side stay adaptive [#5555](https://github.com/MakieOrg/Makie.jl/pull/5555)
78
- Barplot `bar_labels` now support `RichText` (e.g. subscript/superscript) both directly and via `label_formatter` [#5578](https://github.com/MakieOrg/Makie.jl/pull/5578)

Makie/src/basic_recipes/bracket.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function plot!(pl::Bracket)
131131

132132
# TODO: add a broadcast/map version of broadcast_foreach doing this:
133133
bps = BezierPath[]
134-
text_pos = Tuple{String, Point2f}[]
134+
text_pos = Tuple{Union{String, LaTeXStrings.LaTeXString, RichText}, Point2f}[]
135135

136136
broadcast_foreach(startpoints, endpoints, directions, offset, width, style, text) do p1, p2, dir, offset, width, style, str
137137
off = offset * dir

Makie/test/plots/bracket.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Makie.LaTeXStrings
2+
@testset "bracket" begin
3+
@testset "LaTeXString support" begin
4+
# Test that LaTeX strings are preserved in bracket text child plot's input_text
5+
fig = Figure()
6+
ax = Axis(fig[1, 1])
7+
8+
# Regular string should work - check child text plot's input_text
9+
b1 = bracket!(ax, 0, 0, 1, 0, text = "regular text")
10+
@test b1.plots[2].input_text[][1] isa String
11+
12+
# LaTeX string should be preserved as LaTeXString in child text plot's input_text
13+
latex_str = L"u(x) = \sin(x)"
14+
b2 = bracket!(ax, 1, 0, 2, 0, text = latex_str)
15+
@test b2.plots[2].input_text[][1] isa LaTeXString
16+
17+
# Mixed vector should preserve types in child text plot's input_text
18+
texts = ["regular", L"\alpha + \beta"]
19+
b3 = bracket!(ax, [0, 1], [0.5, 0.5], [1, 2], [0.5, 0.5], text = texts)
20+
@test b3.plots[2].input_text[][1] isa String
21+
@test b3.plots[2].input_text[][2] isa LaTeXString
22+
23+
richtext = rich(
24+
"H", subscript("2"), "O is the formula for ",
25+
rich("water", color = :cornflowerblue, font = :italic)
26+
)
27+
b4 = bracket!(ax, 0.0, 0.1, 1, 0.1, text = richtext)
28+
@test b4.plots[2].input_text[][1] isa Makie.RichText
29+
end
30+
end

Makie/test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141
include("plots/generic_attributes.jl")
4242
include("plots/text.jl")
4343
include("plots/barplot.jl")
44+
include("plots/bracket.jl")
4445
include("plots/hist.jl")
4546
include("plots/poly.jl")
4647
include("plots/voronoiplot.jl")

ReferenceTests/src/tests/examples2d.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,10 @@ end
12141214
f, ax, l = lines(0 .. 9, sin; axis = (; xgridvisible = false, ygridvisible = false))
12151215
ylims!(ax, -1.5, 1.5)
12161216

1217-
bracket!(pi / 2, 1, 5pi / 2, 1, offset = 5, text = "Period length", style = :square)
1217+
bracket!(pi / 2, 1, 5pi / 2, 1, offset = 5, text = L"\text{Period length}\,\mathcal{T} = 2\pi", style = :square)
12181218

12191219
bracket!(
1220-
pi / 2, 1, pi / 2, -1, text = "Amplitude", orientation = :down,
1220+
pi / 2, 1, pi / 2, -1, text = rich(rich("Amp", color = :red, font = :bold), rich("litude", color = :darkred)), orientation = :down,
12211221
linestyle = :dash, rotation = 0, align = (:right, :center), textoffset = 4, linewidth = 2, color = :red, textcolor = :red
12221222
)
12231223

0 commit comments

Comments
 (0)