mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
Rename customFuncions to callbacks
This commit is contained in:
parent
c80e0baf20
commit
e04dfd26bc
@ -99,18 +99,18 @@ ArrayNode.prototype.toString = function() {
|
||||
* @param {String} type
|
||||
* @return {String} str
|
||||
*/
|
||||
ArrayNode.prototype._toTex = function(customFunctions) {
|
||||
ArrayNode.prototype._toTex = function(callbacks) {
|
||||
this.latexType = this.latexType || 'bmatrix';
|
||||
var s = '\\begin{' + this.latexType + '}';
|
||||
|
||||
this.nodes.forEach(function(node) {
|
||||
if (node.nodes) {
|
||||
s += node.nodes.map(function(childNode) {
|
||||
return childNode.toTex(customFunctions);
|
||||
return childNode.toTex(callbacks);
|
||||
}).join('&');
|
||||
}
|
||||
else {
|
||||
s += node.toTex(customFunctions);
|
||||
s += node.toTex(callbacks);
|
||||
}
|
||||
|
||||
// new line
|
||||
|
||||
@ -92,11 +92,11 @@ AssignmentNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String}
|
||||
*/
|
||||
AssignmentNode.prototype._toTex = function(customFunctions) {
|
||||
AssignmentNode.prototype._toTex = function(callbacks) {
|
||||
var precedence = operators.getPrecedence(this);
|
||||
var exprPrecedence = operators.getPrecedence(this.expr);
|
||||
|
||||
var expr = this.expr.toTex(customFunctions);
|
||||
var expr = this.expr.toTex(callbacks);
|
||||
if ((exprPrecedence !== null) && (exprPrecedence <= precedence)) {
|
||||
//adds visible round brackets
|
||||
expr = latex.addBraces(expr, true);
|
||||
|
||||
@ -125,9 +125,9 @@ BlockNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
BlockNode.prototype._toTex = function(customFunctions) {
|
||||
BlockNode.prototype._toTex = function(callbacks) {
|
||||
return this.blocks.map(function (param) {
|
||||
return param.node.toTex(customFunctions) + (param.visible ? '' : ';');
|
||||
return param.node.toTex(callbacks) + (param.visible ? '' : ';');
|
||||
}).join('\n');
|
||||
};
|
||||
|
||||
|
||||
@ -154,13 +154,13 @@ ConditionalNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
ConditionalNode.prototype._toTex = function(customFunctions) {
|
||||
ConditionalNode.prototype._toTex = function(callbacks) {
|
||||
var s = (
|
||||
latex.addBraces(this.trueExpr.toTex(customFunctions)) +
|
||||
latex.addBraces(this.trueExpr.toTex(callbacks)) +
|
||||
', &\\quad' +
|
||||
latex.addBraces('\\text{if}\\;' + this.condition.toTex(customFunctions))
|
||||
latex.addBraces('\\text{if}\\;' + this.condition.toTex(callbacks))
|
||||
) + '\\\\' + (
|
||||
latex.addBraces(this.falseExpr.toTex(customFunctions)) +
|
||||
latex.addBraces(this.falseExpr.toTex(callbacks)) +
|
||||
', &\\quad' +
|
||||
latex.addBraces('\\text{otherwise}')
|
||||
);
|
||||
|
||||
@ -159,7 +159,7 @@ ConstantNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
ConstantNode.prototype._toTex = function(customFunctions) {
|
||||
ConstantNode.prototype._toTex = function(callbacks) {
|
||||
var value = this.value,
|
||||
index;
|
||||
switch (this.valueType) {
|
||||
|
||||
@ -113,11 +113,11 @@ FunctionAssignmentNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
FunctionAssignmentNode.prototype._toTex = function(customFunctions) {
|
||||
FunctionAssignmentNode.prototype._toTex = function(callbacks) {
|
||||
var precedence = operators.getPrecedence(this);
|
||||
var exprPrecedence = operators.getPrecedence(this.expr);
|
||||
|
||||
var expr = this.expr.toTex(customFunctions);
|
||||
var expr = this.expr.toTex(callbacks);
|
||||
if ((exprPrecedence !== null) && (exprPrecedence <= precedence)) {
|
||||
//adds visible round brackets
|
||||
expr = latex.addBraces(expr, true);
|
||||
|
||||
@ -116,8 +116,8 @@ FunctionNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
FunctionNode.prototype._toTex = function(customFunctions) {
|
||||
return latex.toArgs(this, customFunctions);
|
||||
FunctionNode.prototype._toTex = function(callbacks) {
|
||||
return latex.toArgs(this, callbacks);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -212,8 +212,8 @@ IndexNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
IndexNode.prototype._toTex = function(customFunctions) {
|
||||
return this.object.toTex(customFunctions) + '[' + this.ranges.join(', ') + ']';
|
||||
IndexNode.prototype._toTex = function(callbacks) {
|
||||
return this.object.toTex(callbacks) + '[' + this.ranges.join(', ') + ']';
|
||||
};
|
||||
|
||||
module.exports = IndexNode;
|
||||
|
||||
@ -239,7 +239,7 @@ OperatorNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
OperatorNode.prototype._toTex = function(customFunctions) {
|
||||
OperatorNode.prototype._toTex = function(callbacks) {
|
||||
var args = this.args;
|
||||
var parens = calculateNecessaryParentheses(this, args);
|
||||
var op = latex.toOperator(this.op); //operator
|
||||
@ -248,7 +248,7 @@ OperatorNode.prototype._toTex = function(customFunctions) {
|
||||
case 1: //unary operators
|
||||
var assoc = operators.getAssociativity(this);
|
||||
|
||||
var operand = args[0].toTex(customFunctions);
|
||||
var operand = args[0].toTex(callbacks);
|
||||
if (parens[0]) {
|
||||
operand = latex.addBraces(operand, true);
|
||||
}
|
||||
@ -266,9 +266,9 @@ OperatorNode.prototype._toTex = function(customFunctions) {
|
||||
case 2: //binary operators
|
||||
var lhs = args[0]; //left hand side
|
||||
//reminder: if parens[0] is false, this puts it in curly braces
|
||||
var lhsTex = latex.addBraces(lhs.toTex(customFunctions), parens[0]);
|
||||
var lhsTex = latex.addBraces(lhs.toTex(callbacks), parens[0]);
|
||||
var rhs = args[1]; //right hand side
|
||||
var rhsTex = latex.addBraces(rhs.toTex(customFunctions), parens[1]);
|
||||
var rhsTex = latex.addBraces(rhs.toTex(callbacks), parens[1]);
|
||||
|
||||
switch (this.getIdentifier()) {
|
||||
case 'OperatorNode:divide':
|
||||
@ -276,7 +276,7 @@ OperatorNode.prototype._toTex = function(customFunctions) {
|
||||
return op + lhsTex + rhsTex;
|
||||
|
||||
case 'OperatorNode:to':
|
||||
rhsTex = latex.toUnit(rhs.toTex(customFunctions));
|
||||
rhsTex = latex.toUnit(rhs.toTex(callbacks));
|
||||
rhsTex = latex.addBraces(rhsTex, parens[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -124,12 +124,12 @@ RangeNode.prototype.toString = function() {
|
||||
* @params {Object|function} callback(s)
|
||||
* @return {String} str
|
||||
*/
|
||||
RangeNode.prototype._toTex = function(customFunctions) {
|
||||
var str = this.start.toTex(customFunctions);
|
||||
RangeNode.prototype._toTex = function(callbacks) {
|
||||
var str = this.start.toTex(callbacks);
|
||||
if (this.step) {
|
||||
str += ':' + this.step.toTex(customFunctions);
|
||||
str += ':' + this.step.toTex(callbacks);
|
||||
}
|
||||
str += ':' + this.end.toTex(customFunctions);
|
||||
str += ':' + this.end.toTex(callbacks);
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
@ -103,8 +103,8 @@ SymbolNode.prototype.toString = function() {
|
||||
* @return {String} str
|
||||
* @override
|
||||
*/
|
||||
SymbolNode.prototype._toTex = function(customFunctions) {
|
||||
return latex.toSymbol(this.name, customFunctions);
|
||||
SymbolNode.prototype._toTex = function(callbacks) {
|
||||
return latex.toSymbol(this.name, callbacks);
|
||||
};
|
||||
|
||||
module.exports = SymbolNode;
|
||||
|
||||
@ -87,8 +87,8 @@ UpdateNode.prototype.toString = function() {
|
||||
* @param {Object|function} callback(s)
|
||||
* @return {String}
|
||||
*/
|
||||
UpdateNode.prototype._toTex = function(customFunctions) {
|
||||
return this.index.toTex(customFunctions) + ' = ' + this.expr.toTex(customFunctions);
|
||||
UpdateNode.prototype._toTex = function(callbacks) {
|
||||
return this.index.toTex(callbacks) + ' = ' + this.expr.toTex(callbacks);
|
||||
};
|
||||
|
||||
module.exports = UpdateNode;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user