Macro to make digits superscript and add non-breaking space
Macro to make digits superscript and add non-breaking space
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.
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 (45.3 KiB) Viewed 20715 times
Re: Macro to make digits superscript and add non-breaking sp
Just apply the formatting in the usual wayNisusUser wrote:It changes the space following to a NBS, but I can't figure out how to include superscript in the "Change to" portion.

philip
Re: Macro to make digits superscript and add non-breaking sp
Just apply the style in the usual wayNisusUser 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.


philip
Re: Macro to make digits superscript and add non-breaking sp
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.
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
Re: Macro to make digits superscript and add non-breaking sp
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.phspaelti wrote:Just apply the formatting in the usual way
What am I doing wrong?
Re: Macro to make digits superscript and add non-breaking sp
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: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.phspaelti wrote:Just apply the formatting in the usual way
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.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?
philip
Re: Macro to make digits superscript and add non-breaking sp
Thanks, Philip. That helps.
But why do I only have "Remove Attributes Except Styles" in the Format menu (see screenshot attached)?
But why do I only have "Remove Attributes Except Styles" in the Format menu (see screenshot attached)?
- Attachments
-
- Format menu 2.0.4.png (70.73 KiB) Viewed 20697 times
Re: Macro to make digits superscript and add non-breaking sp
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
Re: Macro to make digits superscript and add non-breaking sp
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.
Ei, yai, yai! Found it! Format > Baseline.

Re: Macro to make digits superscript and add non-breaking sp
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!
More sage advice?

- Attachments
-
- Working Find-Replace for digits to superscript + NBS.png (45.89 KiB) Viewed 20693 times
-
- Non-working Macroized F-R for digits to superscript + NBS.png (17.64 KiB) Viewed 20693 times
Re: Macro to make digits superscript and add non-breaking sp
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
Re: Macro to make digits superscript and add non-breaking sp
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.

Re: Macro to make digits superscript and add non-breaking sp
Good. I'm glad you got it working.
philip