1+ using Pkg
2+
3+ Pkg. activate (" prototype" )
4+
15using MathTeXEngine
26using CairoMakie
37using Colors
48using GeometryBasics
59using LaTeXStrings
610
711import MathTeXEngine: TeXChar, VLine, HLine, leftinkbound, descender, inkwidth,
8- topinkbound, advance, bottominkbound, rightinkbound, ascender
12+ topinkbound, hadvance, bottominkbound, rightinkbound, ascender,
13+ height_insensitive_boundingbox
914
1015draw_texelement! (args... ; size= 64 ) = nothing
1116
1217function draw_texelement! (ax, texchar:: TeXChar , position, scale ; size= 64 )
13- x = ( position[1 ] + leftinkbound (texchar)) * size
14- y = ( position[2 ] + descender (texchar . font) * scale) * size
18+ x = position[1 ] * size
19+ y = position[2 ] * size
1520 text! (ax, string (texchar. char), font= texchar. font,
1621 position= Point2f (x, y),
1722 textsize= size* scale,
18- space= :data )
23+ space= :data ,
24+ markerspace= :data ,
25+ align= (:left , :baseline ),
26+ offset= (0 , 0 ))
1927end
2028
2129function draw_texelement! (ax, line:: VLine , position, scale ; size= 64 )
@@ -25,7 +33,7 @@ function draw_texelement!(ax, line::VLine, position, scale ; size=64)
2533 x1 = xmid + lw
2634 y1 = y0 + line. height * scale
2735 points = Point2f[(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
28- poly! (ax, points .* size, color= :black , shading= false , linewidth = 0 )
36+ poly! (ax, points .* size, color= :black , shading= false )
2937end
3038
3139function draw_texelement! (ax, line:: HLine , position, scale ; size= 64 )
@@ -35,7 +43,7 @@ function draw_texelement!(ax, line::HLine, position, scale ; size=64)
3543 y0 = ymid - lw
3644 y1 = ymid + lw
3745 points = Point2f[(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
38- mesh ! (ax, points .* size, color= :black , shading= false )
46+ poly ! (ax, points .* size, color= :black , shading= false )
3947end
4048
4149draw_texelement_helpers! (args... ; size= 64 ) = nothing
@@ -47,17 +55,21 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
4755 # their position is relative to the baseline, so we need to offset them
4856 y = position[2 ] * size
4957 w = inkwidth (texchar) * size * scale
50- a = advance (texchar) * size * scale
58+ a = hadvance (texchar) * size * scale
5159 top = topinkbound (texchar) * size * scale
5260 bottom = bottominkbound (texchar) * size * scale
5361 left = leftinkbound (texchar) * size * scale
5462 right = rightinkbound (texchar) * size * scale
5563
56- asc = ascender (texchar) * size * scale
57- desc = descender (texchar) * size * scale
64+ hbbox = height_insensitive_boundingbox (texchar, nothing )
65+ asc = (origin (hbbox)[2 ] + widths (hbbox)[2 ]) * size * scale
66+ desc = origin (hbbox)[2 ] * size * scale
67+
68+ # asc = ascender(texchar) * size * scale
69+ # desc = descender(texchar) * size * scale
5870
5971 # The space between th origin and the left ink bound
60- mesh ! (ax,
72+ poly ! (ax,
6173 Point2f[
6274 (x, y + bottom),
6375 (x + left, y + bottom),
@@ -69,7 +81,7 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
6981 )
7082
7183 # The advance after the right inkbound
72- mesh ! (ax,
84+ poly ! (ax,
7385 Point2f[
7486 (x + right, y + bottom),
7587 (x + a, y + bottom),
@@ -81,7 +93,7 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
8193 )
8294
8395 # The descender
84- mesh ! (ax,
96+ poly ! (ax,
8597 Point2f[
8698 (x + left, y),
8799 (x + right, y),
@@ -93,7 +105,7 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
93105 )
94106
95107 # The inkbound above the baseline
96- mesh ! (ax,
108+ poly ! (ax,
97109 Point2f[
98110 (x + left, y),
99111 (x + right, y),
@@ -134,13 +146,14 @@ function makie_tex!(
134146end
135147
136148begin # Quick test
137- fig = Figure (resolution= (1800 , 600 ))
149+ fig = Figure (resolution= (1800 , 1000 ))
138150 fig[1 , 1 ] = Label (fig, " LaTeX in Makie.jl" , tellwidth= false , textsize= 64 )
139151 ax = Axis (fig[2 , 1 ])
152+ hidedecorations! (ax)
140153 ax. aspect = DataAspect ()
141- tex = L "\l im_{L →\i nfty} \g amma A^\s qrt{2 + 3 + 2} z^2 = \s um_{k = 1}^N \v ec{v}_{(a + \b ar{a})_k} + \s qrt{j} x! \q uad \m athrm{when} \q uad \s qrt{\f rac{\O mega-2}{4+a+x}} < \i nt_{0}^{2π} |\s in(\m u x)| dx"
154+ tex = L "\s um \ l im_{L →\i nfty} \g amma A^\s qrt{A + j + 2 + 3 + 2 + L } z^2 = \s um_{k = 1}^N \v ec{v}_{(a + \b ar{a})_k} + \s qrt{j} x! \q uad \m athrm{when} \q uad \s qrt{\f rac{\O mega-2}{4+a+x}} < \i nt_{0}^{2π} |\s in(\m u x)| dx"
142155
143- makie_tex! (ax, tex, debug= true , size= 300 )
144- makie_tex! (ax, L " \s um x_k y_k " , debug = true , size = 300 , position = ( 0 , - 5 ) )
156+ makie_tex! (ax, tex, debug= true , size= 64 )
157+ fig[ 3 , 1 ] = Label (fig, tex, tellwidth = false , tellheight = false , textsize = 40 )
145158 fig
146159end
0 commit comments