Skip to content

Commit

Permalink
fix: MathML for stretchy accents. #2990 (#2991)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed May 7, 2021
1 parent 0f80a6f commit 1cb6279
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/stretchy.js
Expand Up @@ -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;
};
Expand Down
9 changes: 9 additions & 0 deletions test/katex-spec.js
Expand Up @@ -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();
Expand Down

0 comments on commit 1cb6279

Please sign in to comment.