Finding superscript ordinal numbers

Everything related to our flagship word processor.
Post Reply
Frank Einstein
Posts: 26
Joined: 2004-12-23 21:53:45

Finding superscript ordinal numbers

Post by Frank Einstein »

I would like to find superscript ordinal numbers and replace them with regular formatting. Here is an example of what I would like to find:

On September 30th

In NW the "th" in 30th is formatted as a superscript (doesn't show here), and I would like to replace it with non-superscript "th" There are many occurrences of this in my NW text which I would like to replace (all are ordinal numbers, so 1st, 2nd, 3rd,4th and so on). Can I use the Find function for this? And if so, how?

Thanks in advance.
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Finding superscript ordinal numbers

Post by adryan »

G’day, Frank et al

Using PowerFind Pro, put the following expression in the Find field: (\d)(st|nd|rd|th)

Select the second parenthesized expression and superscript it by choosing Format > Baseline > Superscript. Also tick the Formatting Sensitive checkbox there.

Put the following expression in the Replace field: \1\2

Select the “\2” and choose Format > Baseline > No Super/Sub. Also tick the Replace Formatting checkbox there.

Then click on the Replace All button.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Finding superscript ordinal numbers

Post by xiamenese »

If you don't want to get involved with RegEx:

1) highlight a superscript
2) Look in the "Format Examiner" palette, where you will see Superscript as one of the attributes in "Applied Formatting"
3) Right click on the word Superscript and choose "Select all" from the dropdown
4) turn off superscript using the "Character" palette or the Format > Font > Baseline menu

Job done.

The Format Examiner is very useful for such things.

:)

Mark
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Finding superscript ordinal numbers

Post by adryan »

G'day, Mark et al

The caveat with that approach is that it will de-superscript all superscripts, not just those associated with ordinal numbers. Know your document!

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Finding superscript ordinal numbers

Post by phspaelti »

adryan wrote: 2021-01-15 12:10:57 Using PowerFind Pro, put the following expression in the Find field: (\d)(st|nd|rd|th)

Select the second parenthesized expression and superscript it by choosing Format > Baseline > Superscript. Also tick the Formatting Sensitive checkbox there.
As a slight variant of this approach, I would recommend the following Find expression: (?<=\d)(st|nd|rd|th)
This will select only the suffix.

Also instead of using the Replace expression to turn off the superscript, I would just do "Find All", check the results, and turn off the superscript by hand.

PS: With this find expression, you probably don't even need to bother with attribute sensitive search, since the only likely matches will in fact be such ordinal specific suffixes.
philip
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Finding superscript ordinal numbers

Post by adryan »

G'day, Philip et al

Indeed.

Not because it's at all likely, but just to emphasize (yet again!) the importance of knowing what's in your document before you attack it with the powerful tools Nisus places in your hands, those in the back row need to be very careful that an exponent expression in a mathematical formula does not become collateral damage. You don't want those powerful tools to be de-powering!

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Finding superscript ordinal numbers

Post by phspaelti »

Which is why I wrote "probably".
The method I recommend in general is to use "Replace All" less, and "Find All" more. Look at the number of hits and use "Show list of matches" to see what you get. Regular expressions are famously tricky, so it's best not to try to outthink the regexp engine :)
philip
johseb
Posts: 47
Joined: 2016-02-13 10:01:29

Re: Finding superscript ordinal numbers

Post by johseb »

Checking the results before formatting is for sure a sensible piece of advice.

Correct me if I'm wrong but it seems that the only way to delete a false positive is to re-select it keeping the ⌘ key pressed. Is there any other/better way?
I'm asking because I find the described de-selection operation a bit difficult; it's probably just me but I often end up "destroying" the multi-part selection and I have to start again from the beginning.

It would be easier if we could delete an instance directly in the "Find Results" window (e.g. with a command in the contextual menu).
The "Find Results" window is great to see/navigate/copy results but would be much powerful if it could operate on the underlying multi-part selection.
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Finding superscript ordinal numbers

Post by adryan »

G’day, johseb et al

Let me restate the problem: You would prefer that one or more results in the Results window did not appear there. Right?

As far as I can see, you can’t just delete an item in the Results list and have it deselected in the main document. You can do a Cut (not a Delete) operation in the Results window, but that will Cut the relevant selection from the document, not merely deselect it.

I think you have two choices. You either amend the Find expression (by which I include any subsequent Invert Selection operation) that found all the stuff in the Results window so that it no longer finds the unwanted item, or you amend the unwanted item in the document so that your existing Find expression fails to find it.

Do the first method often enough and you’ll learn a lot about grep!

The second method could get awkward, especially if there are many instances requiring amendment. And you may need to revert those amendments later. Note, though, that if you amend something in the document so that it will no longer be found by your existing Find expression, all the previously selected stuff in the document will be deselected. However, it will still be available in the Results window; selecting all the items there will cause the relevant selections (minus those you have amended) to be visible once more in the main document.

There is no right or wrong way to use a word processor, but different people will prefer different methods.

In this present situation, I would generally use the first method and try to see where I had gone wrong. I would experiment with the generalized expressions used in the Find operation until I got it right. That way, I would improve my knowledge of grep, which would stand me in good stead in future.

BUT! — If I had any concern that some operation I was about to perform could end in disaster (perhaps through a power failure in the middle of making hundreds of automated alterations to my 10,000-page autobiography), I would take the precaution of doing the operation (or conducting a series of experiments) on a duplicate of my document, not on the original. I have advised this many times in this Forum. The example I just gave illustrates how simply relying on Undo (Cmd-Z) to retrieve a situation may not be wise in all circumstances. Another trap in this connection is when you use multiple (language) keyboards which map characters to different keys: using a keyboard shortcut with the wrong keyboard can elicit strings of profanities in multiple languages!

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Finding superscript ordinal numbers

Post by phspaelti »

johseb wrote: 2021-01-16 01:06:04 It would be easier if we could delete an instance directly in the "Find Results" window (e.g. with a command in the contextual menu).
The "Find Results" window is great to see/navigate/copy results but would be much powerful if it could operate on the underlying multi-part selection.
Did you know that you can do "Select All" in the Find Results window, or that you can command click individual hits and add/subtract them from the selection? And of course you can have multiple Find Results windows open, which allow you to recreate a previous (Find based) selection easily. Just as long as you don't edit too much.

Also as I mentioned in another thread, I like to use highlight colors to temporarily "hold" a selection. You can then subtract or add to the selection without having to do those adjusting gymnastics with the non-contiguous selection. Highlights are particularly convenient, since they will stay in place even if you modify the file.
philip
johseb
Posts: 47
Joined: 2016-02-13 10:01:29

Re: Finding superscript ordinal numbers

Post by johseb »

Thank you Adryan and Philip.
I didn't know that you can command click individual hits in the Find Results window to add/subtract them from the selection. That's indeed useful.
There's only a small detail to notice: command clicking an hit doesn't scroll the document to show the hit (as it does when you click a single hit) but usually enlarging the Find Result window is enough to give context for the hits (text before/after each hit).

The technique of using highlight to "hold" a selection is also a good one; I know that trick but I often forget to use it. I must keep it in mind for the more complex substitution or formatting.
Frank Einstein
Posts: 26
Joined: 2004-12-23 21:53:45

Re: Finding superscript ordinal numbers

Post by Frank Einstein »

adryan wrote: 2021-01-15 12:10:57 G’day, Frank et al

Using PowerFind Pro, put the following expression in the Find field: (\d)(st|nd|rd|th)

Select the second parenthesized expression and superscript it by choosing Format > Baseline > Superscript. Also tick the Formatting Sensitive checkbox there.

Put the following expression in the Replace field: \1\2

Select the “\2” and choose Format > Baseline > No Super/Sub. Also tick the Replace Formatting checkbox there.

Then click on the Replace All button.

Cheers,
Adrian
I am having no luck trying to follow your suggestions--probably something I am doing wrong.When I follow your instructions, I get the "Found no occurrences" message from NW. So I am guessing that I am doing something wrong in the Find box. Here is a screen shot. Can you see anything I have done wrong?


Screen Shot 2021-01-16 at 2.25.14 PM.png
Screen Shot 2021-01-16 at 2.25.14 PM.png (69.31 KiB) Viewed 16524 times
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Finding superscript ordinal numbers

Post by adryan »

G’day, Frank et al

I suspect you have just copied and pasted the Find expression from my Forum posting. But the Forum superimposes additional formatting which will be sought by the Formatting Sensitive stipulation but is unlikely to be present in your document.

If you type in the expression afresh yourself and go through the procedure I outlined, it should work. Alternatively, you can select the pasted expression in the Find field, then invoke Format > Remove Formatting and Styles, and then apply the Superscript to the second parenthesized expression once more.

I hope that helps.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Finding superscript ordinal numbers

Post by phspaelti »

Frank Einstein wrote: 2021-01-16 12:31:59 I am having no luck trying to follow your suggestions--probably something I am doing wrong.When I follow your instructions, I get the "Found no occurrences" message from NW. So I am guessing that I am doing something wrong in the Find box. Here is a screen shot. Can you see anything I have done wrong?
Adrian's explanation are fine, but the first step I recommend when you are getting "Found no occurrences" on a styled search, is to turn the "Formatting Sensitive" off. Make sure to try "Find next" or "Find All" rather than "Replace All" at that point. And since in fact there is a good chance in most documents that this will be finding exactly what you want—since most documents do not mix numbers and letters in this way otherwise—you'll have what you want.
The truth is "Formatting Sensitive" search can often be avoided. And I recommend avoiding it whenever possible.

Here is the find expression I recommended earlier. With this you can just change the formatting rather than use "Replace All"
Attachments
Screen Shot 2021-01-19 at 12.55.png
Screen Shot 2021-01-19 at 12.55.png (53.01 KiB) Viewed 16451 times
philip
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Finding superscript ordinal numbers

Post by martin »

Here's a macro of Philip's find all PowerFind pattern. If you run the macro it will select all of the desired numeric ordinals so you can reformat them en-masse. The macro also opens a find results list, so you can skim the results or adjust the matches beforehand.
Attachments
Find All Numeric Ordinals.zip
(2.4 KiB) Downloaded 482 times
Post Reply