Chnage all "st" "nd" etc. to superscript

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
Jester
Posts: 158
Joined: 2009-05-21 11:53:23
Location: Midway through infinity (or Ottawa, Canada).

Chnage all "st" "nd" etc. to superscript

Post by Jester »

Hej!

Is there a macro to change all the "st, nd, rd, th" (that follow a number) to superscript in an entire document?

Grazie,
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Chnage all "st" "nd" etc. to superscript

Post by Kino »

Does this work for you?

Code: Select all

Require Pro Version 2.0

define Command SuperscriptOn
	$sp = ':Format:Baseline:Superscript'
	$check = Menu State $sp
	while $check != 1
		Menu $sp
		$check = Menu State $sp
	end
end

$numFound = Find All '(?<=[0-9])(?:st|nd|rd|th)\b', 'E-i'
if ! $numFound
	exit 'Nothing found, exiting…'
else
	SuperscriptOn
end
This one requires NWP 2.0.

EDIT: Removed a redundant command.
EDIT: Fixed a typo in the find expression.
Last edited by Kino on 2011-05-26 09:09:58, edited 2 times in total.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Chnage all "st" "nd" etc. to superscript

Post by martin »

Kino's macro is great if you have an existing document that you need to format nicely, but I just wanted to mention that QuickFix can do this for you automatically as you are typing up new documents. Open up NWP's QuickFix preferences and turn on the option "superscript ordinals" for the desired languages.
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Chnage all "st" "nd" etc. to superscript

Post by Groucho »

Hello, Kino.
There’s a tiny flaw in line 12. Unless you plan to have rd always followed by a comma, this…

$numFound = Find All '(?<=[0-9])(?:st|nd|rd,|th)\b', 'E-i’

should be substituted by this…

$numFound = Find All '(?<=[0-9])(?:st|nd|rd|th)\b', 'E-i’

Greetings, Henry.
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Chnage all "st" "nd" etc. to superscript

Post by Kino »

Groucho wrote:There’s a tiny flaw in line 12.
Ah, that's a typo. Thank you for pointing it out.
Post Reply