Repository: Khan/KaTeX
Pull request #1371 (2018-05-27 21:41:18)

Fix wide character spacing
Fixes issue #1360.

Visual confirmation:
![widespacing](https://user-images.githubusercontent.com/16403058/40590891-f453298c-61bb-11e8-8eb8-9ef5b2003557.PNG)


codecov[bot]: # [Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=h1) Report
> Merging [#1371](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=desc) into [master](https://codecov.io/gh/Khan/KaTeX/commit/e3fb2f95ae6b5445338239e8458c4aed72d963a6?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.


[![Impacted file tree graph](https://codecov.io/gh/Khan/KaTeX/pull/1371/graphs/tree.svg?width=650&token=vfDnj2P77o&height=150&src=pr)](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1371   +/-   ##
=======================================
  Coverage   81.23%   81.23%           
=======================================
  Files          77       77           
  Lines        4227     4227           
  Branches      731      731           
=======================================
  Hits         3434     3434           
  Misses        673      673           
  Partials      120      120
```


| [Impacted Files](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/buildCommon.js](https://codecov.io/gh/Khan/KaTeX/pull/1371/diff?src=pr&el=tree#diff-c3JjL2J1aWxkQ29tbW9uLmpz) | `89.78% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=footer). Last update [e3fb2f9...d464865](https://codecov.io/gh/Khan/KaTeX/pull/1371?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

ronkok: > This should fix the italic, script, etc. unicode chars right?

Yep. Anything with a high surrogate `\uD835`. 

Patch:
diff --git a/src/buildCommon.js b/src/buildCommon.js
index 1a15ef51..e8f39453 100644
--- a/src/buildCommon.js
+++ b/src/buildCommon.js
@@ -238,7 +238,8 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
     if (value.charCodeAt(0) === 0xD835) {
         // surrogate pairs get special treatment
         const [wideFontName, wideFontClass] = wideCharacterFont(value, mode);
-        return makeSymbol(value, wideFontName, mode, options, [wideFontClass]);
+        return makeSymbol(value, wideFontName, mode, options,
+            classes.concat(wideFontClass));
     } else if (fontOrFamily) {
         let fontName;
         let fontClasses;


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index 406421a3..eb351deb 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -1548,6 +1548,16 @@ describe("An HTML font tree-builder", function() {
         expect(markup).toContain(span);
     });
 
+    it("should render wide characters with mord and with the correct font", function() {
+        const markup = katex.renderToString(String.fromCharCode(0xD835, 0xDC00));
+        expect(markup).toContain("<span class=\"mord mathbf\">A</span>");
+
+        const phrase1 = getBuilt(String.fromCharCode(0xD835, 0xDC00) +
+            " = " + String.fromCharCode(0xD835, 0xDC1A))[0];
+        const phrase2 = getBuilt("\\mathbf A = \\mathbf a")[0];
+        expect(phrase1).toEqual(phrase2);
+    });
+
     it("should throw TypeError when the expression is of the wrong type", function() {
         expect(function() {
             katex.renderToString({badInputType: "yes"});