Recently, I received an interesting question: would it be possible to use our StylePainter freebie to exert some GREP magic and judiciously extend the style range of a particular style?
This was to clean up some text, were some styling was applied to the text, but the styling was not always applied to the punctuation. So, instead of
This!
the text was more like
This!
where the exclamation mark was left out and not italicized.
I figured out a quick-and-dirty way to do it with StylePainter combined with InDesign’s Find/Change magic.
Step 1: First we need to express the targeted style as some inline text marker, so StylePainter can ‘latch on’ to it.
For example, let’s assume it’s about italics. The same trick works for named styles, but to keep it simple, I’ll perform the trick by simply looking at italics.
First, I need to choose some prefix that does not occur naturally in the text; it does not matter what you pick.
I’ll arbitarily choose a text prefix [i]. Any string that does not occur naturally in the text will do. As I don’t have any occurrences of [i] in the text, that’ll do.
Using the standard InDesign Find/Change dialog, I convert
(\w*)
into
[i]$0
(that’s a zero at the end), if font style ‘Italic’ is applied.
This grabs any word formatted in italics (e.g. ‘poisons‘) and prefixes it with [i] (e.g. ‘[i]poisons‘).
Vary this step as needed – e.g. you could instead use Find/Change based on paragraph or character style name, or many other attributes.
Step 2: Use StylePainter to ‘paint’ such prefixed words, including their ‘tail’ character.
I’ve put into the ‘stylepainterframe’:
\[i\]\w*[\.\?\!\,]*
This GREP pattern itself is formatted in italic. This searches for [i] (properly escaped for GREP – so [ becomes \[ and so on), followed by a word, followed by some punctuation character(s).
It applies italics to the whole sequence, starting from [i] up to and including the punctuation.
Now run the ‘paint’ operation. Click ‘into’ the target frame, and select the API – StylePainter – Paint Story menu item.
Which gives us this:
Step 3: Use the find-change dialog to get rid of the [i] prefixes. Replace
\[i\]
with
<nothing>
which gives us:
The same trick for any other styling you might have (e.g. use [B] or whatever for bold, and so on…)
StylePainter is one of our ‘oldy, but goldy’ freebies – I almost forgot about it, until this question was asked. While trying things out, I found out that StylePainter had not been updated since the days of CS4 (!). So, long story short – StylePainter has been spruced up, and it’s now compatible with InDesign CC, all the way down to InDesign CS.
More info here: