InDesign CS5 and GREP Style: No more orphaned words

As you may know, InDesign CS5 offers a lot of support for fixing widows and orphans in its upgraded keep options. It can prevent single lines at the end of a paragraph from wrapping to the next column or spread (orphan) or a single line starting a paragaph at the end of a column or page (widow). The one problem it has not addressed is the the lone orphaned word. That’s when one lone word wraps to the last line of a paragraph.

Designers and production artists have many ways to fix this, by increasing or reducing tracking or adding a forced line break to the word before. All this requires a hands on approach. With InDesign’s GREP styles feature, lone orphaned words can be prevented automatically.

For a good tutorial on GREP styles, Layers Magazine has one called Using GREP Styles in InDesign.

Here is an example of a newsletter. Two of the paragraphs have lone orphaned words, circled in red. (click on the thumbnail)

First, make sure the paragraphs affected have paragraph styles applied. GREP styles work within paragraph styles. Right click on the paragraph style name in the paragraph style panel and select “Edit stylename…” (click on thumnail for larger view)

Select GREP Styles from the left menu of the Edit Paragraph Style dialog.


When you click on “Apply Style,” you can create a new Character Style from the pull down menu (you could also have created this character style before, but I wanted you to see that you can create character styles on the fly. Call this Character Style No Break. Select “Basic Character Formats” and check the “No break” checkbox. Don’t alter anything else. Click okay.

In the “To Text” field, you will need to enter this code:

\<\w+?\>\s\<\w+?\>[.!?]?\r

The first set of characters describes a word: \<\w+?\>.\< is the expression for the beginning of a word. \w is the expression for a word character. The expression +? means that the word character occurs one or more times and is the shortest match. The \> is the expression for the end of a word. \s is the character for a space. Then the first set of characters is repeated. Next [.!?] signifies that one of the characters inside follows the second “word” pattern. It could be a period, an exclamation point, or a question mark. These are the most common punctuation that ends a paragraph.

Warning: This code is specific to my Caption paragraph style. The third character from the end, which is a question mark symbol, is what makes the difference. This question mark symbol follows [.!?] and basically means that the punctuation can occur once or not at all, that is there can be no punctuation but if there is, it should be a period, an exclamation point, or question mark. For my caption, I don’t want to always have to have a punctuation mark, but I do want to avoid orphaned words. For most paragraph styles, leave out the question mark symbol here.

Finally, \r signifies the end of a paragraph. In essence, the GREP expression says, “Look for two words at the end of a sentence (which has a period or an exclamation point or a question mark) which is the last sentence in the paragraph and apply the “No Break” character style to those two words.

For my First Para paragraph style, I can use an alternate expression:

\b\w+?\b \b\w+?\b[.!?]\r

Where \b means “word boundary”. This replaces the “beginning of word” and “end of word” expressions. Also, I put in a literal space instead of the \s expression for whitespace. I removed the question mark symbol after [.!?] because I want for there to always be a punctuation mark at the end of the sentence (at the end of a paragraph).

Now the last two words will stay together on a line so that no lone orphaned word exists.

Note: This has the added benefit of finding those sentences at the end of a paragraph where punctuation may be omitted or an incorrect punctuation mark is used. Since paragraph style is applied, if the GREP style isn’t working, it may because you left out the punctuation, or put in a superfluous character after a period.
Advertisement

About this entry