is now part of CreativePro.com!

Automatically Highlight Text with Spaces

3

A reader in Texas wrote to us with a problem: he was using the tip about highlighting one or more words in a paragraph using a custom underline, but the highlight hugged the sides of the text too closely:

Highlightspaces4

It would be nice if the highlight extended a bit past the left and right edges of the word, no? Well, the trick is to add spaces — actual spaces (either the regular spacebar character, or a thinner or thicker space, which you can find from Type > Insert White Space). The “highlighter” character style applies to those spaces, too, giving a buffer of space around the text.

As I was thinking about that solution, I realized you could actually automate the highlighting a bit by using those spaces and the GREP Styles feature.

First I made a character style for my highlight:

Highlightspaces1

Then I applied it in a grep style inside a paragraph style:

Highlightspaces2

The grep style I used was:
(?<=\s)\s.+?\s(?=\s)
This grep code just looks for text that is in between two spaces. That is, it looks for a space-space before the text and after it, and then applies the highlight character style to the text and just one space on either side of the text:

Highlightspaces3

The great thing about grep styles, of course, is that you don’t have to apply the style manually — in this case, you just type an extra space before and after the word or phrase you want to highlight and it’s done!

(Beginner’s Note: The little dots between the words in the images above are regular spaces; we’re seeing those because I first selected Type > Show Hidden Characters. That’s helpful for seeing where normally-invisible characters, such as spaces, are.)

The nice thing about the \s code is that it works for any whitespace character, not just the spacebar. So you could, for example, use Type > Insert White Space > Thin Space instead.

Of course, the problem with grep styles like this is that it’s really easy to make a mistake? just press two spaces after a dot at the end of a sentence, for example, and the mistake will be, er? unmistakable!

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Hi David,
    Very good tip.
    I have found a typo in the text of the Grep code (not in the Paragraph style’s Grep Style window inserted code).
    You typed: The grep style I used was:
    <?<=\s)\s.+?\s(?=\s)
    when it would get started with an opening parenthesis ( instead of < (this metacharacter does not start any GREP code)
    (?<=\s)\s.+?\s(?=\s)

    For beginners like me, it "plainly" means:
    There is one space (\s) before -positive lookahed- another space and letters (.) appearing one or more times (+?) -a shortest match, inmediately followed by- one space and another space follows it (positive lookbehind).
    .
    Thanks again, and my Best Wishes for the 2013 to come

  • Thank you, Federico! I have fixed that typo in the blog post now. Happy new year!

  • Eugene says:

    What are the chances that Adobe will allow negative values for underline or strikethrough in InDesign CS24 … not likely.

  • >