Macro to change to superscript

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

Macro to change to superscript

Post by NisusUser » 2016-03-05 21:38:02

I would like to take text like the following and put the bold numbers (which can be up to three-digits long, e.g. "150") in superscript. I would like them to remain bold. However, when trying to use PowerFind and apply superscript to the "Replace" text, the find dialog closes. (There is a non-bold space after the digits.)
1 Zzxiixz ii Ziixzxzz ii Jiwxiizixz izzzixxixizčix xzzxxčizi Zizxz Jzxz ii Zizzxzixiz Jzzxiz Ziizixiz. Mzixxz ixwz ii izwxxz xxx Zizxx wxzx Jzxx ii Zizzxziizz Jzzzxz Ziizizxz.
2 Mzz xizxxwzi xzxxizwz Zizxxi xz ixz xizxz, wixzxzwi ixz zzxx wzixxzz, 3 xz xziixxxz wxzx Zizxx ii Jzxx zxixzizxxiz xiiziwixxzwi ixzx 1xzixz, xxii zxxziiz iixziiwzz, ii iiixzz, xxii zxxziiz wziiz, ii izixziwz, xxiiz zxxziiz xziixiixiz xiiiiz, zxxziz i wxzx Zizzxzii Jzzx Ziizix, 4 ii zixxxzwi, 2Zizxx xxwxiziizii xixiizi, ixzx iziixxiwz. 5 Zzz wxzx zxzxxziiiz xzzizix xzz ixz xizx iix zxxziziz, xzi izix xzi zx izxz, ii zx Zxzxiziz Zxzziz, ii zx xizizxx xziixiixixwx, xzix ixz zixxiz, xxxiz wzz izix ixzx xxxxwz ixzx izxxi.
Here is the search as I've done it so far. Selecting the "Captured1" and applying superscript is what causes the problem.
NWP 2.1.4 Applying superscript in PowerFind doesn't work.png
NWP 2.1.4 Applying superscript in PowerFind doesn't work.png (51.57 KiB) Viewed 2186 times
Advice, anyone? Thank you!

xiamenese
Posts: 420
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Macro to change to superscript

Post by xiamenese » 2016-03-06 02:42:19

I have found using Powerfind Pro better when trying to do attribute replacement. Perhaps worth a try; if you just switch your S&R to Powerfind Pro, you shouldn't have to retype your strings.

Mark

NisusUser
Posts: 257
Joined: 2011-01-12 05:32:38

Re: Macro to change to superscript

Post by NisusUser » 2016-03-06 05:16:14

xiamenese wrote:I have found using Powerfind Pro better when trying to do attribute replacement. Perhaps worth a try; if you just switch your S&R to Powerfind Pro, you shouldn't have to retype your strings.

Mark
Thank you, Mark.

I just switched it to PowerFind Pro. However, the problem is the same. (1) It finds all instances just fine, but (2) as it is in the following screenshot, it doesn't change to superscript, which is what I want. And, (3) when I click on the "apply superscript" icon, the S&R dialog box disappears, and it does not superscript anything. I must be doing something wrong, but I don't know what.
NWP 2.1.4 Applying superscript in PowerFind Pro doesn't work.png
NWP 2.1.4 Applying superscript in PowerFind Pro doesn't work.png (43.64 KiB) Viewed 2173 times

xiamenese
Posts: 420
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Macro to change to superscript

Post by xiamenese » 2016-03-06 11:22:27

You need to use the "Format > Baseline> Superscript" … that does it for me. If you use a button on your toolbar, that is on your document, not the find dialog, and clicking it takes you back to the document and so doesn't apply the superscript in the find dialog.

:)

Mark

NisusUser
Posts: 257
Joined: 2011-01-12 05:32:38

Re: Macro to change to superscript

Post by NisusUser » 2016-03-06 11:35:27

Ahhh, thank you very much, Mark. That works!

xiamenese
Posts: 420
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Macro to change to superscript

Post by xiamenese » 2016-03-06 16:07:27

My pleasure!

:)

Mark

User avatar
martin
Official Nisus Person
Posts: 4251
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Macro to change to superscript

Post by martin » 2016-03-08 17:50:20

It sounds like Mark already gave you the solution — thanks Mark! — but I wanted to clear up one thing:
NisusUser wrote:when I click on the "apply superscript" icon, the [Find & Replace] dialog box disappears, and it does not superscript anything
Assuming that the "apply superscript" icon is the one in the palettes, the Find dialog disappears because the palettes are attached to some document window. By clicking the palettes you activate the related document window, deactivating the Find dialog and thus hiding it. The core issue is thus that the palettes cannot be used to apply formatting to the Find dialog; you must use the main menu (or keyboard shortcuts).

And one final tip: if you ever have trouble using a Find & Replace operation to change some text's formatting, remember that you can often break the problem down into two steps:

1. Find all of the desired text.
2. Apply formatting to the existing multi-part selection.

In this case you'd just find all the desired numbers, switch to the document window, and then use the palettes to add superscripting to the selected find results.

NisusUser
Posts: 257
Joined: 2011-01-12 05:32:38

Re: Macro to change to superscript

Post by NisusUser » 2016-03-09 00:21:49

martin wrote:The core issue is thus that the palettes cannot be used to apply formatting to the Find dialog; you must use the main menu (or keyboard shortcuts).
Ahh, now I understand. Makes sense. I'll have to remember that. Thank you.
martin wrote:And one final tip: if you ever have trouble using a Find & Replace operation to change some text's formatting, remember that you can often break the problem down into two steps:

1. Find all of the desired text.
2. Apply formatting to the existing multi-part selection.

In this case you'd just find all the desired numbers, switch to the document window, and then use the palettes to add superscripting to the selected find results.
I could have done that, but I wanted to create a macro so I would be able to do it again quickly.

Thanks for your follow-up, Martin.

User avatar
martin
Official Nisus Person
Posts: 4251
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Macro to change to superscript

Post by martin » 2016-03-09 10:49:11

NisusUser wrote:
martin wrote:And one final tip: if you ever have trouble using a Find & Replace operation to change some text's formatting, remember that you can often break the problem down into two steps:

1. Find all of the desired text.
2. Apply formatting to the existing multi-part selection.
I could have done that, but I wanted to create a macro so I would be able to do it again quickly.
Ah okay, though you can still break apart the steps for a macro. It might look something like this:

Code: Select all

Find All "[[:digit:]]+", "E"
Menu "Superscript"
You can use the macroize feature to create the Find All command, and then add whatever menu commands you'd like to change the formatting. However, a macro like the example above always adjusts superscripting, even if the Find All command has zero matches. It's more likely you want to use code like this:

Code: Select all

If Find All "[[:digit:]]+", "E"
	Menu "Superscript"
End
But now it's getting more complicated, and maybe a single Replace All that also changes the formatting is easiest. The best way depends on the task. I just wanted to share another method :)

Post Reply