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

Charges not behaving as expected #9

Open
wweatherall opened this issue Jul 5, 2024 · 2 comments
Open

Charges not behaving as expected #9

wweatherall opened this issue Jul 5, 2024 · 2 comments

Comments

@wweatherall
Copy link

There is an issue when one tries to add charges. A single charge works fine, but when you try to add multiple you get issues.

image
image
image

@jamesrswift
Copy link
Owner

Regex doesn't have a concept of valence electrons so you'll probably want to either format it manually or use brackets

@wweatherall
Copy link
Author

wweatherall commented Jul 7, 2024

How do you use brackets with it? Or do you mean bracket with #super[]

Having looked at it, your package knows what elements are. Would a regex expression that knew if you had a charge and it would know it would be, be possible?

Like metals are all fairly simple because they aren't diatomic. If there is metal, a number, and then a charge, it would always be an ion.

For the nonmetal ions, they would need to be disambiguated from their polyatomic forms but if the pattern is single nonmetal, a number, then a charge then it would be a charge on an ion.

For polyatomic ions, I wonder if a mcchem style of using carets would do the trick. Beyond what they do, If there is any number between the caret and the charge, I would think to would only possibly be a charge and so that pattern could safely be lifted.

Here is a bit of code that explains what I mean about the carets:


#let ion-fm = regex("(\p{upper}\p{lower}?)(\d+)?(\^(\d*))?([-+])?")

#show ion-fm: it=> {

    let (sm, atom-n, _, ..chg) = it.text.match(ion-fm).captures



    sm

    sub(atom-n)

    super(chg.join())

}

CO2

CO3^2-

Cl3-

H2O

H3O+

2SO4^2- + H2O - 

CO2

CO3^2-

Cl-

H2O

H3O+

Ca^2+

2SO4^2- 

CO3^2-

NH4+

NO2^-

NO3^-

SO3^2-

SO4^2-

HSO4^-

S2O3^2-

C2O4^2-

OH-



PO3^3-

PO4^3-

HPO4^2-

H2PO4^-

ClO4-

ClO3-

ClO2-

ClO-

BrO3^-

IO3^-

CH3COO^-

S2O3^2-

CH3COO^-

That said wouldn't it be cool if it had like a list in your repository that people could add ions to with the correct formatting that is triggered by typing them in the laziest way possible as I did in my example from earlier.

Anyway, thanks for the response. I'm really satisfied with your package so far.

One final thing, I think

#show "<=>": sym.harpoons.rtlb

//to make possible 

#"<=>"

would be a nice little perk in your package.

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