-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing of function expressions #8
Comments
Hi, there is currently no way to declare a function like you are trying. There is no way to know the difference between a function declaration I don't see an obvious way to tell algebra-latex to parse it as a function rather than the product of two variables. Maybe you have an idea? |
Perhaps it could be implemented as an option or a custom method? Some ideas that come to mind:
Sent with GitHawk |
A solution might be to add a configuration object where custom function names could be set. And the parser would know to parse it as a function whenever it sees these names. Like so: new AlgebraLatex({
functions: ['f', 'g', 'func']
}).parseLatex(latexInput) |
I think that your solution is ideal, especially because you can customize the reservations on a per-parse basis. I can try to implement this, although my experience with this library is minuscule. |
Great 🎉 I will encourage you to try to implement it. The important files are: The The keyword method in Parser.js line 144, where it is decided if it should be interpreted as a function. |
So at Parser.js:144 I would just need to mixin the added keywords? |
Exactly, the variable |
The deprecated constructor(latex) {
if (typeof latex === 'undefined') {
return
} else if (typeof latex === 'object') {
this.parseOptions(latex)
return
}
this.parseLatex(latex)
} |
Okay. Just remove the old parameter. |
My fork is a working concept of this, however it does not allow me to define a function with multiple arguments. For example:
This seems to be a result of a regex that accommodates the European decimal. Perhaps I can replace this with another option? |
Your implementation is great, and I will happily merge it, if you send a pull request. The problem with multi-variable functions is a new issue of its own. If you want to try to implement it, here are what needs to be done. If not, I can do it later when I have the time. LexerThe lexer should first determine if the comma is a part of a european number, otherwise it should return a new separator token object maybe Eg. Note that multi-variable functions also can be written as Parser
// f(x, y)
{
type: 'function',
value: 'f',
content: [{
type: 'variable', value: 'x',
}, {
type: 'variable', value: 'y',
}
} FormattersThe formatters should be updated to understand the new parsed formats |
Sorry to bump a dead thread. Working on multivariate arguments, and not sure how to handle the separators in Latex. Popular editors like MathQuill don't support spaces between the arguments, at least not by default. Even the demo page of MathQuill doesn't let you put spaces in the arguments :( Perhaps an option is in order that can disable European decimal detection? |
No issue, i've reopened it.
I agree that it would probably be the best solution to add an option to chose comma separator format. Also I don't see any general solution that would cover all edge-cases. |
Hello, I am attempting to parse
f\left(x\right)=x^2
into a function definition,f(x)=x^2
, which is an acceptable format in Algebrite. Instead,f*x=x^2
is produced.If this is my mistake, how can I declare an algebraic function and have it translate to the desired output above?
If this is not my mistake, and algebra-latex does not support this, are there plans to implement this into the library?
The text was updated successfully, but these errors were encountered: