Newbie needs some help with macros

Get help using and writing Nisus Writer Pro macros.
Post Reply
Warren Rogers
Posts: 5
Joined: 2012-12-27 15:53:07

Newbie needs some help with macros

Post by Warren Rogers »

Hello,
Here's my problem. I'm new to macro writing (and to the list!). I am in the middle of transferring several books from paperback to digital (I read them on my iPad). So, I'm wondering, is there a way to do three things? Obviously, to me at least, it would take at least three macros, right? Anyway, here they are:

1) remove all the carriage returns expect for the end-of-paragraph one which is always followed by a tab,

2) replace the double hyphen with the Nisus Em dash, and

3) a kind of Find and Replace for the words that the OCR changes, e.g., flxxx to some capital letter like Bxxx. The xxx is any word. The important thing is the change at the beginning of the word from two lower case letters to one upper case one.

These are the things I spend most of my time on. Could you help?

Thanks,

Warren Rogers
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Newbie needs some help with macros

Post by Groucho »

Hello, Warren.

I’m sorry I don’t understand your point three. Can you post an example with some text before and after? As for the others, this macro will do the job. Note: I assumed that you wanted to substitute a space for a carriage return.

Code: Select all

Find and Replace "\n(?!\t)", " ", "aE"
Find and Replace "--", "—", “a”
If you simply want to eliminate any carriage return, change the first line as follows:

Code: Select all

Find and Replace "\n(?!\t)", "", "aE"
Greetings, Henry.
User avatar
phspaelti
Posts: 1344
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Newbie needs some help with macros

Post by phspaelti »

Hello Warren,
Warren Rogers wrote: Obviously, to me at least, it would take at least three macros, right?
And "obviously" you would be wrong :)
As Henry showed it's easy to make a single macro to do both 1 and 2. This macro combines two different Find and Replace actions. Note that you could do either of those two directly from the Find and Replace dialog without making a macro.

Now what about...
Warren Rogers wrote:3) a kind of Find and Replace for the words that the OCR changes, e.g., flxxx to some capital letter like Bxxx. The xxx is any word. The important thing is the change at the beginning of the word from two lower case letters to one upper case one.
I can understand the wish for a macro like that very well, but I am sorry to say that unlike 1 and 2 this will be no easy matter. A useful macro for that purpose would probably need dozens (or even hundreds) of Find and Replace statements, and would almost certainly still over- and underperform. Just for the case you mention, some instances of "B" at the beginning of a word will be the result of an OCR mistake for "fl", but many others will not be. There is no easy way to distinguish them. This is a language problem. (OCR would work much better if this were an easy problem.)

For 3 I would recommend that you work with the Find and Replace dialog open. Make a keyboard short cut for "Copy to Find" and "Copy to Replace" then when you find OCR mistakes during proof-reading that are likely to recur copy them to Find and do a global replace (perhaps using "Replace and Find" to check them one at a time). If you do this often you can try combining such Find/Replace statements in a single macro (using the "Macroize" function), but you'll have to review these statements carefully to make sure they don't do more harm than good.

I have tried making such macros, but even though OCR mistakes seem to be very repetitive, most Find/replace statements end up applying only very few time in each file (or they overapply and wreak havoc).

Best
Philip
philip
Warren Rogers
Posts: 5
Joined: 2012-12-27 15:53:07

Re: Newbie needs some help with macros

Post by Warren Rogers »

Thanks Henry and Phillip,

Sorry I haven't gotten back to you sooner. I've had this cold that won't quit. I cough and sleep all the time. The macros work great though, when I've had the time to use them. Henry, could you tell me what the various signs mean in the first one? I know it's asking a lot but I really am a newbie, so any help is appreciated.

Phillip, your thoughts on my third request are very good. I don't spend nearly enough time on that aspect to warrant all the time it would take, if ever, to write a macro for it.

Thanks again,

Warren Rogers
User avatar
phspaelti
Posts: 1344
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Newbie needs some help with macros

Post by phspaelti »

Warren Rogers wrote:Henry, could you tell me what the various signs mean in the first one? I know it's asking a lot but I really am a newbie, so any help is appreciated.
Hello again, Warren.

As you say you are a newbie, let me make the following suggestion. Use Powerfind mode to do Find and Replace. In Powerfind Henry's macro will look like this:
Find expression.tiff
Find expression.tiff (76.03 KiB) Viewed 11358 times
As you can see the bubble expression reads practically like English.
More technically it's:
\n = [ Return ]
(?! … ) = [ NotFollowedBy( ] … [ ) ]
\t = [ Tab ]

Hope this helps
philip
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Newbie needs some help with macros

Post by Groucho »

Also, you can create a macro out of a find/replace find. Write your definition using PowerFind, then switch to PowerFind Pro. Find and replace definition changes to regular expressions. Click on the gear and select Macroize…. Select Replace All and save the expression as a macro file, or copy it to be pasted into an existing macro as a new line.
You can find more about PowerFind Pro and regular expressions in the manual starting from page 313.

Cheers, Henry.
Post Reply