Site Info

This web-site is created and maintained by Cari Jansen, Perth, Western Australia.


Advertisements



« | Main | »

Introducing GREP Styles (1)

Digitip 088 – Adobe InDesign CS4 – GREP Styles (1)

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 introduces the ability to lock this pattern based application of character styles into your Paragraph Styles.

In the upcoming series of tips I hope to introduce some uses of GREP Styles as demoed during the June 2009 – InDesign User Group meeting in Perth.

089_12_applied

This first GREP style tutorial tutorial looks at how we can automatically apply a character style to all text between parentheses.

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 choose 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

Topics: Adobe, GREP, InDesign, digitip | 7 Comments »

7 Responses to “Introducing GREP Styles (1)”

  1. Jochen F. Uebel says:
    July 5th, 2009 at 11:11 pm

    Hi Carl,
    very good, thanks. Think it is very important to communicate these new technologies proudly and intensively.
    Tried something similar just two days ago: with the simple example of figures typogracilly organized in groups of three. Don’t mind the German; GREPs are international ;-)
    http://blog.smi.ch/2009/07/03/automatische-3er-gruppe-zahlen/
    Jochen

  2. Cari Jansen says:
    July 5th, 2009 at 11:26 pm

    Hi Jochen. Great site! Thanks.

  3. Jochen F. Uebel says:
    July 5th, 2009 at 11:28 pm

    BTW: Michael Murphy has shown in his great new book on InDesign Styles that Adobe’s list of GREP Metacharacters is incomplete. What about a quick change of
    http://help.adobe.com/en_US/InDesign/6.0/WSa285fff53dea4f8617383751001ea8cb3f-6f59a.html

  4. Cari Jansen says:
    July 6th, 2009 at 12:07 am

    @Jochen:

    Yep :-)
    http://carijansen.com/2009/05/03/styles-styles-and-more-styles/

    I reckon it’s a must have book for anyone who is serious about learning to work with InDesign productively and using ‘best practice approach’.

  5. Erica Gamet says:
    March 17th, 2010 at 7:08 am

    Thank you, Cari, for being the only resource that mentions shortest match. I’ve been trying to figure out how to find HTML-like tags in a doc, strip them out, and format them when there was more than one instance in a paragraph. Shortest match…who knew one little question mark could mean so much? Thank you, thank you!

  6. Cari Jansen says:
    March 26th, 2010 at 9:29 am

    @Erica Gamet: you are most welcome! Glad I could help.

  7. Archana Matharu says:
    April 14th, 2010 at 3:12 pm

    Grt …Thanks very much.

Comments

Trademarks: Adobe, the Adobe logo, Acrobat, Creative Suite, Illustrator, InDesign, Photoshop, PostScript are trademarks of Adobe Systems Incorporated.

Disclaimer: While every precaution has been taken in the preparation of this web-site, the creator shall not have any liability to any person or entity with respect to any liability, loss, or damage caused or alleged to be caused directly or indirectly by the information or instructions contained in this web-site, or by the computer software and hardware products described therein.