Replies: 1 comment 2 replies
-
It turns out that there was a bug in |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I am trying to figure out a way to selectively load and unload units from my configuration. To give an example, I want to be able to disable 'b' for bits if I am working with the quadratic equation, rather than the "b" in that equation being interpreted as a unit.
I have a handful of questions related to solving this problem, though they touch on a few different areas.
So, first off, it doesn't seem like you can install a version without units any more. I've seen some older Q&As that reference loading "mathjs/core" and then selectively importing the functions you want, but I don't see a reference to this in the official docs. Is this an outdated method for setting up your configuration? If installing mathjs/core is still possible, how do you do this with npm? I don't see a mathjs/core folder in the main repository, nor can I install a package with the name "mathjs/core".
I've attempted to use the method suggested in the official docs for custom bundling (here: https://mathjs.org/docs/custom_bundling.html), but even then, if I remove Unit, UnitDepedencies, unitDependencies, and then create an import from there, it doesn't seem to be any different than the default "all" import. Or, if it is different, it certainly doesn't remove the default units.
I see that there are numerous functions in the namespace mathjs.Unit, such as createUnit and deleteUnit and setUnitSystem, however, calling these on an already instantiated mathjs configuration doesn't seem to have any effect. Certainly, at least, using deleteUnit on a base unit doesn't do anything.
I've tried out and out deleting the units directly from mathjs.Unit.UNITS, while making a deepCopy to store in a "disabledUnits" object so I can restore them later. What is strange about this approach is that if I disable the unit before I call mathjs.evaluate then it actually does work, the units I disable are not recognized. I can even disable and re-enable the unit by restoring it from the deepCopy, and if I do all that before the first call to evaluate, it does work (it remains enabled). However, it seems like after that first call to evaluate, my configuration is locked in, deleting or restoring units after that doesn't have any effect. I can reinstantiate mathjs, but rather than grabbing the current configuration of UNITS when I do that, it just resets back to the default configuration. I suppose I could create a new instance of mathjs and remove all the currently disabled units before each call to evaluate, but there must be a better way.
So what object is storing the unit configuration other than the mathjs.Unit.UNITS object? Where does evaluate go to determine what units are available if not there?
Thank you for any clarification on any of this.
-John
Beta Was this translation helpful? Give feedback.
All reactions