Copy link to clipboard
Copied
Good afternoon,
I am looking for a simple grep script to find chemical compounds without subscripts and change them to subscripts.
They could be with and without parenthesis (C2H4).
Many thanks in advance.
Copy link to clipboard
Copied
Perhaps this thread will be useful:
https://community.adobe.com/t5/indesign-discussions/subscript-basic-chemical-formulas/m-p/7974202
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Use a GREP Style and this expression:
(?<=\u\l)\d+|(?<=\u)\d+
For the nerds: I couldn’t get the OR to work within one PLB.
Copy link to clipboard
Copied
How about:
(?<=\u\l?)\d+
But I'm on my phone so can't check - "?" means "zero or one" so should work?
You are right - looks like "?" can't be used inside Positive LookBehind either.
Copy link to clipboard
Copied
@ronnag74426794
https://community.adobe.com/t5/indesign-discussions/underline-molecular-formulae-of-chemistry-like-h...
Copy link to clipboard
Copied
Just to add to other suggestions (I tried them and didn't quite work forme for some reason)
(?<=(\l|\u))\d+
But Caveat is that it will find other things that you might not want found.
Like C1 and C2 in the example
Copy link to clipboard
Copied
A tip for typographic consideration that you define the subscript as an OpenType subscript (in the Character Style) if the font has it available. This will look much nicer.
Copy link to clipboard
Copied
Most comprehensive one I've seen was written over at CreativePro.com, and this uses GREP styles to do this automatically, but best GREP style is in the comments section by Laurent Tournier: https://creativepro.com/auto-format-superscript-and-subscript-numbers-using-grep-styles/
Copy link to clipboard
Copied
Our colleague Laurent Tournier worked on this GREP fifteen years ago 😉
I guess this compact form should sum it up:
((?<=Uu[bhopqst])|(?<=A[cglmrstu]|B[aehikr]|C[adeflmnorsu]|D[bsy]|E[rsu]|F[emr]|G[ade]|H[efgos]|I[nr]|Kr|L[airu]|M[dgnot]|N[abdeiop]|Os|P[abdmortu]|R[abefghnu]|S[bcegimnr]|T[abcehilm]|Xe|Yb|Z[nr])|(?<=[BCFHIKNOPSUVWY]))[1-9]\d{0,1}
(Edit: if you need more than two digits change the ending \d{0,1} into \d{0,2} or more — I don't know whether it's chemically relevant though.)
Best,
Marc