X-Git-Url: https://mattmccutchen.net/superbchemistry/superbchemistry.git/blobdiff_plain/95510495d953a0e2476569a77d0dd0b1b92f35f6..de16a29a63f3776841af849a99dc65e1aa509ca2:/extension/SuperbChemistry/Main.xba diff --git a/extension/SuperbChemistry/Main.xba b/extension/SuperbChemistry/Main.xba index 33ccbd1..3b0640e 100644 --- a/extension/SuperbChemistry/Main.xba +++ b/extension/SuperbChemistry/Main.xba @@ -1,6 +1,6 @@ -' Matt McCutchen's SuperbChemistry for OpenOffice, version 2 +' Matt McCutchen's SuperbChemistry for OpenOffice, version 2.1 ' ' Applies superscript and subscript formatting to chemical formulas in text. ' @@ -72,12 +72,13 @@ sub FormatDocument ' for further processing. If the replacement text could use ' backreferences, this would be easier. -' Tag candidate quantity/charges following symbols or ). -SuperbReplace(ThisComponent, "([A-Z][a-z]?|[\])}])[0-9]*[-+−]", "&@g@", 0) - -' Disqualify + and - in compound words, etc. -SuperbReplace(ThisComponent, "@g@[[({A-Za-z0-9<>]", "@G@&", 0) -SuperbReplace(ThisComponent, "@G@@g@", "", 0) +' Tag candidate charges following symbols or ), but not in compound words, etc. +' Acceptable next character. (Has to be before end of line to avoid matching @g@ tag itself.) +SuperbReplace(ThisComponent, "([A-Z][a-z]?|[\])}])[0-9]*[-+−][^[({A-Za-z0-9<>]", "&@G@", 0) +' Retag in front. +SuperbReplace(ThisComponent, ".@G@", "@g@&", 0) +' End of line. +SuperbReplace(ThisComponent, "([A-Z][a-z]?|[\])}])[0-9]*[-+−]$", "&@g@", 0) ' O and )]} grab a single digit as quantity. SuperbReplace(ThisComponent, "[\])}O][0-9]", "&@n@", 0)