Copy link to clipboard
Copied
I'm using this GREP expression to fix widows and orphans: [^ ]{1,10}[[:space:]]*$
Problem is, when I create a GREP style in the paragraph style, it doesn't do anything. But if I do a GREP search and replace, it works as intended, so the code is not the issue.
Anyone know how to fix this?
Copy link to clipboard
Copied
Hi
I suppose you've first created a character style, set as "non breaking":
Did you start your GREP expression with a space? If yes, it should work.
If not, don't forget to insert a space at first, or \s
Regards
Copy link to clipboard
Copied
I did both, included a space at the beginning and use non break character style. It did not work.
Again, the code itself is not the problem, because when I did a search an replace, it worked as intended. Only when I create a GREP style within the existing paragraph styles did it not work.
Copy link to clipboard
Copied
Well, it works fine for me
Maybe some screenshots might help.
What INDD version do you use?
Copy link to clipboard
Copied
I'm using ID cc2015 on windows 10. And here are some screen shots
The code is supposed to hunt for every word that has its own line, and replace the space before it with a non-breaking space so that at the end of each paragraph, there will be at least 2 words in a line:
I have the grep like so (note: the character style is Hyperlink because it's easier to notice changes)
But the damn thing, for some reason, only change the character style of the LAST 2 PARAGRAPHS, which doesn't even have orphans!
GREP search, on the other hand, have no problem identify the stand alone words and insert non-breaking space in front of them.
Copy link to clipboard
Copied
Hi again,
OK I understand better...
Your GREP query looks for the last word of every paragraph - including space before - up to ten characters (why not more?): this might explain why it doesn't catch the last word of the other paragraphs (more than 10 characters maybe?)
So, why would it not "catch" the last words as seen of screenshot ? Of course it would, and it's not a problem, if the applied character style have only one setup, which is "NO BREAK"...
Copy link to clipboard
Copied
The first image I shown have a 4-character orphan. The one precedes it also has 4 characters. Including the space between them, there're 9 characters in total, and yet they completely flew under the radar.
Also, the grep search have no issue identify those two, and brought the 2nd-to-last word down to the last line of the paragraph. This is so confusing.
Copy link to clipboard
Copied
Hi again
sorry I missed the first screenshot showing the problem.
Hmmmm, it sure is tricky. I don't have any more ideas really.
Except maybe trying another GREP query, like (\H+?\h?){2}$
I wish I could have a look into your file, but I use CS6.
Maybe a GREP specialist (I'm NOT!) might help you there.
regards
Copy link to clipboard
Copied
> The code is supposed to hunt for every word that has its own line,
No, you code looks for the last string of non-space characters up to 10 characters long.
> and replace the space before it with a non-breaking space so that at the end of each paragraph,
> there will be at least 2 words in a line:
You can't do replacements in GREP styles. You could apply a character style (with no-break set) to the space before the last word.
Peter
Copy link to clipboard
Copied
Wouldn't keep options more suitable for dealing with widows and orphans ?
Apart from that, you may try this:
(?<=.)\s*$
Copy link to clipboard
Copied
If you make your applied character style highly visible, can you see if it does anything at all? See this, for example. It uses your original GREP style - and appears to be working correctly.
What OS and what version of ID are you using? It may be version-dependent (though it sounds like it should not be).
Copy link to clipboard
Copied
Jongware, I think GREP should "catch" the space before, otherwise it sure won't produce any effect...
Copy link to clipboard
Copied
Well yeah, sure. I based my "it is working" on OP's statement that the GREP itself does not work. It does.
Whether or not it does do what OP wants it to is something else.