Just a few last things to touch on regarding GREP in InDesign. Last week’s piece went over the basics.
Apply a style
One of the great features that InDesign’s Find/Change dialog offers is the ability to apply styles to what you find. Speaking of style, if you’re not all that familiar with the difference in usage between paragraph and character styles, I recommend looking back over the piece on understanding styles, and a related exercise.
So, say I want all numbers to be sized down by a half a point. First, highlight one such number, size it down appropriately, and keeping it highlighted, create a new character style called, say, fig.
Next, open the Find/Change dialog (it’s under the Edit menu), make sure you’re on the GREP tab, and in the first field, type in \d. Then, in the Change Format field, select fig, the character style you just made. Hit change all, and you’ve now applied the character style to all digits everywhere in your document. (You can change the scope of your finding/changing in the box below the Change to field.) You can also (obviously) narrow the scope of your search by specifying a paragraph or character style in the Find Format field.
That’s great, but it still means I have to remember to go back through these steps at the very end of modifying my document in order to catch any digits that weren’t previously converted.
Not necessarily. With Grep styles, set up the rule, and it will automatically be applied when anything changes. To illustrate, let’s apply a character style that turns on the OpenType fractions feature whenever there are fractions in a document.
This all happens inside a paragraph style’s settings dialog, so let’s make sure we’ve got a paragraph style already set up. Okay, I made one called Entry and applied it to all the rows in a table of fractions and their decimal equivalents.
Next, I turn on the fraction feature through the OpenType menu in the Character palette. Then I keep that fraction highlighted while I create a new character style called Fraction.
Last, I go into Entry’s style settings, create a new GREP style, and apply Fraction to the following expression:
Just to decode the regular expression above, that’s \d any digit, * occurring zero or more times (applied to the thing immediately before the asterisk), followed by \/ a slash (typed backslash slash), followed by the same thing at the start, zero or more digits, \d*