Several months ago I created a macro for NWX to accomplish a macro I created for NW Classic that would allow chemistry instructors to enter something like Na2(SO4) or SO42- while creating a document and then with one execution have the macro subscript and superscript the appropriate numbers. I have since added one more line to this macro (right above the "print $s" statement) so that power-of-ten numbers like 6.02 X 1023 will also be formatted correctly. The revised macro is below. In my testing it works most of the time. It will sometimes fail if a chemical formula is quite complex. Feel free to use it or to suggest improvements.

#!/usr/bin/perl
#Nisus Macro Block
#source front
#destination new
#Send Text as RTF
#End Nisus Macro Block

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

# end of script

--
Patrick Gormley
Lapeer East High School
Lapeer MI 48446
http://chem.lapeer.org
-Knowledge is proud it knows so much; wisdom is humble it knows no more. --William Cowper
---------------------------------------------------
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 your first name your last name" in the body of the email to
[EMAIL PROTECTED]




Reply via email to