Copy link to clipboard
Copied
Hey there,
today I’m looking for a solution in this case. I got a book with 500+ pages with hundreds
of headlines. This document contains just a paragraph style for the headlines and one for
following copytext of each chapter.
Now I want to apply a new paragraph style "subtitle text" to every first paragraph
after the headlines. The second one is normal copytext until the next headline.
I tried to:
But nothing worked very well. Do you have an idea?
Bad!
Copy link to clipboard
Copied
I don't think you can do this with GREP, but next style is absolutley an option.
To use it, correct the style definitions to cycle as you wish, then you can select entire stories in one go (or the whole document if it's one long thread, and right click the headline style in the Paragraph Styles panel and choose Apply [headline stylename] and Next Style.
Copy link to clipboard
Copied
Supposing 3 para styles:
"ps1" for headlines
"ps2" for sub-headlines
"ps3" for current-text.
and "ps1" and "ps3" alrready applied!
The question is:
How to apply "ps2" to each para following each para with "ps1" applied?
Simplistically with the Grep Find/Replace:
Find: (?<!\r)^. + "ps3"
Replace by: "ps2"
(^/) The Jedi
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Bad!
Copy link to clipboard
Copied
Thanks, that works very well!
Can you explain to me how the grep expression works?
It is a negative lookbehind. But there is no character in front of it. What does it search for?
Copy link to clipboard
Copied
If I understand it correctly, it is looking for the first character in a paragraph of the selected style that is not preceded by a paragraph break of the same style, thus it should find the first character in the body paragraph after following your heading. Since paragraph styles apply to the entire paragraph, changing the style after finding any character in the paragraph changes it for the entire paragraph.
Copy link to clipboard
Copied
The regex searches the first character of a paragraph with the applied para style "3 - black", first char that is not preceded by a carriage return (so, the preceding paragraph) with, obviously, the same para style applied, that is "3 - black"!
Simple, isn't it! 😉
(^/)
Copy link to clipboard
Copied
Understood. Great idea!
Copy link to clipboard
Copied
I realize the next style solution will not work if you have multiple paragraphs following the subhead, and Michel's solution is great.
To get the formatting limitation you want click the magnifier icons to the right of the two formatting boxes below the change field (you'll see that he's done that in his screen captures).
Copy link to clipboard
Copied
Hi @Julian26070731n4t5 ,
There is in fact no way to include a specific paragraph style in a GREP expression.
In the format boxes below you can specify to search for a specific style onle, and replace with a specific style.
@FRIdNGE's solution is very clever (see @Peter Spier's explanation for how it works). But it doesn't allow for explicitly searching for style B that is followed by Style A, rather only for Style B when not preceded by Style B. Useful in some cases, and definitely an answer to the original question.
There is, in fact, no simple way, though, to change the style of one paragraph based on the style of a preceding paragraph in InDesign.
The "Next Style" feature that @Peter Spier suggests would only work if the sequence of styles is entirely regular, one paragraph per style.
Failing that, the simplest way is to use a script, which would do the job with great flexibility in a click or two.
I would recommend my own (https://www.id-extras.com/products/change-consecutive-paragraphs/) and I think there are other scripts available out there as well.
In your case, the rule I would set up (with my script) is:
If (1) Headline is followed by (2) Copytext, replace (1) with (3) [ignore] and (2) with (4) Subtitle.
Click "Execute" and your 500 pages are done with a single click.
You can also save that particular query for future use (and once you've got a few different queries saved, you can chain them together with the batch editor and apply them all to your next book with a single click!)
Ariel
Copy link to clipboard
Copied
Ariel,
you're wrong (see my explanation) and, here, it's totally free!
(^/)
Copy link to clipboard
Copied
Yup, I see. I take that back and apologise for having doubted you 🙂 ! I've edited my previous reply.
The paid-for solution is much easier and more powerful of course, but it's interesting that in some simple cases this is possible in InDesign.
Ariel
Copy link to clipboard
Copied
No worries, Ariel!
About the regex I've used, and just for comment, it is relevant since InDesign CS3 (the beginning of the Grep implementation inside InDesign in march 2007, 17 years ago).
(^/)
Copy link to clipboard
Copied
@FRIdNGE , you are without doubt one of the cleverest users here on the forum. I just wish you would include an expplanation of how your solutions work when you first post them. It's not obviouos to most of us...
Copy link to clipboard
Copied
One danger with @FRIdNGE's solution: It will also find Style 2 if it's the first paragraph in a story, even if it's not preceded by Style 1, or if Style 2 is applied to the first paragraph of a footnote.
Copy link to clipboard
Copied
"One danger" if no other free + simplistic solution that just takes some seconds to be written! 😉
2 regex:
(^/)