1+ """
2+ Return the y value needed for the element to be vertically centered in the
3+ middle of the xheight.
4+ """
5+ function y_for_centered (font_family, elem)
6+ h = inkheight (elem)
7+ return h/ 2 + xheight (font_family)/ 2
8+ end
9+
110"""
211 tex_layout(mathexpr::TeXExpr, font_family)
312
@@ -48,7 +57,7 @@ function tex_layout(expr, state)
4857 Point2f[
4958 (0 , 0 ),
5059 (core_width, - 0.2 ),
51- (core_width, xheight (core) - 0.5 * descender (super ))],
60+ (core_width, 0.8 * xheight (core ))],
5261 [1 , shrink, shrink]
5362 )
5463 elseif head == :delimited
@@ -100,7 +109,7 @@ function tex_layout(expr, state)
100109
101110 return Group (
102111 [line, numerator, denominator],
103- Point2f[(0 ,y0), (x1, ytop), (x2, ybottom)]
112+ Point2f[(0 , y0), (x1, ytop), (x2, ybottom)]
104113 )
105114 elseif head == :function
106115 name = args[1 ]
@@ -123,7 +132,7 @@ function tex_layout(expr, state)
123132 return Group (
124133 [int, sub, super],
125134 Point2f[
126- (0 , h / 2 + xheight (font_family) / 2 ),
135+ (0 , y_for_centered (font_family, int) ),
127136 (
128137 0.15 - inkwidth (sub)* shrink/ 2 ,
129138 - h/ 2 + xheight (font_family)/ 2 - topinkbound (sub)* shrink - pad
@@ -155,23 +164,22 @@ function tex_layout(expr, state)
155164 h = inkheight (sqrt)
156165 y0 = (topinkbound (sqrt) - bottominkbound (sqrt))/ 2 + xheight (font_family)/ 2
157166 else
158- y0 = bottominkbound (content) - bottominkbound (sqrt) - 0.2
167+ y0 = bottominkbound (content) - bottominkbound (sqrt) - 0.1
159168 end
160169
161170 lw = thickness (font_family)
162171
163172 y = y0 + topinkbound (sqrt) - lw
164- xpad = advance (sqrt) - inkwidth (sqrt)
165- w = inkwidth (content) + 2 xpad
166173
167- hline = HLine (w , lw)
174+ hline = HLine (inkwidth (content) + 0.1 , lw)
168175
169176 return Group (
170- [sqrt, hline, content],
177+ [sqrt, hline, content, Space ( 1.2 ) ],
171178 Point2f[
172179 (0 , y0),
173180 (rightinkbound (sqrt) - lw/ 2 , y - lw/ 2 ),
174- (advance (sqrt), 0 )
181+ (rightinkbound (sqrt), 0 ),
182+ (rightinkbound (content), 0 )
175183 ]
176184 )
177185
@@ -188,12 +196,20 @@ function tex_layout(expr, state)
188196 # The leftmost element must have x = 0
189197 x0 = - min (0 , dxsub, dxsuper)
190198
199+ # Special case to deal with sum symbols and the like that do not
200+ # have their baseline properly set in the font
201+ if core isa TeXChar
202+ y0 = y_for_centered (font_family, core)
203+ else
204+ y0 = 0.0
205+ end
206+
191207 return Group (
192208 [core, sub, super],
193209 Point2f[
194- (x0, 0 ),
195- (x0 + dxsub, under_offset),
196- (x0 + dxsuper, over_offset)
210+ (x0, y0 ),
211+ (x0 + dxsub, y0 + under_offset),
212+ (x0 + dxsuper, y0 + over_offset)
197213 ],
198214 [1 , shrink, shrink]
199215 )
0 commit comments