Skip to content

Commit

Permalink
Merge pull request #40 from KQMATH/develop
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
andstor authored Jun 25, 2019
2 parents f8d3138 + f360622 commit 46917f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tex2max",
"version": "1.2.0",
"version": "1.2.1",
"description": "LaTeX math to Maxima code converter",
"main": "lib/tex2max.common.js",
"unpkg": "lib/tex2max.js",
Expand Down
9 changes: 8 additions & 1 deletion src/transpiler/handlers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function getExpressionLength(parsedLatex, types = [], values = []) {
// Locate the next operator + or -, function etc...

let expressionLength = 0;
let condition = null;
let conditionValue = null;

if (parsedLatex[0].type === 'group' && parsedLatex.length === 1) {
expressionLength = 1;
Expand All @@ -27,6 +29,9 @@ export function getExpressionLength(parsedLatex, types = [], values = []) {
if (parsedLatex[i].type === type) {
expressionLength = (i);
foundExpressionLength = true;
condition = 'type';
conditionValue = type;

}
});
}
Expand All @@ -36,6 +41,8 @@ export function getExpressionLength(parsedLatex, types = [], values = []) {
if (parsedLatex[i].value === value) {
expressionLength = (i);
foundExpressionLength = true;
condition = 'value';
conditionValue = value;
}
});
}
Expand All @@ -48,5 +55,5 @@ export function getExpressionLength(parsedLatex, types = [], values = []) {
}
}

return expressionLength;
return {expressionLength: expressionLength, condition: condition, conditionValue: conditionValue};
}
11 changes: 8 additions & 3 deletions src/transpiler/maxima-transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ export function transpiler(parsedLatex) {
}

// Find length of expression....
let functionLength = getExpressionLength(parsedLatex.slice((index + 1)), ['function'], ['+', '-', '+-']);
let {expressionLength: functionLength, condition, conditionValue} = getExpressionLength(parsedLatex.slice((index + 1)), ['function'], ['+', '-', '+-']);

if (functionLength === 0 && condition === 'type' && conditionValue === 'function') {
functionLength = 2;
}

expression += transpiler(wrapForTranspilation(parsedLatex.slice((index + 1), ((index + 1) + functionLength))));
index += functionLength - 1;

Expand Down Expand Up @@ -404,7 +409,7 @@ export function transpiler(parsedLatex) {
limitArgs = handleLimitArguments(limitArgs);

if (typeof parsedLatex[index + 3] !== 'undefined') {
let limitLength = getExpressionLength(parsedLatex.slice((index + 3)), [], ['+', '-', '+-']);
let {expressionLength: limitLength} = getExpressionLength(parsedLatex.slice((index + 3)), [], ['+', '-', '+-']);

expression += transpiler(parsedLatex.slice((index + 3), ((index + 3) + limitLength)));
index += (limitLength - 1);
Expand Down Expand Up @@ -448,7 +453,7 @@ export function transpiler(parsedLatex) {
}

if (typeof parsedLatex[index + 1] !== 'undefined') {
let sumLength = getExpressionLength(parsedLatex.slice((index + 1)), [], ['+', '-', '+-']);
let {expressionLength: sumLength} = getExpressionLength(parsedLatex.slice((index + 1)), [], ['+', '-', '+-']);

expression += transpiler(parsedLatex.slice((index + 1), ((index + 1) + sumLength)));
index += (sumLength);
Expand Down

0 comments on commit 46917f8

Please sign in to comment.