nisus.com
https://www.nisus.com/forum/

Question about Type Text
https://www.nisus.com/forum/viewtopic.php?f=17&t=3754
Page 1 of 1

Author:  goldste4 [ 2010-05-21 06:00:33 ]
Post subject:  Question about Type Text

Hello,
I'm new to NWP and the its macro language (it's been a long time since I've done any programming either), and I thought I could simply modify the following macro which Martin provided in NWP forum.

Code:
While Select Next Note
   If Find '(.*)\s', 'Es$'
      If '.' != $1
         Select Start
         Type Text ā€˜.ā€™
      End
   End
End

The macro puts a '.' after an footnote number (I'm converting files from Wordperfect and the footnote formats don't always convert just right). In addition, I wanted a tab after the period, so modified to the Type Text command
to read:

Code:
Type Text '.\t'


Thinking that, since the text is interpolated first, that the '\t' would be converted to a tab character. However, when the macro is run, the '\t' appears in its un-interpolated form (e.g., 1.\tSome footnote text here.)

What am I missing here?

Thanks,
Josh Goldstein

Author:  martin [ 2010-05-21 06:40:23 ]
Post subject:  Re: Question about Type Text

Hi Josh- you just missed a small detail: use double quotes if you want string interpolation to convert escape sequences into special characters. Single quotes don't do any interpolation.

Author:  goldste4 [ 2010-05-21 08:53:24 ]
Post subject:  Re: Question about Type Text

Hello Martin,

Thanks very much, that did the trick. I went back and look through the manual and did now catch the line that " " are for interpolation and ' ' are for literals. Although it still seems a bit confusing (at least to me) that the Find expressions appear to work the opposite (from the Macro Help Manual):
Quote:
It is important to remember, especially for PowerFind Pro expressions, that string literals undergo interpolation (see [Referenced content is missing.]) before being used by the find commands. For example, the following commands are not the same:
Find '\s+', 'E'
Find "\s+", 'E'
The first finds one or more whitespace characters, as you might expect. The second however searches for one or more of the letter ā€˜sā€™ because the backslash is first interpreted using the rules for string literals. If double-quotes are to be used the backslash must be escaped like so:

From the use of " ", I would have guessed that the first Find expression would find the text "\s" and the second Find expression would find the whitespace, but apparently not! Maybe there is something I'm just not grasping.

Thanks again. As a long time Wordperfect user, I'm quite enjoying NWP.

Josh

Author:  martin [ 2010-05-22 11:00:26 ]
Post subject:  Re: Question about Type Text

I'm glad to hear you're enjoying NWP :)

Let's see if I can explain string interpolation with respect to Find commands. First, let's make distinct the string itself, and the string's representation in the macro. Back to your tab, the typed representation in the macro is "\t", but the actual string is just a single tab character. The Find command sees the actual string, never the typed representation. So, if the Find command is given the representation "\s+", interpolation makes the actual string "s+", eg: the backslash has been removed before the Find command sees it. Only then does the Find command start looking for its own kind of special sequences like "\s" or ".+"

It might be more clear if one separates out the Find command into two steps:
Code:
$pattern = "\s+"
Find $pattern, 'E'

If you ever get confused as to what final string the Find command sees, you could use the Prompt command to display $pattern.

Author:  goldste4 [ 2010-05-25 14:59:25 ]
Post subject:  Re: Question about Type Text

Hello Martin, thanks for the in depth reply, appreciate it. Josh

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/