Files
KaTeX/test/__snapshots__/katex-spec.js.snap
Erik Demaine 6b4e80bfbb fix(builder): combine characters together in all expressions (#2080)
* Combine characters together in all expressions

Call `tryCombineChars` in `buildExpression`

* update screenshots, exclude 'coverage' from lint

* update MathML snapshots

* don't combine two 'mbin's or two 'mord's

* update screenshots

* update screenshots

Co-authored-by: ylemkimon <y@ylem.kim>
Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
2020-12-30 10:34:01 -05:00

1513 lines
28 KiB
Plaintext
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`A begin/end parser should grab \\arraystretch 1`] = `
[
{
"type": "array",
"arraystretch": 1.5,
"body": [
[
{
"type": "styling",
"body": [
{
"type": "ordgroup",
"body": [
{
"type": "mathord",
"loc": {
"end": 37,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"lastIndex": 56
},
"start": 36
},
"mode": "math",
"text": "a"
}
],
"mode": "math"
}
],
"mode": "math",
"style": "text"
},
{
"type": "styling",
"body": [
{
"type": "ordgroup",
"body": [
{
"type": "mathord",
"loc": {
"end": 39,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"lastIndex": 56
},
"start": 38
},
"mode": "math",
"text": "b"
}
],
"mode": "math"
}
],
"mode": "math",
"style": "text"
}
],
[
{
"type": "styling",
"body": [
{
"type": "ordgroup",
"body": [
{
"type": "mathord",
"loc": {
"end": 42,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"lastIndex": 56
},
"start": 41
},
"mode": "math",
"text": "c"
}
],
"mode": "math"
}
],
"mode": "math",
"style": "text"
},
{
"type": "styling",
"body": [
{
"type": "ordgroup",
"body": [
{
"type": "mathord",
"loc": {
"end": 44,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"lastIndex": 56
},
"start": 43
},
"mode": "math",
"text": "d"
}
],
"mode": "math"
}
],
"mode": "math",
"style": "text"
}
]
],
"cols": [
{
"type": "align",
"align": "c"
},
{
"type": "align",
"align": "c"
}
],
"hLinesBeforeRow": [
[
],
[
],
[
]
],
"hskipBeforeAndAfter": false,
"mode": "math",
"rowGaps": [
null
]
}
]
`;
exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = `
[
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "a",
"width": 0.52859
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
],
"classes": [
"mord"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
}
}
],
"classes": [
"mord"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.69444,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "b",
"width": 0.42917
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2777777777777778em"
}
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mrel",
"mathbf"
],
"depth": -0.10889,
"height": 0.39111,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "=",
"width": 0.89444
}
],
"classes": [
"mord"
],
"depth": 0,
"height": 0.39111,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mrel"
],
"depth": 0,
"height": 0.39111,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2777777777777778em"
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.05556,
"style": {
},
"text": "c",
"width": 0.43276
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"mathbf"
],
"depth": 0.13333,
"height": 0.63333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "+",
"width": 0.89444
}
],
"classes": [
"mord"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mbin"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.69444,
"italic": 0,
"maxFontSize": 1,
"skew": 0.16667,
"style": {
},
"text": "d",
"width": 0.52049
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"mathbf"
],
"depth": 0.13333,
"height": 0.63333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "++",
"width": 0.89444
}
],
"classes": [
"mord"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mbin"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.05556,
"style": {
},
"text": "e",
"width": 0.46563
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"boldsymbol"
],
"depth": 0.19444,
"height": 0.44444,
"italic": 0.04213,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "xyz",
"width": 0.65903
}
],
"classes": [
"mord"
],
"depth": 0.19444,
"height": 0.44444,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mord"
],
"depth": 0.19444,
"height": 0.44444,
"maxFontSize": 1,
"style": {
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0.19444,
"height": 0.69444,
"italic": 0.10764,
"maxFontSize": 1,
"skew": 0.16667,
"style": {
},
"text": "f",
"width": 0.48959
}
]
`;
exports[`A macro expander \\let should consume one optional space after equals sign 1`] = `
[
{
"type": "ordgroup",
"body": [
{
"type": "font",
"body": {
"type": "ordgroup",
"body": [
{
"type": "mathord",
"loc": {
"end": 39,
"lexer": {
"input": "\\\\def\\\\bold{\\\\bgroup\\\\bf\\\\let\\\\next= }\\\\bold{a}",
"lastIndex": 40
},
"start": 38
},
"mode": "math",
"text": "a"
}
],
"mode": "math"
},
"font": "mathbf",
"mode": "math"
}
],
"loc": null,
"mode": "math"
}
]
`;
exports[`A parse tree generator generates a tree 1`] = `
[
{
"type": "supsub",
"base": {
"type": "mathord",
"mode": "math",
"text": "\\\\sigma"
},
"mode": "math",
"sup": {
"type": "textord",
"mode": "math",
"text": "2"
}
}
]
`;
exports[`A parser that does not throw on unsupported commands should build katex-error span for other type of KaTeX error 1`] = `
{
"attributes": {
"style": "color:#933",
"title": "ParseError: KaTeX parse error: Double superscript at position 4: 2^2^̲2"
},
"children": [
{
"classes": [
],
"depth": 0,
"height": 0,
"italic": 0,
"maxFontSize": 0,
"skew": 0,
"style": {
},
"text": "2^2^2",
"width": 0
}
],
"classes": [
"katex-error"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
}
}
`;
exports[`A parser that does not throw on unsupported commands should properly escape LaTeX in errors 1`] = `
<span class="katex-error"
title="ParseError: KaTeX parse error: Expected group after &#x27;^&#x27; at position 2: 2^̲&amp;&quot;&lt;&gt;"
style="color:#933"
>
2^&amp;&quot;&lt;&gt;
</span>
`;
exports[`An HTML extension builder should not affect spacing 1`] = `
[
{
"attributes": {
"id": "a"
},
"children": [
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.02778,
"style": {
},
"text": "x",
"width": 0.57153
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"classes": [
"mbin"
],
"depth": 0.08333,
"height": 0.58333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "+",
"width": 0.77778
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
}
],
"classes": [
"enclosing"
],
"depth": 0.08333,
"height": 0.58333,
"maxFontSize": 1,
"style": {
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0.19444,
"height": 0.43056,
"italic": 0.03588,
"maxFontSize": 1,
"skew": 0.05556,
"style": {
},
"text": "y",
"width": 0.49028
}
]
`;
exports[`An HTML extension builder should render with trust and strict setting 1`] = `
[
{
"attributes": {
"id": "bar"
},
"children": [
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.02778,
"style": {
},
"text": "x",
"width": 0.57153
}
],
"classes": [
"enclosing"
],
"depth": 0,
"height": 0.43056,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.02778,
"style": {
},
"text": "x",
"width": 0.57153
}
],
"classes": [
"enclosing",
"foo"
],
"depth": 0,
"height": 0.43056,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
"style": "color: red;"
},
"children": [
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.02778,
"style": {
},
"text": "x",
"width": 0.57153
}
],
"classes": [
"enclosing"
],
"depth": 0,
"height": 0.43056,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
"data-bar": "b",
"data-foo": "a"
},
"children": [
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.02778,
"style": {
},
"text": "x",
"width": 0.57153
}
],
"classes": [
"enclosing"
],
"depth": 0,
"height": 0.43056,
"maxFontSize": 1,
"style": {
}
}
]
`;
exports[`An implicit group parser within optional groups should work style commands \\sqrt[\\textstyle 3]{x} 1`] = `
[
{
"type": "sqrt",
"body": {
"type": "ordgroup",
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"body": [
{
"type": "styling",
"body": [
{
"type": "textord",
"mode": "math",
"text": "3"
}
],
"mode": "math",
"style": "text"
}
],
"mode": "math"
},
"mode": "math"
}
]
`;
exports[`An implicit group parser within optional groups should work with \\color: \\sqrt[\\color{red} 3]{x} 1`] = `
[
{
"type": "sqrt",
"body": {
"type": "ordgroup",
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"body": [
{
"type": "color",
"body": [
{
"type": "textord",
"mode": "math",
"text": "3"
}
],
"color": "red",
"mode": "math"
}
],
"mode": "math"
},
"mode": "math"
}
]
`;
exports[`An implicit group parser within optional groups should work with old font functions: \\sqrt[\\tt 3]{x} 1`] = `
[
{
"type": "sqrt",
"body": {
"type": "ordgroup",
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"body": [
{
"type": "font",
"body": {
"type": "ordgroup",
"body": [
{
"type": "textord",
"mode": "math",
"text": "3"
}
],
"mode": "math"
},
"font": "mathtt",
"mode": "math"
}
],
"mode": "math"
},
"mode": "math"
}
]
`;
exports[`An implicit group parser within optional groups should work with sizing commands: \\sqrt[\\small 3]{x} 1`] = `
[
{
"type": "sqrt",
"body": {
"type": "ordgroup",
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"body": [
{
"type": "sizing",
"body": [
{
"type": "textord",
"mode": "math",
"text": "3"
}
],
"mode": "math",
"size": 5
}
],
"mode": "math"
},
"mode": "math"
}
]
`;
exports[`An includegraphics builder should not render without trust setting 1`] = `
[
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"",
""
],
"depth": 0.25,
"height": 0.75,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
"color": "#cc0000"
},
"text": "\\\\includegraphics",
"width": 0.5
}
],
"classes": [
"mord",
"text"
],
"depth": 0.25,
"height": 0.75,
"maxFontSize": 1,
"style": {
"color": "#cc0000"
}
}
]
`;
exports[`An includegraphics builder should render with trust setting 1`] = `
[
{
"alt": "KA logo",
"classes": [
"mord"
],
"depth": 0,
"height": 0.9,
"src": "https://cdn.kastatic.org/images/apple-touch-icon-57x57-precomposed.new.png",
"style": {
"height": "0.9em",
"width": "0.9em"
}
}
]
`;
exports[`Extending katex by new fonts and symbols Add new font class to new extended symbols 1`] = `
<span class="katex">
<span class="katex-mathml">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<mrow>
<mi mathvariant="normal">
۹
</mi>
<msup>
<mi mathvariant="normal">
۹
</mi>
<mrow>
<mi mathvariant="normal">
۱
</mi>
<mi mathvariant="normal">
۱
</mi>
</mrow>
</msup>
</mrow>
<annotation encoding="application/x-tex">
۹۹^{۱۱}
</annotation>
</semantics>
</math>
</span>
<span class="katex-html"
aria-hidden="true"
>
<span class="base">
<span class="strut"
style="height:0.84425em;vertical-align:0em;"
>
</span>
<span class="mord mockEasternArabicFont-Regular">
۹
</span>
<span class="mord">
<span class="mord mockEasternArabicFont-Regular">
۹
</span>
<span class="msupsub">
<span class="vlist-t">
<span class="vlist-r">
<span class="vlist"
style="height:0.84425em;"
>
<span style="top:-3.063em;margin-right:0.05em;">
<span class="pstrut"
style="height:2.7em;"
>
</span>
<span class="sizing reset-size6 size3 mtight">
<span class="mord mtight">
<span class="mord mockEasternArabicFont-Regular mtight">
۱۱
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
`;
exports[`Newlines via \\\\ and \\newline \\\\ causes newline, even after mrel and mop 1`] = `
<span class="katex">
<span class="katex-mathml">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<mrow>
<mi>
M
</mi>
<mo>
=
</mo>
<mspace linebreak="newline">
</mspace>
<mi>
a
</mi>
<mo>
+
</mo>
<mspace linebreak="newline">
</mspace>
<mi>
b
</mi>
<mspace linebreak="newline">
</mspace>
<mi>
c
</mi>
</mrow>
<annotation encoding="application/x-tex">
M = \\\\ a + \\\\ b \\\\ c
</annotation>
</semantics>
</math>
</span>
<span class="katex-html"
aria-hidden="true"
>
<span class="base">
<span class="strut"
style="height:0.68333em;vertical-align:0em;"
>
</span>
<span class="mord mathnormal"
style="margin-right:0.10903em;"
>
M
</span>
<span class="mspace"
style="margin-right:0.2777777777777778em;"
>
</span>
<span class="mrel">
=
</span>
</span>
<span class="mspace newline">
</span>
<span class="base">
<span class="strut"
style="height:0.66666em;vertical-align:-0.08333em;"
>
</span>
<span class="mord mathnormal">
a
</span>
<span class="mspace"
style="margin-right:0.2222222222222222em;"
>
</span>
<span class="mbin">
+
</span>
</span>
<span class="mspace newline">
</span>
<span class="base">
<span class="strut"
style="height:0.69444em;vertical-align:0em;"
>
</span>
<span class="mord mathnormal">
b
</span>
</span>
<span class="mspace newline">
</span>
<span class="base">
<span class="strut"
style="height:0.43056em;vertical-align:0em;"
>
</span>
<span class="mord mathnormal">
c
</span>
</span>
</span>
</span>
`;
exports[`href and url commands should allow all protocols when trust option is true 1`] = `
[
{
"type": "href",
"body": [
{
"type": "mathord",
"loc": {
"end": 16,
"lexer": {
"input": "\\\\href{ftp://x}{foo}",
"lastIndex": 19
},
"start": 15
},
"mode": "math",
"text": "f"
},
{
"type": "mathord",
"loc": {
"end": 17,
"lexer": {
"input": "\\\\href{ftp://x}{foo}",
"lastIndex": 19
},
"start": 16
},
"mode": "math",
"text": "o"
},
{
"type": "mathord",
"loc": {
"end": 18,
"lexer": {
"input": "\\\\href{ftp://x}{foo}",
"lastIndex": 19
},
"start": 17
},
"mode": "math",
"text": "o"
}
],
"href": "ftp://x",
"mode": "math"
}
]
`;
exports[`href and url commands should allow explicitly allowed protocols 1`] = `
[
{
"type": "href",
"body": [
{
"type": "mathord",
"loc": {
"end": 16,
"lexer": {
"input": "\\\\href{ftp://x}{foo}",
"lastIndex": 19
},
"start": 15
},
"mode": "math",
"text": "f"
},
{
"type": "mathord",
"loc": {
"end": 17,
"lexer": {
"input": "\\\\href{ftp://x}{foo}",
"lastIndex": 19
},
"start": 16
},
"mode": "math",
"text": "o"
},
{
"type": "mathord",
"loc": {
"end": 18,
"lexer": {
"input": "\\\\href{ftp://x}{foo}",
"lastIndex": 19
},
"start": 17
},
"mode": "math",
"text": "o"
}
],
"href": "ftp://x",
"mode": "math"
}
]
`;
exports[`href and url commands should forbid relative URLs when trust option is false 1`] = `
[
{
"type": "color",
"body": [
{
"type": "text",
"body": [
{
"type": "textord",
"mode": "text",
"text": "\\\\"
},
{
"type": "textord",
"mode": "text",
"text": "h"
},
{
"type": "textord",
"mode": "text",
"text": "r"
},
{
"type": "textord",
"mode": "text",
"text": "e"
},
{
"type": "textord",
"mode": "text",
"text": "f"
}
],
"mode": "math"
}
],
"color": "#cc0000",
"mode": "math"
}
]
`;
exports[`href and url commands should not affect spacing around 1`] = `
[
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "a",
"width": 0.52859
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"attributes": {
"href": "http://example.com/"
},
"children": [
{
"classes": [
"mbin"
],
"depth": 0.08333,
"height": 0.58333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "+",
"width": 0.77778
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"classes": [
"mord",
"mathnormal"
],
"depth": 0,
"height": 0.69444,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"text": "b",
"width": 0.42917
}
],
"classes": [
],
"depth": 0.08333,
"height": 0.69444,
"maxFontSize": 1,
"style": {
}
}
]
`;
exports[`href and url commands should not allow explicitly disallow protocols 1`] = `
[
{
"type": "color",
"body": [
{
"type": "text",
"body": [
{
"type": "textord",
"mode": "text",
"text": "\\\\"
},
{
"type": "textord",
"mode": "text",
"text": "h"
},
{
"type": "textord",
"mode": "text",
"text": "r"
},
{
"type": "textord",
"mode": "text",
"text": "e"
},
{
"type": "textord",
"mode": "text",
"text": "f"
}
],
"mode": "math"
}
],
"color": "#cc0000",
"mode": "math"
}
]
`;