mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-10 13:38:39 +00:00
Add \ in front of functions in the parser
Auditors: alpert
This commit is contained in:
2
Lexer.js
2
Lexer.js
@@ -45,7 +45,7 @@ Lexer.prototype.lex = function(pos) {
|
|||||||
var match;
|
var match;
|
||||||
if ((match = input.match(anyFunc))) {
|
if ((match = input.match(anyFunc))) {
|
||||||
// If we match one of the tokens, extract the type
|
// If we match one of the tokens, extract the type
|
||||||
return new LexResult(match[1], match[0], pos + match[0].length);
|
return new LexResult(match[0], match[0], pos + match[0].length);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, we look through the normal token regexes and see if it's
|
// Otherwise, we look through the normal token regexes and see if it's
|
||||||
// one of them.
|
// one of them.
|
||||||
|
29
Parser.js
29
Parser.js
@@ -172,7 +172,7 @@ function contains(list, elem) {
|
|||||||
|
|
||||||
// A list of 1-argument color functions
|
// A list of 1-argument color functions
|
||||||
var colorFuncs = [
|
var colorFuncs = [
|
||||||
"blue", "orange", "pink", "red", "green", "gray", "purple"
|
"\\blue", "\\orange", "\\pink", "\\red", "\\green", "\\gray", "\\purple"
|
||||||
];
|
];
|
||||||
|
|
||||||
// A map of elements that don't have arguments, and should simply be placed
|
// A map of elements that don't have arguments, and should simply be placed
|
||||||
@@ -185,15 +185,16 @@ var colorFuncs = [
|
|||||||
var copyFuncs = {
|
var copyFuncs = {
|
||||||
"textord": ["textord"],
|
"textord": ["textord"],
|
||||||
"mathord": ["mathord"],
|
"mathord": ["mathord"],
|
||||||
"bin": ["bin", "pm", "div", "cdot"],
|
"bin": ["bin", "\\pm", "\\div", "\\cdot"],
|
||||||
"open": ["open", "lvert"],
|
"open": ["open", "\\lvert"],
|
||||||
"close": ["close", "rvert"],
|
"close": ["close", "\\rvert"],
|
||||||
"rel": ["rel", "leq", "geq", "neq", "nleq", "ngeq"],
|
"rel": ["rel", "\\leq", "\\geq", "\\neq", "\\nleq", "\\ngeq"],
|
||||||
"spacing": ["qquad", "quad", "space", " ", ",", ":", ";"],
|
"spacing": ["\\qquad", "\\quad", "\\space", "\\ ", "\\,", "\\:", "\\;"],
|
||||||
"punct": ["punct", "colon"],
|
"punct": ["punct", "\\colon"],
|
||||||
"namedfn": ["arcsin", "arccos", "arctan", "arg", "cos", "cosh", "cot",
|
"namedfn": ["\\arcsin", "\\arccos", "\\arctan", "\\arg", "\\cos", "\\cosh",
|
||||||
"coth", "csc", "deg", "dim", "exp", "hom", "ker", "lg", "ln", "log",
|
"\\cot", "\\coth", "\\csc", "\\deg", "\\dim", "\\exp", "\\hom",
|
||||||
"sec", "sin", "sinh", "tan", "tanh"]
|
"\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", "\\sinh", "\\tan",
|
||||||
|
"\\tanh"]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build a list of all of the different functions in the copyFuncs list, to
|
// Build a list of all of the different functions in the copyFuncs list, to
|
||||||
@@ -217,22 +218,22 @@ Parser.prototype.parseNucleus = function(pos) {
|
|||||||
if (group) {
|
if (group) {
|
||||||
return new ParseResult(
|
return new ParseResult(
|
||||||
new ParseNode("color",
|
new ParseNode("color",
|
||||||
{color: nucleus.type, value: group.result}),
|
{color: nucleus.type.slice(1), value: group.result}),
|
||||||
group.position);
|
group.position);
|
||||||
} else {
|
} else {
|
||||||
throw "Parse error: Expected group after '" + nucleus.text + "'";
|
throw "Parse error: Expected group after '" + nucleus.text + "'";
|
||||||
}
|
}
|
||||||
} else if (nucleus.type === "llap" || nucleus.type === "rlap") {
|
} else if (nucleus.type === "\\llap" || nucleus.type === "\\rlap") {
|
||||||
// If this is an llap or rlap, parse its argument and return
|
// If this is an llap or rlap, parse its argument and return
|
||||||
var group = this.parseGroup(nucleus.position);
|
var group = this.parseGroup(nucleus.position);
|
||||||
if (group) {
|
if (group) {
|
||||||
return new ParseResult(
|
return new ParseResult(
|
||||||
new ParseNode(nucleus.type, nucleus.text),
|
new ParseNode(nucleus.type.slice(1), nucleus.text),
|
||||||
group.position);
|
group.position);
|
||||||
} else {
|
} else {
|
||||||
throw "Parse error: Expected group after '" + nucleus.text + "'";
|
throw "Parse error: Expected group after '" + nucleus.text + "'";
|
||||||
}
|
}
|
||||||
} else if (nucleus.type === "dfrac") {
|
} else if (nucleus.type === "\\dfrac") {
|
||||||
// If this is a dfrac, parse its two arguments and return
|
// If this is a dfrac, parse its two arguments and return
|
||||||
var numer = this.parseGroup(nucleus.position);
|
var numer = this.parseGroup(nucleus.position);
|
||||||
if (numer) {
|
if (numer) {
|
||||||
|
Reference in New Issue
Block a user