# Feature request: implementation of the mhchem extension to KaTex

**URL:** <https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765>\
**Category:** Features\
**Created:** [4 October 2019 11:45 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765 "2019-10-04T11:45:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nafets](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@nafets](https://discourse.joplinapp.org/u/nafets)\
**Post date:** [4 October 2019 11:45 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/1 "2019-10-04T11:45:55Z")

</div>

It would be very helpful if the mhchem extension to the KaTex editor could be added to Joplin.  
So that it is easy to add chemical reactions when using Joplin for laboratory note-taking.  
Best,  
Stefan

---

<div class="post-metadata">

**Author:** ![CalebJohn](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/calebjohn/32/356_2.png) [@CalebJohn](https://discourse.joplinapp.org/u/CalebJohn)\
**Post date:** [4 October 2019 16:14 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/2 "2019-10-04T16:14:17Z")

</div>

@laurent would you accept a pull request for this? From the [Katex plugin page](https://github.com/KaTeX/KaTeX/blob/master/contrib/mhchem/README.md) it looks like we’ll just need to include another script to add support for this.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [4 October 2019 16:37 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/3 "2019-10-04T16:37:52Z")

</div>

Yes if you can figure it out I’d accept a PR. I think it would be a bit more complicated as we need to include the script conditionally depending on whether Katex is enabled or not. Also we’d need to somehow bundle this script with the two apps (mobile and desktop) as it needs to work offline too.

If possible I think the best way would be to include and run this plugin at rendering time (like Katex now), and that way we don’t need to load an external script in the HTML view, and it works directly in both desktop and mobile.

---

<div class="post-metadata">

**Author:** ![CalebJohn](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/calebjohn/32/356_2.png) [@CalebJohn](https://discourse.joplinapp.org/u/CalebJohn)\
**Post date:** [5 October 2019 17:44 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/4 "2019-10-05T17:44:34Z")

</div>

Thanks for the notes @laurent I spent a couple of hours this morning trying to get it working, but it looks like the plugin doesn’t properly support node yet…  
We might need to wait for this plugin to mature before adding it.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [5 October 2019 21:28 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/5 "2019-10-05T21:28:29Z")

</div>

Ok thanks for checking @CalebJohn, let’s wait and see if it gets improved then.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [12 October 2019 22:27 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/6 "2019-10-12T22:27:34Z")

</div>

I’ve ended up wrapping their JS file [in a function](https://github.com/laurent22/joplin/commit/9f5da92ab4a4c48e34688a4fff72598311cd5165) so that it can be imported into Joplin, so next version will support mhchem.

![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/1/14319d3e4f0bd84f84f2b948f5653ff3829fe4a1.png)

---

<div class="post-metadata">

**Author:** ![CalebJohn](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/calebjohn/32/356_2.png) [@CalebJohn](https://discourse.joplinapp.org/u/CalebJohn)\
**Post date:** [12 October 2019 23:00 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/7 "2019-10-12T23:00:36Z")

</div>

Much easier than I realized! Looks like I need to brush up on my javascript! Nice work @laurent

---

<div class="post-metadata">

**Author:** ![nafets](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@nafets](https://discourse.joplinapp.org/u/nafets)\
**Post date:** [14 October 2019 13:04 UTC](https://discourse.joplinapp.org/t/feature-request-implementation-of-the-mhchem-extension-to-katex/3765/8 "2019-10-14T13:04:34Z")

</div>

Sound great @laurent!  
Looking forward to the new version 😉  
Thanks!
