Fix \hphantom width (#1809)

* Fix \hphantom width

* Spin up phony screenshot test

* Make better choice of smash screenshot test

* Real screenshotter test

* Add strict mode

* Fix lint error

* useStrictBehavior

* Revert to previous strict setting

* useStrictBehavior "phantomSpacing"

* Fix tests via nonstrictSettings

* Fix documentation

* Remove bin|rel
This commit is contained in:
Ron Kok
2019-01-01 08:49:24 -08:00
committed by ylemkimon
parent 8346294bf3
commit f5234a2f01
9 changed files with 29 additions and 13 deletions

View File

@@ -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. - `"commentAtEnd"`: Use of `%` comment without a terminating newline.
LaTeX would thereby comment out the end of math mode (e.g. `$`), LaTeX would thereby comment out the end of math mode (e.g. `$`),
causing an error. causing an error.
A second category of `errorCode`s never throw errors, but their strictness A second category of `errorCode`s never throw errors, but their strictness
affects the behavior of KaTeX: affects the behavior of KaTeX:
- `"newLineInDisplayMode"`: Use of `\\` or `\newline` in display mode - `"newLineInDisplayMode"`: Use of `\\` or `\newline` in display mode

View File

@@ -71,7 +71,8 @@ defineFunction({
children: [{type: "elem", elem: node}], children: [{type: "elem", elem: node}],
}, options); }, 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) => { mathmlBuilder: (group, options) => {
const inner = mml.buildExpression(ordargument(group.body), options); const inner = mml.buildExpression(ordargument(group.body), options);

View File

@@ -55,7 +55,7 @@ defineFunction({
}, },
htmlBuilder: (group, options) => { htmlBuilder: (group, options) => {
const node = buildCommon.makeSpan( const node = buildCommon.makeSpan(
["mord"], [html.buildGroup(group.body, options)]); [], [html.buildGroup(group.body, options)]);
if (!group.smashHeight && !group.smashDepth) { if (!group.smashHeight && !group.smashDepth) {
return node; return node;
@@ -85,10 +85,13 @@ defineFunction({
// makeVList applies "display: table-cell", which prevents the browser // makeVList applies "display: table-cell", which prevents the browser
// from acting on that line height. So we'll call makeVList now. // from acting on that line height. So we'll call makeVList now.
return buildCommon.makeVList({ const smashedNode = buildCommon.makeVList({
positionType: "firstBaseline", positionType: "firstBaseline",
children: [{type: "elem", elem: node}], children: [{type: "elem", elem: node}],
}, options); }, options);
// For spacing, TeX treats \hphantom as a math group (same spacing as ord).
return buildCommon.makeSpan(["mord"], [smashedNode], options);
}, },
mathmlBuilder: (group, options) => { mathmlBuilder: (group, options) => {
const node = new mathMLTree.MathNode( const node = new mathMLTree.MathNode(

View File

@@ -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() { describe("A markup generator", function() {
it("marks trees up", function() { it("marks trees up", function() {
// Just a few quick sanity checks here... // Just a few quick sanity checks here...
@@ -2462,15 +2473,15 @@ describe("A smash parser", function() {
describe("A smash builder", function() { describe("A smash builder", function() {
it("should not fail", function() { it("should not fail", function() {
expect`\smash{x}`.toBuild(); expect`\smash{x}`.toBuild(nonstrictSettings);
expect`\smash{x^2}`.toBuild(); expect`\smash{x^2}`.toBuild(nonstrictSettings);
expect`\smash{x}^2`.toBuild(); expect`\smash{x}^2`.toBuild(nonstrictSettings);
expect`\smash x`.toBuild(); expect`\smash x`.toBuild(nonstrictSettings);
expect`\smash[b]{x}`.toBuild(); expect`\smash[b]{x}`.toBuild(nonstrictSettings);
expect`\smash[b]{x^2}`.toBuild(); expect`\smash[b]{x^2}`.toBuild(nonstrictSettings);
expect`\smash[b]{x}^2`.toBuild(); expect`\smash[b]{x}^2`.toBuild(nonstrictSettings);
expect`\smash[b] x`.toBuild(); expect`\smash[b] x`.toBuild(nonstrictSettings);
}); });
}); });

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@@ -280,7 +280,7 @@ OverUnderset: |
\end{array} \end{array}
Phantom: \begin{array}{l} 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)\\ \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} \end{array}
Pmb: \mu\pmb{\mu}\pmb{=}\mu\pmb{+}\mu Pmb: \mu\pmb{\mu}\pmb{=}\mu\pmb{+}\mu
PrimeSpacing: f'+f_2'+f^{f'} PrimeSpacing: f'+f_2'+f^{f'}
@@ -308,7 +308,7 @@ SizingBaseline:
post: M post: M
Sizing: | Sizing: |
{\Huge x}{\LARGE y}{\normalsize z}{\scriptsize w}\sqrt[\small 3]{x+1} {\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: | Spacing: |
\begin{matrix} \begin{matrix}
^3+[-1][1-1]1=1(=1)\lvert a\rvert~b \\ ^3+[-1][1-1]1=1(=1)\lvert a\rvert~b \\