Skip to content

docs: explain exponents on parenthesized units - #3714

Open
Hugohong258 wants to merge 4 commits into
josdejong:developfrom
Hugohong258:docs/unit-group-exponents
Open

Hugohong258 wants to merge 4 commits into
josdejong:developfrom
Hugohong258:docs/unit-group-exponents

Conversation

@Hugohong258

@Hugohong258 Hugohong258 commented Oct 8, 2026 •

Copy link
Copy Markdown

math.unit('(m/s)^2') throws a syntax error, although parentheses are supported for grouping units. The units guide now explains that exponents must follow individual units and shows math.unit('m^2/s^2') and math.evaluate('(m/s)^2') as alternatives.

The units guide and expression syntax page also explain that, by default, min and sec resolve to the minimum and secant functions in expressions, and show the unambiguous unit names and math.unit() alternatives. The unit list now includes sec and calls out both name clashes. A user-supplied scope can override these symbols. This incorporates the documentation from #3709 and addresses the maintainer's follow-up on #3714. No parser behavior changes.

Fixes #2771
Fixes #2095

Validation on Windows, Node 24.15.0, using the existing dependency installation from the earlier checkout:

  • Executed the documented grouped-unit and min/sec examples, including explicit scope overrides, against the source.
  • npm run test:src: 6,652 passing, 22 pending.
  • git diff --check passed. No website build or full lint run was performed.

@gwhitney

Copy link
Copy Markdown
Collaborator

Thanks for the contribution, this is pretty nice as far as it goes. Since this is just one small change to the docs, I think we would prefer if someone, perhaps you, could identify the most appropriate place(s) in the documentation to address the unit min[ute]/function min[imum] and unit sec[ond]/function sec[ant] clashes to minimize those confusions as well, so that we can close #2771 in a single PR. Any chance you could add a proposed change to the documentation for that? Thanks for considering.

@gwhitney

Copy link
Copy Markdown
Collaborator

Oh I see, you have #3709 already for that. OK, please could you (a) combine the two PRs into one and mark that as resolving #2771, and (b) add further mentions of the min/sec conflict in the documentation in some or all of the following list of places? Thank you so much.

  • Somewhere in the documentation for mathjs syntax and/or the evaluate function, note that function symbols override unit abbreviations, specifically in the min and sec cases [definitely needed]
  • If there is a list somewhere in the documentation of all of the unit abbreviations, add warnings by min and sec that they will be overridden in mathjs expressions by the min and sec functions [needed if there is such a list], and
  • On the documentation pages for the min and sec functions, note the name clashes but point out that the function interpretations for those symbols will always be used in the mathjs expression parser, even if the unit abbrevs were intended [this one is a judgment call, include if you think it would be useful].

Thanks again.

Comment thread docs/datatypes/units.md Outdated
Comment thread docs/datatypes/units.md Outdated
Comment thread docs/expressions/syntax.md Outdated
@gwhitney

Copy link
Copy Markdown
Collaborator

OK, reviewed. I see you decided not to say anything on the min and sec function documentation pages. I think that is OK, just wanted to make sure that was a deliberate decision on your part, not just overlooking the possiblity. Should be good for merging when you've adjusted for the review.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Parsing unit fails with parentheses and exponents; documentation unclear [Document the] secant function messing up sec unit

2 participants