Superscripts and Subscripts

I am sure this is possible and it is just a coding thing I don’t know but how can I add a superscript or subscript for chemical formulas into a snippet? for example Cl2

Hi Amanda, this has been asked before and this is currently the best way to achieve it that I’m aware of:

https://community.textexpander.com/t/preserve-perfect-formatting-with-this-javascript-html-snippet-hack/

I would be happy to help you create the Snippet you need.

1 Like

Hi @AmandaEdson ,

I saw your question and I thought a visual might be helpful in addition to the community post.

You can see an example of how to do this in this video :backhand_index_pointing_right: https://share.zight.com/YEuYKnp1

While the example is different the concept and steps are the same.

If you still need a hand don’t hesitate to reach out to us at support@textexpander.com where you can get a much faster response :slight_smile:

I hope this helps, and I hope you have a great day!

All the best,
-Nick

1 Like

@NickKreiter thanks so much! That helps a lot because I am not adept at coding but have picked up bits and pieces which makes it even harder since I don’t know what I don’t know :smiley: Also I am going to play around because editing in word allows me to do a lot of the things I have been wishing for that have been tricky. I am excited to give it a try!

1 Like

I’m so glad to hear this helped!

Let us know if you get stuck :grinning_face:

Hi @AmandaEdson,

I remembered helping you here a little while back and I just created a new snippet that I think will really help you out.

This JavaScript Snippet will allow you to type something like H2SO4, and it’ll expand as H₂SO₄. One snippet handles any compound this way, so you won’t need to build one per formula.

Here’s what to do :slight_smile:

  1. Create a new snippet and set the content type to JavaScript.
  2. Click the Fill-ins button in the editing bar → insert a Single Line Field → name it Formula.
  3. Paste this script:
var formula = "%fill:Formula%";
var subs = {"0":"₀","1":"₁","2":"₂","3":"₃","4":"₄","5":"₅","6":"₆","7":"₇","8":"₈","9":"₉"};
formula.replace(/[0-9]/g, function(d){ return subs[d]; });
  1. Give it an abbreviation, like ;sub.

When you expand it, a box will pop up asking for “Formula” just type out what you need and just like that, you’re ready to go!

Let me know if you need any help

All the best,

  • NIck
1 Like

@NickKreiter I just got back from leave so I had missed this, but this is so awesome thanks!!