From: Matt McCutchen Date: Tue, 8 Sep 2020 00:16:13 +0000 (-0400) Subject: Import SuperbChemistry version 1 X-Git-Url: https://mattmccutchen.net/superbchemistry/superbchemistry.git/commitdiff_plain/071359bbe67282d6ae69693d0596b1f03476fcc8 Import SuperbChemistry version 1 Modification time: 2007-02-04 19:38:04 -0500 --- 071359bbe67282d6ae69693d0596b1f03476fcc8 diff --git a/SuperbChemistry-test.odt b/SuperbChemistry-test.odt new file mode 100644 index 0000000..49b74ad Binary files /dev/null and b/SuperbChemistry-test.odt differ diff --git a/extension/META-INF/manifest.xml b/extension/META-INF/manifest.xml new file mode 100644 index 0000000..184035e --- /dev/null +++ b/extension/META-INF/manifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/extension/SuperbChemistry/Main.xba b/extension/SuperbChemistry/Main.xba new file mode 100644 index 0000000..e5a5a82 --- /dev/null +++ b/extension/SuperbChemistry/Main.xba @@ -0,0 +1,76 @@ + + +' Matt McCutchen's SuperbChemistry for OpenOffice, version 1 +' +' Applies superscript and subscript formatting to chemical formulas in text. +' +' Examples: +' C12345 ==> C_{12345} +' H+ ==> H^+ +' Cl- ==> Cl^- +' Fe3+ ==> Fe^{3+} +' C1232+ ==> C_{123}^{2+} +' N2- ==> N^{2-} +' Exception for O and ): NO3- ==> NO_3^-, Fe(OH)2- ==> Fe(OH)_2^- +' But still O12 ==> O_{12} +' 4+ ==> 4+ (not a superscript by itself) + +' Regular expression replace in the document, +' creating superscripts if superb > 0 or subscripts if superb < 0. +' Used by SuperbChemistry. +sub SuperbReplace(doc as object, searchStr as string, replaceStr as string, superb as integer) + +dim rd as object +rd = doc.createReplaceDescriptor() + +rd.SearchRegularExpression = true +rd.setSearchString(searchStr) +rd.setReplaceString(replaceStr) + +if superb <> 0 then + dim replaceAttrs(1) as new com.sun.star.beans.PropertyValue + replaceAttrs(0).Name = "CharEscapement" + if superb > 0 then + replaceAttrs(0).Value = 33 + else + replaceAttrs(0).Value = -9 + end if + replaceAttrs(1).Name = "CharEscapementHeight" + replaceAttrs(1).Value = 58 + rd.setReplaceAttributes(replaceAttrs) +end if + +doc.replaceAll(rd) + +end sub + +' Formats the current document +sub FormatDocument + +' Mark candidate superscripts so we know they follow letters or ). +SuperbReplace(ThisComponent, "[A-Za-z)][0-9]*[-+−]", "&@l@", 0) + +' O and ) grab a single digit. Block it off from becoming a superscript. +SuperbReplace(ThisComponent, "[O)][0-9]", "&@n@", 0) + +' Real minus signs in superscripts. +SuperbReplace(ThisComponent, "-@l@", "−@l@", 0) + +' Make superscripts: at most one digit. +SuperbReplace(ThisComponent, "[0-9]?[−+]@l@", "@q@&", 1) + +' Remove the O and ) markers. +SuperbReplace(ThisComponent, "@n@", "", 0) + +' Mark off subscripts: as many digits as we can still grab. +SuperbReplace(ThisComponent, "[A-Za-z)][0-9]+", "&@n@", 0) + +' Make subscripts. +SuperbReplace(ThisComponent, "[0-9]+@n@", "&", -1) + +' Clean up all markers. +SuperbReplace(ThisComponent, "@[lnq]@", "", 0) + +end sub + + \ No newline at end of file diff --git a/extension/SuperbChemistry/dialog.xlb b/extension/SuperbChemistry/dialog.xlb new file mode 100644 index 0000000..8d924f4 --- /dev/null +++ b/extension/SuperbChemistry/dialog.xlb @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/extension/SuperbChemistry/script.xlb b/extension/SuperbChemistry/script.xlb new file mode 100644 index 0000000..815dca2 --- /dev/null +++ b/extension/SuperbChemistry/script.xlb @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file