mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-07 20:28:38 +00:00
Vertically center single-character \mathop. (#745)
* Vertically center single-character \mathop. Fix #726. * Add screenshotter test
This commit is contained in:
committed by
Erik Demaine
parent
b866cd5224
commit
aa1722c8b6
@@ -793,30 +793,21 @@ groupTypes.op = function(group, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let base;
|
let base;
|
||||||
let baseShift = 0;
|
|
||||||
let slant = 0;
|
|
||||||
if (group.value.symbol) {
|
if (group.value.symbol) {
|
||||||
// If this is a symbol, create the symbol.
|
// If this is a symbol, create the symbol.
|
||||||
const fontName = large ? "Size2-Regular" : "Size1-Regular";
|
const fontName = large ? "Size2-Regular" : "Size1-Regular";
|
||||||
base = buildCommon.makeSymbol(
|
base = buildCommon.makeSymbol(
|
||||||
group.value.body, fontName, "math", options,
|
group.value.body, fontName, "math", options,
|
||||||
["mop", "op-symbol", large ? "large-op" : "small-op"]);
|
["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) {
|
} else if (group.value.value) {
|
||||||
// If this is a list, compose that list.
|
// If this is a list, compose that list.
|
||||||
const inner = buildExpression(group.value.value, options, true);
|
const inner = buildExpression(group.value.value, options, true);
|
||||||
|
if (inner.length === 1 && inner[0] instanceof domTree.symbolNode) {
|
||||||
base = makeSpan(["mop"], inner, options);
|
base = inner[0];
|
||||||
|
base.classes[0] = "mop"; // replace old mclass
|
||||||
|
} else {
|
||||||
|
base = makeSpan(["mop"], inner, options);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, this is a text operator. Build the text from the
|
// Otherwise, this is a text operator. Build the text from the
|
||||||
// operator's name.
|
// operator's name.
|
||||||
@@ -829,6 +820,21 @@ groupTypes.op = function(group, options) {
|
|||||||
base = makeSpan(["mop"], output, 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) {
|
if (hasLimits) {
|
||||||
// IE 8 clips \int if it is in a display: inline-block. We wrap it
|
// 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.
|
// 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);
|
return makeSpan(["mop", "op-limits"], [finalGroup], options);
|
||||||
} else {
|
} else {
|
||||||
if (group.value.symbol) {
|
if (baseShift) {
|
||||||
|
base.style.position = "relative";
|
||||||
base.style.top = baseShift + "em";
|
base.style.top = baseShift + "em";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
test/screenshotter/images/MathOp-chrome.png
Normal file
BIN
test/screenshotter/images/MathOp-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
test/screenshotter/images/MathOp-firefox.png
Normal file
BIN
test/screenshotter/images/MathOp-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
@@ -127,6 +127,7 @@ MathBf: \mathbf{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
|||||||
MathCal: \mathcal{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}
|
MathFrak: \mathfrak{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
||||||
MathIt: \mathit{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}
|
MathRm: \mathrm{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
||||||
MathSf: \mathsf{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}
|
MathScr: \mathscr{Ax2k\breve{a}\omega\Omega\imath+\KaTeX}
|
||||||
|
Reference in New Issue
Block a user