Skip to content

Commit e315be2

Browse files
committed
Reorganize fraction layout in order to align fraction lines better. (Probably should do something similar for munderover and possibly msupsub as well.) Resolves issue #1348.
1 parent 24a6cf7 commit e315be2

File tree

1 file changed

+28
-11
lines changed
  • unpacked/jax/output/CommonHTML

1 file changed

+28
-11
lines changed

unpacked/jax/output/CommonHTML/jax.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181

8282
".mjx-numerator": {display:"block", "text-align":"center"},
8383
".mjx-denominator": {display:"block", "text-align":"center"},
84-
".MJXc-fpad": {"padding-left":".1em", "padding-right":".1em"},
84+
".MJXc-stacked": {height:0, position:"relative"},
85+
".MJXc-stacked > *": {position: "absolute"},
8586
".MJXc-bevelled > *": {display:"inline-block"},
8687

8788
".mjx-stack": {display:"inline-block"},
@@ -128,8 +129,9 @@
128129
".mjx-row": {display:"table-row"},
129130
".mjx-cell": {display:"table-cell"},
130131
".mjx-table": {display:"table", width:"100%"},
131-
".mjx-line": {display:"block", width:"100%", "border-top":"0 solid"},
132+
".mjx-line": {display:"block", height:0},
132133
".mjx-strut": {width:0, "padding-top":STRUTHEIGHT+"em"},
134+
".mjx-vsize": {width:0},
133135

134136
".MJXc-space1": {"margin-left":".167em"},
135137
".MJXc-space2": {"margin-left":".222em"},
@@ -1626,7 +1628,7 @@
16261628
CHTMLdrawBBox: function (node,bbox) {
16271629
if (!bbox) bbox = this.CHTML;
16281630
var box = CHTML.Element("mjx-box",
1629-
{style:{"font-size":node.style.fontSize, opacity:.25,"margin-left":CHTML.Em(-(bbox.w+(bbox.R||0)))}},[
1631+
{style:{opacity:.25,"margin-left":CHTML.Em(-(bbox.w+(bbox.R||0)))}},[
16301632
["mjx-box",{style:{
16311633
height:CHTML.Em(bbox.h),width:CHTML.Em(bbox.w),
16321634
"background-color":"red"
@@ -2409,32 +2411,47 @@
24092411
BBOX.combine(dbox,nscale*nbox.w+bbox.w-delta,v);
24102412
BBOX.clean();
24112413
} else {
2414+
frac.className += " MJXc-stacked";
24122415
if (isDisplay) {u = CHTML.TEX.num1; v = CHTML.TEX.denom1}
24132416
else {u = (t === 0 ? CHTML.TEX.num3 : CHTML.TEX.num2); v = CHTML.TEX.denom2}
24142417
if (t === 0) { // \atop
24152418
p = Math.max((isDisplay ? 7 : 3) * CHTML.TEX.rule_thickness, 2*mt); // force to at least 2 px
24162419
q = (u - nbox.d*nscale) - (dbox.h*dscale - v);
24172420
if (q < p) {u += (p - q)/2; v += (p - q)/2}
2418-
frac.style.verticalAlign = CHTML.Em(-v);
24192421
} else { // \over
24202422
p = Math.max((isDisplay ? 2 : 0) * mt + t, t/2 + 1.5*mt);
24212423
t = Math.max(t,mt);
24222424
q = (u - nbox.d*nscale) - (a + t/2); if (q < p) u += (p - q);
24232425
q = (a - t/2) - (dbox.h*dscale - v); if (q < p) v += (p - q);
2424-
frac.style.verticalAlign = CHTML.Em(t/2-v);
2425-
num.style.borderBottom = CHTML.Px(t/nscale*nbox.scale,1)+" solid";
2426-
num.className += " MJXc-fpad"; nbox.L = nbox.R = .1;
2427-
denom.className += " MJXc-fpad"; dbox.L = dbox.R = .1;
2426+
nbox.L = nbox.R = dbox.L = dbox.R = .1; // account for padding in BBOX width
2427+
var rule = CHTML.addElement(frac,"mjx-line",{style: {
2428+
"border-bottom":CHTML.Px(t*BBOX.scale,1)+" solid", top: CHTML.Em(-t/2-a)
2429+
}});
24282430
}
24292431
//
24302432
// Determine the new bounding box and place the parts
24312433
//
24322434
BBOX.combine(nbox,0,u);
24332435
BBOX.combine(dbox,0,-v);
24342436
BBOX.clean();
2435-
u -= nscale*nbox.d + a + t/2; v -= dscale*dbox.h - a + t/2;
2436-
if (u) num.style[u > 0 ? "paddingBottom" : "marginBottom"] = CHTML.Em(u/nscale);
2437-
if (v) denom.style[v > 0 ? "paddingTop" : "marginTop"] = CHTML.Em(v/dscale);
2437+
//
2438+
// Force elements to the correct width
2439+
//
2440+
frac.style.width = CHTML.Em(BBOX.w);
2441+
num.style.width = CHTML.Em(BBOX.w/nscale);
2442+
denom.style.width = CHTML.Em(BBOX.w/dscale);
2443+
if (rule) rule.style.width = frac.style.width;
2444+
//
2445+
// Place the numerator and denominator in relation to the baseline
2446+
//
2447+
num.style.top = CHTML.Em(-BBOX.h/nscale);
2448+
denom.style.bottom = CHTML.Em(-BBOX.d/dscale);
2449+
//
2450+
// Force the size of the surrounding box, since everything is absolutely positioned
2451+
//
2452+
CHTML.addElement(node,"mjx-vsize",{style: {
2453+
height: CHTML.Em(BBOX.h+BBOX.d), verticalAlign: CHTML.Em(-BBOX.d)
2454+
}});
24382455
}
24392456
//
24402457
// Add nulldelimiterspace around the fraction

0 commit comments

Comments
 (0)