***************
#!/usr/bin/perl #Nisus Macro Block #source front #destination new #Send Text as RTF #End Nisus Macro Block
# dochemsubcripts.pl -- perl script to sniff out molecular formulas in an
# RTF file and insert subscript tags for the numbers, superscript tags for
# ionic signs. JL 8/2003
@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;
print $s;
}# end of script
***************
On Sunday, August 17, 2003, at 07:03 PM, Jonathan Levi, M.D. wrote:
Hi Patrick,
I'm glad that my macro seems to be working at least fairly well. Actually, I have the Nisus Writer Express demo in my office, and I'm impressed that when I put my dochemsubscripts.pl macro into a file, copied your formulas into another file and ran the macro, it worked! (My first Nisus Writer Express macro.)
The problem, as I see it, is that there appears to be a syntactic ambiguity in your formulas. In your last line "Ni(CN)42- ", for example, it could be that the the four and the two should both be subscripted, the four should be subscripted and the two should be superscripted, or both digits should be superscripted, along with the minus sign. If we could have some kind of convention as to which digits go with the proceeding atom or group and which digits go with the following sign, we could build that convention into the macro. However, I can't see a convention off the top of my head that would be foolproof.
A better tactic, if you're willing, would be to introduce an extra character, such as a colon, in front of the terminal sign and any digits meant to go with it. Then, for instance, "S:2-" would mean a single sulfur atom, doubly ionized, whereas "S2:-" would mean a molecule of two sulfur atoms, singly ionized. (This is hypothetical; I don't know if either of these forms occurs in nature!) We could further have the understanding that if there is no colon, than only the terminal sign goes into the superscript; then you wouldn't have to write a colon unless you specifically wanted to put the last digit or digits into the superscript. The colon would nly be a directive to the macro, of course; it would disappear in the final expression. How does such an idea strike you?
As to your comment about having to create a whole new file: the thing to do would probably be to go back to my previous version of the macro that embodied Kino's directives for cutting and pasting into the current file, rather than creating a new one. It may turn out, however, that the entire RTF code will be shown as text, rather than being turned into appropriate formatting.
For what it's worth, my personal bias would be to create a new file; that way, if something went wrong, you would still have the untouched original to try again with. Unfortunately, I didn't redirect that version to my office, so I don't have it here to play with, and I don't know the syntax of Nisus macro directives well enough yet (after a single effort!) to make them up de novo.
Best wishes,
Jonathan
Addendum: I discovered that I had indeed redirected the version of my macro with the copy-and-paste directives to my office, so I saved it as a Nisus macro and tried it on a selection from Patrick's file. It didn't work, because Nisus incorporated the RTF tags into the file's actual text, rather than using them as formatting information. _Nisus_Team,_please_take_note_: there should be some way to notify the Clipboard that RTF tags should be used as formatting information. This would be analogous to showing styled text and modifying that styling in the clipboard window.
At 2:49 PM -0400 8/17/03, Patrick Gormley wrote:I tried the script posted here by Jonathan by creating a file that contained many possible combinations of subscripts and superscripted formulas. These are below:
Ca(SO4(H2O)2 Ca2+ S2- 6H2O 6Ca2+ 4S2- SO42- 3SO42- 6Cr2O72- Cu(H2O)62+ Ni(CN)42-
I found that the original code did not always handle superscripts well so I made one change to the first line (changed the parans). This worked better. I then added another line of code and placed this first. Now everything works as expected except for the last two formulas above. The six and the 4 need to be subscripted and the 2+ and 2- need to be superscripted. The revised macro is below. Maybe someone can make the necessary revisions to get it to work with the last two formulas.
##My revisions #!/usr/bin/perl #Nisus Macro Block #source front #destination new #Send Text as RTF #End Nisus Macro Block
### dochemsubscripts.pl
# dochemsubcripts.pl -- perl script to sniff out molecular formulas in an
# RTF file and insert subscript tags for the numbers, superscript tags for
# ionic signs. JL 8/2003
@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/([A-Z][a-z]?)([0-9]+)/$1\{\\sub $2\}/g; $s=~s/\)([0-9]+)/\)\{\\sub $1\}/g; print $s; }
# end of script
--------------------------------------------------- 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]
-- Patrick Gormley Lapeer East High School Lapeer MI 48446 http://chem.lapeer.org ---What in the world isn't chemistry!
--------------------------------------------------- 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]
