Skip to content
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

Custom math functions #48

Open
markhats opened this issue Sep 15, 2022 · 3 comments
Open

Custom math functions #48

markhats opened this issue Sep 15, 2022 · 3 comments

Comments

@markhats
Copy link

markhats commented Sep 15, 2022

Hi

Just wondered if there was a way to add custom math functions to the parsing and evaluation of expressions?

Thanks.

@dqnykamp
Copy link
Member

You can add new functions to the appliedFunctionSymbols argument when creating latexToAst or testToAst, which will parse "\myFunction(x)" (latex) or "myFunction(x)" (text) to the ast ["apply", "myFunction", "x"]. If that function is known to mathjs, then it will call the mathjs function when evaluating it. If producing latex, you also need to add it to allowedLatexSymbols of astToLatex so that the result going back to latex is "\myFunction(x)".

@markhats
Copy link
Author

markhats commented Sep 28, 2022

Thanks for the info.

I assume if it isn't a function known to mathjs, then I need to implement it as a custom mathjs function, as detailed here: https://mathjs.org/docs/core/extension.html ? Or is there a better way?

@dqnykamp
Copy link
Member

That's right. That's what I did to add some functions from numeric.js, and it seemed to work without a hitch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants