diff --git a/Lexer.js b/Lexer.js index b1d8d6aae..01e4b611b 100644 --- a/Lexer.js +++ b/Lexer.js @@ -25,13 +25,15 @@ var mathNormals = [ [/^{/, "{"], [/^}/, "}"], [/^[(\[]/, "open"], - [/^[)\]?!]/, "close"] + [/^[)\]?!]/, "close"], + [/^~/, "spacing"] ]; var textNormals = [ [/^[a-zA-Z0-9`!@*()-=+\[\]'";:?\/.,]/, "textord"], [/^{/, "{"], - [/^}/, "}"] + [/^}/, "}"], + [/^~/, "spacing"] ]; // Build a regex to easily parse the functions diff --git a/buildTree.js b/buildTree.js index 2e16993e5..2cc8441b6 100644 --- a/buildTree.js +++ b/buildTree.js @@ -317,13 +317,11 @@ var groupTypes = { spacing: function(group, options, prev) { if (group.value === "\\ " || group.value === "\\space" || - group.value === " ") { + group.value === " " || group.value === "~") { return makeSpan( ["mord", "mspace"], [mathrm(group.value, group.mode)] ); - } else if(group.value === "~") { - return makeSpan(["mord", "mspace"], [mathrm(" ", group.mode)]); } else { var spacingClassMap = { "\\qquad": "qquad", diff --git a/symbols.js b/symbols.js index d4294f325..fd65d71e4 100644 --- a/symbols.js +++ b/symbols.js @@ -437,6 +437,11 @@ var symbols = { group: "spacing", replace: "\u00a0" }, + "~": { + font: "main", + group: "spacing", + replace: "\u00a0" + }, "\\,": { font: "main", group: "spacing" @@ -565,6 +570,11 @@ var symbols = { font: "main", group: "spacing", replace: "\u00a0" + }, + "~": { + font: "main", + group: "spacing", + replace: "\u00a0" } } }; diff --git a/test/huxley/Huxleyfile b/test/huxley/Huxleyfile index dd6cc6af0..1d339e613 100644 --- a/test/huxley/Huxleyfile +++ b/test/huxley/Huxleyfile @@ -20,7 +20,7 @@ url=http://localhost:7936/test/huxley/test.html?m=\alpha\beta\gamma\omega url=http://localhost:7936/test/huxley/test.html?m=a+b-c\cdot d/e [Spacing] -url=http://localhost:7936/test/huxley/test.html?m=[-1][1-1]1%%3D1(%%3D1)\lvert a\rvert +url=http://localhost:7936/test/huxley/test.html?m=[-1][1-1]1%%3D1(%%3D1)\lvert a\rvert~b [Functions] url=http://localhost:7936/test/huxley/test.html?m=\sin\cos\tan\ln\log @@ -35,7 +35,7 @@ url=http://localhost:7936/test/huxley/test.html?m=\Huge{x}\LARGE{y}\normalsize{z url=http://localhost:7936/test/huxley/test.html?m=\tiny{a+b}a+b\Huge{a+b}&pre=x&post=M [Text] -url=http://localhost:7936/test/huxley/test.html?m=\frac{a}{b}\text{c {ab} \ e}+fg +url=http://localhost:7936/test/huxley/test.html?m=\frac{a}{b}\text{c~ {ab} \ e}+fg [KaTeX] url=http://localhost:7936/test/huxley/test.html?m=\KaTeX diff --git a/test/huxley/Spacing.huxley/screenshot0.png b/test/huxley/Spacing.huxley/screenshot0.png index 633b2914a..27ce66acc 100644 Binary files a/test/huxley/Spacing.huxley/screenshot0.png and b/test/huxley/Spacing.huxley/screenshot0.png differ diff --git a/test/huxley/Text.huxley/screenshot0.png b/test/huxley/Text.huxley/screenshot0.png index f5e477fa6..617ab0749 100644 Binary files a/test/huxley/Text.huxley/screenshot0.png and b/test/huxley/Text.huxley/screenshot0.png differ diff --git a/test/katex-tests.js b/test/katex-tests.js index eed2e8333..6b0ba15b6 100644 --- a/test/katex-tests.js +++ b/test/katex-tests.js @@ -534,3 +534,40 @@ describe("A color parser", function() { }).toThrow(); }); }); + +describe("A tie parser", function() { + var mathTie = "a~b"; + var textTie = "\\text{a~ b}"; + + it("should parse ties in math mode", function() { + expect(function() { + parseTree(mathTie); + }).not.toThrow(); + }); + + it("should parse ties in text mode", function() { + expect(function() { + parseTree(textTie); + }).not.toThrow(); + }); + + it("should produce spacing in math mode", function() { + var parse = parseTree(mathTie); + + expect(parse[1].type).toMatch("spacing"); + }); + + it("should produce spacing in text mode", function() { + var text = parseTree(textTie)[0]; + var parse = text.value.value; + + expect(parse[1].type).toMatch("spacing"); + }); + + it("should not contract with spaces in text mode", function() { + var text = parseTree(textTie)[0]; + var parse = text.value.value; + + expect(parse[2].type).toMatch("spacing"); + }); +});