mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-10 13:38:39 +00:00
allow sizing commands inside optional groups (#885)
* allow sizing commands inside optional groups * allow color, old font, and style commands inside optional groups
This commit is contained in:
178
test/__snapshots__/katex-spec.js.snap
Normal file
178
test/__snapshots__/katex-spec.js.snap
Normal file
@@ -0,0 +1,178 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`An implicit group parser within optional groups should work style commands \\sqrt[\\textstyle 3]{x} 1`] = `
|
||||
[
|
||||
{
|
||||
"type": "sqrt",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "sqrt",
|
||||
"body": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"mode": "math",
|
||||
"value": "x"
|
||||
}
|
||||
]
|
||||
},
|
||||
"index": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "styling",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"style": "text",
|
||||
"value": [
|
||||
{
|
||||
"type": "textord",
|
||||
"mode": "math",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`An implicit group parser within optional groups should work with \\color: \\sqrt[\\color{red} 3]{x} 1`] = `
|
||||
[
|
||||
{
|
||||
"type": "sqrt",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "sqrt",
|
||||
"body": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"mode": "math",
|
||||
"value": "x"
|
||||
}
|
||||
]
|
||||
},
|
||||
"index": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "color",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "color",
|
||||
"color": "red",
|
||||
"value": [
|
||||
{
|
||||
"type": "textord",
|
||||
"mode": "math",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`An implicit group parser within optional groups should work with sizing commands: \\sqrt[\\small 3]{x} 1`] = `
|
||||
[
|
||||
{
|
||||
"type": "sqrt",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "sqrt",
|
||||
"body": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"mode": "math",
|
||||
"value": "x"
|
||||
}
|
||||
]
|
||||
},
|
||||
"index": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "sizing",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"size": 5,
|
||||
"value": [
|
||||
{
|
||||
"type": "textord",
|
||||
"mode": "math",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`An implicit group parser within optional groups should work wwith old font functions: \\sqrt[\\tt 3]{x} 1`] = `
|
||||
[
|
||||
{
|
||||
"type": "sqrt",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"type": "sqrt",
|
||||
"body": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "mathord",
|
||||
"mode": "math",
|
||||
"value": "x"
|
||||
}
|
||||
]
|
||||
},
|
||||
"index": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "font",
|
||||
"mode": "math",
|
||||
"value": {
|
||||
"body": {
|
||||
"type": "ordgroup",
|
||||
"mode": "math",
|
||||
"value": [
|
||||
{
|
||||
"type": "textord",
|
||||
"mode": "math",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
},
|
||||
"font": "mathtt"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
`;
|
@@ -3,6 +3,7 @@
|
||||
/* global expect: false */
|
||||
/* global it: false */
|
||||
/* global describe: false */
|
||||
import stringify from 'json-stable-stringify';
|
||||
|
||||
import buildMathML from "../src/buildMathML";
|
||||
import buildTree from "../src/buildTree";
|
||||
@@ -13,6 +14,27 @@ import Options from "../src/Options";
|
||||
import Settings from "../src/Settings";
|
||||
import Style from "../src/Style";
|
||||
|
||||
const typeFirstCompare = (a, b) => {
|
||||
if (a.key === 'type') {
|
||||
return -1;
|
||||
} else if (b.key === 'type') {
|
||||
return 1;
|
||||
} else {
|
||||
return a.key < b.key ? -1 : 1;
|
||||
}
|
||||
};
|
||||
|
||||
const serializer = {
|
||||
print(val) {
|
||||
return stringify(val, {cmp: typeFirstCompare, space: ' '});
|
||||
},
|
||||
test() {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
expect.addSnapshotSerializer(serializer);
|
||||
|
||||
const defaultSettings = new Settings({});
|
||||
const defaultOptions = new Options({
|
||||
style: Style.TEXT,
|
||||
@@ -520,6 +542,28 @@ describe("An implicit group parser", function() {
|
||||
expect(sizing.type).toEqual("sizing");
|
||||
expect(sizing.value.value.length).toBe(1);
|
||||
});
|
||||
|
||||
describe("within optional groups", () => {
|
||||
it("should work with sizing commands: \\sqrt[\\small 3]{x}", () => {
|
||||
const tree = stripPositions(getParsed("\\sqrt[\\small 3]{x}"));
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("should work with \\color: \\sqrt[\\color{red} 3]{x}", () => {
|
||||
const tree = stripPositions(getParsed("\\sqrt[\\color{red} 3]{x}"));
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("should work style commands \\sqrt[\\textstyle 3]{x}", () => {
|
||||
const tree = stripPositions(getParsed("\\sqrt[\\textstyle 3]{x}"));
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("should work wwith old font functions: \\sqrt[\\tt 3]{x}", () => {
|
||||
const tree = stripPositions(getParsed("\\sqrt[\\tt 3]{x}"));
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("A function parser", function() {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 9.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 9.5 KiB |
@@ -214,7 +214,7 @@ SizingBaseline:
|
||||
pre: x
|
||||
post: M
|
||||
Sizing: |
|
||||
{\Huge x}{\LARGE y}{\normalsize z}{\scriptsize w}
|
||||
{\Huge x}{\LARGE y}{\normalsize z}{\scriptsize w}\sqrt[\small 3]{x+1}
|
||||
Smash: \left( X^{\smash 2} \right) \sqrt{\smash[b]{y}}
|
||||
Spacing: ^3+[-1][1-1]1=1(=1)\lvert a\rvert~b
|
||||
Sqrt: |
|
||||
|
Reference in New Issue
Block a user