Macro to make digits superscript and add non-breaking space

Get help using and writing Nisus Writer Pro macros.
Post Reply
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Macro to make digits superscript and add non-breaking space

Post by NisusUser »

I would like to make a macro that will render in superscript sequences of digits (from 1 to 3 digits). These sequences of digits always occur with a space before and after them. I want the space after them to be changed to a non-breaking space.

The attached screenshot shows what I came up with. It changes the space following to a NBS, but I can't figure out how to include superscript in the "Change to" portion.

BTW, I found it strange that in the "Special Characters" pallette there was "Space", but none of the unusual spaces. Nonetheless, Cmd-NBS worked to insert it.

Thanks for your help!

Oops, I forgot to mention that I only want this to be done to text in a certain style. How do I do that? Thanks.
Attachments
Attempt to superscript digits and add NBS.png
Attempt to superscript digits and add NBS.png (45.3 KiB) Viewed 18407 times
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

NisusUser wrote:It changes the space following to a NBS, but I can't figure out how to include superscript in the "Change to" portion.
Just apply the formatting in the usual way :)
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

NisusUser wrote:Oops, I forgot to mention that I only want this to be done to text in a certain style. How do I do that? Thanks.
Just apply the style in the usual way :) :)
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

PS: In case my comments aren't clear: The Find and Replace window allows formatting just like any other window. If may feel a little strange to apply formatting to wildcards, but it works just the same.
And about the special space: If Nisus wanted to add all the possible special characters possible in that menu it would get very crowded. But you can just type them in to the Find or Replace box. Or you can use Unicode notation, if you prefer the "code" look.
philip
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to make digits superscript and add non-breaking sp

Post by NisusUser »

phspaelti wrote:Just apply the formatting in the usual way :)
Well, I admit I felt silly for not thinking of that, especially since I was able to figure out the Cmd-NBS part. However, I'm afraid I'm going to have to admit to a more severe case of inability here: I tried to format the target text. As soon as I click on the superscript button in the Character pallette, the Find box goes away. Well, OK, I thought, it probably "took" the attributes, but just lost focus. However, I tried the Find/Replace routine, and it does not work, i.e. the paragraph style I tried to apply to the Find and Replace boxes doesn't seem to have stuck, either (can only character styles be applied?). And the superscript didn't stick.

What am I doing wrong?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

NisusUser wrote:
phspaelti wrote:Just apply the formatting in the usual way :)
Well, I admit I felt silly for not thinking of that, especially since I was able to figure out the Cmd-NBS part. However, I'm afraid I'm going to have to admit to a more severe case of inability here: I tried to format the target text. As soon as I click on the superscript button in the Character pallette, the Find box goes away. Well, OK, I thought, it probably "took" the attributes, but just lost focus.
Ok, so maybe not that "usual way". The palette belongs to the document window. You will have to apply the superscript using the menu (or a key combination).
NisusUser wrote:However, I tried the Find/Replace routine, and it does not work, i.e. the paragraph style I tried to apply to the Find and Replace boxes doesn't seem to have stuck, either (can only character styles be applied?). And the superscript didn't stick.

What am I doing wrong?
No, any styles can be applied, but generally you will have to apply them from the regular menus. Also make sure that you don't apply any style that you do not want. Make sure the text is completely free of styles before you start. If necessary select all text in the Find box and use "Remove Attributes and Styles" from the menu, if necessary. Then apply only the styles you want.
philip
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to make digits superscript and add non-breaking sp

Post by NisusUser »

Thanks, Philip. That helps.

But why do I only have "Remove Attributes Except Styles" in the Format menu (see screenshot attached)?
Attachments
Format menu 2.0.4.png
Format menu 2.0.4.png (70.73 KiB) Viewed 18389 times
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

You're right in the Find box that menu command changes to "Any attributes" which is better. And since it's checked in your case you have "any attributes", so no stray attributes there.
philip
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to make digits superscript and add non-breaking sp

Post by NisusUser »

I think I'm getting somewhere now, but I've never seen (nor do I now see) a "Superscript" menu item in the Format menu. I've always used the Character pallette. I don't really want to create a character style and have to deal with that, too. Am I just missing the "Superscript" command somewhere?

Ei, yai, yai! Found it! Format > Baseline. :)
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to make digits superscript and add non-breaking sp

Post by NisusUser »

Strangely enough, the find-replace regex is working fine (see screenshot). However, I macroized it, and the macro doesn't find anything to change. Also, it seems to me the macro doesn't have the attributes included.

More sage advice? :) By the way, thanks, Philip, for all your help!
Attachments
Working Find-Replace for digits to superscript + NBS.png
Working Find-Replace for digits to superscript + NBS.png (45.89 KiB) Viewed 18385 times
Non-working Macroized F-R for digits to superscript + NBS.png
Non-working Macroized F-R for digits to superscript + NBS.png (17.64 KiB) Viewed 18385 times
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

Your screen shot indicates that the superscript attribute did get transferred to the macro. However this is a known difficulty. You should be able to fix this by editing the macro. Open the macro select the line with the find expression and check the style. Here you will have to use "Remove Attributes and Styles" if necessary, and apply the ones you want.
philip
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Macro to make digits superscript and add non-breaking sp

Post by NisusUser »

I think what you were saying is that the Paragraph Style didn't transfer. That's maybe probably because it opened a new file that did not yet have that style in it. I opened the macro file, added the Paragraph Style, applied it. It works! I think the case is closed! :) Thanks so much for your patience, Philip.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro to make digits superscript and add non-breaking sp

Post by phspaelti »

Good. I'm glad you got it working.
philip
Post Reply