Fix \underset (#1277)

* Fix \underset

This PR modifies `\underset` and `\overset` to align with LaTeX behavior when a superscript is applied after the `\underset`.  Fixes issue #1275.

I also changed the spacing from KaTeX `mop` to KaTeX `rmel`. The result seems to be a closer visual match to LaTeX.

* Update screenshots
This commit is contained in:
Ron Kok
2018-05-03 13:50:18 -07:00
committed by Erik Demaine
parent 98b85097eb
commit 7fec5ae5dc
6 changed files with 15 additions and 21 deletions

View File

@@ -62,26 +62,26 @@ defineFunction([
}; };
}); });
// Build a relation by placing one symbol on top of another // Build a relation or stacked op by placing one symbol on top of another
defineFunction(["\\stackrel"], { defineFunction(["\\stackrel", "\\overset", "\\underset"], {
numArgs: 2, numArgs: 2,
}, function(context, args) { }, function(context, args) {
const top = args[0]; const mathAxisArg = args[1];
const bottom = args[1]; const shiftedArg = args[0];
const bottomop = new ParseNode("op", { const xAxisOp = new ParseNode("op", {
type: "op", type: "op",
limits: true, limits: true,
alwaysHandleSupSub: true, alwaysHandleSupSub: true,
symbol: false, symbol: false,
value: ordargument(bottom), value: ordargument(mathAxisArg),
}, bottom.mode); }, mathAxisArg.mode);
const supsub = new ParseNode("supsub", { const supsub = new ParseNode("supsub", {
base: bottomop, base: xAxisOp,
sup: top, sup: context.funcName === "\\underset" ? null : shiftedArg,
sub: null, sub: context.funcName === "\\underset" ? shiftedArg : null,
}, top.mode); }, shiftedArg.mode);
return { return {
type: "mclass", type: "mclass",

View File

@@ -169,10 +169,6 @@ defineMacro("\\varPhi", "\\mathit{\\Phi}");
defineMacro("\\varPsi", "\\mathit{\\Psi}"); defineMacro("\\varPsi", "\\mathit{\\Psi}");
defineMacro("\\varOmega", "\\mathit{\\Omega}"); defineMacro("\\varOmega", "\\mathit{\\Omega}");
// \def\overset#1#2{\binrel@{#2}\binrel@@{\mathop{\kern\z@#2}\limits^{#1}}}
defineMacro("\\overset", "\\mathop{#2}\\limits^{#1}");
defineMacro("\\underset", "\\mathop{#2}\\limits_{#1}");
// \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}} // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
defineMacro("\\boxed", "\\fbox{\\displaystyle{#1}}"); defineMacro("\\boxed", "\\fbox{\\displaystyle{#1}}");

View File

@@ -2779,11 +2779,9 @@ describe("A macro expander", function() {
}); });
*/ */
it("should expand the \\overset macro as expected", function() { it("should build \\overset and \\underset", function() {
expect("\\overset?=").toParseLike("\\mathop{=}\\limits^{?}"); expect("\\overset{f}{\\rightarrow} Y").toBuild();
expect("\\overset{x=y}{\\sqrt{ab}}") expect("\\underset{f}{\\rightarrow} Y").toBuild();
.toParseLike("\\mathop{\\sqrt{ab}}\\limits^{x=y}");
expect("\\overset {?} =").toParseLike("\\mathop{=}\\limits^{?}");
}); });
it("should build \\iff, \\implies, \\impliedby", function() { it("should build \\iff, \\implies, \\impliedby", function() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -218,7 +218,7 @@ OpLimits: |
OverUnderline: x\underline{x}\underline{\underline{x}}\underline{x_{x_{x_x}}}\underline{x^{x^{x^x}}}\overline{x}\overline{x}\overline{x^{x^{x^x}}} \blue{\overline{\underline{x}}\underline{\overline{x}}} OverUnderline: x\underline{x}\underline{\underline{x}}\underline{x_{x_{x_x}}}\underline{x^{x^{x^x}}}\overline{x}\overline{x}\overline{x^{x^{x^x}}} \blue{\overline{\underline{x}}\underline{\overline{x}}}
OverUnderset: | OverUnderset: |
\begin{array}{l} \begin{array}{l}
x\overset?=1\\ x\overset?=1 \quad \underset{*}{x}^2 \\
{\displaystyle\lim_{t\underset{>0}\to0}}\\ {\displaystyle\lim_{t\underset{>0}\to0}}\\
a+b+c+d\overset{b+c=0}\longrightarrow a+d\\ a+b+c+d\overset{b+c=0}\longrightarrow a+d\\
\overset { x = y } { \sqrt { a b } } \overset { x = y } { \sqrt { a b } }