Skip to content

Commit 156b99a

Browse files
committed
Implement the TeX alignment of subscripts [skip ci]
No point running the tests if we are absolutely sure they are going to fail.
1 parent f278686 commit 156b99a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/matplotlib/_mathtext.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,7 @@ def set_names_and_parse_actions():
18301830
| p.underset
18311831
| p.sqrt
18321832
| p.overline
1833+
| p.auto_delim
18331834
)
18341835

18351836
p.simple <<= (
@@ -2206,6 +2207,16 @@ def subsuper(self, s, loc, toks):
22062207
result = Hlist([vlist])
22072208
return [result]
22082209

2210+
# Set the minimum shifts for the superscript and subscript.
2211+
constants = _get_font_constant_set(state)
2212+
if isinstance(nucleus, Char):
2213+
shift_up = 0
2214+
shift_down = 0
2215+
else:
2216+
# TODO Optimise and reduce line length.
2217+
shift_up = nucleus.height - constants.subdrop * xHeight * SHRINK_FACTOR
2218+
shift_down = nucleus.depth + constants.subdrop * xHeight * SHRINK_FACTOR
2219+
22092220
# We remove kerning on the last character for consistency (otherwise
22102221
# it will compute kerning based on non-shrunk characters and may put
22112222
# them too close together when superscripted)
@@ -2232,7 +2243,6 @@ def subsuper(self, s, loc, toks):
22322243
nucleus = Hlist([nucleus])
22332244

22342245
# Handle regular sub/superscripts
2235-
constants = _get_font_constant_set(state)
22362246
lc_height = last_char.height
22372247
lc_baseline = 0
22382248
if self.is_dropsub(last_char):
@@ -2260,7 +2270,12 @@ def subsuper(self, s, loc, toks):
22602270
if self.is_dropsub(last_char):
22612271
shift_down = lc_baseline + constants.subdrop * xHeight
22622272
else:
2263-
shift_down = constants.sub1 * xHeight
2273+
# TODO Optimise.
2274+
if shift_down < constants.sub1 * xHeight:
2275+
shift_down = constants.sub1 * xHeight
2276+
clr = x.height - xHeight * 4 / 5
2277+
if shift_down < clr:
2278+
shift_down = clr
22642279
x.shift_amount = shift_down
22652280
else:
22662281
x = Hlist([Kern(superkern), super])

0 commit comments

Comments
 (0)