GREP Resources

The May meeting of the Portland InDesign User Group focused on Paragraph & Character Styles, with a considerable portion of the time devoted to Nested Styles and GREP. The purpose of this article is to summarize the information I presented in the meeting.

Key Concepts

  • Apply Paragraph Styles to everything. Apply Character Styles only to text that is different from the rest of the paragraph.
  • Use Nested & GREP Styles to automatically apply Character Styles within a Paragraph Style.
  • Nested Styles are best for formatting that happens in a predictable order starting at the beginning of the paragraph and continuing throughout the end.  GREP Styles are best for when the desired text could be located anywhere in the paragraph, or at the end.

3 Paragraph Style Settings Guaranteed to Improve your Typography

  • Keep Options: for body text, keep 2 at start and 2 at end to prevent widows & orphans; for headings, keep with next.
  • Hyphenation: Default settings are terrible. Recommend 8-4-4-1, all 3 checkboxes at bottom off, and then adjust as needed.
  • Justification: Default settings will cause awkward gaps in justified text. Recommend letter spacing of -5, 0, 5 for starters; adjust settings as needed.

Style Order of Operations

  1. Paragraph Styles are applied first. All other formatting overrides them.
  2. Nested Styles are overridden by GREP styles.
  3. GREP styles are applied in the order in which they appear in the list. Styles down the list override previous styles.
  4. Manually applied Character Styles override Grep Styles.
  5. And of course you can always apply local overrides.

What is GREP?

(from wikipedia) Grep is a command-line utility for searching plain-text data sets for lines matching a regular expression. Its name comes from the ed command g/re/p (globally search a regular expression and print).

GREP has been incorporated into InDesign as a powerful means to search for patterns in text. It can be used either in the Find/Change dialog or in a paragraph style, to apply character styles automatically through the use of GREP styles.

GREP Samples

Here is a copy of the example InDD file used in the meeting. It is in IDML format for backward compatibility to CS4.
GREP Samples-ONLINE

It includes examples of the following GREP queries in action:

  • Automatically format English text and numbers found in otherwise non-Latin languages (Chinese, Japanese, Thai, Arabic, etc).
  • Automatically format prices, in this example to hide the $ and . characters and superscript the cents.
  • change the formatting of a single character (In this example, the ‘?’.
  • Format HTML so that tags, URLs, etc. are color coded.
  • Prevent runts (also called orphans, when you have a single word on the last line of a paragraph).

GREP Resources

So you want to learn GREP? I’d recommend you start with the excellent interactive GREP Tutor at rorohiko.com. It’s how I learned the basics of GREP. It features a series of easy-to-understand lessons as well as a real-time GREP query testing area.
https://www.rorohiko.com/greptutor/GrepTutor.html#

Then there is this excellent GREP test utility. I use this to troubleshoot and figure out GREP strings that aren’t quite working in InDesign.
http://www.regexr.com

InDesign Secrets has a page listing many resources:
http://indesignsecrets.com/resources/grep

And then there is the InDesign help page listing many GREP codes:
http://help.adobe.com/en_US/indesign/cs/using/WSFB3603CC-8D84-48d8-9F77-F3E0644CB0B6a.html#WS1952D538-1335-4b1d-BA5E-FA5A176FDC9Fa

Multiple Find/Change Scripts

We also discussed two great free scripts that can run multiple find/changes in your document. Both of these offer a GUI and support GREP as well as regular InDesign find/replace functionality.

XStrings saves find/change or GREP replacements in a text file and allows you to apply them individually or in sequence. It does not use InDesign’s own saved queries, so it’s good for special uses in which you don’t want your list of queries to be stored in your InDesign Find/Change dialog. I used this tool for the Victor Borge Inflationary English example.

DoQueryList allows you to run multiple InDesign saved queries in sequence. If you’ve already saved your queries in InDesign but want to run several succession, this tool works great.

Related Creative Progression Articles

InDesign Styles 101
Resolving InDesign’s Justification Problems
Inflationary English: A GREP Tribute to Victor Borge

 

, , ,

No comments yet.

Leave a Reply