Hi Patrick,

My apologies for not looking more closely at your revision of my script.

I've looked at it now, and still have my questions regarding syntactic ambiguity. First, let me list the substitution statements from your modification vs my original; I am inserting line numbers:

Your revision:
1.      $s=~s/([A-Z][a-z]?[0-9]*)([0-9][+-])/$1\{\\super $2\}/g;
2.      $s=~s/([A-Z][a-z]?)([0-9]*[+-])/$1\{\\super $2\}/g;
3.      $s=~s/\)([+-])/\)\{\\super $1\}/g;
4.      $s=~s/([A-Z][a-z]?)([0-9]+)/$1\{\\sub $2\}/g;
5.      $s=~s/\)([0-9]+)/\)\{\\sub $1\}/g;

My original:
1.      $s=~s/([A-Z][a-z]?[0-9]*)([0-9][+-])/$1\{\\super $2\}/g;
2.      $s=~s/([A-Z][a-z]?)([0-9]*[+-])/$1\{\\super $2\}/g;
3.      $s=~s/\)([+-])/\)\{\\super $1\}/g;
4.      $s=~s/\)([0-9]+)([0-9][+-])/\)\{\\sub $1\}{\\super $2\}/g;
5.      $s=~s/([A-Z][a-z]?)([0-9]+)/$1\{\\sub $2\}/g;
6.      $s=~s/\)([0-9]+)/\)\{\\sub $1\}/g;

Clearly, my original has one more substitution then your revision; line-by-line comparison seems to show me that the only difference is that you have deleted my line 4, leaving everything else unchanged.

As I see it, my line 4 is needed to handle a formula such as the following, from your list of formulas:

Cu(H2O)62+

as you currently have no line that handles the combination of a right parenthesis, digits, and a sign. (Indeed, when I made a Nisus macro file from your revised script and a source file from your list of formulas, the + following the 62 did not receive a superscript.)

The missing line in my original script handles this combination, but locks one into using the last digit and only the last digit as part of the superscript. As I discussed previously, this might not actually be what you want: I gave the hypothetical example "S2-" and noted that conceivably we might want the 2 to modify either the S or the -, but neither of our scripts gives us a mechanism to make that choice. Accordingly, I suggested the insertion of a colon as a way to tell the macro how that digit is to be handled.

I'll be happy to continue the discussion of this macro if you wish. In any case, thank you for inducing me to make my introduction to the macro system of Nisus Writer Express.

Sincerely,

Jonathan At 10:30 AM -0400 8/18/03, Patrick Gormley wrote:
<x-flowed>There is a problem with the syntactic ambiguity in my formulas. However, you made no mention of my fix (sent a few hours later), so I
will reproduce it below. (Note: the massive power outage has been
giving me a major headache with regards to e-mail. Sometimes it works,
sometimes it doesn't.) I have not tested my fix on a lot of formulas
and will try to do this in the next few days. My fix works on the
formulas referenced earlier. Jonathan's original macro along with my
revisions is below:
***************


#!/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]


</x-flowed>


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