Reply to topic  [ 13 posts ] 
Macro to make digits superscript and add non-breaking space 
Author Message

Joined: 2011-01-12 05:32:38
Posts: 256
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 6606 times ]
2013-03-01 00:59:46
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-03-01 02:29:58
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-03-01 02:31:05
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-03-01 02:43:17
Profile

Joined: 2011-01-12 05:32:38
Posts: 256
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?


2013-03-01 06:07:27
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-03-01 06:47:21
Profile

Joined: 2011-01-12 05:32:38
Posts: 256
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 6588 times ]
2013-03-01 06:58:03
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-03-01 07:06:44
Profile

Joined: 2011-01-12 05:32:38
Posts: 256
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. :)


2013-03-01 07:22:42
Profile

Joined: 2011-01-12 05:32:38
Posts: 256
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 6584 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 6584 times ]
2013-03-01 07:39:22
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-03-01 07:54:24
Profile

Joined: 2011-01-12 05:32:38
Posts: 256
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.


2013-03-01 08:04:03
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Good. I'm glad you got it working.

_________________
philip


2013-03-01 08:10:25
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software