scientific macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
patrickg
Posts: 5
Joined: 2004-09-13 05:41:49

scientific macro

Post by patrickg »

I'm a chemistry teacher and one of the things I've always wanted to do with NW Express (and now with NW Pro) is duplicate a macro that I created for NW Classic that would take care of subscripting numbers in chemical formulas, superscripting powers of 10, and superscripting charges on chemical ions. The following macro seems to do this with a great deal of accuracy. I offer it to anyone who has need for it.

Powers of 10 should be entered as 6.2 X 106 or 6.2 X 10-6
Chemical formulas should be entered as Fe2(CrO4)3 or Fe4[Fe(CN)6]3
Ions as Fe(CN)64-

When you are done, highlight the entire block of text (or document if there are a lot of them) and select your macro from the "Macro" menu.

To create the macro copy the text below and follow the directions given in the documentation of either NW Express or NW Pro.

--Enjoy



#Nisus Macro Block
#source front selection
#destination front selection
#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
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

Thanks for sharing. I don't work with scientific formulas, but there's always been a special place in my heart for properly sized and baselined numbers :)
Post Reply