@@ -5,7 +5,7 @@ using GeometryBasics
55using LaTeXStrings
66
77import MathTeXEngine: TeXChar, VLine, HLine, leftinkbound, descender, inkwidth,
8- topinkbound, advance, bottominkbound, rightinkbound
8+ topinkbound, advance, bottominkbound, rightinkbound, ascender
99
1010draw_texelement! (args... ; size= 64 ) = nothing
1111
@@ -47,19 +47,22 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
4747 # their position is relative to the baseline, so we need to offset them
4848 y = position[2 ] * size
4949 w = inkwidth (texchar) * size * scale
50- h = topinkbound (texchar) * size * scale
5150 a = advance (texchar) * size * scale
52- d = bottominkbound (texchar) * size * scale
51+ top = topinkbound (texchar) * size * scale
52+ bottom = bottominkbound (texchar) * size * scale
5353 left = leftinkbound (texchar) * size * scale
5454 right = rightinkbound (texchar) * size * scale
5555
56+ asc = ascender (texchar) * size * scale
57+ desc = descender (texchar) * size * scale
58+
5659 # The space between th origin and the left ink bound
5760 mesh! (ax,
5861 Point2f[
59- (x, y + d ),
60- (x + left, y + d ),
61- (x + left, y + h ),
62- (x, y + h )
62+ (x, y + bottom ),
63+ (x + left, y + bottom ),
64+ (x + left, y + top ),
65+ (x, y + top )
6366 ],
6467 color= RGBA (1 , 1 , 0 , 0.6 ),
6568 shading= false
@@ -68,10 +71,10 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
6871 # The advance after the right inkbound
6972 mesh! (ax,
7073 Point2f[
71- (x + right, y + d ),
72- (x + a, y + d ),
73- (x + a, y + h ),
74- (x + right, y + h )
74+ (x + right, y + bottom ),
75+ (x + a, y + bottom ),
76+ (x + a, y + top ),
77+ (x + right, y + top )
7578 ],
7679 color= RGBA (0 , 1 , 0 , 0.3 ),
7780 shading= false
@@ -82,8 +85,8 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
8285 Point2f[
8386 (x + left, y),
8487 (x + right, y),
85- (x + right, y + d ),
86- (x + left, y + d )
88+ (x + right, y + bottom ),
89+ (x + left, y + bottom )
8790 ],
8891 color= RGBA (0 , 0 , 1 , 0.3 ),
8992 shading= false
@@ -94,30 +97,50 @@ function draw_texelement_helpers!(ax, texchar::TeXChar, position, scale ; size=6
9497 Point2f[
9598 (x + left, y),
9699 (x + right, y),
97- (x + right, y + h ),
98- (x + left, y + h )
100+ (x + right, y + top ),
101+ (x + left, y + top )
99102 ],
100103 color= RGBA (1 , 0 , 0 , 0.5 ),
101104 shading= false
102105 )
106+
107+ # Descender
108+ lines! (ax,
109+ [x + left, x + a],
110+ [y + desc, y + desc],
111+ color= :green
112+ )
113+
114+ # Ascender
115+ lines! (ax,
116+ [x + left, x + a],
117+ [y + asc, y + asc],
118+ color= :blue
119+ )
103120end
104121
105- function makie_tex! (ax, latex:: LaTeXString ; debug= false , size= 64 )
122+ function makie_tex! (
123+ ax, latex:: LaTeXString ;
124+ debug= false ,
125+ size= 64 ,
126+ position= [0 , 0 ])
127+
106128 for (elem, pos, scale) in generate_tex_elements (latex)
107- draw_texelement! (ax, elem, pos, scale ; size= size)
129+ draw_texelement! (ax, elem, pos .+ position , scale ; size= size)
108130 if debug
109- draw_texelement_helpers! (ax, elem, pos, scale ; size= size)
131+ draw_texelement_helpers! (ax, elem, pos .+ position , scale ; size= size)
110132 end
111133 end
112134end
113135
114136begin # Quick test
115- fig = Figure ()
137+ fig = Figure (resolution = ( 1800 , 600 ) )
116138 fig[1 , 1 ] = Label (fig, " LaTeX in Makie.jl" , tellwidth= false , textsize= 64 )
117139 ax = Axis (fig[2 , 1 ])
118140 ax. aspect = DataAspect ()
119141 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"
120142
121- makie_tex! (ax, tex, debug= false , size= 300 )
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 ))
122145 fig
123- end
146+ end
0 commit comments