commit a5840aae4bb5d9a12eea80d371e758d4e82397aa
parent c774b69de8ab4229a621ddbcc84c1156f8578d89
Author: Ben Alpert <spicyjalapeno@gmail.com>
Date: Sun, 14 Jul 2013 22:53:43 -0700
Add more symbols
Summary:
', \angle, \circ, \gets, \infty, \leftarrow, \prime, \rightarrow, \times, \to
Fixes T1191.
Reviewers: emily
Reviewed By: emily
Maniphest Tasks: T1191
Differential Revision: http://phabricator.khanacademy.org/D3053
Diffstat:
| M | Lexer.js | | | 1 | + |
| M | Parser.js | | | 86 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- |
| M | katex.js | | | 25 | +++++++++++++++++-------- |
3 files changed, 93 insertions(+), 19 deletions(-)
diff --git a/Lexer.js b/Lexer.js
@@ -17,6 +17,7 @@ var normals = [
[/^[*+-]/, 'bin'],
[/^[=<>]/, 'rel'],
[/^[,;]/, 'punct'],
+ [/^'/, "'"],
[/^\^/, '^'],
[/^_/, '_'],
[/^{/, '{'],
diff --git a/Parser.js b/Parser.js
@@ -78,6 +78,10 @@ Parser.prototype.parseSuperscript = function(pos) {
// Throw an error if we didn't find a group
throw "Parse error: Couldn't find group after '^'";
}
+ } else if (sup.type === "'") {
+ var pos = sup.position;
+ return new ParseResult(
+ new ParseNode("textord", "\\prime"), sup.position);
} else {
return null;
}
@@ -179,18 +183,78 @@ var colorFuncs = [
// For example, if the lexer returns something of type "colon", we should
// return a node of type "punct"
var copyFuncs = {
- "textord": ["textord"],
+ "textord": [
+ "textord",
+ "\\angle",
+ "\\infty",
+ "\\prime"
+ ],
"mathord": ["mathord"],
- "bin": ["bin", "\\pm", "\\div", "\\cdot"],
- "open": ["open", "\\lvert"],
- "close": ["close", "\\rvert"],
- "rel": ["rel", "\\leq", "\\geq", "\\neq", "\\nleq", "\\ngeq"],
- "spacing": ["\\qquad", "\\quad", "\\space", "\\ ", "\\,", "\\:", "\\;"],
- "punct": ["punct", "\\colon"],
- "namedfn": ["\\arcsin", "\\arccos", "\\arctan", "\\arg", "\\cos", "\\cosh",
- "\\cot", "\\coth", "\\csc", "\\deg", "\\dim", "\\exp", "\\hom",
- "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", "\\sinh", "\\tan",
- "\\tanh"]
+ "bin": [
+ "bin",
+ "\\cdot",
+ "\\circ",
+ "\\div",
+ "\\pm",
+ "\\times"
+ ],
+ "open": [
+ "open",
+ "\\lvert"
+ ],
+ "close": [
+ "close",
+ "\\rvert"
+ ],
+ "rel": [
+ "rel",
+ "\\geq",
+ "\\gets",
+ "\\leftarrow",
+ "\\leq",
+ "\\neq",
+ "\\ngeq",
+ "\\nleq",
+ "\\rightarrow",
+ "\\to"
+ ],
+ "spacing": [
+ "\\ ",
+ "\\,",
+ "\\:",
+ "\\;",
+ "\\qquad",
+ "\\quad",
+ "\\space"
+ ],
+ "punct": [
+ "punct",
+ "\\colon"
+ ],
+ "namedfn": [
+ "\\arcsin",
+ "\\arccos",
+ "\\arctan",
+ "\\arg",
+ "\\cos",
+ "\\cosh",
+ "\\cot",
+ "\\coth",
+ "\\csc",
+ "\\deg",
+ "\\dim",
+ "\\exp",
+ "\\hom",
+ "\\ker",
+ "\\lg",
+ "\\ln",
+ "\\log",
+ "\\sec",
+ "\\sin",
+ "\\sinh",
+ "\\tan",
+ "\\tanh"
+ ]
};
// Build a list of all of the different functions in the copyFuncs list, to
diff --git a/katex.js b/katex.js
@@ -151,19 +151,28 @@ var charLookup = {
"*": "\u2217",
"-": "\u2212",
"`": "\u2018",
- "\\cdot": "\u22C5",
- "\\lvert": "|",
- "\\rvert": "|",
- "\\pm": "\u00b1",
+ "\\ ": "\u00a0",
+ "\\angle": "\u2220",
+ "\\cdot": "\u22c5",
+ "\\circ": "\u2218",
+ "\\colon": ":",
"\\div": "\u00f7",
- "\\leq": "\u2264",
"\\geq": "\u2265",
+ "\\gets": "\u2190",
+ "\\infty": "\u221e",
+ "\\leftarrow": "\u2190",
+ "\\leq": "\u2264",
+ "\\lvert": "|",
"\\neq": "\u2260",
- "\\nleq": "\u2270",
"\\ngeq": "\u2271",
- "\\ ": "\u00a0",
+ "\\nleq": "\u2270",
+ "\\pm": "\u00b1",
+ "\\prime": "\u2032",
+ "\\rightarrow": "\u2192",
+ "\\rvert": "|",
"\\space": "\u00a0",
- "\\colon": ":"
+ "\\times": "\u00d7",
+ "\\to": "\u2192"
};
var textit = function(value) {