10 Replies Latest reply on Feb 12, 2012 2:29 PM by Gobit180 Branched to a new discussion.

    how to search for runts, orphans, widows using GREP

    me_wanna_learn

      Hello,

       

      I've been trying to bust my brains on how to do a search by locating single words at the end of a paragraph and on a single line by themselves. Yes, you guessed it! I'm trying to hunt down those orphans, widows that are sometimes called runts. I just don't want to do it manually and you always seem to miss one or two of them. I'm already using the techniques detailed and discussed in length on how to deal with orphans and widows but we have to hunt them down first...

       

      Here's the closest GREP search I can get:

       

      (\w+)(.)\r^

       

      but this searches for all words at the end of a paragraph regardless of whether or not they are sitting on their own on a single line. I need to pin point on single words on a single line.

       

      Unless of course there's a much easier way than GREP, then by all means do tell..

       

      Using cs4.

       

      Any input would be much appreciated.

       

       

        • 1. Re: how to search for runts, orphans, widows using GREP
          [Jongware] Most Valuable Participant

          GREP does not work with lines, only with entire paragraphs. So you need to look into other means.

          1 person found this helpful
          • 2. Re: how to search for runts, orphans, widows using GREP
            Peter Spier Most Valuable Participant (Moderator)

            Unless there's some sort of forced break in the paragraph I wouldn't expect to see a runt anywhere EXCEPT as the last word in a paragraph.

             

            That said, this has had a lot of discussion in the past. Questions that arise are just how many words or characters do you consider to be the minmum on the last line? Does it depend on the column width or the size of the type? Will you allow a really long last word to break?

             

            The normal strategies that are proposed are things like making the last space in the paragraph non-breaking, or applying No Break to the last x characters, both of which are pretty easy to do using GREP.

            1 person found this helpful
            • 3. Re: how to search for runts, orphans, widows using GREP
              me_wanna_learn Level 1

              Hello all,

               

              Thank you taking the time to help me out. I am using the No Break suggestion already and that works great. Too bad there isn't any way to locate runts automatically.;(

              • 4. Re: how to search for runts, orphans, widows using GREP
                [Jongware] Most Valuable Participant

                There is always Blatner Tools: http://www.dtptools.com/product.asp?id=blid

                 

                (You can think of it as being able to locate runts, and you get 11 more useful tools for free!)

                • 5. Re: how to search for runts, orphans, widows using GREP
                  Peter Spier Most Valuable Participant (Moderator)

                  me_wanna_learn wrote:

                   

                  Hello all,

                   

                  Thank you taking the time to help me out. I am using the No Break suggestion already and that works great. Too bad there isn't any way to locate runts automatically.;(

                  I don't think we're fully communicating here. If by runt you mean just a single word on the last line, that's doable in GREP, but I don't think that's a good criterion. Is a single seven-letter word less desirable than two three-letter words with a space between? In a column that's 30 characters wide, is a single 10-character word at the end a runt? If it is, is that really a problem?

                   

                  In reality you will almost always find paragraphs that don't have a full or near-full last line, and how short is too short is often a judgment call based on what the paragraph looks like and the size of the type in relation to the column width. Slavish adherence to an artificial rule about the number of characters to leave in the last line is almost certain to create other, often worse, spacing problems elsewhere in at least some paragraphs. In short (no pun intended) I would advocate that you NOT use any sort of automated runt control, and use your judgment instead.

                  • 6. Re: how to search for runts, orphans, widows using GREP
                    me_wanna_learn Level 1

                    hello Peter,

                     

                    Thanks for the reply. Yes, I do mean runt as in the single word on the last line. I can understand your argument and yes I do agree with that. However I just need a way to find those runts automatically and once the search has found one I will  manually assess it if I need to apply any adjustments to it or not. It's just intially looking for them is the part that I would like to make quicker. You mentioned it is doable in GREP? So what is the GREP code for that to allow Indesign to search for it? Thanks

                    • 7. Re: how to search for runts, orphans, widows using GREP
                      Peter Spier Most Valuable Participant (Moderator)

                      We're probably miscommunicating here. It's easy to find the last word in a paragraph -- \w+[[:punct:]]*$ will find the last word and following punctuation (but not trailing space), but it doesn't care if the word is a runt, it finds them all.

                       

                      I don't think it's possible to find only last words alone on the line (except maybe with Blatner Tools, which I've never used). My point was that if you don't want to have a single last word you could do something like find ( )(\w+[[:punct:]])$ (there's a space between the first set of parentheses) and replace with ~S$2 and that will replace the last space in EVERY paragraph with a non-breaking space, guaranteeing either at least two words, or only part of a hyphenated last word if two words won't fit, and that latter option is less desirable than having a whole single last word. Applying No Break to the last word instead will send text into overset if the last word is wider than the column. In my testing in CS5.5 disallowing hyphenation of the last word is safer since ID seems to break the rule rather than force otherwise hypenated text into overset (but that's when you wind up with only part of a word on the last line).

                       

                      I suppose you could then search for non-breaking spaces and decide if they should be changed back, but ultimately that's just as much work as doing a visual scan of the text without the intervention of GREP at all.

                       

                      If the goal is to find lines that have less than x characters, where x is some variable number that varies with the width of the column. I suppose it might work to search for .{x}$ (where x is the value of the minimum number of characters you must have). You can then applly No Break to that last string. This is going to cause some paragraphs not to change appearance, and others to recompose very badly (you have the potential for a short paragraph with a runt on the first line), but it will guarantee that every last line has at least x characters.

                       

                      There is no benefit to running this query, or any of the previous ones, and making a case by case judgement other than it automates the selection. It still stops at the end of every paragraph, runt or not.

                       

                      So back to my original point, which was that you can use GREP to automate a solution that will guarantee no runts, but it won't necessarily be a good solution as it is non-discriminatory, so Jongware's initial answer may really be more correct than mine -- you can't use GREP to find runts, only to find ALL last words or last x characters ina paragraph.

                      • 8. Re: how to search for runts, orphans, widows using GREP
                        Gobit180

                        Hi Peter

                         

                        I posted the following in the IndesignSecrets forum and Jongware kindly pointed me at this thread

                         

                        I'm laying up a 600-odd page book for a client who went to design school some years ago where it was drilled into her that "Thou shalt never ever have an orphan" (she means runt). She is insisting that every last runt in the book be exterminated irrespective of word or line length, rivers created or insane ragging. The book contains a lot of text-wrapped anchored boxes,diagrams, etc so of course, every time there's a copy change these move creating new runts. Instead of proofing for important things like correlation of diagrams with text, etc she is fixated on these runts.

                        To prevent what little brain I have left from exploding I'd like to write the following Find/Change but have not been able to get the language correct:

                        Find: Any word preceded by a space and followed by a paragraph mark

                        Change: the space to a nonbreaking space

                        Blatner Tools lets me find the runts but they still need changing manually so I've tried your below Find/Change Grep:

                        Peter Spier wrote:

                         

                        I don't think it's possible to find only last words alone on the line (except maybe with Blatner Tools, which I've never used). My point was that if you don't want to have a single last word you could do something like find ( )(\w+[[:punct:]])$ (there's a space between the first set of parentheses) and replace with ~S$2 and that will replace the last space in EVERY paragraph with a non-breaking space ...

                        Unfortunately,I can't quite get the GREP to run properly. It works for plain ordinary paragraphs but for some reason it only works randomly in bullet/numbered lists of which I unfortunately have quite a few. Also, if the last sentence of a paragraph contains a footnote marker (again many of these),  it changes the last word of the actual footnote but not the paragraph which contains the footnote marker.

                         

                        Are you able to help with a tweak please.

                         

                        Thanks n cheers, Gobit

                        • 9. Re: how to search for runts, orphans, widows using GREP
                          Peter Spier Most Valuable Participant (Moderator)

                          My epression presumed that all paragraphs end in some sort of puntuation. You could add the footnote marker fairly easily I think, and perhaps you want an anchored object marker, too? The previous query also fails to find a paragraph that ends in multiple punctuation, like a quote.

                           

                          ( )(\w+[[:punct:]]*~F?~a?)$   fixes the multiple punctuation problem as well as working on a list item that has no ending punctuation, I think, and adds an optional single footnote at the end, and an optional anchored object marker after that. This is still not universally perfect. Trailing white space will fail, for example, as will multiple footnotes, or an anchored object that is not the last character, but it should get you a bit further, I think.

                          • 10. Re: how to search for runts, orphans, widows using GREP
                            Gobit180 Level 1

                            G'day Peter

                             

                            Indeed it does get me a lot further.

                             

                            Many thanks for your time. Much appreciated.

                             

                            Kind regards, Gobit