Thursday, July 14, 2016

Add or remove subscripts in Google Sheets



Hello fans (do you use singular or plural when you have zero fans?)! Wrote a little script to add or remove subscripts in a Google Sheet.

I found this useful because I made an interactive equation balancing sheet and I was typing in a lot of chemical formulas, but getting tired of the fact that I had to keep copying and pasting the unicode characters for subscripts.

Here's the code for it:
https://docs.google.com/document/d/1ajGXGrvnxXNLgslz9MCE-6nUBsIoilAUJSu-Fq0eN2M/edit?usp=sharing

Example: H2SO4 gets converted to H₂SO₄. I also made another script that will de-convert back to non-subscript. The advantage to this is that you can search what you made, which is difficult with the unicode subscripts. You'd deconvert everything back to no subscripts, search for what you want, and re-convert it back.

Caution: this might mess with formulas you have in your sheet. 

A note about my programming skillz: I have none. I used a kludg-y method to deal with the coefficients (so that they are not subscripted) and I'm not entirely thrilled with it. It won't subscriptify anything with a coefficient between 0-39, but beyond that (which I've never seen, to be honest) it might get funky. So...have fun with that. Anyone with a suggestion for how to improve my regular expression code will get a free drink from me (note: 100% of the drink will be water, and you will have to procure it from your local water supply yourself). 

No comments:

Post a Comment