You’re working with InDesign and looking to avoid orphans, widows, and runts, so you’ve got your keep options up and running for those first two and you have Brennen Reece’s article bookmarked so you can reference that GREP expression. Good job!

So you’ve got \s(?=\w+~S?[[:punct:]]$) running in your basic paragraph style keyed to a no break character style, cascading down through all those styles based on that, and all is good. That’s such a good bit of GREPiness. What it does is this:

“As long as there is a space followed by a word with at least one punctuation mark at the end of a paragraph, apply a certain style to the space.” In this case, a no break character style.

Aside: No Break

This is a wonderful little character style that you’ll love with this GREP style. Just create a character style and the only thing in it is the No Break checkbox checked under “Basic Character Formats”. That’s it!

So Here’s the Problem

My workflow was just changed to include InCopy, which lets the editors and writers check out whole sections of text, edit them, and check them back into me. It saves me a ton of time doing proofreaders’ edits — they can do them — and I don’t have to waste time going back and forth with an editor or writer, adding or removing or rewriting copy to fill the page.

While that’s great, sometimes the person using InCopy accidentally adds a space at the end of the paragraph.

They can’t see it, but that regular expression sure can! When it looks at the paragraph, there isn’t a space followed by a word with at least one punctuation mark at the end of the paragraph. There’s just a space at the end of the paragraph! And there are no words or punctuation marks after it! So no, we don’t need to apply no break here.

And if the layout is just right, we get a runt.

So, instead of that, we’re cleaning up the regular expression somewhat. First, we go back to the original regular expression and see that it’s slightly different than the one on Brennen’s page. He’s got \w+~S? in there instead of \w+ before the call for punctuation marks. That ~S? is a bit confusing — there, he’s saying a space followed by one or more words and zero or one non-whitespace characters. (And then there’s the punctuation mark lookup.)

I don’t really need that, so let’s simplify it down to just \w+.

And we need to have the expression say “for a space followed by a word and a punctuation mark at the end of a paragraph, with an optional space after the punctuation”, so we get this:

\s(?=\w+[[:punct:]]?\s$)

And there we are: all those paragraphs still keep their errant spaces, and we don’t wind up with a line with just one word at the end of our paragraphs.

One Comment

  • liseann

    I am looking for grep that only makes last space no break in cases when the last word is 7 letters or less.
    This is the what I use now.
    (?=\w+ ?[[:punct:]]$)
    But it is causing loose lines, on some narrow justified text, when the last word has a higher letter count.
    Like this.

    fortable and efficient? Equipment and
    good sanitation.

Leave a Reply

Your email address will not be published. Required fields are marked *