Find/Change all straight quotes to smart quotes

Everything related to our flagship word processor.
Post Reply
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Find/Change all straight quotes to smart quotes

Post by NisusUser »

In 2.0.7 I tried to change all straight quotation marks from a pasted text to curly quotation marks. Since my settings in NWP's Preferences seem right [(QuickFix > Language (English (U.S.)) has "Use smart punctuation" checked (and set to "Standard")], I assumed that by replacing " with " NWP would automatically change the " used as opening quotation marks to “ and those used as closing quotation marks to ”. It doesn't. It just leaves straight quotation marks there. If I tell NWP to change all straight quotation marks to “, it does so regardless of whether they are opening or closing marks. So do I need to do a more complex search with any space + straight quotes being changed to opening curly quotes and then another search/replace changing any straight quotes followed by any punctuation or space being changed to closing curly quotes? (I think that would miss some.). I also need to change the single quotation mark to a curly one in words like "it's" (to "it’s"). I looked in the macros that ship with NWP or that I've added on my machine, and I don't see anything that would do this. Seems it'd be good to have some macro or built-in function for this (maybe going both ways, since sometimes you want to change back, although admittedly that is easier to do with simple find/replace).

Thanks for any advice!
m.danielsson
Posts: 12
Joined: 2014-07-12 03:21:50

Re: Find/Change all straight quotes to smart quotes

Post by m.danielsson »

PowerFind Pro
Find: "([^"]+?)"
Replace: “\1”

Find straight quotation mark followed by 1 or more chars (could be '*' instead of '+' to match zero or more) that are not straight qouation marks. Non greedy, ie stop at next straight quotation mark.

reverse:
“([^”]+?)”
"\1"

Regards,
Martin
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Find/Change all straight quotes to smart quotes

Post by NisusUser »

Thank you, Martin. Works great.
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Find/Change all straight quotes to smart quotes

Post by NisusUser »

m.danielsson wrote:PowerFind Pro
Find: "([^"]+?)"
Replace: “\1”
Martin, (or anyone else who knows)

Q1. What exactly does the following code mean? (Or, what does the PowerFind search look like that converts to this when it becomes PowerFind Pro or is macroized?)

Code: Select all

[^"]+?
On p. 318 in the NWP manual (PDF), it says that ^ means "Represents the beginning of paragraph position", but I don't see what " means there. Also it seems contradictory to me (I'm sure it is not in fact contradictory) to have +? together, since the manual says + means "Expression that precedes occurs one or more times" and ? means "Expression that precedes occurs zero or once". Were you saying that +? is equal to *? (Since the manual says * means "Expression that precedes occurs zero or more times".

Q2. I find that dealing with the single quotation marks is far more difficult than dealing with double ones. Here's why: the single is also used as an apostrophe, in words such as "it's," "Tom's," as well as "summers'," "years'," "peoples'," "Ph.D.'s." I realize now that if find/replace functions are not done in the right order, it gets all messed up. Thus I did three macros (first 3 attached). Unfortunately, they don't catch "summers'," "years'," or "Ph.D.'s", etc. I could only do those as two separate functions, so I have a total of five macros (attached), and they must be run in the listed order. Questions: (Q2a) What better way could I have done this? (Q2b) Can I just put them all in one macro one after the other? (Q2c) On a big file (say 100 pages), some seem to take a while. Do I need to put a pause in the combined macro? How do I do that?

Thanks for any help on this!
Eric

EDIT: Added "(Or, what does the PowerFind search look like that converts to this when it becomes PowerFind Pro or is macroized?)"
Attachments
Quotation marks - change from straight to curly (incl. apostrophe).zip
5 macros to change from straight quotes to curly quotes
(85.25 KiB) Downloaded 449 times
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Find/Change all straight quotes to smart quotes

Post by NisusUser »

NisusUser wrote:
m.danielsson wrote:Q1. What exactly does the following code mean? (Or, what does the PowerFind search look like that converts to this when it becomes PowerFind Pro or is macroized?)

Code: Select all

[^"]+?
"
I didn't know there was a way to see what each PowerFind expression looks like when it's converted to RegEx (PowerFind Pro). What a relief to find it! (Last item under gear in Find/Replace box)

So now I know that …
[^"] is RegEx for the Match menu item CharacterNotInSet and it "Matches any one single character not inside the set brackets."
+? is RegEx for Repeat menu item +1 Shortest and it will "Match the shortest string that matches the preceding sub-expression one or more times."

I kept thinking there had to be a list of those "translations" from PowerFind to PowerFind Pro, but I couldn't find it in the manual. Whew! Relief.

Now I understand why your macro works, Martin. I'm a happy camper.

EDIT: added screen shots.
Attachments
CharacterNotInSet.png
CharacterNotInSet.png (65.12 KiB) Viewed 14380 times
Show PowerFind Browser.png
Show PowerFind Browser.png (60.11 KiB) Viewed 14380 times
m.danielsson
Posts: 12
Joined: 2014-07-12 03:21:50

Re: Find/Change all straight quotes to smart quotes

Post by m.danielsson »

A note: the '?' in the pattern is actually redundant. It still works but the '?´-qualifier is unnecessary:
"([^"]+?)"

could have, and really it should have ;), been written:
"([^"]+)"

since [^"]+ means one or more characters not in character class, ie one or more not-", the match would have stopped at the first " without the '?'-qualifier.

I was a bit hasty and had below pattern in mind while writing above:
"(.+)"

Match double quote and catch one or more characters of any kind into the capture group. In NWP this means match to the end of the paragraph. Since the pattern still has to match a double quote after the capture group to succeed, it backtraces a character at a time untill the pattern is satisfied. Thus the match would be from the first opening double quote to the last closing double qoute:
In ”pellentesque” faucibus vestibulum. ”Nulla” at nulla justo,

So in the case of "(.+)" the '?' qualifier is needed to match only a single qoute. I'm sure you got that the ? wasn't necessary, but I thought I should mention it.

Regards,
Martin
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Find/Change all straight quotes to smart quotes

Post by phspaelti »

While I'm a big fan of writing macros, there is a built-in feature under Edit > Convert > Plain Quotes to Smart Quotes (and Smart Quotes to Plain Quotes). This works on a selection…
philip
NisusUser
Posts: 317
Joined: 2011-01-12 05:32:38

Re: Find/Change all straight quotes to smart quotes

Post by NisusUser »

phspaelti wrote:While I'm a big fan of writing macros, there is a built-in feature under Edit > Convert > Plain Quotes to Smart Quotes (and Smart Quotes to Plain Quotes). This works on a selection…
Oh, no! I kept thinking this feature had to be somewhere, but I never found it mentioned in the manual, wasn't alert (or intuitive) enough to see it in the menus, and no one responded before you, so I just assumed it didn't exist. Oh, well. I learned a bit more about macros :)
m.danielsson
Posts: 12
Joined: 2014-07-12 03:21:50

Re: Find/Change all straight quotes to smart quotes

Post by m.danielsson »

phspaelti wrote:While I'm a big fan of writing macros, there is a built-in feature under Edit > Convert > Plain Quotes to Smart Quotes (and Smart Quotes to Plain Quotes). This works on a selection…
Did not know about that. Apart from it always being better to use built-ins, 'Edit > Convert > ..quotes..' handles unbalanced quotes correctly, so it is really the only way to go.
Post Reply