Imported function help
When using math.import and importing a function I would like for it to work with the help function
// define new functions and variables
math.import({
myvalue: 42,
hello: function (name) {
/**
* This function says hello
*
* Syntax:
*
* math.hello("David")
* math.hello("Jos")
*
* Examples:
*
* math.hello("David") // returns "hello, David"
*
* See also:
*
* compare, compareNatural
*
* @param {... *} args A single string or a list of strings
* @return {*} all strings
*/
return 'hello, ' + name + '!'
}
})
help(hello)
This function says hello
Syntax:
math.hello("David")
math.hello("Jos")
Examples:
math.hello("David") // returns "hello, David"
See also:
compare, compareNatural
https://mathjs.org/docs/core/extension.html#extension
Hm that is a good question, there isn't really an API for that right now.
I can think of two workarounds:
-
When using the ES6 library, you can add your docs to the globally exported
docsimport { create, all, docs } from 'mathjs' const math = create(all) const myHelloDocs = { name: 'hello', category: '...', syntax: [ '...' ], description: '....', examples: [ '...' ], seealso: [ '...' ] } // add custom docs to the globally exported docs docs.hello = myHelloDocs // now you can use help(hello) -
Override the function
helpwith your own version which first checks whether the input ishello, if so returnnew Help(myHelloDocs), and otherwise call the originalhelpfunction.
Thank you, I will try both.
I'm working on an implementation of mathjs with some thermodynamics properties from coolprop. It benefits greatly from the physical units of mathjs.
Thanks, good to hear 👍😄
Closing as duplicate of #2047.