Adds JSHint to the build system and tidies up code.
This commit is contained in:
parent
6aa70e33e4
commit
fec04614b8
67
.jshintrc
Normal file
67
.jshintrc
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
{
|
||||||
|
"bitwise" : true,
|
||||||
|
"camelcase" : true,
|
||||||
|
"curly" : true,
|
||||||
|
"eqeqeq" : false,
|
||||||
|
"es3" : true,
|
||||||
|
"forin" : false,
|
||||||
|
"immed" : true,
|
||||||
|
"indent" : 4,
|
||||||
|
"latedef" : false,
|
||||||
|
"newcap" : true,
|
||||||
|
"noarg" : true,
|
||||||
|
"noempty" : true,
|
||||||
|
"nonbsp" : true,
|
||||||
|
"nonew" : true,
|
||||||
|
"plusplus" : false,
|
||||||
|
"quotmark" : "double",
|
||||||
|
"undef" : true,
|
||||||
|
"unused" : "vars",
|
||||||
|
"strict" : false,
|
||||||
|
"trailing" : true,
|
||||||
|
"maxparams" : 7,
|
||||||
|
"maxdepth" : 6,
|
||||||
|
|
||||||
|
"asi" : false,
|
||||||
|
"boss" : false,
|
||||||
|
"debug" : false,
|
||||||
|
"eqnull" : true,
|
||||||
|
"esnext" : false,
|
||||||
|
"evil" : false,
|
||||||
|
"expr" : true,
|
||||||
|
"funcscope" : false,
|
||||||
|
"globalstrict" : false,
|
||||||
|
"iterator" : false,
|
||||||
|
"lastsemic" : false,
|
||||||
|
"laxbreak" : true,
|
||||||
|
"laxcomma" : false,
|
||||||
|
"loopfunc" : false,
|
||||||
|
"maxerr" : 50,
|
||||||
|
"multistr" : false,
|
||||||
|
"notypeof" : false,
|
||||||
|
"proto" : true,
|
||||||
|
"scripturl" : false,
|
||||||
|
"smarttabs" : false,
|
||||||
|
"shadow" : false,
|
||||||
|
"sub" : false,
|
||||||
|
"supernew" : false,
|
||||||
|
"validthis" : false,
|
||||||
|
"noyield" : false,
|
||||||
|
|
||||||
|
"browser" : true,
|
||||||
|
"couch" : false,
|
||||||
|
"devel" : false,
|
||||||
|
"dojo" : false,
|
||||||
|
"jquery" : false,
|
||||||
|
"mootools" : false,
|
||||||
|
"node" : true,
|
||||||
|
"nonstandard" : false,
|
||||||
|
"prototypejs" : false,
|
||||||
|
"rhino" : false,
|
||||||
|
"worker" : false,
|
||||||
|
"wsh" : false,
|
||||||
|
"yui" : false,
|
||||||
|
"globals": {
|
||||||
|
"console": true
|
||||||
|
}
|
||||||
|
}
|
7
Makefile
7
Makefile
|
@ -1,9 +1,12 @@
|
||||||
.PHONY: build setup copy serve clean metrics test zip
|
.PHONY: build lint setup copy serve clean metrics test zip
|
||||||
build: setup build/katex.min.js build/katex.min.css zip compress
|
build: setup lint build/katex.min.js build/katex.min.css zip compress
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
|
lint: katex.js $(wildcard src/*.js)
|
||||||
|
./node_modules/.bin/jshint $^
|
||||||
|
|
||||||
build/katex.js: katex.js $(wildcard src/*.js)
|
build/katex.js: katex.js $(wildcard src/*.js)
|
||||||
./node_modules/.bin/browserify $< --standalone katex > $@
|
./node_modules/.bin/browserify $< --standalone katex > $@
|
||||||
|
|
||||||
|
|
11
package.json
11
package.json
|
@ -15,15 +15,16 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "~2.29.1",
|
"browserify": "~2.29.1",
|
||||||
"express": "~3.3.3",
|
|
||||||
"less": "~1.7.5",
|
|
||||||
"uglify-js": "~2.4.15",
|
|
||||||
"clean-css": "~2.2.15",
|
"clean-css": "~2.2.15",
|
||||||
|
"express": "~3.3.3",
|
||||||
"huxley": "~0.8.1",
|
"huxley": "~0.8.1",
|
||||||
"jasmine-node": "git://github.com/mhevery/jasmine-node.git#Jasmine2.0"
|
"jasmine-node": "git://github.com/mhevery/jasmine-node.git#Jasmine2.0",
|
||||||
|
"jshint": "^2.5.6",
|
||||||
|
"less": "~1.7.5",
|
||||||
|
"uglify-js": "~2.4.15"
|
||||||
},
|
},
|
||||||
"bin": "cli.js",
|
"bin": "cli.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "make test"
|
"test": "make lint test"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
src/Lexer.js
13
src/Lexer.js
|
@ -16,7 +16,7 @@ var ParseError = require("./ParseError");
|
||||||
// The main lexer class
|
// The main lexer class
|
||||||
function Lexer(input) {
|
function Lexer(input) {
|
||||||
this._input = input;
|
this._input = input;
|
||||||
};
|
}
|
||||||
|
|
||||||
// The resulting token returned from `lex`.
|
// The resulting token returned from `lex`.
|
||||||
function Token(text, data, position) {
|
function Token(text, data, position) {
|
||||||
|
@ -35,7 +35,7 @@ var mathNormals = [
|
||||||
/^['\^_{}]/, // misc
|
/^['\^_{}]/, // misc
|
||||||
/^[(\[]/, // opens
|
/^[(\[]/, // opens
|
||||||
/^[)\]?!]/, // closes
|
/^[)\]?!]/, // closes
|
||||||
/^~/, // spacing
|
/^~/ // spacing
|
||||||
];
|
];
|
||||||
|
|
||||||
// These are "normal" tokens like above, but should instead be parsed in text
|
// These are "normal" tokens like above, but should instead be parsed in text
|
||||||
|
@ -43,7 +43,7 @@ var mathNormals = [
|
||||||
var textNormals = [
|
var textNormals = [
|
||||||
/^[a-zA-Z0-9`!@*()-=+\[\]'";:?\/.,]/, // ords
|
/^[a-zA-Z0-9`!@*()-=+\[\]'";:?\/.,]/, // ords
|
||||||
/^[{}]/, // grouping
|
/^[{}]/, // grouping
|
||||||
/^~/, // spacing
|
/^~/ // spacing
|
||||||
];
|
];
|
||||||
|
|
||||||
// Regexes for matching whitespace
|
// Regexes for matching whitespace
|
||||||
|
@ -61,15 +61,16 @@ var anyFunc = /^\\(?:[a-zA-Z]+|.)/;
|
||||||
*/
|
*/
|
||||||
Lexer.prototype._innerLex = function(pos, normals, ignoreWhitespace) {
|
Lexer.prototype._innerLex = function(pos, normals, ignoreWhitespace) {
|
||||||
var input = this._input.slice(pos);
|
var input = this._input.slice(pos);
|
||||||
|
var whitespace;
|
||||||
|
|
||||||
if (ignoreWhitespace) {
|
if (ignoreWhitespace) {
|
||||||
// Get rid of whitespace.
|
// Get rid of whitespace.
|
||||||
var whitespace = input.match(whitespaceRegex)[0];
|
whitespace = input.match(whitespaceRegex)[0];
|
||||||
pos += whitespace.length;
|
pos += whitespace.length;
|
||||||
input = input.slice(whitespace.length);
|
input = input.slice(whitespace.length);
|
||||||
} else {
|
} else {
|
||||||
// Do the funky concatenation of whitespace that happens in text mode.
|
// Do the funky concatenation of whitespace that happens in text mode.
|
||||||
var whitespace = input.match(whitespaceConcatRegex);
|
whitespace = input.match(whitespaceConcatRegex);
|
||||||
if (whitespace !== null) {
|
if (whitespace !== null) {
|
||||||
return new Token(" ", null, pos + whitespace[0].length);
|
return new Token(" ", null, pos + whitespace[0].length);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +101,7 @@ Lexer.prototype._innerLex = function(pos, normals, ignoreWhitespace) {
|
||||||
|
|
||||||
throw new ParseError("Unexpected character: '" + input[0] +
|
throw new ParseError("Unexpected character: '" + input[0] +
|
||||||
"'", this, pos);
|
"'", this, pos);
|
||||||
}
|
};
|
||||||
|
|
||||||
// A regex to match a CSS color (like #ffffff or BlueViolet)
|
// A regex to match a CSS color (like #ffffff or BlueViolet)
|
||||||
var cssColor = /^(#[a-z0-9]+|[a-z]+)/i;
|
var cssColor = /^(#[a-z0-9]+|[a-z]+)/i;
|
||||||
|
|
|
@ -46,7 +46,7 @@ var ParseError = require("./ParseError");
|
||||||
function Parser(input) {
|
function Parser(input) {
|
||||||
// Make a new lexer
|
// Make a new lexer
|
||||||
this.lexer = new Lexer(input);
|
this.lexer = new Lexer(input);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resulting parse tree nodes of the parse tree.
|
* The resulting parse tree nodes of the parse tree.
|
||||||
|
@ -260,18 +260,18 @@ Parser.prototype.parseAtom = function(pos, mode) {
|
||||||
|
|
||||||
var superscript;
|
var superscript;
|
||||||
var subscript;
|
var subscript;
|
||||||
|
var result;
|
||||||
while (true) {
|
while (true) {
|
||||||
// Lex the first token
|
// Lex the first token
|
||||||
var lex = this.lexer.lex(currPos, mode);
|
var lex = this.lexer.lex(currPos, mode);
|
||||||
|
|
||||||
var group;
|
|
||||||
if (lex.text === "^") {
|
if (lex.text === "^") {
|
||||||
// We got a superscript start
|
// We got a superscript start
|
||||||
if (superscript) {
|
if (superscript) {
|
||||||
throw new ParseError(
|
throw new ParseError(
|
||||||
"Double superscript", this.lexer, currPos);
|
"Double superscript", this.lexer, currPos);
|
||||||
}
|
}
|
||||||
var result = this.handleSupSubscript(
|
result = this.handleSupSubscript(
|
||||||
lex.position, mode, lex.text, "superscript");
|
lex.position, mode, lex.text, "superscript");
|
||||||
currPos = result.position;
|
currPos = result.position;
|
||||||
superscript = result.result;
|
superscript = result.result;
|
||||||
|
@ -281,7 +281,7 @@ Parser.prototype.parseAtom = function(pos, mode) {
|
||||||
throw new ParseError(
|
throw new ParseError(
|
||||||
"Double subscript", this.lexer, currPos);
|
"Double subscript", this.lexer, currPos);
|
||||||
}
|
}
|
||||||
var result = this.handleSupSubscript(
|
result = this.handleSupSubscript(
|
||||||
lex.position, mode, lex.text, "subscript");
|
lex.position, mode, lex.text, "subscript");
|
||||||
currPos = result.position;
|
currPos = result.position;
|
||||||
subscript = result.result;
|
subscript = result.result;
|
||||||
|
@ -352,13 +352,14 @@ Parser.prototype.parseImplicitGroup = function(pos, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var func = start.result.result;
|
var func = start.result.result;
|
||||||
|
var body;
|
||||||
|
|
||||||
if (func === "\\left") {
|
if (func === "\\left") {
|
||||||
// If we see a left:
|
// If we see a left:
|
||||||
// Parse the entire left function (including the delimiter)
|
// Parse the entire left function (including the delimiter)
|
||||||
var left = this.parseFunction(pos, mode);
|
var left = this.parseFunction(pos, mode);
|
||||||
// Parse out the implicit body
|
// Parse out the implicit body
|
||||||
var body = this.parseExpression(left.position, mode, false, "}");
|
body = this.parseExpression(left.position, mode, false, "}");
|
||||||
// Check the next token
|
// Check the next token
|
||||||
var rightLex = this.parseSymbol(body.position, mode);
|
var rightLex = this.parseSymbol(body.position, mode);
|
||||||
|
|
||||||
|
@ -382,7 +383,7 @@ Parser.prototype.parseImplicitGroup = function(pos, mode) {
|
||||||
return null;
|
return null;
|
||||||
} else if (utils.contains(sizeFuncs, func)) {
|
} else if (utils.contains(sizeFuncs, func)) {
|
||||||
// If we see a sizing function, parse out the implict body
|
// If we see a sizing function, parse out the implict body
|
||||||
var body = this.parseExpression(start.result.position, mode, false, "}");
|
body = this.parseExpression(start.result.position, mode, false, "}");
|
||||||
return new ParseResult(
|
return new ParseResult(
|
||||||
new ParseNode("sizing", {
|
new ParseNode("sizing", {
|
||||||
// Figure out what size to use based on the list of functions above
|
// Figure out what size to use based on the list of functions above
|
||||||
|
@ -392,7 +393,7 @@ Parser.prototype.parseImplicitGroup = function(pos, mode) {
|
||||||
body.position);
|
body.position);
|
||||||
} else if (utils.contains(styleFuncs, func)) {
|
} else if (utils.contains(styleFuncs, func)) {
|
||||||
// If we see a styling function, parse out the implict body
|
// If we see a styling function, parse out the implict body
|
||||||
var body = this.parseExpression(start.result.position, mode, true, "}");
|
body = this.parseExpression(start.result.position, mode, true, "}");
|
||||||
return new ParseResult(
|
return new ParseResult(
|
||||||
new ParseNode("styling", {
|
new ParseNode("styling", {
|
||||||
// Figure out what style to use by pulling out the style from
|
// Figure out what style to use by pulling out the style from
|
||||||
|
|
|
@ -94,7 +94,7 @@ var resetNames = [
|
||||||
"reset-textstyle",
|
"reset-textstyle",
|
||||||
"reset-textstyle",
|
"reset-textstyle",
|
||||||
"reset-scriptstyle",
|
"reset-scriptstyle",
|
||||||
"reset-scriptscriptstyle",
|
"reset-scriptscriptstyle"
|
||||||
];
|
];
|
||||||
|
|
||||||
// Instances of the different styles
|
// Instances of the different styles
|
||||||
|
|
|
@ -173,6 +173,8 @@ var makeFontSizer = function(options, fontSize) {
|
||||||
*/
|
*/
|
||||||
var makeVList = function(children, positionType, positionData, options) {
|
var makeVList = function(children, positionType, positionData, options) {
|
||||||
var depth;
|
var depth;
|
||||||
|
var currPos;
|
||||||
|
var i;
|
||||||
if (positionType === "individualShift") {
|
if (positionType === "individualShift") {
|
||||||
var oldChildren = children;
|
var oldChildren = children;
|
||||||
children = [oldChildren[0]];
|
children = [oldChildren[0]];
|
||||||
|
@ -180,8 +182,8 @@ var makeVList = function(children, positionType, positionData, options) {
|
||||||
// Add in kerns to the list of children to get each element to be
|
// Add in kerns to the list of children to get each element to be
|
||||||
// shifted to the correct specified shift
|
// shifted to the correct specified shift
|
||||||
depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
|
depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
|
||||||
var currPos = depth;
|
currPos = depth;
|
||||||
for (var i = 1; i < oldChildren.length; i++) {
|
for (i = 1; i < oldChildren.length; i++) {
|
||||||
var diff = -oldChildren[i].shift - currPos -
|
var diff = -oldChildren[i].shift - currPos -
|
||||||
oldChildren[i].elem.depth;
|
oldChildren[i].elem.depth;
|
||||||
var size = diff -
|
var size = diff -
|
||||||
|
@ -197,7 +199,7 @@ var makeVList = function(children, positionType, positionData, options) {
|
||||||
// We always start at the bottom, so calculate the bottom by adding up
|
// We always start at the bottom, so calculate the bottom by adding up
|
||||||
// all the sizes
|
// all the sizes
|
||||||
var bottom = positionData;
|
var bottom = positionData;
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (i = 0; i < children.length; i++) {
|
||||||
if (children[i].type === "kern") {
|
if (children[i].type === "kern") {
|
||||||
bottom -= children[i].size;
|
bottom -= children[i].size;
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,7 +219,7 @@ var makeVList = function(children, positionType, positionData, options) {
|
||||||
|
|
||||||
// Make the fontSizer
|
// Make the fontSizer
|
||||||
var maxFontSize = 0;
|
var maxFontSize = 0;
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (i = 0; i < children.length; i++) {
|
||||||
if (children[i].type === "elem") {
|
if (children[i].type === "elem") {
|
||||||
maxFontSize = Math.max(maxFontSize, children[i].elem.maxFontSize);
|
maxFontSize = Math.max(maxFontSize, children[i].elem.maxFontSize);
|
||||||
}
|
}
|
||||||
|
@ -226,8 +228,8 @@ var makeVList = function(children, positionType, positionData, options) {
|
||||||
|
|
||||||
// Create a new list of actual children at the correct offsets
|
// Create a new list of actual children at the correct offsets
|
||||||
var realChildren = [];
|
var realChildren = [];
|
||||||
var currPos = depth;
|
currPos = depth;
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (i = 0; i < children.length; i++) {
|
||||||
if (children[i].type === "kern") {
|
if (children[i].type === "kern") {
|
||||||
currPos += children[i].size;
|
currPos += children[i].size;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,8 +13,6 @@ var buildCommon = require("./buildCommon");
|
||||||
var delimiter = require("./delimiter");
|
var delimiter = require("./delimiter");
|
||||||
var domTree = require("./domTree");
|
var domTree = require("./domTree");
|
||||||
var fontMetrics = require("./fontMetrics");
|
var fontMetrics = require("./fontMetrics");
|
||||||
var parseTree = require("./parseTree");
|
|
||||||
var symbols = require("./symbols");
|
|
||||||
var utils = require("./utils");
|
var utils = require("./utils");
|
||||||
|
|
||||||
var makeSpan = buildCommon.makeSpan;
|
var makeSpan = buildCommon.makeSpan;
|
||||||
|
@ -99,7 +97,7 @@ var getTypeOfGroup = function(group) {
|
||||||
* handling them itself.
|
* handling them itself.
|
||||||
*/
|
*/
|
||||||
var shouldHandleSupSub = function(group, options) {
|
var shouldHandleSupSub = function(group, options) {
|
||||||
if (group == null) {
|
if (!group) {
|
||||||
return false;
|
return false;
|
||||||
} else if (group.type === "op") {
|
} else if (group.type === "op") {
|
||||||
// Operators handle supsubs differently when they have limits
|
// Operators handle supsubs differently when they have limits
|
||||||
|
@ -118,7 +116,7 @@ var shouldHandleSupSub = function(group, options) {
|
||||||
* a single element, we want to pull that out.
|
* a single element, we want to pull that out.
|
||||||
*/
|
*/
|
||||||
var getBaseElem = function(group) {
|
var getBaseElem = function(group) {
|
||||||
if (group == null) {
|
if (!group) {
|
||||||
return false;
|
return false;
|
||||||
} else if (group.type === "ordgroup") {
|
} else if (group.type === "ordgroup") {
|
||||||
if (group.value.length === 1) {
|
if (group.value.length === 1) {
|
||||||
|
@ -248,7 +246,6 @@ var groupTypes = {
|
||||||
supsub: function(group, options, prev) {
|
supsub: function(group, options, prev) {
|
||||||
// Superscript and subscripts are handled in the TeXbook on page
|
// Superscript and subscripts are handled in the TeXbook on page
|
||||||
// 445-446, rules 18(a-f).
|
// 445-446, rules 18(a-f).
|
||||||
var baseGroup = group.value.base;
|
|
||||||
|
|
||||||
// Here is where we defer to the inner group if it should handle
|
// Here is where we defer to the inner group if it should handle
|
||||||
// superscripts and subscripts itself.
|
// superscripts and subscripts itself.
|
||||||
|
@ -257,18 +254,19 @@ var groupTypes = {
|
||||||
}
|
}
|
||||||
|
|
||||||
var base = buildGroup(group.value.base, options.reset());
|
var base = buildGroup(group.value.base, options.reset());
|
||||||
|
var supmid, submid, sup, sub;
|
||||||
|
|
||||||
if (group.value.sup) {
|
if (group.value.sup) {
|
||||||
var sup = buildGroup(group.value.sup,
|
sup = buildGroup(group.value.sup,
|
||||||
options.withStyle(options.style.sup()));
|
options.withStyle(options.style.sup()));
|
||||||
var supmid = makeSpan(
|
supmid = makeSpan(
|
||||||
[options.style.reset(), options.style.sup().cls()], [sup]);
|
[options.style.reset(), options.style.sup().cls()], [sup]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.value.sub) {
|
if (group.value.sub) {
|
||||||
var sub = buildGroup(group.value.sub,
|
sub = buildGroup(group.value.sub,
|
||||||
options.withStyle(options.style.sub()));
|
options.withStyle(options.style.sub()));
|
||||||
var submid = makeSpan(
|
submid = makeSpan(
|
||||||
[options.style.reset(), options.style.sub().cls()], [sub]);
|
[options.style.reset(), options.style.sub().cls()], [sub]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +382,7 @@ var groupTypes = {
|
||||||
var numerreset = makeSpan([fstyle.reset(), nstyle.cls()], [numer]);
|
var numerreset = makeSpan([fstyle.reset(), nstyle.cls()], [numer]);
|
||||||
|
|
||||||
var denom = buildGroup(group.value.denom, options.withStyle(dstyle));
|
var denom = buildGroup(group.value.denom, options.withStyle(dstyle));
|
||||||
var denomreset = makeSpan([fstyle.reset(), dstyle.cls()], [denom])
|
var denomreset = makeSpan([fstyle.reset(), dstyle.cls()], [denom]);
|
||||||
|
|
||||||
var ruleWidth = fontMetrics.metrics.defaultRuleThickness /
|
var ruleWidth = fontMetrics.metrics.defaultRuleThickness /
|
||||||
options.style.sizeMultiplier;
|
options.style.sizeMultiplier;
|
||||||
|
@ -551,7 +549,7 @@ var groupTypes = {
|
||||||
if (hasLimits) {
|
if (hasLimits) {
|
||||||
// IE 8 clips \int if it is in a display: inline-block. We wrap it
|
// IE 8 clips \int if it is in a display: inline-block. We wrap it
|
||||||
// in a new span so it is an inline, and works.
|
// in a new span so it is an inline, and works.
|
||||||
var base = makeSpan([], [base]);
|
base = makeSpan([], [base]);
|
||||||
|
|
||||||
var supmid, supKern, submid, subKern;
|
var supmid, supKern, submid, subKern;
|
||||||
// We manually have to handle the superscripts and subscripts. This,
|
// We manually have to handle the superscripts and subscripts. This,
|
||||||
|
@ -581,9 +579,9 @@ var groupTypes = {
|
||||||
|
|
||||||
// Build the final group as a vlist of the possible subscript, base,
|
// Build the final group as a vlist of the possible subscript, base,
|
||||||
// and possible superscript.
|
// and possible superscript.
|
||||||
var finalGroup;
|
var finalGroup, top, bottom;
|
||||||
if (!supGroup) {
|
if (!supGroup) {
|
||||||
var top = base.height - baseShift;
|
top = base.height - baseShift;
|
||||||
|
|
||||||
finalGroup = buildCommon.makeVList([
|
finalGroup = buildCommon.makeVList([
|
||||||
{type: "kern", size: fontMetrics.metrics.bigOpSpacing5},
|
{type: "kern", size: fontMetrics.metrics.bigOpSpacing5},
|
||||||
|
@ -598,7 +596,7 @@ var groupTypes = {
|
||||||
// margin will shift by 1/2 that.
|
// margin will shift by 1/2 that.
|
||||||
finalGroup.children[0].style.marginLeft = -slant + "em";
|
finalGroup.children[0].style.marginLeft = -slant + "em";
|
||||||
} else if (!subGroup) {
|
} else if (!subGroup) {
|
||||||
var bottom = base.depth + baseShift;
|
bottom = base.depth + baseShift;
|
||||||
|
|
||||||
finalGroup = buildCommon.makeVList([
|
finalGroup = buildCommon.makeVList([
|
||||||
{type: "elem", elem: base},
|
{type: "elem", elem: base},
|
||||||
|
@ -615,7 +613,7 @@ var groupTypes = {
|
||||||
// subscript) but be safe.
|
// subscript) but be safe.
|
||||||
return base;
|
return base;
|
||||||
} else {
|
} else {
|
||||||
var bottom = fontMetrics.metrics.bigOpSpacing5 +
|
bottom = fontMetrics.metrics.bigOpSpacing5 +
|
||||||
submid.height + submid.depth +
|
submid.height + submid.depth +
|
||||||
subKern +
|
subKern +
|
||||||
base.depth + baseShift;
|
base.depth + baseShift;
|
||||||
|
@ -743,7 +741,7 @@ var groupTypes = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shift the delimiter so that its top lines up with the top of the line
|
// Shift the delimiter so that its top lines up with the top of the line
|
||||||
delimShift = -(inner.height + lineClearance + ruleWidth) + delim.height;
|
var delimShift = -(inner.height + lineClearance + ruleWidth) + delim.height;
|
||||||
delim.style.top = delimShift + "em";
|
delim.style.top = delimShift + "em";
|
||||||
delim.height -= delimShift;
|
delim.height -= delimShift;
|
||||||
delim.depth += delimShift;
|
delim.depth += delimShift;
|
||||||
|
@ -989,7 +987,7 @@ var groupTypes = {
|
||||||
var accentBody = makeSpan(["accent-body", vecClass], [
|
var accentBody = makeSpan(["accent-body", vecClass], [
|
||||||
makeSpan([], [accent])]);
|
makeSpan([], [accent])]);
|
||||||
|
|
||||||
var accentBody = buildCommon.makeVList([
|
accentBody = buildCommon.makeVList([
|
||||||
{type: "elem", elem: body},
|
{type: "elem", elem: body},
|
||||||
{type: "kern", size: -clearance},
|
{type: "kern", size: -clearance},
|
||||||
{type: "elem", elem: accentBody}
|
{type: "elem", elem: accentBody}
|
||||||
|
@ -1047,11 +1045,12 @@ var buildGroup = function(group, options, prev) {
|
||||||
if (groupTypes[group.type]) {
|
if (groupTypes[group.type]) {
|
||||||
// Call the groupTypes function
|
// Call the groupTypes function
|
||||||
var groupNode = groupTypes[group.type](group, options, prev);
|
var groupNode = groupTypes[group.type](group, options, prev);
|
||||||
|
var multiplier;
|
||||||
|
|
||||||
// If the style changed between the parent and the current group,
|
// If the style changed between the parent and the current group,
|
||||||
// account for the size difference
|
// account for the size difference
|
||||||
if (options.style !== options.parentStyle) {
|
if (options.style !== options.parentStyle) {
|
||||||
var multiplier = options.style.sizeMultiplier /
|
multiplier = options.style.sizeMultiplier /
|
||||||
options.parentStyle.sizeMultiplier;
|
options.parentStyle.sizeMultiplier;
|
||||||
|
|
||||||
groupNode.height *= multiplier;
|
groupNode.height *= multiplier;
|
||||||
|
@ -1061,7 +1060,7 @@ var buildGroup = function(group, options, prev) {
|
||||||
// If the size changed between the parent and the current group, account
|
// If the size changed between the parent and the current group, account
|
||||||
// for that size difference.
|
// for that size difference.
|
||||||
if (options.size !== options.parentSize) {
|
if (options.size !== options.parentSize) {
|
||||||
var multiplier = sizingMultiplier[options.size] /
|
multiplier = sizingMultiplier[options.size] /
|
||||||
sizingMultiplier[options.parentSize];
|
sizingMultiplier[options.parentSize];
|
||||||
|
|
||||||
groupNode.height *= multiplier;
|
groupNode.height *= multiplier;
|
||||||
|
|
|
@ -20,14 +20,11 @@
|
||||||
* used in `\left` and `\right`.
|
* used in `\left` and `\right`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Options = require("./Options");
|
|
||||||
var ParseError = require("./ParseError");
|
var ParseError = require("./ParseError");
|
||||||
var Style = require("./Style");
|
var Style = require("./Style");
|
||||||
|
|
||||||
var buildCommon = require("./buildCommon");
|
var buildCommon = require("./buildCommon");
|
||||||
var domTree = require("./domTree");
|
|
||||||
var fontMetrics = require("./fontMetrics");
|
var fontMetrics = require("./fontMetrics");
|
||||||
var parseTree = require("./parseTree");
|
|
||||||
var symbols = require("./symbols");
|
var symbols = require("./symbols");
|
||||||
var utils = require("./utils");
|
var utils = require("./utils");
|
||||||
|
|
||||||
|
@ -38,9 +35,9 @@ var makeSpan = buildCommon.makeSpan;
|
||||||
* after following replacement from symbols.js)
|
* after following replacement from symbols.js)
|
||||||
*/
|
*/
|
||||||
var getMetrics = function(symbol, font) {
|
var getMetrics = function(symbol, font) {
|
||||||
if (symbols["math"][symbol] && symbols["math"][symbol].replace) {
|
if (symbols.math[symbol] && symbols.math[symbol].replace) {
|
||||||
return fontMetrics.getCharacterMetrics(
|
return fontMetrics.getCharacterMetrics(
|
||||||
symbols["math"][symbol].replace, font);
|
symbols.math[symbol].replace, font);
|
||||||
} else {
|
} else {
|
||||||
return fontMetrics.getCharacterMetrics(
|
return fontMetrics.getCharacterMetrics(
|
||||||
symbol, font);
|
symbol, font);
|
||||||
|
@ -172,8 +169,6 @@ var makeStackedDelim = function(delim, heightTotal, center, options, mode) {
|
||||||
top = "\\Uparrow";
|
top = "\\Uparrow";
|
||||||
repeat = "\u2016";
|
repeat = "\u2016";
|
||||||
bottom = "\\Downarrow";
|
bottom = "\\Downarrow";
|
||||||
} else if (delim === "|" || delim === "\\vert") {
|
|
||||||
} else if (delim === "\\|" || delim === "\\Vert") {
|
|
||||||
} else if (delim === "[" || delim === "\\lbrack") {
|
} else if (delim === "[" || delim === "\\lbrack") {
|
||||||
top = "\u23a1";
|
top = "\u23a1";
|
||||||
repeat = "\u23a2";
|
repeat = "\u23a2";
|
||||||
|
@ -267,8 +262,7 @@ var makeStackedDelim = function(delim, heightTotal, center, options, mode) {
|
||||||
if (center) {
|
if (center) {
|
||||||
axisHeight *= options.style.sizeMultiplier;
|
axisHeight *= options.style.sizeMultiplier;
|
||||||
}
|
}
|
||||||
// Calculate the height and depth
|
// Calculate the depth
|
||||||
var height = realHeightTotal / 2 + axisHeight;
|
|
||||||
var depth = realHeightTotal / 2 - axisHeight;
|
var depth = realHeightTotal / 2 - axisHeight;
|
||||||
|
|
||||||
// Now, we start building the pieces that will go into the vlist
|
// Now, we start building the pieces that will go into the vlist
|
||||||
|
@ -279,13 +273,14 @@ var makeStackedDelim = function(delim, heightTotal, center, options, mode) {
|
||||||
// Add the bottom symbol
|
// Add the bottom symbol
|
||||||
inners.push(makeInner(bottom, font, mode));
|
inners.push(makeInner(bottom, font, mode));
|
||||||
|
|
||||||
|
var i;
|
||||||
if (middle === null) {
|
if (middle === null) {
|
||||||
// Calculate the number of repeated symbols we need
|
// Calculate the number of repeated symbols we need
|
||||||
var repeatHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
|
var repeatHeight = realHeightTotal - topHeightTotal - bottomHeightTotal;
|
||||||
var symbolCount = Math.ceil(repeatHeight / repeatHeightTotal);
|
var symbolCount = Math.ceil(repeatHeight / repeatHeightTotal);
|
||||||
|
|
||||||
// Add that many symbols
|
// Add that many symbols
|
||||||
for (var i = 0; i < symbolCount; i++) {
|
for (i = 0; i < symbolCount; i++) {
|
||||||
inners.push(makeInner(repeat, font, mode));
|
inners.push(makeInner(repeat, font, mode));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -304,7 +299,7 @@ var makeStackedDelim = function(delim, heightTotal, center, options, mode) {
|
||||||
Math.ceil(bottomRepeatHeight / repeatHeightTotal);
|
Math.ceil(bottomRepeatHeight / repeatHeightTotal);
|
||||||
|
|
||||||
// Add the top repeated part
|
// Add the top repeated part
|
||||||
for (var i = 0; i < topSymbolCount; i++) {
|
for (i = 0; i < topSymbolCount; i++) {
|
||||||
inners.push(makeInner(repeat, font, mode));
|
inners.push(makeInner(repeat, font, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +307,7 @@ var makeStackedDelim = function(delim, heightTotal, center, options, mode) {
|
||||||
inners.push(makeInner(middle, font, mode));
|
inners.push(makeInner(middle, font, mode));
|
||||||
|
|
||||||
// Add the bottom repeated part
|
// Add the bottom repeated part
|
||||||
for (var i = 0; i < bottomSymbolCount; i++) {
|
for (i = 0; i < bottomSymbolCount; i++) {
|
||||||
inners.push(makeInner(repeat, font, mode));
|
inners.push(makeInner(repeat, font, mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,8 +360,6 @@ var makeSizedDelim = function(delim, size, options, mode) {
|
||||||
delim = "\\rangle";
|
delim = "\\rangle";
|
||||||
}
|
}
|
||||||
|
|
||||||
var retDelim;
|
|
||||||
|
|
||||||
// Sized delimiters are never centered.
|
// Sized delimiters are never centered.
|
||||||
if (utils.contains(stackLargeDelimiters, delim) ||
|
if (utils.contains(stackLargeDelimiters, delim) ||
|
||||||
utils.contains(stackNeverDelimiters, delim)) {
|
utils.contains(stackNeverDelimiters, delim)) {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* jshint unused:false */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file contains metrics regarding fonts and individual symbols. The sigma
|
* This file contains metrics regarding fonts and individual symbols. The sigma
|
||||||
* and xi variables, as well as the metricMap map contain data extracted from
|
* and xi variables, as well as the metricMap map contain data extracted from
|
||||||
|
@ -45,15 +47,15 @@ var xi1 = 0;
|
||||||
var xi2 = 0;
|
var xi2 = 0;
|
||||||
var xi3 = 0;
|
var xi3 = 0;
|
||||||
var xi4 = 0;
|
var xi4 = 0;
|
||||||
var xi5 = .431;
|
var xi5 = 0.431;
|
||||||
var xi6 = 1;
|
var xi6 = 1;
|
||||||
var xi7 = 0;
|
var xi7 = 0;
|
||||||
var xi8 = .04;
|
var xi8 = 0.04;
|
||||||
var xi9 = .111;
|
var xi9 = 0.111;
|
||||||
var xi10 = .166;
|
var xi10 = 0.166;
|
||||||
var xi11 = .2;
|
var xi11 = 0.2;
|
||||||
var xi12 = .6;
|
var xi12 = 0.6;
|
||||||
var xi13 = .1;
|
var xi13 = 0.1;
|
||||||
|
|
||||||
// This value determines how large a pt is, for metrics which are defined in
|
// This value determines how large a pt is, for metrics which are defined in
|
||||||
// terms of pts.
|
// terms of pts.
|
||||||
|
|
|
@ -172,7 +172,7 @@ var functions = {
|
||||||
return {
|
return {
|
||||||
type: "infix",
|
type: "infix",
|
||||||
replaceWith: "\\frac"
|
replaceWith: "\\frac"
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,6 +12,6 @@ var parseTree = function(toParse) {
|
||||||
var parser = new Parser(toParse);
|
var parser = new Parser(toParse);
|
||||||
|
|
||||||
return parser.parse();
|
return parser.parse();
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = parseTree;
|
module.exports = parseTree;
|
||||||
|
|
|
@ -973,7 +973,7 @@ var symbols = {
|
||||||
var mathTextSymbols = "0123456789/@.\"";
|
var mathTextSymbols = "0123456789/@.\"";
|
||||||
for (var i = 0; i < mathTextSymbols.length; i++) {
|
for (var i = 0; i < mathTextSymbols.length; i++) {
|
||||||
var ch = mathTextSymbols.charAt(i);
|
var ch = mathTextSymbols.charAt(i);
|
||||||
symbols["math"][ch] = {
|
symbols.math[ch] = {
|
||||||
font: "main",
|
font: "main",
|
||||||
group: "textord"
|
group: "textord"
|
||||||
};
|
};
|
||||||
|
@ -983,7 +983,7 @@ for (var i = 0; i < mathTextSymbols.length; i++) {
|
||||||
var textSymbols = "0123456789`!@*()-=+[]'\";:?/.,";
|
var textSymbols = "0123456789`!@*()-=+[]'\";:?/.,";
|
||||||
for (var i = 0; i < textSymbols.length; i++) {
|
for (var i = 0; i < textSymbols.length; i++) {
|
||||||
var ch = textSymbols.charAt(i);
|
var ch = textSymbols.charAt(i);
|
||||||
symbols["text"][ch] = {
|
symbols.text[ch] = {
|
||||||
font: "main",
|
font: "main",
|
||||||
group: "textord"
|
group: "textord"
|
||||||
};
|
};
|
||||||
|
@ -993,11 +993,11 @@ for (var i = 0; i < textSymbols.length; i++) {
|
||||||
var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
for (var i = 0; i < letters.length; i++) {
|
for (var i = 0; i < letters.length; i++) {
|
||||||
var ch = letters.charAt(i);
|
var ch = letters.charAt(i);
|
||||||
symbols["math"][ch] = {
|
symbols.math[ch] = {
|
||||||
font: "main",
|
font: "main",
|
||||||
group: "mathord"
|
group: "mathord"
|
||||||
};
|
};
|
||||||
symbols["text"][ch] = {
|
symbols.text[ch] = {
|
||||||
font: "main",
|
font: "main",
|
||||||
group: "textord"
|
group: "textord"
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,7 +59,7 @@ function escaper(match) {
|
||||||
* @return {string} An escaped string.
|
* @return {string} An escaped string.
|
||||||
*/
|
*/
|
||||||
function escape(text) {
|
function escape(text) {
|
||||||
return ('' + text).replace(ESCAPE_REGEX, escaper);
|
return ("" + text).replace(ESCAPE_REGEX, escaper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user