Repository: Khan/KaTeX
Pull request #951 (2017-10-24 20:43:48)

Support Unicode Binary Operators
This is the fourth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `bin` atoms.

ronkok: As in PR #933, the following table shows the KaTeX function to which each character is mapped and confirmation whether [unicode math](http://ctan.sharelatex.com/tex-archive/macros/latex/contrib/unicode-math/unicode-math-table.tex) and/or John Cook’s [conversion page](https://www.johndcook.com/unidata.js) map it the same way.

| **Character** | **Code point** | **Maps to**       | **unicode math** | **Cook** | **Other**   |
|:-------------:|:--------------:|:------------------|:----------------:|:--------:|:-----------:|
| ±             | U+00B1         | \\pm              | ✓                | ✓        |             |
| ×             | U+00D7         | \\times           | ✓                | ✓        |             |
| ÷             | U+00F7         | \\div             | ✓                | ✓        |             |
| ∓             | U+2213         | \\mp              | ✓                | ✓        |             |
| ∔             | U+2214         | \\dotplus         | ✓                | ✓        |             |
| ∧             | U+2227         | \\wedge           | ✓                | ✓        | \\land      |
| ∨             | U+2228         | \\vee             | ✓                | ✓        | \\lor       |
| ∩             | U+2229         | \\cap             | ✓                | ✓        |             |
| ∪             | U+222A         | \\cup             | ✓                | ✓        |             |
| ≀             | U+2240         | \\wr              | ✓                | ✓        |             |
| ⊎             | U+228E         | \\uplus           | ✓                | ✓        |             |
| ⊓             | U+2293         | \\sqcap           | ✓                | ✓        |             |
| ⊔             | U+2294         | \\sqcup           | ✓                | ✓        |             |
| ⊕             | U+2295         | \\oplus           | ✓                | ✓        |             |
| ⊖             | U+2296         | \\ominus          | ✓                | ✓        |             |
| ⊗             | U+2297         | \\otimes          | ✓                | ✓        |             |
| ⊘             | U+2298         | \\oslash          | ✓                | ✓        |             |
| ⊙             | U+2299         | \\odot            | ✓                | ✓        |             |
| ⊚             | U+229A         | \\circledcirc     | ✓                | ✓        |             |
| ⊛             | U+229B         | \\circledast      | ✓                | ✓        |             |
| ⊝             | U+229D         | \\circleddash     | ✓                | ✓        |             |
| ⊞             | U+229E         | \\boxplus         | ✓                | ✓        |             |
| ⊟             | U+229F         | \\boxminus        | ✓                | ✓        |             |
| ⊠             | U+22A0         | \\boxtimes        | ✓                | ✓        |             |
| ⊡             | U+22A1         | \\boxdot          | ✓                | ✓        |             |
| ⊺             | U+22BA         | \\intercal        | ✓                | ✓        |             |
| ⊻             | U+22BB         | \\veebar          | ✓                | ✓        |             |
| ⊼             | U+22BC         | \\barwedge        | ✓                | ✓        |             |
| ⋇             | U+22C7         | \\divideontimes   | ✓                | ✓        |             |
| ⋉             | U+22C9         | \\ltimes          | ✓                | ✓        |             |
| ⋊             | U+22CA         | \\rtimes          | ✓                | ✓        |             |
| ⋋             | U+22CB         | \\leftthreetimes  | ✓                | ✓        |             |
| ⋌             | U+22CC         | \\rightthreetimes | ✓                | ✓        |             |
| ⋎             | U+22CE         | \\curlyvee        | ✓                | ✓        |             |
| ⋏             | U+22CF         | \\curlywedge      | ✓                | ✓        |             |
| ⋒             | U+22D2         | \\Cap             | ✓                | ✓        | \\doublecap |
| ⋓             | U+22D3         | \\Cup             | ✓                | ✓        | \\doublecup |
| ⩞             | U+2A5E         | \\doublebarwedge  | ✓                | ✓        |             |

Patch:
diff --git a/src/symbols.js b/src/symbols.js
index 5bf55011..2d168220 100644
--- a/src/symbols.js
+++ b/src/symbols.js
@@ -140,16 +140,16 @@ defineSymbol(math, main, close, "\u27ef", "\\rgroup");
 defineSymbol(math, main, open, "\u27ee", "\\lgroup");
 
 // Binary Operators
-defineSymbol(math, main, bin, "\u2213", "\\mp");
-defineSymbol(math, main, bin, "\u2296", "\\ominus");
-defineSymbol(math, main, bin, "\u228e", "\\uplus");
-defineSymbol(math, main, bin, "\u2293", "\\sqcap");
+defineSymbol(math, main, bin, "\u2213", "\\mp", true);
+defineSymbol(math, main, bin, "\u2296", "\\ominus", true);
+defineSymbol(math, main, bin, "\u228e", "\\uplus", true);
+defineSymbol(math, main, bin, "\u2293", "\\sqcap", true);
 defineSymbol(math, main, bin, "\u2217", "\\ast");
-defineSymbol(math, main, bin, "\u2294", "\\sqcup");
+defineSymbol(math, main, bin, "\u2294", "\\sqcup", true);
 defineSymbol(math, main, bin, "\u25ef", "\\bigcirc");
 defineSymbol(math, main, bin, "\u2219", "\\bullet");
 defineSymbol(math, main, bin, "\u2021", "\\ddagger");
-defineSymbol(math, main, bin, "\u2240", "\\wr");
+defineSymbol(math, main, bin, "\u2240", "\\wr", true);
 defineSymbol(math, main, bin, "\u2a3f", "\\amalg");
 defineSymbol(math, main, bin, "\u0026", "\\And");  // from amsmath
 
@@ -363,27 +363,27 @@ defineSymbol(math, main, rel, "\u22c8", "\\Join");
 defineSymbol(math, ams, rel, "\u2251", "\\Doteq", true);
 
 // AMS Binary Operators
-defineSymbol(math, ams, bin, "\u2214", "\\dotplus");
+defineSymbol(math, ams, bin, "\u2214", "\\dotplus", true);
 defineSymbol(math, ams, bin, "\u2216", "\\smallsetminus");
-defineSymbol(math, ams, bin, "\u22d2", "\\Cap");
-defineSymbol(math, ams, bin, "\u22d3", "\\Cup");
-defineSymbol(math, ams, bin, "\u2a5e", "\\doublebarwedge");
-defineSymbol(math, ams, bin, "\u229f", "\\boxminus");
-defineSymbol(math, ams, bin, "\u229e", "\\boxplus");
-defineSymbol(math, ams, bin, "\u22c7", "\\divideontimes");
-defineSymbol(math, ams, bin, "\u22c9", "\\ltimes");
-defineSymbol(math, ams, bin, "\u22ca", "\\rtimes");
-defineSymbol(math, ams, bin, "\u22cb", "\\leftthreetimes");
-defineSymbol(math, ams, bin, "\u22cc", "\\rightthreetimes");
-defineSymbol(math, ams, bin, "\u22cf", "\\curlywedge");
-defineSymbol(math, ams, bin, "\u22ce", "\\curlyvee");
-defineSymbol(math, ams, bin, "\u229d", "\\circleddash");
-defineSymbol(math, ams, bin, "\u229b", "\\circledast");
+defineSymbol(math, ams, bin, "\u22d2", "\\Cap", true);
+defineSymbol(math, ams, bin, "\u22d3", "\\Cup", true);
+defineSymbol(math, ams, bin, "\u2a5e", "\\doublebarwedge", true);
+defineSymbol(math, ams, bin, "\u229f", "\\boxminus", true);
+defineSymbol(math, ams, bin, "\u229e", "\\boxplus", true);
+defineSymbol(math, ams, bin, "\u22c7", "\\divideontimes", true);
+defineSymbol(math, ams, bin, "\u22c9", "\\ltimes", true);
+defineSymbol(math, ams, bin, "\u22ca", "\\rtimes", true);
+defineSymbol(math, ams, bin, "\u22cb", "\\leftthreetimes", true);
+defineSymbol(math, ams, bin, "\u22cc", "\\rightthreetimes", true);
+defineSymbol(math, ams, bin, "\u22cf", "\\curlywedge", true);
+defineSymbol(math, ams, bin, "\u22ce", "\\curlyvee", true);
+defineSymbol(math, ams, bin, "\u229d", "\\circleddash", true);
+defineSymbol(math, ams, bin, "\u229b", "\\circledast", true);
 defineSymbol(math, ams, bin, "\u22c5", "\\centerdot");
-defineSymbol(math, ams, bin, "\u22ba", "\\intercal");
+defineSymbol(math, ams, bin, "\u22ba", "\\intercal", true);
 defineSymbol(math, ams, bin, "\u22d2", "\\doublecap");
 defineSymbol(math, ams, bin, "\u22d3", "\\doublecup");
-defineSymbol(math, ams, bin, "\u22a0", "\\boxtimes");
+defineSymbol(math, ams, bin, "\u22a0", "\\boxtimes", true);
 
 // AMS Arrows
 defineSymbol(math, ams, rel, "\u21e2", "\\dashrightarrow");
@@ -484,16 +484,16 @@ defineSymbol(math, main, bin, "+", "+");
 defineSymbol(math, main, bin, "\u2212", "-");
 defineSymbol(math, main, bin, "\u22c5", "\\cdot");
 defineSymbol(math, main, bin, "\u2218", "\\circ");
-defineSymbol(math, main, bin, "\u00f7", "\\div");
-defineSymbol(math, main, bin, "\u00b1", "\\pm");
-defineSymbol(math, main, bin, "\u00d7", "\\times");
-defineSymbol(math, main, bin, "\u2229", "\\cap");
-defineSymbol(math, main, bin, "\u222a", "\\cup");
+defineSymbol(math, main, bin, "\u00f7", "\\div", true);
+defineSymbol(math, main, bin, "\u00b1", "\\pm", true);
+defineSymbol(math, main, bin, "\u00d7", "\\times", true);
+defineSymbol(math, main, bin, "\u2229", "\\cap", true);
+defineSymbol(math, main, bin, "\u222a", "\\cup", true);
 defineSymbol(math, main, bin, "\u2216", "\\setminus");
 defineSymbol(math, main, bin, "\u2227", "\\land");
 defineSymbol(math, main, bin, "\u2228", "\\lor");
-defineSymbol(math, main, bin, "\u2227", "\\wedge");
-defineSymbol(math, main, bin, "\u2228", "\\vee");
+defineSymbol(math, main, bin, "\u2227", "\\wedge", true);
+defineSymbol(math, main, bin, "\u2228", "\\vee", true);
 defineSymbol(math, main, textord, "\u221a", "\\surd");
 defineSymbol(math, main, open, "(", "(");
 defineSymbol(math, main, open, "[", "[");
@@ -550,15 +550,15 @@ defineSymbol(math, main, spacing, "\u00a0", "\\space");
 defineSymbol(math, main, punct, ",", ",");
 defineSymbol(math, main, punct, ";", ";");
 defineSymbol(math, main, punct, ":", "\\colon");
-defineSymbol(math, ams, bin, "\u22bc", "\\barwedge");
-defineSymbol(math, ams, bin, "\u22bb", "\\veebar");
-defineSymbol(math, main, bin, "\u2299", "\\odot");
-defineSymbol(math, main, bin, "\u2295", "\\oplus");
-defineSymbol(math, main, bin, "\u2297", "\\otimes");
+defineSymbol(math, ams, bin, "\u22bc", "\\barwedge", true);
+defineSymbol(math, ams, bin, "\u22bb", "\\veebar", true);
+defineSymbol(math, main, bin, "\u2299", "\\odot", true);
+defineSymbol(math, main, bin, "\u2295", "\\oplus", true);
+defineSymbol(math, main, bin, "\u2297", "\\otimes", true);
 defineSymbol(math, main, textord, "\u2202", "\\partial");
-defineSymbol(math, main, bin, "\u2298", "\\oslash");
-defineSymbol(math, ams, bin, "\u229a", "\\circledcirc");
-defineSymbol(math, ams, bin, "\u22a1", "\\boxdot");
+defineSymbol(math, main, bin, "\u2298", "\\oslash", true);
+defineSymbol(math, ams, bin, "\u229a", "\\circledcirc", true);
+defineSymbol(math, ams, bin, "\u22a1", "\\boxdot", true);
 defineSymbol(math, main, bin, "\u25b3", "\\bigtriangleup");
 defineSymbol(math, main, bin, "\u25bd", "\\bigtriangledown");
 defineSymbol(math, main, bin, "\u2020", "\\dagger");


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index 06631a1b..2f23a763 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -2633,6 +2633,10 @@ describe("Unicode", function() {
     it("should parse more relations", function() {
         expect("⊂⊃⊆⊇⊏⊐⊑⊒⊢⊣⊩⊪⊸⋈⋍⋐⋑⋔⋙⋛⋞⋟⌢⌣⩾⪆⪌⪕⪖⪯⪰⪷⪸⫅⫆").toParse();
     });
+
+    it("should parse binary operators", function() {
+        expect("±×÷∓∔∧∨∩∪≀⊎⊓⊔⊕⊖⊗⊘⊙⊚⊛⊝⊞⊟⊠⊡⊺⊻⊼⋇⋉⋊⋋⋌⋎⋏⋒⋓⩞").toParse();
+    });
 });
 
 describe("The maxSize setting", function() {