Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb15a1c1

Browse files
committed
Make mathtext's fraction alignment resemble LaTeX's
1 parent756d1d4 commitb15a1c1

File tree

302 files changed

+21007
-19078
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+21007
-19078
lines changed

‎lib/matplotlib/_mathtext.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,6 +2759,9 @@ def subsuper(self, s, loc, toks):
27592759

27602760
def_genfrac(self,ldelim,rdelim,rule,style,num,den):
27612761
state=self.get_state()
2762+
cap_height=state.font_output.get_metrics(
2763+
state.font,mpl.rcParams['mathtext.default'],
2764+
'H',state.fontsize,state.dpi).height
27622765
thickness=state.font_output.get_underline_thickness(
27632766
state.font,state.fontsize,state.dpi)
27642767

@@ -2767,26 +2770,38 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den):
27672770
ifstyleisnotself._MathStyle.DISPLAYSTYLE:
27682771
num.shrink()
27692772
den.shrink()
2773+
min_clearance=np.ceil(0.5*thickness)
2774+
cap_height*=0.7
2775+
else:
2776+
min_clearance=1.5*thickness
27702777
cnum=HCentered([num])
27712778
cden=HCentered([den])
27722779
width=max(num.width,den.width)
27732780
cnum.hpack(width,'exactly')
27742781
cden.hpack(width,'exactly')
2775-
vlist=Vlist([cnum,# numerator
2776-
Vbox(0,thickness*2.0),# space
2777-
Hrule(state,rule),# rule
2778-
Vbox(0,thickness*2.0),# space
2779-
cden# denominator
2780-
])
2782+
2783+
numerator_padding=max(
2784+
3/5*cap_height-cnum.depth,min_clearance)-thickness
2785+
denominator_padding=max(
2786+
4/3*cap_height-cden.height,min_clearance)+thickness
2787+
vlist_builder= []
2788+
ifcnum.height<cap_height:
2789+
vlist_builder.append(Vbox(0,cap_height-cnum.height))
2790+
vlist_builder+= [cnum,# numerator
2791+
Vbox(0,numerator_padding),# space
2792+
Hrule(state,rule),# rule
2793+
Vbox(0,denominator_padding),# space
2794+
cden# denominator
2795+
]
2796+
vlist=Vlist(vlist_builder)
27812797

27822798
# Shift so the fraction line sits in the middle of the
2783-
#equals sign
2799+
#minus sign
27842800
metrics=state.font_output.get_metrics(
27852801
state.font,mpl.rcParams['mathtext.default'],
2786-
'=',state.fontsize,state.dpi)
2787-
shift= (cden.height-
2788-
((metrics.ymax+metrics.ymin)/2-
2789-
thickness*3.0))
2802+
'\u2212',state.fontsize,state.dpi)
2803+
shift= (denominator_padding+cden.height-
2804+
(metrics.ymax+metrics.ymin)/2-rule/2)
27902805
vlist.shift_amount=shift
27912806

27922807
result= [Hlist([vlist,Hbox(thickness*2.)])]
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp