Comments (3)
If someone else also has this problem, this quick hack can work, although I don't know if it will break some other expressions.
It detects the ^ symbol, and adds brackets between the ^ and the next dissimilar character.
eg. x^34+y -> x^{34}+y
eg. 45^x+3 -> 45^{x}+3
eg. 45^xy+3 -> 45^{xy}+3
eg. 45^{x+y+3} -> 45^{{x+y+3}}
Use the function fixExpLatex() on the TeX part of the Algebrite output, make sure the TeX string does not contain any spaces.
const isLetter = function(char) {
return char.toLowerCase() !== char.toUpperCase();
};
const isNumber = function(char) {
return +char === +char;
};
const findNextDifferentChar = function(str, index) { //find the next dissimilar character
if (isNumber(str[index])) { //if character is a number, return next character that isn't a number
for (let i=index; i<str.length; i++) {
if (!isNumber(str[i])) {
return i;
}
}
return str.length;
} else if (isLetter(str[index])) { //if character is a letter, return next character that isn't a letter
for (let i=index; i<str.length; i++) {
if (!isLetter(str[i])) {
return i;
}
}
return str.length;
} else if (str[index] === "{") { //if character is a bracket, return next character that is the inverted bracket, so as to not modify existing expressions
for (let i=index; i<str.length; i++) {
if (str[i] === "}") {
return i;
}
}
return str.length;
} else { //if character is a parenthesis or a symbol, return the end index
return str.length;
}
};
const fixExpLatex = function(str) {
let textPart = [];
let lastindex = 0;
for (let i=0; i<str.length-1; i++) {
if (str[i] === "^") {
const nextindex = findNextDifferentChar(str, i+1); //find next character that isn't similar to the one after the "^"
textPart.push(str.slice(lastindex, i+1)); //push the unchanged part
textPart.push("{" + str.slice(i+1, nextindex) + "}"); //push the exponent part in brackets
lastindex = nextindex;
i = nextindex-1; //skip the part already saved
}
}
textPart.push(str.slice(lastindex, str.length)); //push in the last part that was not detected
return textPart.join("");
};
from algebrite.
acknowledged. Will examine the suggested fix. Should be more compact to fix the buggy code in the print routine inside but I'll check.
from algebrite.
fixed in 0.4.2 release notes here: http://algebrite.org/docs/index.html
from algebrite.
Related Issues (20)
- Solving Boolean expressions
- Solving systems of equations
- Absolute value syntax errors
- Solving equations involving fractions
- Simplify
- GUI for user to edit/enter the equation in HTML
- Testing equivalance could be more smart, easily
- Update NPM version
- cann't simpifay apk
- the order of the powers of the polynomial is reversed HOT 1
- How to solve equations? HOT 2
- How to identify if an expression given by a human is in its simplified form HOT 4
- Is there some kind of AST ? HOT 1
- draw function is needed HOT 1
- Can't return numerical results < 1e-6. Can't substitute variables with scientific notation
- Infinite loop when try to inverse a 1x1 matrix
- Computation of binomial
- Display order of polynomial monomials
- simplification with exponents HOT 1
- i raised to exponents bigger than 4 is not calculated correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algebrite.