Skip to content

Conversation

@ml-evs
Copy link
Member

@ml-evs ml-evs commented Apr 13, 2025

For now, this PR simply starts listing some rules on chemical formulae formatting that we can follow eventually, e.g.:

    chemFormulaFormat() {
      // Need to capture several groups, if the overall format doesn't apply, then
      // there should be no additional formatting whatsoever
      //
      // Some rules:
      //
      // * numbers between element symbols need to be subscripted, including "." and variables like "x"
      //    - e.g., Na3P => Na<sub>3</sub>P, Na3+xP => Na<sub>3+x</sub>P
      // * charges need to be handled separately and superscripted
      //    - e.g., Na+Cl- => Na<sup>+</sup>Cl<sup>-</sup>
      // * empirical labels for formula units like [pyr] must be left alone
      // * dots, when not used within numbers, must be treated as an interpunct "dot product" style dot
      //     - e.g., Cu2SO4.H2O => Cu<sub>2</sub>SO<sub>4</sub> · H<sub>2</sub>O

I think many of these can be handled selectively with some judicious regexes, and beyond formatting, the same rules could be used to validate e.g., empirical formulae in JS used for computing yields and the like.

@codecov
Copy link

codecov bot commented Apr 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.44%. Comparing base (4d53d7f) to head (b253762).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1121   +/-   ##
=======================================
  Coverage   80.44%   80.44%           
=======================================
  Files          70       70           
  Lines        4771     4771           
=======================================
  Hits         3838     3838           
  Misses        933      933           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cypress
Copy link

cypress bot commented Apr 13, 2025

datalab    Run #4008

Run Properties:  status check passed Passed #4008  •  git commit 95398d546f ℹ️: Merge b253762023fd368673d9e17d376e5d9fe523b53f into 4d53d7f10c6dae206bd59bd51c2c...
Project datalab
Branch Review ml-evs/chemform
Run status status check passed Passed #4008
Run duration 06m 28s
Commit git commit 95398d546f ℹ️: Merge b253762023fd368673d9e17d376e5d9fe523b53f into 4d53d7f10c6dae206bd59bd51c2c...
Committer Matthew Evans
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 189
View all changes introduced in this branch ↗︎

@BenjaminCharmes
Copy link
Contributor

@ml-evs I've pushed my changes for #1337 in this PR. If you'd prefer to do it in two separate PRs, I can create a new one.

@ml-evs ml-evs marked this pull request as ready for review October 28, 2025 10:36
@ml-evs ml-evs self-assigned this Oct 28, 2025
@ml-evs ml-evs removed the on-hold label Oct 28, 2025
@ml-evs ml-evs changed the title [WIP] Improving formatting of valid chemical formulae Improving formatting of valid chemical formulae Oct 28, 2025
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.

Adding subscripts and special characters/symbols to the chemical formula

3 participants