| Barry MacDonnell's
Toolbox for WordPerfect
Macros, tips, and
templates for Corel® WordPerfect® for Windows®
| Page updated Jul 11, 2018
Main tips page | Browse tips
Hyphens, hard hyphens,
Using "Other Codes" in WordPerfect (Format > Line > Other Codes)
Edit > Paste
Special > Unformatted Text helps solve formatting problems when
copying blocks of text or macro code from the Internet or between
- A macro that helps prevent long web addresses (URLs) and e-mail
addresses from wrapping to the next line as a single block of text
From WordPerfect Help (F1):
divides words that span the hyphenation zone, a
narrow area that surrounds the right margin of a document. You can
enable automatic hyphenation [see below]. You can
also change the width of the hyphenation zone. Increasing the
hyphenation zone hyphenates fewer words, and decreasing the hyphenation
zone hyphenates more words. As well, you can create a nonbreaking
☼ A hyphen is what you get when you press the "-" key next to the "0" (zero) key.
In Reveal Codes it produces a [- Hyphen] code. Words containing hyphen codes will wrap at the hyphen to the next line. This type of hyphen is often called a "regular hyphen" to distinguish it from the other types below.
¤ A word divided by a [- Hyphen] code is considered to be a single word by WordPerfect when selecting or searching for the item (see Tips) and also when you ask the program to do a word count (under File, Properties).
• Sometimes WordPerfect's hyphens do not translate to another program, so in those cases you may want to use hard hyphens (next item below) in the source document instead of regular hyphens.
• When you use Find and Replace to locate a hyphenated word or number, you must use the same type of hyphen in the Find and Replace fields as exists in the item to be searched in the document. Hence, to find a regular hyphen, the item must contain regular hyphens (i.e., codes). To find hard hyphens (see next section below), the item must contain hard hyphens (which are characters, not codes).
Similarly, you will need to distinguish between regular and hard hyphens when indexing a document (see here).
• Macro writers:
Searching for a word or phrase containing regular hyphens (i.e., [-Hyphen] codes) that are stored in a macro variable causes the hyphen codes to be converted to hard hyphens (i.e., hyphen characters).
Therefore, to use SearchString() in a macro to find such an item, you must first use StrTransform() on the variable to transform the regular hyphen code into something the macro can use.
See the example in Footnote 1 (which also has an example that does not require StrTransform since it does not first store an item with hyphens in a macro variable).
Search for the hyphen code using the equivalent NToC() code with something like this:
See example #3 in Footnote 1 below for an example of using the hyphen's NToC code in a search.
- See the code in the PageLine macro in the Library.
- See this post at WordPerfect Universe, here, which demonstrates a macro that searches for two hyphens and replaces them with an en-dash (or em-dash).
☼ A hard hyphen (a.k.a. "character hyphen," "non-breaking hyphen," or "hyphenation character") is what you get when you click Format, Line, Other codes, Hyphen character, or simply press <Ctrl+hyphen>.
¤ Hard hyphens are sometimes inserted when pasting material from another program or Internet source with Ctrl+v, or when pasting using WordPerfect's Edit, Paste Special, Unformatted text (in WP10 and later versions, as explained here).
¤ A hard hyphen acts like any other "real" keyboard character (a,b,c,1,2,3, etc.); therefore, it doesn't produce any code in Reveal Codes (the hyphen you see there is a text character, not a format code).
¤ It is often used to "glue" compound items together such as dates (2000-2003) or part numbers (123-001) so that part of the item won't wrap to the next line.
¤ It also can be useful to ensure that hyphens are translated as hyphens in some other programs.
¤ A word divided by a hard (character) hyphen is considered to be a single word by WordPerfect when selecting or searching for the item (see Tips) and also when you ask the program to do a word count (under File, Properties).
• For easy access, you can assign "Hyphenation Character" to the <Ctrl+hyphen> keys if it is not already assigned to them. (See the tip about creating such shortcut keys below.)
• When you use Find and Replace to locate a hard-hyphenated word or number, you must use hard hyphens (not soft [-Hyphen] codes as in the above section) in the Find and Replace fields. WordPerfect's search function sees these as two different things, so you'll need to explicitly tell it what to look for,
Similarly, you will need to distinguish between regular (soft) hyphens and hard hyphens when indexing a document (see here).
• Macro writers:
The Type() command will change hard hyphens to regular hyphens (i.e., [- Hyphen] codes), even if they are contained in a variable that is then used as the Type() command's parameter.
You can work around this with the MinusSign command.
Type("ABC") MinusSign Type("123") will produce "ABC-123".
Use the ClipboardPut() command (new in WordPerfect 10) to store the item, then paste (not type) the item:
x:="ABC" y:="123" ClipboardPut(x +"-" + y) Paste
Result: "ABC-123" (connected with hard hyphen).
[Thanks to Greg Turner at WordPerfect universe.]
¤ This type of hyphen only becomes visible on the main editing screen (and in print) when the joined characters or words span the hyphenation zone. Otherwise you won't see it (but you can still see it in Reveal Codes as a [- Soft Hyphen] code).
¤ Unlike the other two forms of hyphen above, WordPerfect might count both words on either side of a [- Soft Hyphen] code separately (at least in recent versions of the program). Hence the program's word count (under File, Properties) would show such a soft hyphenated word -- when the hyphen is not visible on screen (or in print) and not at the margin -- as two words, not one word. Further, if the word is split at the margin the program might not even see the word during a word count, resulting in an erroneous count!
• A special soft hyphen code ([Auto Hyphen EOL]) can be inserted automatically by the program when needed. See Tools, Language, Hyphenation to turn automatic hyphenation "on" and (optionally) adjust the hyphenation zone.
• You can also insert a soft hyphen ([- Soft Hyphen]) manually wherever you decide you might need one. There are several ways to do it:
[A] Use Format, Line, Other codes, Soft hyphen -- or just use <Ctrl+Shift+hyphen> (which should be the factory default). In Reveal Codes, it produces a [- Soft Hyphen] code at the cursor location.
[B] For an alternative shortcut you could re-assign "Hyphen Soft" to (e.g.) the <Alt+hyphen> keys. (See the tip about creating such shortcut keys below.) Then when holding down the <Alt> key and pressing the hyphen key it will insert a [- Soft Hyphen] at the cursor location.
[C] You could record a simple macro (Tools, Macro, Record) and click Format, Line, Other codes, Soft hyphen, Insert. End the macro recording with the Stop button on the property bar. [If you were to edit the macro you will see the macro command SoftHyphen.] The macro can then be assigned to a toolbar, menu or shortcut key; see here. When played it inserts a [- Soft Hyphen] at the cursor location
In brief, it acts like a hyphen by dividing a word but it does not show a hyphen on the main screen or in print. In Reveal Codes, it produces a [Hyph SRt] code.
It is often used following a slash (stroke) mark ("/") or a dash ("—") to allow wrapping at that location. This can be especially useful for long Internet addresses (email addresses or website URLs) containing slash marks.
¤ Like the soft hyphen above, WordPerfect might count both words on either side of a [Hyph SRt] code separately (at least in recent versions of the program). Hence the program's word count (under File, Properties) would show such a divided word as two words, not one word.
• You can insert a hyphenation soft return with Format, Line, Other codes, Hyphenation soft return.
• You could also assign "Hyphenation Soft Return" to the <Alt+hyphen>, <Ctrl+Alt+hyphen>, or other available hyphen key combination. (See the tip about creating such shortcut keys below.)
• You can use the author's SoftWrap macro to automatically add hyphenation soft returns at appropriate locations in a block of text, such as e-mail and web page addresses, to prevent the entire text block from wrapping to the next line. (Just select the text first and play the macro.)
• For more general needs using dashes and slashes (strokes) along with hyphenation soft returns, see the sample WordPerfect document, "Dashes and Slashes.wpd," downloadable here.
What is a "hard" space?
Hard spaces, like hard hyphens, are useful in several circumstances to "glue" words, numbers or dates together to prevent them from splitting to the next line by the program's word wrap function. For example, they can keep items like "Mr. Roberts" on the same line.
Hard spaces can be entered from the keyboard by pressing <Ctrl+spacebar>. They produce a code ([HSpace]) in Reveal Codes.
[Arcane information: Normally, pressing the <spacebar> key produces a space character (ASCII 32), not a WordPerfect code (as with the hard space). On the other hand, pressing the hyphen key produces a WordPerfect code, not a hyphen character (ASCII 45). Both allow word wrapping without any extra steps.]
Notes and tips
☼ Shortcut keys: Hard hyphens, soft hyphens, and hyphenation soft returns can be assigned to the indicated keyboard shortcuts (if they are not already assigned) -- or to any available shortcut keys -- to make them easy to access while typing.
These three items are found under the Features tab in the Features category "Format," when you click on Tools, Settings, Customize, Keyboards tab, <keyboard name>, Edit. Then scroll down in the shortcut key list to find the -+Ctrl, -+Alt, etc., shortcut keys, remove the old assignment (if any), then Assign the feature to the key combination. (For more help on assigning features, macros, etc., to shortcut keys, see here.)
☼ Hyphenation zone. Hyphenation divides words that start before the left boundary of this zone (a narrow area that surrounds the right margin of a document) and extend past the right boundary of the zone. You can change it with Tools, Language, Hyphenation (earlier versions: Format, Line, Hyphenation). This is what the dialog looks like:
Enable the checkbox to turn automatic hyphenation on.
Most users find that it is best to use automatic hyphenation on the final draft of the document (if they use it at all) to minimize distractions during editing.
The left dotted line in the page representation represents the left boundary of the hyphenation zone; the middle solid line represents the right margin; and the right dotted line represents the right boundary of the hyphenation zone. The zone is measured as a percentage of the line length (determined by the current left and right margin settings).
Place the cursor where you want to change the zone.
Specify new percentages. Increase the percentages to hyphenate fewer words; decrease the percentages to hyphenate more words.
You might want to also set the prompt option in Tools, Settings, Environment, Prompts to your preference about when to stop and prompt you about an item to hyphenate: Always, Never, or (probably the best one) When Required. (If prompted, you can [a] insert a (Soft) hyphen, [b] insert a space, or [c] insert a hyphenated soft return, or ignore the word.)
☼ Re-hyphenate? If Hyphenation was turned on before you made changes, WordPerfect may prompt you to re-hyphenate some words. You can remove this message from older documents where hyphenation was previously turned on, but where it is currently turned off, with a macro: See UPDATER.
☼ You have to insert some of these items manually. Hard spaces (see above), regular hyphens, soft hyphens, and hyphenation soft returns must be deliberately inserted by the user in WordPerfect, while hard hyphens can be either deliberately inserted, imported from an external source, or converted by WordPerfect during certain "paste special" operations (see next item).
☼ Changes WordPerfect might make without telling you. If you paste material as "unformatted text" you should note the way WordPerfect 11 and later versions treat regular hyphens, soft hyphens, hyphenation soft returns, and hard spaces from a source document. See here for more (especially under the "Notes" section on that page).
☼ The en-dash is often used to "hyphenate" dates (e.g., 2012–2013), times, compound modifiers (e.g., two-word proper nouns), or already hyphenated compounds (e.g., "pre-word–post-word formatting"). WordPerfect 8 and later versions allow you to use QuickCorrect's QuickSymbols feature to create en- and em-dashes by typing either 2 or 3 hyphens consecutively. However, you may find that using simple macros that incorporate hyphenation soft returns suit your needs better since the items will then split at the margin rather than being moved to the next line. (See here for some example macros.)
[...continued from above:]
As noted above, storing a word or phrase
containing regular hyphens (i.e., [-Hyphen] codes) in a macro variable causes
the hyphen codes to be converted to hard hyphens. Therefore, to use
SearchString() in a macro to find such an item, you can first use
StrTransform() on the variable to transform any regular hyphens found to a code the macro can
use. This probably is most useful when storing a search item in a variable first, before doing the search. See macro #2 below.
EXAMPLE macro #1:
Alternative (simpler) method:
For simple searches, you might be able to use
the Codes button on the Macro Toolbar to insert the [-Hyphen] code
between two quote marks in the SearchString() command, as demonstrated
in example macro #1 below. [Note that
this appears as [Macro Func] in Reveal Codes.] Then you can have the
macro use an old trick to convert regular hyphens to hard hyphens: Cut
the found item to the clipboard and immediate paste it back as
Unformatted text -- which changes hyphen codes to hyphen characters. (Lots of other format codes can be converted this way.)
To make macro #1 process just one hyphen at a time, disable or delete the SelectWord command.
To make it change all found items from the cursor location forward simply enable both the While() and Endwhile commands, which currently are disabled with two slash marks.
// Macro begins here
This example macro below uses StrTransform(). It just pauses at each item found (here, "Smith-Jones") until you press <Enter>.
The "-" between the double quote marks in the "Smith-Jones" variable was inserted in the macro with the normal hyphen key (next to the zero key). The "-" between the double quote marks in the StrTransform() command below was also inserted in the macro with the normal hyphen key (next to the zero key). That is, all "-" items in the macro are actually normal hyphen codes, not hard hyphens [Ctrl+hyphen].
On the other hand, the [-Hyphen] (also between two double quote marks) in the StrTransform() command below was inserted with the Codes button on the macro toolbar. You must replace that text "placeholder" with the actual Code!
Instead of "Smith-Jones" you can use just a single hyphen (inserted with the hyphen key) to find all hyphen codes. For example: vStr:="-"
// Macro begins here
This example expands on Example #2 above.
It allows searching for BOTH normal
hyphens -- i.e., hyphens produced with the normal hyphen key (next to the zero
key) -- and hard hyphens produced with Ctrl+hyphen keys.
In this example the macro will search first for all instances of "Smith-Jones" where the hyphen might be a normal hyphen; then it searches for any instances of "Smith-Jones" where the hyphen might be a hard hyphen. (See the programming notes under the macro code for further explanation, especially about the use of the NToC() code.)
Finally, as with Example #2: Instead of
"Smith-Jones" you can find just the hyphen whether they are hyphen
codes or hard hyphens. For example, use vStr1:=NToC(64261) only for hyphen codes and vStr2:="-" only for hard hyphens. (In this case you might want to enable the Pausekey() command.)
// Macro begins here
 Note that an NToC(64261) code was used in the first variable (vStr1) above. This is equivalent to inserting a [-Hyphen] code (by pressing the hyphen key) in the macro's vStr:="Smith-Jones" command (and also in the StrTransform command) in macro #2 above. But in this example it does away with the need to use a separate StrTransform command because it already has transformed the normal hyphen code into a [Macro Func] code that the macro language can use.
[NToC() codes can be useful to macro writers for many of the various items listed in the Macro Toolbar's CODES button list. The NToC() codes for each of the various 400+ listed macro functions can be found in a MacroFuncCodes (PDF) file that you can download from the Library here.]
 Three commands -- SearchFindWholeWordsOnly, SearchCaseSensitive, and Pausekey(Enter!) -- are optional; hence they are simply commented out (///) in the macro. The Pausekey command, if enabled, will let you pause at each item to view it. (If that command is used, pressing Escape during macro play will pop a message and let you exit the macro.)
EXAMPLE macro #4:
This example expands on Example #3 above.
Like Example 3 it allows searching for BOTH normal hyphens -- i.e., hyphens produced with the normal hyphen key (next to the zero key) -- and hard hyphens produced with Ctrl+hyphen keys.
However, unlike the above examples which hard-code variables directly in the code (e.g., vStr:="Smith-Jones"), this macro employs a user-input dialog.
While this method is more flexible it has a small downside:
User-input devices such as the GetString() command or a custom dialog will typically automatically convert a normal hyphen's format code ([- Hyphen]) that was stored in the device's input variable to a hard hyphen (-), and a macro search using such a converted variable will fail to find the desired items containing hyphen codes. In short, a hard hyphen is not identical to a hyphen code as far as the program is concerned.
Use the PerfectScript StrTransform() command to convert the variable's hard hyphen back into a hyphen code, then do the search using the new converted variable.
Here we assume you want to search for both
varieties of a search term such as "Smith-Jones" -- one that might
contain the hard hyphen and one that might contain the hyphen code --
you can use something like the following code. (The code should be
adjusted to fit your needs and tested thoroughly.)
// Macro begins here (ALL commands should be on 1 line ending with a HRt)