mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
util/latex: Make use of templates based on number of arguments
This commit is contained in:
parent
29fd97839f
commit
2076bebdb0
@ -128,30 +128,21 @@ var functions = {
|
||||
'gcd': '\\gcd\\left(%*%\\right)',
|
||||
'lcm': defaultTemplate,
|
||||
'log10': '\\log_{10}\\left(%0%\\right)',
|
||||
'log': function (node, callbacks) { //TODO use templates for that?
|
||||
if (node.args.length === 1) {
|
||||
return '\\ln\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
}
|
||||
return '\\log_{' + node.args[1].toTex(callbacks)
|
||||
+ '}\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
'log': {
|
||||
1: '\\ln\\left(%0%\\right)',
|
||||
2: '\\log_%1%\\left(%0%\\right)'
|
||||
},
|
||||
'mod': '\\left(%0%' + exports.operators['mod'] + '%1%\\right)',
|
||||
'multiply': '\\left(%0%' + exports.operators['multiply'] + '%1%\\right)',
|
||||
'norm': function (node, callbacks) { //TODO use templates for that?
|
||||
if (node.args.length === 1) {
|
||||
return '\\left\\|{' + node.args[0].toTex(callbacks) + '}\\right\\|';
|
||||
}
|
||||
else {
|
||||
return '\\mathrm{norm}\\left(' + functionArgs(node.args, callbacks) + '\\right)';
|
||||
}
|
||||
'norm': {
|
||||
1: '\\left\\|%0%\\right\\|',
|
||||
2: defaultTemplate
|
||||
},
|
||||
'nthRoot': '\\sqrt[%1%]%0%',
|
||||
'pow': '\\left(%0%' + exports.operators['pow'] + '%1%\\right)',
|
||||
'round': function (node, callbacks) { //TODO use templates for that?
|
||||
if (node.args.length === 1) {
|
||||
return '\\left\\lfloor{' + node.args[0].toTex(callbacks) + '}\\right\\rceil';
|
||||
}
|
||||
return '\\mathrm{round}\\left(' + functionArgs(node.args, callbacks) + '\\right)';
|
||||
'round': {
|
||||
1: '\\left\\lfloor%0%\\right\\rceil',
|
||||
2: defaultTemplate
|
||||
},
|
||||
'sign': defaultTemplate,
|
||||
'sqrt': '\\sqrt%0%',
|
||||
@ -177,56 +168,39 @@ var functions = {
|
||||
're': '\\Re\\left\\lbrace%0%\\right\\rbrace',
|
||||
|
||||
//construction
|
||||
'bignumber': function (node, callbacks) { //TODO use templates for that?
|
||||
if (node.args.length === 0) {
|
||||
return '0';
|
||||
}
|
||||
return '\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
'bignumber': {
|
||||
0: '0',
|
||||
1: '\\left(%0%\\right)'
|
||||
},
|
||||
'boolean': defaultTemplate,
|
||||
'chain': defaultTemplate,
|
||||
'complex': function (node, callbacks) { //TODO use templates for that?
|
||||
switch (node.args.length) {
|
||||
case 0:
|
||||
return '0';
|
||||
case 1:
|
||||
return '\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
case 2:
|
||||
return '\\left({\\left({' + node.args[0].toTex(callbacks)
|
||||
+ '}\\right)+i\\cdot\\left({' + node.args[1].toTex(callbacks) + '}\\right)}\\right)';
|
||||
}
|
||||
'complex': {
|
||||
0: '0',
|
||||
1: '\\left(%0%\\right)',
|
||||
2: '\\left({\\left(%0%\\right)+'
|
||||
+ exports.symbols['i'] + '\\cdot\\left(%1%\\right)}\\right)',
|
||||
},
|
||||
'index': defaultTemplate,
|
||||
'matrix': function (node, callbacks) { //TODO use templates for that?
|
||||
if (node.args.length === 0) {
|
||||
return '\\begin{bmatrix}\\end{bmatrix}';
|
||||
}
|
||||
return '\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
'matrix': {
|
||||
0: '\\begin{bmatrix}\\end{bmatrix}',
|
||||
1: '\\left(%0%\\right)',
|
||||
2: '\\left(%0%\\right)'
|
||||
},
|
||||
'number': function (node, callbacks) { //TODO use templates for that?
|
||||
switch (node.args.length) {
|
||||
case 0:
|
||||
return '0';
|
||||
case 1:
|
||||
return '\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
case 2:
|
||||
return '\\left(\\left({' + node.args[0].toTex(callbacks)
|
||||
+ '}\\right){' + node.args[1].toTex(callbacks) + '}\\right)';
|
||||
}
|
||||
'number': {
|
||||
0: '0',
|
||||
1: '\\left(%0%\\right)',
|
||||
2: '\\left(\\left(%0%\\right)%1%\\right)'
|
||||
},
|
||||
'parser': defaultTemplate,
|
||||
'string': function (node, callbacks) { //TODO use templates for that?
|
||||
if (node.args.length === 0) {
|
||||
return '""';
|
||||
'string': {
|
||||
0: '""',
|
||||
1: function (node) {
|
||||
return '"' + node.args[0].toString() + '"';
|
||||
}
|
||||
return '"' + node.args[0].toString() + '"';
|
||||
},
|
||||
'unit': function (node, callbacks) {
|
||||
if (node.args.length === 1) {
|
||||
return '\\left({' + node.args[0].toTex(callbacks) + '}\\right)';
|
||||
}
|
||||
return '\\left({\\left({' + node.args[0].toTex(callbacks)
|
||||
+ '}\\right){' + node.args[1].toTex() + '}}\\right)';
|
||||
'unit': {
|
||||
1: '\\left(%0%\\right)',
|
||||
2: '\\left({\\left(%0%\\right)%1%}\\right)'
|
||||
},
|
||||
|
||||
//expression TODO does the default even work in this case? (.toTex on the args)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user