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!
Find/Change all straight quotes to smart quotes
-
- Posts: 12
- Joined: 2014-07-12 03:21:50
Re: Find/Change all straight quotes to smart quotes
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
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
Re: Find/Change all straight quotes to smart quotes
Thank you, Martin. Works great.
Re: Find/Change all straight quotes to smart quotes
Martin, (or anyone else who knows)m.danielsson wrote:PowerFind Pro
Find: "([^"]+?)"
Replace: “\1”
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
[^"]+?
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 457 times
Re: Find/Change all straight quotes to smart quotes
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)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
[^"]+?
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 (65.12 KiB) Viewed 14424 times
-
- Show PowerFind Browser.png (60.11 KiB) Viewed 14424 times
-
- Posts: 12
- Joined: 2014-07-12 03:21:50
Re: Find/Change all straight quotes to smart quotes
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
"([^"]+?)"
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
Re: Find/Change all straight quotes to smart quotes
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
Re: Find/Change all straight quotes to smart quotes
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 macrosphspaelti 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…
-
- Posts: 12
- Joined: 2014-07-12 03:21:50
Re: Find/Change all straight quotes to smart quotes
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.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…