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

mhchem: Charge not displayed properly after numerical element subscript #223

Open
twoframesperminute opened this issue Apr 8, 2022 · 2 comments

Comments

@twoframesperminute
Copy link

In mhchem, the charge is propertly displayed when it follows an element with a numerical subscript.
E.g. in \ce{HCO3- + H+ <-> H2CO3} the negative charge of the HCO3 molecule is rendered as a minus sign, not a negative charge, while the positive charge after the H molecule is rendered properly.

In the mhchem filter, a Charge can only follow a letter (AZ or az) or a bracket/brace/parenthesis, not a number. I think changing line 108 and 109 to the line below (adding R"09") fixes the issue, but I'm not well-versed enough in Lua/Lpeg to see whether this adds problems down the line.

Charge = B(R"AZ" + R"az" + R"09" + S")]}") * (S"+-") * #-R"AZ" /
    render.superscript ;

Screenshot 2022-04-08 at 16 55 19

@jgm
Copy link
Member

jgm commented Apr 8, 2022

That seems reasonable to me.
Maybe you could modify your filter along these lines, use it for a while, and inspect the results to make sure nothing unexpected happens. It could also be useful to add a new test case for this to test.txt, and to run the modified filter on test.txt to make sure nothing changes for the other formulas.

If you can test it out in this way, I'd be happy to incorporate the change.

@twoframesperminute
Copy link
Author

I will try it out in my current project. I will also add test cases (copied from the mhchem LaTeX package documentation) and check the current test cases. If it seems OK, I will create a pull request.

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