WinEdt Macro Library  | text previous macro  | next macro

# smartQuote2

## Description

This macro will insert (single or double) quotes depending on the document's mode or submode. Additionally, it's a bit smarter than WinEdt's default Smart Quote.edt macro.

It will not simply toggle quotes, but will determine whether opening or closing quotation marks are desired by looking at the preceding character. (You can turn off extra smartness by changing one line in the macro file.)

The quotation style will be determined as follows:

1. If a style for the document's mode is defined (e.g. TeX, or TeX:DE), take the corresponding quotes;
2. else try whether a style is defined if we subtract submode(s)
(e.g. if the document's mode is TeX:US:UNIX, it would be TeX:US, if it were TeX:ES:MAC, it would be TeX).
3. If it's a TEX document, the macro will also search the document's preamble for a line like:
% !smartQuote:: "French"

4. If all fails, take default quotes.

It is also possible to have both opening and closing quotation marks typed in one go (useful for programming).

## Installation

Put the macro in %b\Macros\text\, and assign a shortcut to it:

For WinEdt 5.6 or older:

1. go to Options | Menu Setup | Main Menu, double-click on Shortcuts,
2. at the end of the list, Insert a new Macro item called "Smart Double Quotes",
3. the Macro field must contain:
[Assign("smartQuote","double");Exe("%b\Macros\text\smartQuote2.edt");]

4. Click in the Shortcut field and type the double quote character " (this will be translated to the actual combination of keys that produces a double quote on your keyboard).
5. Optionally, repeat these steps for the single quote character.
(Here, the Macro field must read:
[Assign("smartQuote","single");Exe("%b\Macros\text\smartQuote2.edt");]

and the shortcut must be the single quote character ' )

1. add the following lines to the "Shortcuts" submenu in the Main Menu (accessible through the Options Interface):
ITEM="Smart_Double_Quotes"
CAPTION="Smart Double Quotes"
MACRO="Assign('smartQuote','double');Exe('%b\Macros\text\smartQuote2.edt');"
SHORTCUT="___"

2. in the last line, insert the shortcut for the double quote character (by double-clicking on "SHORTCUT" or using the Insert Shortcut button)
3. Optionally, repeat these steps for the single quote character:
ITEM="Smart_Single_Quotes"
CAPTION="Smart Single Quotes"
MACRO="Assign('smartQuote','single');Exe('%b\Macros\text\smartQuote2.edt');"
SHORTCUT="___"

You do not need to add a second shortcut to be able to insert a normal quotation mark (as was necessary with previous versions of this macro). Instead, typing the quotation mark twice will give you the default. (This, too, can be turned off.)

## Options

You can easily define different types of quotation characters for modes, submodes, and have local styles for TEX files.