diff --git a/docs/options.md b/docs/options.md index 109609d1..a740d940 100644 --- a/docs/options.md +++ b/docs/options.md @@ -21,6 +21,7 @@ You can provide an object of options as the last argument to [`katex.render` and - `"commentAtEnd"`: Use of `%` comment without a terminating newline. LaTeX would thereby comment out the end of math mode (e.g. `$`), causing an error. + A second category of `errorCode`s never throw errors, but their strictness affects the behavior of KaTeX: - `"newLineInDisplayMode"`: Use of `\\` or `\newline` in display mode diff --git a/src/functions/phantom.js b/src/functions/phantom.js index 626479a6..e098f66a 100644 --- a/src/functions/phantom.js +++ b/src/functions/phantom.js @@ -71,7 +71,8 @@ defineFunction({ children: [{type: "elem", elem: node}], }, options); - return node; + // For spacing, TeX treats \smash as a math group (same spacing as ord). + return buildCommon.makeSpan(["mord"], [node], options); }, mathmlBuilder: (group, options) => { const inner = mml.buildExpression(ordargument(group.body), options); diff --git a/src/functions/smash.js b/src/functions/smash.js index ae85d166..90bf4677 100644 --- a/src/functions/smash.js +++ b/src/functions/smash.js @@ -55,7 +55,7 @@ defineFunction({ }, htmlBuilder: (group, options) => { const node = buildCommon.makeSpan( - ["mord"], [html.buildGroup(group.body, options)]); + [], [html.buildGroup(group.body, options)]); if (!group.smashHeight && !group.smashDepth) { return node; @@ -85,10 +85,13 @@ defineFunction({ // makeVList applies "display: table-cell", which prevents the browser // from acting on that line height. So we'll call makeVList now. - return buildCommon.makeVList({ + const smashedNode = buildCommon.makeVList({ positionType: "firstBaseline", children: [{type: "elem", elem: node}], }, options); + + // For spacing, TeX treats \hphantom as a math group (same spacing as ord). + return buildCommon.makeSpan(["mord"], [smashedNode], options); }, mathmlBuilder: (group, options) => { const node = new mathMLTree.MathNode( diff --git a/test/katex-spec.js b/test/katex-spec.js index fee9de9a..1f49cff2 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -2008,6 +2008,17 @@ describe("A bin builder", function() { }); }); +describe("A \\phantom builder and \\smash builder", function() { + it("should both build a mord", function() { + expect(getBuilt`\hphantom{a}`[0].classes).toContain("mord"); + expect(getBuilt`a\hphantom{=}b`[2].classes).toContain("mord"); + expect(getBuilt`a\hphantom{+}b`[2].classes).toContain("mord"); + expect(getBuilt`\smash{a}`[0].classes).toContain("mord"); + expect(getBuilt`\smash{=}`[0].classes).toContain("mord"); + expect(getBuilt`a\smash{+}b`[2].classes).toContain("mord"); + }); +}); + describe("A markup generator", function() { it("marks trees up", function() { // Just a few quick sanity checks here... @@ -2462,15 +2473,15 @@ describe("A smash parser", function() { describe("A smash builder", function() { it("should not fail", function() { - expect`\smash{x}`.toBuild(); - expect`\smash{x^2}`.toBuild(); - expect`\smash{x}^2`.toBuild(); - expect`\smash x`.toBuild(); + expect`\smash{x}`.toBuild(nonstrictSettings); + expect`\smash{x^2}`.toBuild(nonstrictSettings); + expect`\smash{x}^2`.toBuild(nonstrictSettings); + expect`\smash x`.toBuild(nonstrictSettings); - expect`\smash[b]{x}`.toBuild(); - expect`\smash[b]{x^2}`.toBuild(); - expect`\smash[b]{x}^2`.toBuild(); - expect`\smash[b] x`.toBuild(); + expect`\smash[b]{x}`.toBuild(nonstrictSettings); + expect`\smash[b]{x^2}`.toBuild(nonstrictSettings); + expect`\smash[b]{x}^2`.toBuild(nonstrictSettings); + expect`\smash[b] x`.toBuild(nonstrictSettings); }); }); diff --git a/test/screenshotter/images/Phantom-chrome.png b/test/screenshotter/images/Phantom-chrome.png index 6cc165f5..071d28a7 100644 Binary files a/test/screenshotter/images/Phantom-chrome.png and b/test/screenshotter/images/Phantom-chrome.png differ diff --git a/test/screenshotter/images/Phantom-firefox.png b/test/screenshotter/images/Phantom-firefox.png index c596b1fc..abf344e1 100644 Binary files a/test/screenshotter/images/Phantom-firefox.png and b/test/screenshotter/images/Phantom-firefox.png differ diff --git a/test/screenshotter/images/Smash-chrome.png b/test/screenshotter/images/Smash-chrome.png index 97f765bf..7073a63e 100644 Binary files a/test/screenshotter/images/Smash-chrome.png and b/test/screenshotter/images/Smash-chrome.png differ diff --git a/test/screenshotter/images/Smash-firefox.png b/test/screenshotter/images/Smash-firefox.png index 590dbd95..bb587838 100644 Binary files a/test/screenshotter/images/Smash-firefox.png and b/test/screenshotter/images/Smash-firefox.png differ diff --git a/test/screenshotter/ss_data.yaml b/test/screenshotter/ss_data.yaml index 8d9b9d5b..3e3ef9a1 100644 --- a/test/screenshotter/ss_data.yaml +++ b/test/screenshotter/ss_data.yaml @@ -280,7 +280,7 @@ OverUnderset: | \end{array} Phantom: \begin{array}{l} \dfrac{1+\phantom{x^{\blue{2}}} = x}{1+x^{\blue{2}} = x} \left(\vphantom{\int_t} zzz \right) \left( X \hphantom{\frac{\frac X X}{X}} \right)\\ - \text{a \phantom{123} b \hphantom{45678} c \vphantom{101112} d} + \text{a \phantom{123}} b \hphantom{\frac{1}{2}}=c \vphantom{101112} d \end{array} Pmb: \mu\pmb{\mu}\pmb{=}\mu\pmb{+}\mu PrimeSpacing: f'+f_2'+f^{f'} @@ -308,7 +308,7 @@ SizingBaseline: post: M Sizing: | {\Huge x}{\LARGE y}{\normalsize z}{\scriptsize w}\sqrt[\small 3]{x+1} -Smash: \left( X^{\smash 2} \right) \sqrt{\smash[b]{y}} +Smash: \left( X^{\smash 2} \right) \sqrt{\smash[b]{y=}} Spacing: | \begin{matrix} ^3+[-1][1-1]1=1(=1)\lvert a\rvert~b \\