From 38e2d600fd20c556a332f69e6b4c5c6f88d57173 Mon Sep 17 00:00:00 2001 From: Emily Eisenberg Date: Sat, 13 Jul 2013 00:05:41 -0700 Subject: [PATCH] Allow some functions to have letters after them Summary: Allow there to be letters immediately after \ , \;, \,, \:. Test Plan: Run the tests Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D3031 --- Lexer.js | 23 +---------------------- test/katex-tests.js | 6 ++++++ 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Lexer.js b/Lexer.js index 02fea64e0..a8e2305c8 100644 --- a/Lexer.js +++ b/Lexer.js @@ -25,29 +25,8 @@ var normals = [ [/^[)\]?!]/, 'close'] ]; -// Different functions -var funcs = [ - // Bin symbols - 'cdot', 'pm', 'div', - // Rel symbols - 'leq', 'geq', 'neq', 'nleq', 'ngeq', - // Open/close symbols - 'lvert', 'rvert', - // Punct symbols - 'colon', - // Spacing symbols - 'qquad', 'quad', ' ', 'space', ',', ':', ';', - // Colors - 'blue', 'orange', 'pink', 'red', 'green', 'gray', 'purple', - // Mathy functions - "arcsin", "arccos", "arctan", "arg", "cos", "cosh", "cot", "coth", "csc", - "deg", "dim", "exp", "hom", "ker", "lg", "ln", "log", "sec", "sin", "sinh", - "tan", "tanh", - // Other functions - 'dfrac', 'llap', 'rlap' -]; // Build a regex to easily parse the functions -var anyFunc = new RegExp("^\\\\(" + funcs.join("|") + ")(?![a-zA-Z])"); +var anyFunc = /^\\([a-zA-Z]+|.)/; // Lex a single token Lexer.prototype.lex = function(pos) { diff --git a/test/katex-tests.js b/test/katex-tests.js index a9b5b9102..762b0e6e6 100644 --- a/test/katex-tests.js +++ b/test/katex-tests.js @@ -319,6 +319,12 @@ describe("A function parser", function() { parseTree("\\dfrac12"); }).not.toThrow(); }); + + it("should parse some functions with text right after it", function() { + expect(function() { + parseTree("\\;x"); + }).not.toThrow(); + }); }); describe("A dfrac parser", function() {