Two macros into one: Typographer's Quotes

Get help using and writing Nisus Writer Pro macros.
Post Reply
jb
Posts: 89
Joined: 2007-11-09 15:27:25

Two macros into one: Typographer's Quotes

Post by jb » 2009-11-11 10:14:50

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?

Groucho
Posts: 496
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Two macros into one: Typographer's Quotes

Post by Groucho » 2009-11-11 11:44:13

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.

jb
Posts: 89
Joined: 2007-11-09 15:27:25

Re: Two macros into one: Typographer's Quotes

Post by jb » 2009-11-11 13:11:04

Ah, thank you.
Didn't see that. I assumed it would be in the form of a macro...

Groucho
Posts: 496
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Two macros into one: Typographer's Quotes

Post by Groucho » 2009-11-12 02:15:02

Now that we are at that, consider this macro:

Code: Select all

Find and Replace '(\w)"', '\1”, 'Ea'
Find and Replace '"(\w)', '“\1', 'Ea'
Or, if you want a macro that takes punctuation into account:

Code: Select all

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.

jb
Posts: 89
Joined: 2007-11-09 15:27:25

Re: Two macros into one: Typographer's Quotes

Post by jb » 2009-11-12 06:46:37

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.

Groucho
Posts: 496
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Two macros into one: Typographer's Quotes

Post by Groucho » 2009-11-13 00:20:01

Sorry, the macro was lacking a single quote. This will do:

Code: Select all

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: Select all

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

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Two macros into one: Typographer's Quotes

Post by Kino » 2010-09-17 10:07:57

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 ###

Post Reply