Repository: Khan/KaTeX
Pull request #1151 (2018-02-09 03:00:24)

Support Unicode colon equals
This PR adds support for three Unicode characters: `≔` `≕` `⩴`

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

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

```diff
@@            Coverage Diff             @@
##           master    #1151      +/-   ##
==========================================
+ Coverage   78.95%   79.01%   +0.06%     
==========================================
  Files          59       59              
  Lines        3872     3875       +3     
  Branches      655      655              
==========================================
+ Hits         3057     3062       +5     
+ Misses        674      672       -2     
  Partials      141      141
```


| [Impacted Files](https://codecov.io/gh/Khan/KaTeX/pull/1151?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/macros.js](https://codecov.io/gh/Khan/KaTeX/pull/1151/diff?src=pr&el=tree#diff-c3JjL21hY3Jvcy5qcw==) | `82.6% <100%> (+0.38%)` | :arrow_up: |
| [src/functions.js](https://codecov.io/gh/Khan/KaTeX/pull/1151/diff?src=pr&el=tree#diff-c3JjL2Z1bmN0aW9ucy5qcw==) | `87.03% <0%> (+3.7%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1151?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/1151?src=pr&el=footer). Last update [383a68b...b59a506](https://codecov.io/gh/Khan/KaTeX/pull/1151?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

ronkok: I withheld these characters from PR #933 because three packages address these characters and they all disagree on the alias.

| **Character** | **Code Point** | **mathtools and KaTeX** | **colonequals and KaTeX** | **unicode-math** |
|:--------------|:---------------------|:------------------------|:--------------------------|:-----------------|
| ≔             | U+2254               | \\coloneqq              | \\colonequals             | \\coloneq        |
| ≕             | U+2255               | \\eqqcolon              | \\equalscolon             | \\eqcolon        |
| ⩴             | U+2A74               | \\Eqqcolon              | \\equalscoloncolon        | \\Coloneq        |

Not only that, but the Unicode math aliases are used by mathtools to render a different character.

|   Alias   | unicode-math    | mathtools and KaTeX |
|:----------|:--------------------:|:-----------------------------------------------:|
| \\coloneq | ≔                    | :−                                              |
| \\eqcolon | ≕                    | −:                                              |
| \\Coloneq | ⩴                    | ::−                                             |

I have said in earlier PRs that for Unicode support, the internal alias is only a means, not an end. What matters is that the author must get the results desired from the input of a specific Unicode character. That is still true, so I have implemented these Unicode characters by writing macros that call the `mathtools` aliases.

It’s a good thing that those internal aliases don’t really matter. This could have been ugly.
ronkok: Visual confirmation:
![colonequals](https://user-images.githubusercontent.com/16403058/36010071-4f6e26e4-0d04-11e8-94a9-90d23db1f9a5.PNG)


Patch:
diff --git a/src/macros.js b/src/macros.js
index d31b02d2..59d1e7db 100644
--- a/src/macros.js
+++ b/src/macros.js
@@ -397,6 +397,11 @@ defineMacro("\\colonsim", "\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim");
 // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
 defineMacro("\\Colonsim", "\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim");
 
+// Some Unicode characters are implemented with macros to mathtools functions.
+defineMacro("\u2254", "\\coloneqq");  // :=
+defineMacro("\u2255", "\\eqqcolon");  // =:
+defineMacro("\u2A74", "\\Coloneqq");  // ::=
+
 //////////////////////////////////////////////////////////////////////
 // colonequals.sty
 


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index e1d432af..0113f65d 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -2915,7 +2915,7 @@ describe("Unicode", function() {
     });
 
     it("should parse relations", function() {
-        expect("∈∋∝∼∽≂≃≅≈≊≍≎≏≐≑≒≓≖≗≜≡≤≥≦≧≫≬≳≷≺≻≼≽≾≿∴∵∣").toParse();
+        expect("∈∋∝∼∽≂≃≅≈≊≍≎≏≐≑≒≓≖≗≜≡≤≥≦≧≫≬≳≷≺≻≼≽≾≿∴∵∣≔≕⩴").toParse();
     });
 
     it("should parse big operators", function() {