is now part of CreativePro.com!

GREP of the Month: White Space

2 15
This article appeared in Issue 84 of InDesign Magazine.

Poor white space, it never gets the credit it deserves. Think about it: without spaces, your text would all run together and you wouldn’t know where one word ended and the other began. According to the book Space Between Words by Paul Saenger, separating words with spaces didn’t really catch on until the tenth century; before that, it was up to the reader to decide where one word ended and the next began. Fun!!

Space between words is called “white space” because there’s no visible glyph; it’s the absence of ink. You may think there’s only one kind of white space—the kind you get by hitting the spacebar. Wrong! InDesign’s GREP allows you to search for and replace a dozen different kinds of white space, from the spacebar-created ones to complex constructs like figure spaces; to see them all, open the Find/Change dialog box, click the @ symbol, and then choose the White Space menu item. You can search for these white space characters the same as any other character.

Let’s say you’re a designer who likes to use en dashes with a space on each side – like this. But some smart aleck comes up to you and says you should really use nonbreaking spaces, so that your dash doesn’t accidentally wrap to the next line. 

Type \s~=\s in the Find What field and ~S~=~S in the Change To field to change all those ordinary spaces to nonbreaking ones.

That \s character (“any white space”) is also handy if you want to change every instance of more than one space to a single space. Find \s{2,} and change to \s. The {2,} construct means “anything with two or more consecutive.”  Or you can use InDesign’s built-in Multiple Space to Single Space query, which does the same thing in a more verbose way.

More after the jump! Continue reading below
Free and Premium members see fewer ads! Sign up and log-in today.

Parting tip: When playing with spaces, it’s best to turn on Type > Show Hidden Characters. 

Chuck Weger is Principal at Elara Concepts LLC. He has over 20 years experience as owner of a computer consulting company, specializing in helping clients automate publishing workflows.
  • Erica Gamet says:

    Thanks, Chuck! Recently I decided to use the less verbose h{2,} to delete multiple space… and learned with an “oops!” moment that this expression will also zap out multiple tabs. I’ve since gone back to the verbose expression when just trying to zap out extra spaces.

    Is there any difference between h and s at all? I only recently realized that s also includes the tab (I had it in my head that it didn’t).

    • Dhafir Photo says:

      Hi Erica!
      There are many differences between s (Space) and h (Horizontal whitespace)
      s Matches all horizontal whitespaces, breaks (tab, right indent tab, and indent to here), and all vertical whitespaces (forced line break, carriage return and other break characters like page, frame, column breaks, …etc.).
      h Matches only the horizontal whitespaces including a tab.
      Therefor, it’s very wrong to use s with all cases, especially in this regex s{2,} because if there any space or more before break character, or carriage return at the end of paragraph, that will merge it with the next line.
      So, the better method is using h instead of s, and p{Zs} (regular whitespaces) instead of h if we do not need including tab.

  • >