Skip to main content
casinclaire
Inspiring
November 30, 2022
Question

GREP phrase not taking effect when added as an update to a paragraph style

  • November 30, 2022
  • 20 replies
  • 2000 views

I have searched and found probably four or five different GREP expressions that are supposed to prevent single-letter words from landing at the end of a line of text in mid-paragraph (also found some for end of paragraph, but that isn't my goal at the moment).

 

I've edited my paragraph style to test each expression I've found and, so far, the page I hoped would adjust doesn't even flicker. I still have three "I"s hanging out at the ends of lines in the middle of the paragraph, and that's just one page of the book I'm working on. Now I'm wondering if a GREP expression perhaps does not work if it isn't implemented from the beginning of a project.  If this is NOT the case, how do I get my GREP expression to work?

 

And also, and does anyone know an expression for this situation that actually DOES work? With so many out there online -- and none of them similar to one another -- I'm pretty confused about which expression I SHOULD try as none seem to work right now. All of them say to apply the No Break character style, and I have, but nothing ever changes. Is there something else I should be doing to make a GREP work?

 

Hope this makes sense. Any help is appreciated -- especially quick responses, since I'm in the middle of this mess right now -- and thanks in advance!

This topic has been closed for replies.

20 replies

pixxxelschubser
Community Expert
Community Expert
December 1, 2022

In order to be able to create the grep, you definitely have to know at which positions the individual letters are to be searched for. And no. There are wildcard searches in Grep. For example, [\l\u] finds every upper and/or lower case letter.

casinclaire
Inspiring
December 1, 2022

I definitely need to study GREP more thoroughly! I don't use it often but when I need it, it sure would be good to have a better familiarity than I do. Thanks for your help. 🙂

 

Peter Spier
Community Expert
Community Expert
December 1, 2022

Get yourself a copy of Peter Kahrel's fabulous tutorial PDF: https://creativepro.com/now-available-grep-in-indesign-3rd-edition/

Peter Kahrel
Community Expert
Community Expert
December 1, 2022

I agree with Peter S. that doing this with a GREP style could cause some serious lags. I would use this expression:

\b[\u\l]\h.

that is, a word boundary followed by an upper- or lower-case letter followed by a space (which is not a return) and any character.

 

casinclaire
Inspiring
December 1, 2022

Thank you, Peter. I will give this expression a try for sure. Looks like I'm going to be doing a lot of experimenting today!

Happy holidays to you. 🙂

Peter Spier
Community Expert
Community Expert
November 30, 2022

You say these expressions are meant to prevent single character words at the end of a line mid-paragraph. That's a really tough task given that line ends are in constant flux, and I'm actually not sure it can be accomplished with GREP.

Can you share the expressions you think are supposed to do that?

casinclaire
Inspiring
December 1, 2022

Most of the solutions I've found are part of a Q&A in support or elseewhere on the net, so rather than type out all of that, I'll give you a few links to look at where I found expressions I tried:

 

https://creativepro.com/topic/grep-moving-one-letter-words-to-next-line/ -- this one, the questioner seemed happy with but it made not an iota of difference when I applied it to my paragraph style.

 

https://graphicdesign.stackexchange.com/questions/84523/indesign-grep-style-to-move-single-i-words-to-next-line -- another expression given in this answer

 

https://community.adobe.com/t5/indesign-discussions/avoid-a-single-letter-at-the-end-of-a-line/m-p/12566038 -- There are a couple expressions offered in these answers.

 

I've tried them all so far and have seen no difference, though some of the questioners seem to have had success when they tried what the answers offered.  I personally don't know enough about GREP to "read" the expressions to compare their purposes, but it seems odd to me that so many different expressions would supposedly work for this one need or function.

Peter Spier
Community Expert
Community Expert
December 1, 2022

OK, in the first link I think the problem is the forum software has messed up the code that Jongware wrote (and I can promise you the correct version would have worked -- Jongware is a legend). Unfortunatley I'm not sure quite what the "real expression looked like.

In the seond link, (?<=\s)i\W+ is looking for the letter i with a space before, and any "non-word" characters following. You could change that to (?<=\s)[\u\l]\W+ to find any single letter followed by a non-word character rather than restricting it to the letter i. This would find not only single letters folloed by a space, but also by numbers or punctuation, including at the end of a paragraph, but I don't see this as a serious problem.

I think any of the expressions listed in the third link also should work, so if none of these are working for you I suspect that the miossing part is the creation of the "no-break" character style and applying it as part of the paragraph style.

I see that in the third link I mentioned that this method (globally applying No Break to single letters and the next character to prevent a line break) is likely to put some drag on the performance, and James Gifford offered a possible solution for using Find/Change to replace an ordinary space with a non-breaking space after a single letter. While not automatic, I think this is actually a better way to go.

Mike Witherell
Community Expert
Community Expert
November 30, 2022

GREP tricks can be applied to paragraph styles early or late in the layout process. That should not be a factor.

 

The one I usually do is a passive GREP style in my BodyCopy paragraph style:

Apply Style: NoBreak

.{24}$

 

My last paragraph lines have to be at least 24 characters long, thus discouraging short runt lines.

Mike Witherell
casinclaire
Inspiring
November 30, 2022

Thanks, Mike. Good to know that the GREP should work no matter when incorporated into the paragraph style. I thought it odd that it wasn't taking effect, so it must be the GREP expressions I've found that aren't working for some reason.

 

I'll try your expression, but if I'm reading correctly, it sounds like it is mainly to make sure there are no runts at the end of paragraphs. That is also something I need, so thank you. But right now I'm primarily needing a GREP expression that will prevent words like "I" and "a" from landing -- and staying -- at the end of any line in a paragraph; I would like to push them to the next line in the para. Do you have any ideas about that?

 

I really need to learn more about GREP! <sigh>