diff --git a/src/buildHTML.js b/src/buildHTML.js index 9d492dac..07691260 100644 --- a/src/buildHTML.js +++ b/src/buildHTML.js @@ -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"; } diff --git a/test/screenshotter/images/MathOp-chrome.png b/test/screenshotter/images/MathOp-chrome.png new file mode 100644 index 00000000..95a6267b Binary files /dev/null and b/test/screenshotter/images/MathOp-chrome.png differ diff --git a/test/screenshotter/images/MathOp-firefox.png b/test/screenshotter/images/MathOp-firefox.png new file mode 100644 index 00000000..179764e7 Binary files /dev/null and b/test/screenshotter/images/MathOp-firefox.png differ diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 58cbc574..e62555dd 100644 --- a/test/screenshotter/ss_data.yaml +++ b/test/screenshotter/ss_data.yaml @@ -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}