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

No Break with minimum-word limits

Contributor ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

I have this working, but wanted to make sure I did not overlook something.

My book looks best with a character style "No break" applied as a grep style within my paragraph style.  Because the book is in Spanish, there are some very short words I wanted to account for.  I chose 5 words as the quantifying value.

Here is my GREP.  Let me know if I have left out anything.

 

\w{5}

TOPICS
EPUB , Scripting , Type

Views

457

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

Community Expert , Apr 13, 2022 Apr 13, 2022

So you did mean word,not word character. Your \w{5} means 'keep 5 word characters together'. To keep 5 words together  at the end of the paragraph (which is excessive by any standard), you need this:

 

(\h[^\s]+){4}$

 

 

Votes

Translate

Translate
Community Expert ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

My language environment is Japanese, but the regular expression part would be helpful.
Note that it is a backslash, not a slash.

スクリーンショット 2022-04-13 12.59.01.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
Contributor ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

Very cool, Ajabon.   Are these approaches just different with the same result, or do they add on checks and balances to mine?  Thanks!

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 ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

I divided the regular expression into three parts because I thought it would be better to emphasize visibility than to write it on a single line in a cool way.
The first is at the beginning of a paragraph, the second in the middle of a paragraph, and the third at the end of a paragraph. But this may not be necessary since I think there is usually punctuation at the end of a line. But just in case.

Regards.

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 ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

Hi @MadMac55 , have you considered setting a Hyphenation rule in your Paragraph Style?

 

Setting Words with at Least to 6 would prevent any words with 5 characters or less from breaking:

 

Screen Shot 33.pngScreen Shot 34.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
Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

Thanks, Rob.  The style for body text in the book is justified, no hyphenation, so that alone wouldn't keep a minimum word count at the end of a paragraph where No Break actually impacts 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 Expert ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

@MadMac55 

 

> I chose 5 words as the quantifying value.

 

You mean 5 word characters (letters and digits), right?

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
Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

Mr Kahrel!   No I meant words.  Because the book is Spanish, there are very short words that could encourage very short lines (this sounds picky, but...).  So, to minimize the presentation of the short lines, I used an arbitrary number of words (5) to have the No Break control the presentation.  If that makes sense.

 

As I poured my first coffee, I did have a thought along this line that I did not take into account digits and should have included /w|/d

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 ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

So you did mean word,not word character. Your \w{5} means 'keep 5 word characters together'. To keep 5 words together  at the end of the paragraph (which is excessive by any standard), you need this:

 

(\h[^\s]+){4}$

 

 

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
Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

After testing, I believe the \h was hanging this up.  I was wrong; it was an extra space between words that caused the problem.  Works great.  Thank you again.

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
Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

Peter, can you explain the "\h" ?   I looked this up in Reg-ex for what it symbolizes, but it's escaping that character.  Why that character?

 

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 ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

\h stands for 'horizontal space', it covers all space characters (normal, en, em, fixed, etc.) and the tab. Not the return characters. What that character? To avoid the paragraph resurn and to capture normal and fixed-width spaces. You could use \s as well probably (any space, including the paragraph mark).

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
Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

LATEST

Great one.  I could not find that.  I bet if I go back to your GREP book I will.  Jesus.  Thanks for the explainer.

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