Page 1 of 1

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

Posted: 2011-05-25 09:39:43
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,

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

Posted: 2011-05-25 10:03:42
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.

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

Posted: 2011-05-25 13:17:52
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.

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

Posted: 2011-05-25 22:29:53
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.

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

Posted: 2011-05-26 09:09:18
by Kino
Groucho wrote:There’s a tiny flaw in line 12.
Ah, that's a typo. Thank you for pointing it out.