is now part of CreativePro.com!

Highlight a Specific Set of Words in InDesign

2

Have you ever needed to highlight or otherwise style a set of words in InDesign? Maybe you have a set of state names that you need to stand out or maybe you have a set of cooking terms you want to style a particular way.

There is a semi-magical way to do that. If you know me and my InDesign interests at all, you’ll know I’m going to show you a way to do this using the power of GREP.

Let’s use the cooking terms example. And let’s imagine that we need to style terms like grilling, baking, and boiling. The list could be very long, but we’ll keep the sample list short… the GREP window in InDesign is pretty tiny. Stick around for a solution for that problem at the end of the how-to.

Here’s our sample text:

You could apply formatting via the Find/Change dialog box—one of the places GREP lives in InDesign—but you would have to rerun the operation every time you update the text or if you decide to add a new term to the list. Instead, let’s build the expression into a paragraph style, so the terms will get styled on-the-fly.

First come up with the list of words to search for:

  • Include any variants you might need to find, like grill, grilling, bake, baking, fry, frying.

Next, create the styles:

  • Make a paragraph style for the text called cooking text.
  • Make the character style that will highlight the words from the list; we’ll make our style bold and green and call it cooking terms.

Finally, create the GREP expression. This is what I call the either-or expression. Though in our case it’s more like either-this-or-that-or-that-or-that. The expression uses the pipe character (found above the backslash key on your keyboard) to divide the words. A shortened version of our list might look like this to start: grilling|boiling|baking|frying. This expression says to find grilling or boiling or baking or frying.

We can enter that expression within a paragraph style so that any text formatted with that style will have our cooking terms character style applied to it. To do this, right-click on the cooking text style in the Paragraph Styles panel and choose Edit. In the GREP Style area of the dialog box click the New GREP Style button. Choose the cooking terms character style from the Apply Style menu and enter the GREP expression in the To Text field. Make sure Preview is turned on so you can see the styling and confirm that your new GREP style is working as expected.

Notice that the character style is not being applied to terms matching the GREP expression that appear at the beginning of sentences. That’s because GREP is case-sensitive by default. There are several ways to write an expression that will catch both Frying and frying. For our example, let’s just tell it to be case-insensitive. Add (?i) to the beginning of the expression and now it will catch both Baking and baking.

An either-or expression will find everything on each side of the pipe, so you may need to set off your word list in parentheses. If your expression reads Kitchen Sink Stopper|Utensils|Towel, the first segment will look for Kitchen Sink Stopper, and it will also search for Utensils or Towel. But what if you wanted to find each of those terms with the word Kitchen in front? You could type Kitchen in front of each word, but that makes for a really long expression. Instead, your expression could be: Kitchen (Sink Stopper|Utensils|Towel). That will find the word Kitchen followed by any one of those other words.

Bonus GREP Tips

  • If your text includes words that contain other words you’re searching for—like grill and grilling—then you need to put the longer word before the shorter one in the expression. Otherwise, it would match and format grill (even when it’s part of grilling) then continue on with the search, never matching the full word grilling.
  • The little window in the Find/Change dialog box is quite small for creating GREP expressions. If you want more room to work, try the GREP Editor script by Peter Kahrel. You can load a GREP expression into the Find/Change dialog box, then open the GREP Editor, and load the expression into the spacious window!

Using this either-or type of expression is great when you know all the words you need to format and it’s especially handy when you use it as part of a style that will automatically format your chosen words as you work.

Erica Gamet has been involved in the graphics industry for over 35 years. She is a speaker, writer, trainer, and content creator focusing on Adobe InDesign, Apple Keynote, and varied production topics. She is a regular presenter at CreativePro Week, regular contributor to CreativePro Magazine, and has spoken at Canada’s ebookcraft, Adobe MAX, and Making Design in Oslo, Norway. Find Erica online at the CreativePro YouTube channel, CreativeLive.com and through her own YouTube channel. When she isn’t at her computer she’s probably daydreaming about travel or living in a Nordic noir landscape.

Website
LinkedIn
Instagram
  • Meert Nonkel says:

    Thanks for this usefull grep Erica,
    I’m using a similar grep style, and was wondering if the expression in your example also finds a word after the parentheses?

    • Erica Gamet says:

      If the word fits a pattern or is consistent. Like if you wanted to find the phrases from the example above:
      Kitchen Sink Stopper Merchants OR Kitchen Towel Merchants
      you would put Merchants after the parenthesis (and a space of course)
      Kitchen (term|next term|term three) Merchants

  • >
    Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo