Technical Writer, Production Support, Software Training

InDesign: Introducing GREP Styles (1)

089_12_applied
InDesign CS3 introduced the ability to perform GREP Find/Changes, making it easier for us to apply character styles to text pattern strings such as ‘all text’ between parentheses.  InDesign CS4 continued the “GREP-theme’ through its  ability to lock this pattern based application of character styles into your Paragraph Styles.

The following tutorial is part of a 4-part series on GREP Styles.

Part 2: Change the appearance of numbers (figures) within a given paragraph style

Part 3: Converting text typed in Capital Letters to Small Caps (OpenType feature)

Part 4: Formatting price tags containing dollars and cents with multiple character styles

In this first tutorial we start with a simple GREP style tutorial that looks at how we can automatically apply a character style to all text between parentheses.

Task at hand

All of the paragraphs for which the text between parenthesis must be set in Italic have already had a Paragraph Style “Body Text” applied to it.

Define a Character Style

In preparation for the GREP style, I prefer to create the Character Styles required prior to defining the GREP style components (Character Style and Expression).

To define a Character Style: Highlight some text in the Body Text paragraphs and change its formatting. I’ve changed the Font Style to Medium Italic.

089_01_newcharst

Next choose New Character Style from the Character Styles panel menu and Name the Style. I’m naming mine “Medium Italic”.

089_02_namestyle

Click OK to add the style to the Control Panel. I’m purposely not clicking “Apply Style to Selection’, as the text I formatted with Medium Italic is only used as the basis for the Character Style definition.

089_03_clearoverride

Because we set some of the text in Medium Italic (Font Style), our Paragraph Style now indicates with the ‘+’ icon that this format is not native to the Paragraph Style. Let’s remove this format override, by clicing the Clear Overrides icon at the bottom of the Paragraph Styles panel.

It is now time to add the GREP Style to our Paragraph Style.

089_04_editbodytext

GREP Style

Right-click the Paragraph Style and select Edit “Body Text” to edit the style. The Paragraph Style Options dialog appears. Click GREP Styles.

089_05_newgrepstyle

First of all lets set the Character Style that we’re going to apply to the GREP Expression we’re inserting in just a moment. From the Apply Style drop down choose the Character Style created earlier.

089_06_applystyle

The Character Style we want to apply is “Medium Italic”.

Oops did you forget to create the Character Style? Don’t worry, from InDesign CS4, you have the ability to create your Character Style right here in the Paragraph Style Options dialog. Have a look at the bottom of the Apply Style pop-up and notice the “New Character Style”.

GREP Expression

It’s time to get GREPPING… so what was that pattern again we were looking for? An Open Parenthesis character, followed by any type of text (alpha-numerical, spaces etc. all allowed), finished off with a Closing Parenthesis character.

Symbols

If you are already a GREP wiz you might be able to enter the required GREP expression in the To Text field. However, I personally prefer constructing the expression bit-by-bit. The Special Characters For Search pop-up is a great help in constructing the expression. InDesign will automatically insert the correct expression data.

089_07_openbracket

Our Open Parenthesis Character is part of the Symbols group.

As you select this component, you might notice that the text entered in the To Text field is now set to \(.  Certain symbols are reserved by GREP for particular expression components. The Parenthesis form part of this group of characters. For our GREP Expression to recognise the  “(” as a literal character it must be preceded by a “\” character. This “\” is referred to as an Escape Character.

Each of the following characters is reserved by GREP: * ^ } ] ) $ . { [ ( | + ? ~

If you want to use these characters as a literal character in a GREP expression, you must escape them with the “\”.

Wildcards

Next we’re after our next part of the expression: The any text or words etc. that are inserted prior to the closing parenthesis.

089_08_anycharacter

When you are looking for ANYTHING… Think of the fact that you know that this ANYTHING might be an “a” or a “b” or really any character of the alphabet, and even numbers or spaces.

Wildcards are a way of defining an “ANYTHING”.  And as we’re looking for any type of character, not just Digits (numbers), Letters (alphabetical) or White Space (spaces), we’re choosing Wildcards > Any Character.

089_09_oneormore

A “.” is added to the GREP expression.

Repeat

You might think at this stage that you’re there… Not quite… GREP Expressions need to know home many times on ef these Any Characters can occur… So we need to know tell the Expression how many times this Any Character can repeat itself.

Let’s assume we don’t encounter “()” (without text between the parentheses). So we’re looking at One or More occurrences.

Shortest Match

So what would happen if there is more than one set of “()” within a paragraph? Well, this is where the Shortest Match option comes in handy. Shortest Match looks for the first occurrence of the “(” and the first occurrence of the “)”, the shortest possible string it can find in the paragraph, and that is exactly what we’re after 🙂

So let’s choose Repeat > One or More Times (Shortest Match).  This adds “+?” to the expression.

We’re almost there at this stage. All we need to add to our expression now is the Closing Parenthesis character. We jump back to Symbols for that one.

Choose Symbols > Close Parenthesis Character

Our finished expression is \(.+?\)

089_11_finished

Any text between brackets is now set using our GREP style. Click OK to apply the GREP style to the Paragraph Style and see the finished result.

089_12_applied

Video Tutorial

 

Similar posts
  • Adobe InDesign and XML: A Reference Guide The following is a reference guide I have compiled over time for those of you who are looking at doing a little more with XML in InDesign (originally published Feb. 2011, last updated Feb 2018). If you have any extra information you’d like to see added to this guide, feel free to message me. Mapping XML tags to InDesign [...]
  • How to change the colour of bullet points in InDesig... A few weeks ago I recorded a short quick tip tutorial. InDesign’s Control panel, gives users a quick and easy way to format text as a bulleted list. Highlight the text, and click the Bulleted List button in the Paragraph Formatting Controls mode for the Control panel. This applies a universal bullet character as the [...]
  • Creating a pop-up window in a PDF with Adobe InDesig... In the following YouTube tutorial, we’ll create an interactive PDF from Adobe InDesign, in which we click on a button, which in turn opens up a simple pop-up window containing a close-box. When the close-box is clicked the pop-up window disappears [...]
  • InDesign: Facing pages with odd-numbered left pages Back in 2004 I wrote a tip for InDesign CS on how you could have the first page of your document be a left page AND have it start with page number 1. It’s hard to believe this is almost a decade ago… But a recent question on Facebook, made me think I should really [...]
  • Negative Lookbehind – GREP for Designers This is the fourth and final blog-posts in a series of posts on lookaheads and lookbehinds in GREP, written after speaking at the Perth InDesign User Group. My speaker notes are also available: What is GREP? (PDF download) (2.4Mb). In the previous three posts I briefly introduced GREP, and we took a look at Positive [...]

1 Comment

  1. March 3, 2018    

    Study the psychic sphere regarding the ins and outs, skills that you could acquire, and it is abilities.
    We should judge the unexplained using criteria and seeking results which might be fair, reasonable and appropriate.
    It isn’t uncommon to know these words and come across a topic at regular intervals about
    fortune telling.

Leave a Reply

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