Repository: KaTeX/KaTeX (js)

Issue:
\widehat mathml toNode error
> Before reporting a bug
- [x] Check [common issues](https://katex.org/docs/issues.html).
- [x] Check the bug is reproducible in [the demo](https://katex.org). If not, check KaTeX is up-to-date and installed correctly.
- [x] Search for [existing issues](https://github.com/KaTeX/KaTeX/issues).

**Describe the bug:**
A clear and concise description of what the bug is. If your installation is available on the web or you can provide a minimal repo or CodePen that reproduces the bug, please add the link to it.

**To Reproduce:**
Steps to reproduce the behavior:
1. Open https://katex.org/
2. Input `\widetilde{ABCD}\tilde{ABCD}` in the demo-input textarea
3. Press F12 open Chrome DevTools
4. Switch to Elements tab and focus on the 'katex-mathml' element

**Expected behavior:**
The expected mathml should be: 
```html
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mover accent="true"><mi>x</mi><mo stretchy="true">^</mo></mover><mover accent="true"><mi>x</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\widehat{x}\hat{x}</annotation></semantics></math>
```

while, now it gets below:
```html
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mover accent="true"><mi>x</mi><mo stretchy="true">undefined</mo></mover><mover accent="true"><mi>x</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\widehat{x}\hat{x}</annotation></semantics></math>
```

The **key** question is the `widehat` mathml render to an undefined textnode.

**Screenshots:**
![image](https://user-images.githubusercontent.com/1737782/117308963-94479e80-aeb4-11eb-96b5-a230669e5a16.png)

**Environment (please complete the following information):**
 - KaTeX Version: [0.13.6]
 - Device: [Desktop]
 - OS: [Mac OS Catalina 10.15.7]
 - Browser: [Chrome]
 - Version: [90]

**Additional context:**
None


Pull request description:
fix: MathML for stretchy accents. #2990
fix make stretchyCodePoint to textNode bug.

Patch:
diff --git a/src/stretchy.js b/src/stretchy.js
index c451632f..be04c4f3 100644
--- a/src/stretchy.js
+++ b/src/stretchy.js
@@ -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;
 };


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index 51979469..79127164 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -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();