Repository: Khan/KaTeX
Pull request #1015 (2017-12-10 02:22:19)

Support Unicode middle dot
This PR adds support for Unicode characters U+00B7 MIDDLE DOT and U+22C5 DOT OPERATOR.

ronkok: More detail on the contents and background of this PR.

| Character | Code point | Maps to | Atom Type | unicode math | Other Options               |
|:---------:|:----------:|:-------:|:---------:|:------------:|:---------------------------:|
| ·         | U+00B7     | \\cdotp | punct     | ✓            | \\textperiodcentered        |
| ⋅         | U+22C5     | \\cdot  | bin       | ✓            | \\ centerdot<br>\\tnyblkcircle |
ronkok: I do not intend to write a PR for U+2219 BULLET OPERATOR. The `unicode math` choice for that code point is `\vysmblkcircle`. The KaTeX function `\bullet`, at that same code point, displays a somewhat large circle, so we have a conflict. This seems like the sort of thing that could break in the future. I will leave it alone.

Similarly, I will not do a PR for any of the following Unicode characters.

| Character | Code point | unicode math    | Atom Type |
|:---------:|:----------:|:---------------:|:---------:|
| •         | U+2022     | \\smblkcircle   | bin       |
| ●         | U+25CF     | \\mdlgblkcircle | ord       |
| ⚫         | U+26ab     | \\mdblkcircle   | ord       |
| ⦁         | U+2081     | \\mdsmblkcircle | ord       |
| ⬤         | U+2B24     | \\lgblkcircle   | ord       |


ronkok: Done.

Patch:
diff --git a/src/macros.js b/src/macros.js
index fcb39f81..a128ed33 100644
--- a/src/macros.js
+++ b/src/macros.js
@@ -86,6 +86,11 @@ defineMacro("\u211A", "\\mathbb{Q}");
 defineMacro("\u211D", "\\mathbb{R}");
 defineMacro("\u2124", "\\mathbb{Z}");
 
+// Unicode middle dot
+// The KaTeX fonts do not contain U+00B7. Instead, \cdotp displays
+// the dot at U+22C5 and gives it punct spacing.
+defineMacro("\u00b7", "\\cdotp");
+
 // \llap and \rlap render their contents in text mode
 defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
 defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
diff --git a/src/symbols.js b/src/symbols.js
index 05bdc02b..f626adcd 100644
--- a/src/symbols.js
+++ b/src/symbols.js
@@ -496,7 +496,7 @@ defineSymbol(math, main, mathord, "\u03c6", "\\varphi", true);
 defineSymbol(math, main, bin, "\u2217", "*");
 defineSymbol(math, main, bin, "+", "+");
 defineSymbol(math, main, bin, "\u2212", "-");
-defineSymbol(math, main, bin, "\u22c5", "\\cdot");
+defineSymbol(math, main, bin, "\u22c5", "\\cdot", true);
 defineSymbol(math, main, bin, "\u2218", "\\circ");
 defineSymbol(math, main, bin, "\u00f7", "\\div", true);
 defineSymbol(math, main, bin, "\u00b1", "\\pm", true);


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index 21164c2d..64bd1218 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -2706,7 +2706,7 @@ describe("Unicode", function() {
     });
 
     it("should parse symbols", function() {
-        expect("£¥ðℂℍℑℓℕ℘ℙℚℜℝℤℲℵℶℷℸ⅁∀∁∂∃∇∞∠∡∢♠♡♢♣♭♮♯✓").toParse();
+        expect("£¥ðℂℍℑℓℕ℘ℙℚℜℝℤℲℵℶℷℸ⅁∀∁∂∃∇∞∠∡∢♠♡♢♣♭♮♯✓\u00b7").toParse();
     });
 
     it("should parse arrows", function() {
@@ -2718,7 +2718,7 @@ describe("Unicode", function() {
     });
 
     it("should parse binary operators", function() {
-        expect("±×÷∓∔∧∨∩∪≀⊎⊓⊔⊕⊖⊗⊘⊙⊚⊛⊝⊞⊟⊠⊡⊺⊻⊼⋇⋉⋊⋋⋌⋎⋏⋒⋓⩞").toParse();
+        expect("±×÷∓∔∧∨∩∪≀⊎⊓⊔⊕⊖⊗⊘⊙⊚⊛⊝⊞⊟⊠⊡⊺⊻⊼⋇⋉⋊⋋⋌⋎⋏⋒⋓⩞\u22C5").toParse();
     });
 });