Section 2.6. Replacements on the Fly


2.6. Replacements on the Fly

A program may process your input so that it is immediately changed as you type. This is usually based on assumptions on what people really want to type but cannot type directly, due to keyboard limitations. Sometimes such features are very convenient, sometimes really frustrating, if the user does not know how to override or undo their effects.

2.6.1. Default Replacements in MS Word

Word processors often modify user input so that when you have typed, for example, the three characters (c), the program changes that string, both internally and visibly, to the single character ©. This substitution is often convenient, especially if you can add your own rules for modifications. On the other hand, it causes unpleasant surprises and problems when you actually meant what you wrotee.g., you wanted to write letter "c" in parentheses.

Use Ctrl-Z as the immediate cure to an undesired on-the-fly conversion in MS Word. If you are uncertain of what happened, use Edit Undo instead (since Word will show which operation will be undone).


In MS Word, there are several automatic conversions like the one described above. They can be modified: you can remove conversions that you regard as annoying, and you can add conversions of your own.

Figure 2-15. The Tools menu in MS Word


2.6.1.1. Viewing and changing the rules

There are many different settings in MS Word, and their organization is not always what we might expect. In the Tools menu, as shown in Figure 2-15, the Customize and Options commands lead to various settings, but the automatic replacements are found via the command AutoCorrect. Having selected the command, you get a new window, where the first pane is as in Figure 2-16.

In addition to some settings related to the case of letters, the AutoCorrect pane contains a table of replacements. It has default rules, such as replacing (c) with ©, and you can click on a rule and then click the Delete button to remove it. You can add your own rules. In Figure 2-16, the user has typed ^2 into the Replace box and 2 into the With box, and by clicking on Add, she will add a rule that makes it easier to type superscript 2.

You can enter special characters in the With box using the methods explained above, such as the Windows Character Map. It can be a bit awkward, but once you have gone through it, you have an input method that you have designed for yourself. Beware, however, that the replacement is (in general) performed only when the string to be replaced appears as a "word," i.e., surrounded by spaces or other whitespace characters. Thus, you may need to type a space and delete it later.

Figure 2-16. The AutoCorrect settings in MS Word


2.6.1.2. Language dependency

The settings for replacements are language-dependent in the sense that they depend on the language of the text as guessed by Word or as explicitly told to it. As a reminder of this, the settings have the current language name in the window's title bar (see Figure 2-16). In particular, check the language setting if you have changed the keyboard settings, since setting the keyboard layout often changes the assumed language of text in Word.

Thus, you could set things up so that when typing in English, the two hyphens in "foo--bar" get converted to an em dash, producing "foobar," but two consecutive hyphens are preserved when typing in French.

This not quite as comfortable as it may seem, since Word is not perfect in guessing the language, and human beings are not perfect in remembering to check such things. Moreover, things get a bit awkward if you would like to have certain replacements applied regardless of language. You need to copy these replacements into the settings for all languages.

Figure 2-17. AutoFormat settings in MS Word: contextual replacements


2.6.1.3. Autoformatting in MS Word

In the AutoCorrect window, there are some other panes as well. One of them is related to character processing: the AutoFormat pane, as shown in Figure 2-17. The settings vary by Word version, but the general idea is the same: automatic replacements that are not all just simple string replacement but involve some contextual analysis. You can select which replacements are enabled by checking or unchecking the checkboxes.

Some of the AutoFormat settings are actually simple string replacements, but one setting (like "Ordinals (1st) with superscript") can correspond to a collection of settings (e.g., 1st, 2nd, etc.).

Even the setting that is described as replacing -- with actually does other things as well; it replaces the following:

  • A single hyphen with an en dash, if the hyphen is preceded by a space: -foo becomes foo

  • Two consecutive hyphens with an en dash, if the hyphens are preceded by a space: foo -- bar becomes foo bar (helping to write British-style dashes)

  • Two consecutive hyphens with an em dash, if not preceded by a space: foo--bar becomes foobar

2.6.1.4. Example: quotation marks

Language-dependency is essential for quotation marks. Their use varies greatly by language. Here are some examples:

  • "foo" (U.S. English style)

  • « foo » (French style)

  • "foo" (German style)

  • "foo" (Swedish style; note that the quotes are identical)

Normally, you can just type text, and Word converts, say, your input "foo" (typed using the normal key for ASCII quotation mark) to a language-specific form. However, this requires that Word knows or guesses right the language you use. Therefore, it is a good idea to check first, when starting to create a document, that Word has the right idea of language. Normally the language indicator appears on the bottom row of Word's window. You can click on it to change the language, or you can use Tools Language.

Whether this happens depends on whether the checkbox about replacing "Straight quotes" with "smart quotes" has been checked in the AutoFormat settings (see Figure 2-17). Thus, the setting has a more general meaning than its name suggests.

MS Word does not know the British English style of using single quotation marks for normal quotations. However, you can simply use the key for ASCII apostrophe, and Word will convert your input 'foo' to 'foo' when in English mode.

The automatic conversion of ASCII quotes to language-dependent quotes might fail to work, for example, if your version of Word does not support a particular language or the feature has been disabled. You can type the correct quotation marks manually. Appendix A contains some quick references for this. For example, Ctrl-' " (control-apostrophe followed by quotation mark) creates a right double quotation mark, ".

2.6.2. Defining Your Own Shortcuts

Shortcuts are key combinations using Alt, AltGr, or Ctrl for special purposes, such as typing special characters. They differ from the replacements discussed above, since the replacements modify the data that has been typed. In practice, however, the two methods serve similar purposes and can be used as alternatives. For example, MS Word may by default replace the character sequence (r) with the character ®, but in many situations, you can also write ® by pressing AltGr-R (or Alt-Ctrl-R).

In MS Word, you can locate a character in the Character Map and then click on the Shortcut Key button to enter a dialog in which you can define a shortcut for the character. (See Figure 2-11.) By default, this definition will be saved into the Normal.dot file, so it can be used whenever you later edit documents based on that template. In Figure 2-18, the user has entered the dialog and typed Alt-P (echoed in a text box as Alt+P), because that's the shortcut he wants to use for the character he selected.

Using this dialog, there are a few things to note:

Figure 2-18. MS Word dialog for defining a shortcut for a character


  • Use this technique primarily for characters that will be needed often and that are difficult to type using other methods.

  • Select a shortcut that has some connection with the character. For example, Alt-P for a circled P is easy to remember. See Table 2-3 for some additional ideas. You cannot use normal keys as such; you need to involve Ctrl, Alt, or AltGr (and optionally Shift). However, as a second key, you can use a normal key as such (example: Ctrl-/ a).

  • Check that you are not going to override any existing shortcut you may need. The existing setting, if any, can be seen under the text "Currently assigned to."

  • Check that you are defining a shortcut for the right character (shown under Symbol).

  • Remember to click on Assign before clicking on Close.

  • After defining the shortcut, check immediately that it works in the desired way. You will be in a good position to fix things if needed; later, you might not remember what you were really about to do.

  • It is a good idea to write down the assignments you have defined. You can, however, check them later: select the character from the map and enter the dialog, and look under "Current keys."

  • As the plural "Current keys" suggests, you can define several alternative shortcuts for a character. This can be a good idea especially if you are designing a working environment for other people, who might not understand and remember quite clearly whether they need to use Alt-P, AltGr-P, or Ctrl-P. However, there is then a risk of overriding some shortcut definitions they might need. If you use the Ctrl key, you probably will not mask out any useful existing assignment in MS Word.

Table 2-3. Possible ideas for shortcuts

Shortcut

Meaning

Context for use

Ctrl-/ L

(L with stroke, U+0141)

Polish names

Ctrl-. e

(e with dot above, U+0117)

Lithuanian names

Ctrl-- -

(right arrow, U+2192)

Mathematical texts, references

Alt-Ctrl-2

2 (superscript two, U+00B2)

General text containing, for example, m2

Alt-S c

(black club suit, U+2663)

Bridge column

AltGr-S

(s with caron, U+0161)

Czech names

Alt-f

(female sign, U+2640)

Biological texts




Unicode Explained
Unicode Explained
ISBN: 059610121X
EAN: 2147483647
Year: 2006
Pages: 139

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net