fix: MathML for stretchy accents. #2990 (#2991)

* fix #2990

fix make stretchycode to textNode bug.

* fix: fix stretchy.js@mathMLnode line too long

* chore(screenshotter): update stretchy snapshots

* fix: remove dup '\' in cdrightarrow cdleftarrow and cdlongequal

* test: add stretchy MathML builder test case

Co-authored-by: nferzhuang <nferzhuang@tencent.com>
Co-authored-by: Ron Kok <ronkok@comcast.net>
This commit is contained in:
Nfer Zhuang
2021-05-07 11:31:52 +08:00
committed by GitHub
parent 0f80a6ffcd
commit 1cb62799c6
2 changed files with 15 additions and 4 deletions

View File

@@ -54,14 +54,16 @@ const stretchyCodePoint: {[string]: string} = {
xrightleftarrows: "\u21c4",
xrightequilibrium: "\u21cc", // Not a perfect match.
xleftequilibrium: "\u21cb", // None better available.
"\\\\cdrightarrow": "\u2192",
"\\\\cdleftarrow": "\u2190",
"\\\\cdlongequal": "=",
"\\cdrightarrow": "\u2192",
"\\cdleftarrow": "\u2190",
"\\cdlongequal": "=",
};
const mathMLnode = function(label: string): mathMLTree.MathNode {
const node = new mathMLTree.MathNode(
"mo", [new mathMLTree.TextNode(stretchyCodePoint[label])]);
"mo",
[new mathMLTree.TextNode(stretchyCodePoint[label.replace(/^\\/, '')])],
);
node.setAttribute("stretchy", "true");
return node;
};

View File

@@ -2245,6 +2245,15 @@ describe("A stretchy and non-shifty accent builder", function() {
});
});
describe("A stretchy MathML builder", function() {
it("should properly render stretchy accents", function() {
const tex = `\\widetilde{ABCD}`;
const tree = getParsed(tex);
const markup = buildMathML(tree, tex, defaultOptions).toMarkup();
expect(markup).toContain('<mo stretchy="true">~</mo>');
});
});
describe("An under-accent parser", function() {
it("should not fail", function() {
expect("\\underrightarrow{x}").toParse();