scientific macro
Page 1 of 1

Author:  patrickg [ 2007-05-30 07:05:25 ]
Post subject:  scientific macro

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.


#Nisus Macro Block
#source front selection
#destination front selection
#Send Text as RTF
#End Nisus Macro Block

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[code][/code]

Author:  martin [ 2007-05-30 16:02:36 ]
Post subject: 

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 :)

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group