Import SuperbChemistry version 1
authorMatt McCutchen <matt@mattmccutchen.net>
Tue, 8 Sep 2020 00:16:13 +0000 (20:16 -0400)
committerMatt McCutchen <matt@mattmccutchen.net>
Tue, 8 Sep 2020 00:16:13 +0000 (20:16 -0400)
Modification time: 2007-02-04 19:38:04 -0500

SuperbChemistry-test.odt [new file with mode: 0644]
extension/META-INF/manifest.xml [new file with mode: 0644]
extension/SuperbChemistry/Main.xba [new file with mode: 0644]
extension/SuperbChemistry/dialog.xlb [new file with mode: 0644]
extension/SuperbChemistry/script.xlb [new file with mode: 0644]

diff --git a/SuperbChemistry-test.odt b/SuperbChemistry-test.odt
new file mode 100644 (file)
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 (file)
index 0000000..184035e
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest:manifest>
+ <manifest:file-entry manifest:full-path="SuperbChemistry/" manifest:media-type="application/vnd.sun.star.basic-library"/>
+</manifest:manifest>
\ No newline at end of file
diff --git a/extension/SuperbChemistry/Main.xba b/extension/SuperbChemistry/Main.xba
new file mode 100644 (file)
index 0000000..e5a5a82
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
+<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Main" script:language="StarBasic">&apos; Matt McCutchen&apos;s SuperbChemistry for OpenOffice, version 1
+&apos;
+&apos; Applies superscript and subscript formatting to chemical formulas in text.
+&apos;
+&apos; Examples:
+&apos; C12345 ==&gt; C_{12345}
+&apos; H+ ==&gt; H^+
+&apos; Cl- ==&gt; Cl^-
+&apos; Fe3+ ==&gt; Fe^{3+}
+&apos; C1232+ ==&gt; C_{123}^{2+}
+&apos; N2- ==&gt; N^{2-}
+&apos; Exception for O and ): NO3- ==&gt; NO_3^-, Fe(OH)2- ==&gt; Fe(OH)_2^-
+&apos; But still O12 ==&gt; O_{12}
+&apos; 4+ ==&gt; 4+ (not a superscript by itself)
+
+&apos; Regular expression replace in the document,
+&apos; creating superscripts if superb &gt; 0 or subscripts if superb &lt; 0.
+&apos; 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 &lt;&gt; 0 then
+       dim replaceAttrs(1) as new com.sun.star.beans.PropertyValue
+       replaceAttrs(0).Name = &quot;CharEscapement&quot;
+       if superb &gt; 0 then
+               replaceAttrs(0).Value = 33
+       else
+               replaceAttrs(0).Value = -9
+       end if
+       replaceAttrs(1).Name = &quot;CharEscapementHeight&quot;
+       replaceAttrs(1).Value = 58
+       rd.setReplaceAttributes(replaceAttrs)
+end if
+
+doc.replaceAll(rd)
+
+end sub
+
+&apos; Formats the current document
+sub FormatDocument
+
+&apos; Mark candidate superscripts so we know they follow letters or ).
+SuperbReplace(ThisComponent, &quot;[A-Za-z)][0-9]*[-+−]&quot;, &quot;&amp;@l@&quot;, 0)
+
+&apos; O and ) grab a single digit.  Block it off from becoming a superscript.
+SuperbReplace(ThisComponent, &quot;[O)][0-9]&quot;, &quot;&amp;@n@&quot;, 0)
+
+&apos; Real minus signs in superscripts.
+SuperbReplace(ThisComponent, &quot;-@l@&quot;, &quot;−@l@&quot;, 0)
+
+&apos; Make superscripts: at most one digit.
+SuperbReplace(ThisComponent, &quot;[0-9]?[−+]@l@&quot;, &quot;@q@&amp;&quot;, 1)
+
+&apos; Remove the O and ) markers.
+SuperbReplace(ThisComponent, &quot;@n@&quot;, &quot;&quot;, 0)
+
+&apos; Mark off subscripts: as many digits as we can still grab.
+SuperbReplace(ThisComponent, &quot;[A-Za-z)][0-9]+&quot;, &quot;&amp;@n@&quot;, 0)
+
+&apos; Make subscripts.
+SuperbReplace(ThisComponent, &quot;[0-9]+@n@&quot;, &quot;&amp;&quot;, -1)
+
+&apos; Clean up all markers.
+SuperbReplace(ThisComponent, &quot;@[lnq]@&quot;, &quot;&quot;, 0)
+
+end sub
+
+</script:module>
\ No newline at end of file
diff --git a/extension/SuperbChemistry/dialog.xlb b/extension/SuperbChemistry/dialog.xlb
new file mode 100644 (file)
index 0000000..8d924f4
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
+<library:library xmlns:library="http://openoffice.org/2000/library" library:name="SuperbChemistry" library:readonly="false" library:passwordprotected="false"/>
\ No newline at end of file
diff --git a/extension/SuperbChemistry/script.xlb b/extension/SuperbChemistry/script.xlb
new file mode 100644 (file)
index 0000000..815dca2
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
+<library:library xmlns:library="http://openoffice.org/2000/library" library:name="SuperbChemistry" library:readonly="false" library:passwordprotected="false">
+ <library:element library:name="Main"/>
+</library:library>
\ No newline at end of file