mathjax / MathJax-src

MathJax source code for version 3 and beyond

Home Page:https://www.mathjax.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use mhchemParser written in TypeScript

mhchem opened this issue · comments

I converted the mhchem parser from JavaScript to TypeScript. I would suggest the following actions

I am new to TypeScript, so please give me some hints for improvement. For instance, I am not sure how your tool chain works and if I should somehow namespace all the type definitions. If you would find a solution for the @ts-ignores I had to use for the deletes, that would be appreciated.

(As the parser is a small algorithm working on a large data structure, the conversion was a little bit unconventional, I guess. Basically, most of the type checking works on data structure strings, to make sure that, for instance, functions with two parameters are only paired with RegExps that have two ()-groups.) I did a straight-forward conversion. Later on, I will have a look at replacing string ids with enums.

  • 2. I implement the suggested changes and publish mhchemParser v4.0.0

  • 3. You copy mhchemParser.ts v4.0.0 to MathJax-src and modify your toolchain.

I don't want to create a pull request, because your toolchain needs some adaptations. For instance, package-lock.json's last change was about mhchem.

Thanks for doing this conversion! I will take a look at it as soon as I can.

For 2, do you mean that you will publish an npm package for mhchemParser? That would be great, as we would be able to just include it in our package.json and link to your npm version directly. It would not need to be included in the MathJax-src tree at all.

For 2, when I wrote "publish" I thought about adding a proper version number and a GitHub release tag, nothing more. To be honest, I really appreciated the "common sense check"* when an experienced developer took my parser file and copied it to MathJax. (* I hope this word conveys what I want to say.) On the other hand, if you say an npm package would be the best way to go, I could do it.

Any updates, @dpvc ?

Sorry for the long delay in this. your original message came when I was just starting up teaching int he fall. My first remote experience, which took all my free time. I'm afraid your request fell through the cracks at that time.

I will try to get to this next week. We are in process for a 3.1.3 release, and an update to mhchem would be a good addition.

Well, at long last, I was able to look through the code. I don't have any problems with what I saw, though I admit that I didn't go over everything in detail. I did hook it into MathJax v3 (locally) to try it out, and everything seems to work fine.

I mentioned above the idea of using an npm package as the means of including this into MathJax. As we move forward with more extensions, and especially ones developed by others, copying the external code into the MathJax core will become more difficult from a maintenance standpoint, so we would like to go with npm packages as the way to manage that. That makes it very easy for us to include your code.

One possible advantage to that approach would be that, if you included the webpacked extension in your npm package, it would automatically be available on cdn.jsdeliver.net whenever you published the npm package, so you could update the extension without having to wait for MathJax to do so. We can talk about that if you want to go that route.

Thanks a lot. I'd be happy to create an npm package. Is the file structure and the API okay for you?

Yes, those will work. Thanks for being flexible about this!

Any news on an npm package for this? We are putting the final touches on v3.1.3, and I'd like to include your new version. If necessary, I can copy the code, as you initially suggested, for this release, and then move to the npm package for v3.2.

I needed some learning. I hope everything is okay with npm package mhchemparser
https://www.npmjs.com/package/mhchemparser
https://github.com/mhchem/mhchemParser

This looks good. I am easily able to incorporate it into MathJax now. Thanks a lot!

This new version has been included in 3.1.3 via the npm package.

@mhchem, it turns out that we are having an issue with the mhchem npm package. You have targeted es6, while MathJax is still using es5, and that means people need to change their MathJax server-side scripts to use es6 features.

Would you be willing to change from es6 to es5 (or to include both in your npm package)? That would make things easier for MathJax. For now, I had to roll back the use of the npm package, and temporarily added the .ts file into MathJax's mhchem directory directly (as you originally envisioned). But I'd still like to go to using mhchemparser as an npm package.

@dpvc Of course. I switched to es5. New packages uploaded to npm and GitHub.

Thanks so much!