FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

mathtext: Finetuning sup/super block to match TeX reference by zblz · Pull Request #4873 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Prev Previous commit
Next Next commit
apply different rules for dropsub (integrals)
  • Loading branch information
zblz committed Aug 7, 2015
commit 84ace6128e9550c53ce68c990f3c41fe498d0a3b
61 changes: 42 additions & 19 deletions lib/matplotlib/mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1187,15 +1187,15 @@ def get_underline_thickness(self, font, fontsize, dpi):
# get any smaller
NUM_SIZE_LEVELS = 6
# Percentage of x-height of additional horiz. space after sub/superscripts
SCRIPT_SPACE = {'cm': 0.03,
SCRIPT_SPACE = {'cm': 0.05,
'stix': 0.10,
'stixsans': 0.10}
## Percentage of x-height that sub/superscripts drop below the baseline
SUBDROP = {'cm': 0.3,
'stix': 0.3,
'stixsans': 0.3}
# Percentage of x-height that superscripts drop below the baseline
SUP1 = {'cm': 0.4,
'stix': 0.4,
'stixsans': 0.4}
# Percentage of x-height that superscripts are raised from the baseline
SUP1 = {'cm': 0.45,
'stix': 0.8,
'stixsans': 0.8}
# Percentage of x-height that subscripts drop below the baseline
Expand All @@ -1212,6 +1212,11 @@ def get_underline_thickness(self, font, fontsize, dpi):
DELTA = {'cm': 0.10,
'stix': 0.15,
'stixsans': 0.25}
# Percentage of x-height that supercripts are offset relative to the subscript
# for integrals
DELTAINTEGRAL = {'cm': 0.5,
'stix': 0.5,
'stixsans': 0.4}

class MathTextWarning(Warning):
pass
Expand Down Expand Up @@ -2752,35 +2757,53 @@ def subsuper(self, s, loc, toks):
return [result]

# Handle regular sub/superscripts
shift_up = nucleus.height - SUBDROP[fs] * xHeight
if self.is_dropsub(nucleus):
shift_down = nucleus.depth + SUBDROP[fs] * xHeight
else:
shift_down = SUBDROP[fs] * xHeight
lc_height = last_char.height
lc_baseline = 0
if self.is_dropsub(last_char):
lc_baseline = last_char.depth
if super is None:
# node757
x = Hlist([sub])
if self.is_dropsub(last_char):
x = Hlist([Kern(-DELTA[fs] * last_char.height),sub])
else:
x = Hlist([sub])
x.shrink()
x.width += SCRIPT_SPACE[fs] * xHeight
shift_down = max(shift_down, SUB1[fs] * xHeight)
#clr = x.height - (abs(xHeight * 4.0) / 5.0)
#shift_down = max(shift_down, clr)
x.shift_amount = shift_down / 2.
shift_down = max(lc_baseline + SUBDROP[fs] * xHeight,
SUB1[fs] * xHeight)
if not self.is_dropsub(last_char):
shift_down /= 2
x.shift_amount = shift_down
else:
if self.is_dropsub(last_char):
delta = DELTAINTEGRAL[fs]
else:
delta = DELTA[fs]

if self.is_slanted(last_char):
x = Hlist([Kern(DELTA[fs] * super.height),super])
x = Hlist([Kern(delta * last_char.height),super])
else:
x = Hlist([super])
x.shrink()
x.width += SCRIPT_SPACE[fs] * xHeight
shift_up = SUP1[fs] * xHeight
if self.is_dropsub(last_char):
shift_up = lc_height - SUBDROP[fs] * xHeight
else:
shift_up = SUP1[fs] * xHeight
if sub is None:
x.shift_amount = -shift_up
else: # Both sub and superscript
y = Hlist([sub])
if self.is_dropsub(last_char):
y = Hlist([Kern(-DELTA[fs] * last_char.height),sub])
else:
y = Hlist([sub])
#y = Hlist([sub])
y.shrink()
y.width += SCRIPT_SPACE[fs] * xHeight
shift_down = max(shift_down, SUB2[fs] * xHeight)
if self.is_dropsub(last_char):
shift_down = lc_baseline + SUBDROP[fs] * xHeight
else:
shift_down = SUB2[fs] * xHeight
# If sub and superscript collide, move sup up
clr = (2.0 * rule_thickness -
((shift_up - x.depth) - (y.height - shift_down)))
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
r'$\dotplus$ $\doteq$ $\doteqdot$ $\ddots$',
r'$x_kx^py^{p-2} d_i^jb_jc_kd x^j_i E^0 E^0_u$', # github issue #4873
r'${x}_{k}{x}^{p}{y}^{p-2} {d}_{i}^{j}{b}_{j}{c}_{k}{d} {x}^{j}_{i}{E}^{0}{E}^0_u$',
r'${\int}_x^x x\oint_x^x x\int_{X}^{X}x\int_x x \int^x x \int_{x} x\int^{x}{\int}_{x} x{\int}^{x}_{x}x$',

]

digits = "0123456789"
Expand Down

Back | FazBrowse Home | New Git URL