Making Magic Happen with GREP
March 4, 2014 Publisher Advice- How to Bookmark and Tag a PDF Using Adobe Creative Suite
- Tips for Blogging from Microsoft Word
- Prepare Your Game Manuscript to Send to Layout Pt. 1
- Prepare Your Game Manuscript to Send to Layout Pt. 2
- Prepare Your Game Manuscript to Send to Layout Pt. 3
- How to Import a Manuscript to InDesign CS6
- The Secret to Simple Manuscript Import with InDesign CS6
- How to Apply GREP Quickly with InDesign Scripts
- Making Magic Happen with GREP
- Keeping Your Text Flow Flowing: Removing Text Dams
- So What Does an Accessible PDF Look Like?
- Layering Your PDFs Using Adobe InDesign CS6
- Why Accommodating Others is Your Best Investment
- Uploading Unwatermarked PDFs to DTRPG
- Accessible PDFs with InDesign Alternatives
- Prepare Your PDF for Print
- Accessible Guide to RPG Layout Now Available
- Organizing Your Files to Send to Layout
Introduction
If you have been following along lately, you’ll be familiar with how to access GREP (Global Real Expression Parser) from InDesign’s Find / Change dialog. If not, I recommend reading the last two posts in the series to get yourself up to speed.
GREP is a powerful tool worth mastering. Learning to use it effectively improves productivity and sets you apart from the pack. It can’t make your designs better all by themselves, but it will certainly help you implement your designs quickly, easily, and consistently.
If you’ve spent any time reading GREP tutorials on the internet, you’ll notice a lot of techniques are geared toward general purpose design work. It can be difficult to find expressions that are geared toward the special needs and common design scenarios used by RPG and board game publishers. This week, I’ll share a few of the favorites I’ve either learned or developed on my own.
A Quick Plug
Earlier this week, I happened upon an electronic magazine from InDesignSecrets.com. Their March issue, out now, is all about “Getting a Grip on GREP.” If you have $7.95 USD to spare, I’d recommend checking it out. These articles are great for novices and the issue contains a two-page list of some great GREP expressions. They’re not all applicable to game design, but you may wish to take a look anyway. (Note: this isn’t an affiliate link and I don’t get anything for pointing you toward their website.)
GREP in the Paragraph Styles Dialog
Until now, I have focused primarily on using GREP from the Find / Change Dialog. There’s another place you can go to access some of GREP’s super features though: the Paragraph Styles Dialog. Whether you’re creating a new Paragraph Style or editing an existing one, simply click “GREP Styles” in the list of tabs to access the feature.
Using this tab, you can create GREP definitions which apply to an entire Paragraph Style. For example, if you commonly bold every word at the beginning of a paragraph that comes before a colon (an inline header) you can use GREP to search for all text up to (and or including) the colon and apply a Bold Character Style to that text.
This is useful for many RPGs which define terminology commonly used by the game. Here’s how we’d do that using the GREP Styles tab:
1. Click the New GREP Style button.
2. In the Apply Style: field, select a Character Style from the drop-down list. Since you’ll be applying this style to all text within an existing Paragraph Style, you can only choose Character Styles on this dialog.
3. In the To Text: field, enter your GREP expression. This can be ust about anything, but in the example above, you would use the following expression:
(?<=)(.+)(:\s)
4. Click OK. InDesign automatically searches all text within the chosen Paragraph Style (for example, the Body Copy style) for text matching the expression you entered and applies the character style you chose.
But What’s it Mean?
This expression tells InDesign to look for all characters (.+) which come before (?<=) a colon and a space (:\s). Every time InDesign encounters a colon and a space together, it will look behind that text for all previous characters in the paragraph and apply the Bold style (or another style of your choice).
Building Your Own Expressions
InDesign has a huge list of special characters and strings which tell the program what to look for. You don’t need to memorize all of that funky code, though. In every dialog where you can enter a new GREP expression, InDesign has a menu of expression available for you to point and choose from.
To the right of any GREP text box is an “at symbol” (@) icon. Click on it to reveal a whole list of commands to choose from. Feel free to play around with them and discover new uses for them on your own.
A Few of My Favorite GREPs
Below are a few of my favorite uses for GREP.
Flip-Flop Phrases
Whoops! You’ve been handed a manuscript that seemed complete, but now you receive word from the publisher that all of the entries in the Equipment section have a mistake: the Price and Weight entries have been flip-flopped. It would be time-consuming to change all of these entries by hand, but thankfully there’s a GREP for that.
You need to change: “Price: [any]; Weight: [any]” to “Weight: [any]; Price: [any].”
Find What: (Price: .+?)(; )(Weight: .+)
Change To: $3$2$1
Result: The entries are reversed. This calls out Price and Weight as their own sentences and leaves the semicolon where it’s at.
Apply Paragraph Styles to Markup
I am repeating this from previous articles for the sake of completion.
You need to change: <h1>Heading Style 1 to Heading Style 1 with an applied Paragraph Style.
Find What: (<h1>)(.+)
Change To: $2; add the Paragraph Style Heading 1 to the Change Format dialog.
Result: The markup tag, <h1>, is removed and the text of the heading is retained. The appropriate Paragraph Style is applied to the text.
Apply Character Styles to Markup
You need to change: <b>Bold text.</b> to bold text and remove the markup tags. You don’t want to change any of the other text in the paragraph.
Find What: (<b>)(.+?)(</b>)
Change To: $2; apply the Bold Character Style in the Change Format dialog.
Result: The appropriate text is bolded and the markup tags are removed.
Apply a Numbered List Style to Manually-Numbered List
You need to change: a manually-numbered list to a numbered list Paragraph Style.
Find What: ^\d+\. ?(.)
Change To: $1; apply a numbered list Paragraph Style in the Change Format dialog.
Result: You change a boring numbered list into an auto-numbered list using an appropriate Paragraph Style.
Clean Up Extra Spaces
You need to change: Against my advice, you were handed a manuscript with too much white space. Either the author added two spaces after every period or they added two carriage returns after every paragraph.
Find What: (\s)(\s+)
Change To: $1
Result: Kazaam! You just zapped all that extra white space. Now your sentences are tighter and you can use Paragraph Styles to determine leading, or line height.
Changing Formatted Text That Didn’t Use Styles
You need to change: The author handed you a manuscript in which they manually applied text formatting to change the appearance of every Heading.
Find What: This one requires some legwork on your part. You need to open the manuscript and find the format changes, such as Font Size and Font Face. For example, every Heading 1 element was created as being 18pt Arial. In the Find Format box, select 18pt and Arial as the format options to look for. Note that you will need to import your manuscript with text formatting intact.
Change To: A Paragraph Style of your choice, such as Heading 1.
Result: You apply an appropriate Paragraph Style to manually formatted text. Remember to keep an eye out for any text that wasn’t formatted identically to what you searched for.
Applying Superscript to Ordinals
You need to change: 1st, 2nd, 3rd, and 4th so the letters are in superscript.
Find What: (?<=\d)(rd|th|st|nd)
Change To: Apply a Character Style to the found text. This is a great expression to use in the Paragraph Styles -> GREP Styles tab, because generally you need to apply it to a whole document.
Result: All of the letters in your ordinals are changed to a superscript style.
Final Thoughts
There are loads of other great GREP expressions out there. Have you found any favorites yet? Is there something frustrating you that you need help devising an expression for? Let me know in the comments!
Donate
Do you enjoy these Accessible Games Tutorials? They’ll always be free to you, but if you’d like to leave a token of appreciation than please consider donating.
Donate through our Gumroad Store.
Did you know I’m also available for hire? Contact me if you have a layout project that you’re not ready to tackle yourself.
Indie+
This post also appears on Indie+ and is covered by the Indie+ Community Standards.