www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4154c370ec1ac120480dde532dedfbed4b734fd8
parent d729ba528171ca1a3d4633cbe0edd018ec62a734
Author: Emily Eisenberg <emily@khanacademy.org>
Date:   Thu, 27 Mar 2014 19:23:15 -0400

Add tie symbol (~)

Summary:
Add real support for the tie symbol. Also, get rid of any of the
leftover bad support

Test Plan:
 - See the new normal tests succeed
 - See huxley tests didn't change except the new ones, which looks good

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D7772

Diffstat:
MLexer.js | 6++++--
MbuildTree.js | 4+---
Msymbols.js | 10++++++++++
Mtest/huxley/Huxleyfile | 4++--
Mtest/huxley/Spacing.huxley/screenshot0.png | 0
Mtest/huxley/Text.huxley/screenshot0.png | 0
Mtest/katex-tests.js | 37+++++++++++++++++++++++++++++++++++++
7 files changed, 54 insertions(+), 7 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 Binary files differ. diff --git a/test/huxley/Text.huxley/screenshot0.png b/test/huxley/Text.huxley/screenshot0.png Binary files differ. diff --git 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"); + }); +});