(I tried to send this yesterday, but it failed because its original title confused the server -- I'm trying again.)

At 7:04 AM -0400 8/14/03, Patrick Gormley wrote:
I am a chemistry teacher and would like to design a macro that would take text like Na2SO4 and have the macro drop all numbers to subscripts...

Here is a trio of scripts I'm working on. They seem to work for a couple of simple files, making from a file foo.rtf a new file foo.rtf.subbed.rtf with numbers subscripted in molecular formulas. Clearly the routine to name the new output file needs improvement -- one would want a name such as 'foo-subbed.rtf' not 'foo.rtf.subbed.rtf' -- but it's a start. Please supply a few files with molecular formulas (even if you don't want to use this method, it's an educational experience for me.) -- Jonathan


-----------------------------------------------------------------------------
1. AppleScript droplet "subscriptwrapper":

(*
Droplet to send a file to the "dochemsubscripts.pl":
The file is assumed to be an .rtf file containing
molecular formulas.

Can also be double-clicked.

J. Levi 8/2003.
*)

on open {doclist}
        sendtoshell(item 1 of (doclist as list))
end open

on run {}
        set f to choose file with prompt "RTF file to be subscripted?"
        sendtoshell(f)
end run

on sendtoshell(f)
        tell application "Finder" to �
                set fpath to quoted form of POSIX path of (f as Unicode text)
        tell application "Terminal"
                activate
                do script ("subscriptwrapper.sh " & fpath)
        end tell --Terminal
end sendtoshell

-----------------------------------------------------------------------------
2. Shell script "subscriptwrapper.sh"

#!/sw/bin/bash
# subscriptwrapper.sh -- sends an rtf file containing chemical
# formulas to dochemsubscripts.pl

OUTFILE=${1//\.rtf/-subbed.rtf}
dochemsubscripts.pl < $1 > $OUTFILE
open $OUTFILE

-----------------------------------------------------------------------------
3. Perl script "dochemsubscripts.pl"

#!/sw/bin/perl
# dochemsubcripts.pl -- perl script to sniff out molecular formulas in an
# RTF file and insert subscript tags for the numbers. JL 8/2003

@myfile=<STDIN>;
foreach $s (@myfile){
        $s=~s/([A-Z][a-z]?)([0-9]+)/$1\\sub $2\\nosupersub /g;
        print $s;
}

---------------------------------------------------
The Nisus Interactive List
[EMAIL PROTECTED]

Searchable archives:
http://www.mail-archive.com/nisus-interactive%40nisus.com/

To unsubscribe from this list please send a message with "unsubscribe
nisus-interactive" in the body of the email to [EMAIL PROTECTED]




Reply via email to