Vertically center single-character \mathop. (#745)

* Vertically center single-character \mathop.

Fix #726.

* Add screenshotter test
This commit is contained in:
Eddie Kohler
2017-06-30 11:49:00 -04:00
committed by Erik Demaine
parent b866cd5224
commit aa1722c8b6
4 changed files with 24 additions and 16 deletions

View File

@@ -793,30 +793,21 @@ groupTypes.op = function(group, options) {
}
let base;
let baseShift = 0;
let slant = 0;
if (group.value.symbol) {
// If this is a symbol, create the symbol.
const fontName = large ? "Size2-Regular" : "Size1-Regular";
base = buildCommon.makeSymbol(
group.value.body, fontName, "math", options,
["mop", "op-symbol", large ? "large-op" : "small-op"]);
// Shift the symbol so its center lies on the axis (rule 13). It
// appears that our fonts have the centers of the symbols already
// almost on the axis, so these numbers are very small. Note we
// don't actually apply this here, but instead it is used either in
// the vlist creation or separately when there are no limits.
baseShift = (base.height - base.depth) / 2 -
style.metrics.axisHeight * options.sizeMultiplier;
// The slant of the symbol is just its italic correction.
slant = base.italic;
} else if (group.value.value) {
// If this is a list, compose that list.
const inner = buildExpression(group.value.value, options, true);
base = makeSpan(["mop"], inner, options);
if (inner.length === 1 && inner[0] instanceof domTree.symbolNode) {
base = inner[0];
base.classes[0] = "mop"; // replace old mclass
} else {
base = makeSpan(["mop"], inner, options);
}
} else {
// Otherwise, this is a text operator. Build the text from the
// operator's name.
@@ -829,6 +820,21 @@ groupTypes.op = function(group, options) {
base = makeSpan(["mop"], output, options);
}
// If content of op is a single symbol, shift it vertically.
let baseShift = 0;
let slant = 0;
if (base instanceof domTree.symbolNode) {
// Shift the symbol so its center lies on the axis (rule 13). It
// appears that our fonts have the centers of the symbols already
// almost on the axis, so these numbers are very small. Note we
// don't actually apply this here, but instead it is used either in
// the vlist creation or separately when there are no limits.
baseShift = (base.height - base.depth) / 2 - style.metrics.axisHeight;
// The slant of the symbol is just its italic correction.
slant = base.italic;
}
if (hasLimits) {
// IE 8 clips \int if it is in a display: inline-block. We wrap it
// in a new span so it is an inline, and works.
@@ -919,7 +925,8 @@ groupTypes.op = function(group, options) {
return makeSpan(["mop", "op-limits"], [finalGroup], options);
} else {
if (group.value.symbol) {
if (baseShift) {
base.style.position = "relative";
base.style.top = baseShift + "em";
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -127,6 +127,7 @@ MathBf: \mathbf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
MathCal: \mathcal{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
MathFrak: \mathfrak{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
MathIt: \mathit{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
MathOp: a\mathop+b\mathop:c\mathop{\delta}e\mathop{\textrm{and}}f\mathrel{\mathop{:}}=g\sin h
MathRm: \mathrm{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
MathSf: \mathsf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
MathScr: \mathscr{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}