• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

GREP: Find paragraph after a specific paragraph style

Community Beginner ,
Feb 07, 2024 Feb 07, 2024

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:

  • Working with "next style" in the paragraph style option, but it is necessary to mark the paragraphs to utilize the function. This doesn’t work so smart, because I have to mark it for every occurrence.
  • Searching with GREP-styles (lookahead for example) combined with the paragraph
    "find-"selection

 

But nothing worked very well. Do you have an idea?

TOPICS
Experiment

Views

541

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Feb 07, 2024 Feb 07, 2024

Bad!

 

Capture d’écran 2024-02-07 à 10.26.05.pngCapture d’écran 2024-02-07 à 10.27.40.png

Votes

Translate

Translate
Community Expert ,
Feb 07, 2024 Feb 07, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2024 Feb 07, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

Thank you!

 

Hm, this doesn’t work in my case.

Do you have some documentaries of "how to include a specific paragraph style
in a grep expression" as you did? Looks interesting. Maybe I have to adjust something.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

Bad!

 

Capture d’écran 2024-02-07 à 10.26.05.pngCapture d’écran 2024-02-07 à 10.27.40.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 07, 2024 Feb 07, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2024 Feb 07, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2024 Feb 07, 2024

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!  😉

 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

Understood. Great idea!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2024 Feb 07, 2024

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 07, 2024 Feb 07, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

Ariel,

 

you're wrong (see my explanation) and, here, it's totally free!

 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 07, 2024 Feb 07, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2024 Feb 07, 2024

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).

 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2024 Feb 07, 2024

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 07, 2024 Feb 07, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2024 Feb 07, 2024

Copy link to clipboard

Copied

LATEST

"One danger" if no other free + simplistic solution that just takes some seconds to be written!  😉

 

2 regex:

 

Capture d’écran 2024-02-07 à 12.31.59.pngCapture d’écran 2024-02-07 à 12.35.49.png

 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines