Reply to topic  [ 7 posts ] 
Two macros into one: Typographer's Quotes 
Author Message

Joined: 2007-11-09 15:27:25
Posts: 86
I’ve made two macros via the Macroize feature of the Find dialog box. Each works fine. But I want to run them in succession. When I simply copy/paste the contents of #2 after #1 and make a single macro, nothing happens.

I’m sure it’s child’s play, but I have no idea why.

Here are the two macros (to convert straight quotes to typographer’s quotes):

1) Find and Replace '(")((?:\b\w+\b)+)', '“\2', 'ea'


2) Find and Replace '((?:\b\w+\b)+)(")', '\1”', 'ea'

How can I rewrite these to work in tandem, or one after the other?


2009-11-11 10:14:50
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Hello, jb.

First: I can’t see why you want to use a macro to accomplish a task that NWP already does. Just select the text you want to change and go to Edit > Convert > Plain Quotes to Smart Quotes.

Second: Your macro might be simpler. Anyway, options must be Ea, not ea, in order to tell NWP that the Find/Replace expression is a regular expression.

Third: Your macro won’t have any effect on a word followed by a punctuation mark followed by double quote.

Greetings, Henry.


2009-11-11 11:44:13
Profile

Joined: 2007-11-09 15:27:25
Posts: 86
Ah, thank you.
Didn't see that. I assumed it would be in the form of a macro...


2009-11-11 13:11:04
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Now that we are at that, consider this macro:

Code:
Find and Replace '(\w)"', '\1”, 'Ea'
Find and Replace '"(\w)', '“\1', 'Ea'


Or, if you want a macro that takes punctuation into account:

Code:
Find and Replace '(\w|[,.;:!?])"', '\1”, 'Ea'
Find and Replace '"(\w)', '“\1', 'Ea'


If you are using more punctuation marks, you might want to add them to the [,.;:!?] regular expression.

Greetings, Henry.


2009-11-12 02:15:02
Profile

Joined: 2007-11-09 15:27:25
Posts: 86
Thanks, Henry.

When I run these I get an error: expected "," to separate arguments.

In any case, I can’t produce a combination of quotes and punctuation that flusters the built-in ‘Convert' menu command. It seems to meet my needs just fine.


2009-11-12 06:46:37
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Sorry, the macro was lacking a single quote. This will do:
Code:
Find and Replace '"(\w)', '“\1', 'Ea'
Find and Replace '(\w|[,.;:!?])"', '\1”', 'Ea'

Anyway, the menu command has (had?) some shortcomings, mostly when single quotes are combined with double ones. Years ago I developed this macro, which converts quotes and fixes them.
Code:
Find and Replace "`", "'", "a"
Select All
Edit:Convert:Plain Quotes to Smart Quotes

Find and Replace "\“ \‘", "\“\‘", "a"
Find and Replace "\’ \”", "\’\”", "a"
Find and Replace "\‘\“\n", "\’\”\n", "aE"
Find and Replace "\“\n", "\”\n", "aE"
Find and Replace "\‘\“ ", "\’\” ", "aE"

This macro also takes account of the grave accent (`) diacritic, which is sometimes used, esp. in obsolete documents, instead of opening curly quote.

Greetings, Henry


2009-11-13 00:20:01
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
Perhaps this macro might be helpful for those who are familiar with NW Classic macro and are willing to update their NW Classic macros for NWP.
________________________________________________________

### Smart Quotes for NW Pro based on the SQ macro coming with NW Classic ###

# The original code is preceded by # (dark blue) and the original comments by # // (dark red).
# My comments are preceded by #k> (dark green).

# As explained below, the macro converts straight quotes into curly quotes

# skipping those used as feet/minutes designators and inches/seconds designators.

# ////=== Smart Quotes ===========

# //This macro replaces almost all (exceptions noted below) single and
# //double straight quotes with curly quotes. It does not replace a

# //single quote following a digit (feet designator) and two single
# //quotes at the end of a digit (inches designator).



# // Replace double quotes preceded by a space, a return, tab, left
# // parenthesis, brace or bracket, with curly opening quotes.
# Find/Replace "\(:<[\s\r\t([{]""\)|:s""" "“" "a-wAgt"

Find and Replace '(?<=[\s(\[{])"|\A"', '“', 'Ea'
#k> - (?<=<re>) corresponds to NW Classic's :< (character on left).
#k> - In NWPro, \s matches space, return, tab and more.
#k> - You have to put a backslash before [ in a set.
#k> - \A corresponds to :s (document start) but you can use

#k> also ^ (paragraph start) in this macro.


# // Replace all remaining double quotes with curly closing quotes.

# Find/Replace """" "”" "a-wAgt"
Find and Replace '"', '”', 'Ea'


# // The same for single opening quotes.
# Find/Replace "\(:<[ \r\t([{]'\)|:s'" "‘" "a-wAgt"
Find and Replace '(?<=[\s(\[{])\'|\A\'', '\‘', 'Ea'
#k> - You have to put "\" before single quotes.
#k> - You have to put a backslash before [ in a set.



# // Replace single opening quote nested next to a double opening
# // quote

# Find/Replace ":<“'" "‘" "a-wAgt"
Find and Replace '(?<=“)\'', '\‘', 'Ea'
#k> - You have to put "\" before smart opening single quotes too.


# // Replace closing quotes which are not preceded by a digit or
# // another single quote with closing single quote.

# Find/Replace ":<[^'0-9]\>'" "’" "a-wAgt"
Find and Replace '(?<![\'0-9])\>\'', '\’', 'Ea'
#k> - (?<!<re>) corresponds to NW Classic's :< followed by a negative set.
#k> - Instead of [0-9], you can use \d which matches non-European digits too.
#k> - Again, you have to put "\" before smart closing single quotes.
#k> - The original macro assumes that feet/minutes designator is

#k> represented by a straight single quote and inches/seconds
#k> designator by two consecutive straight single quotes.


# // The remaining single quotes not preceded by a digit (or another
# // single quote and not followed by a single quite) must be
# // apostrophes.

# Find/Replace ":<[^'0-9]':>[^']" "’" "a-wAgt"
Find and Replace '(?<![\'0-9])\'(?!\')', '\’', 'Ea'
#k> - :> (character on right) is supported as the positive
#k> (?=<re>) and the negative (?!<re>) where <re> is an
#k> expression representing text of variable length.


### end of macro ###


2010-09-17 10:07:57
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software