5 Replies Latest reply on Nov 15, 2011 7:56 AM by Peter Spier

    GREP for changing paragraph style?

    dunaz Level 1

      Okay folks, I have another one for all you smart people out there. I think GREP can be used to change formatting in the following instance, but I have no idea how to set it up.

       

      I have a very long document, essentially a phone book-type listing of names, phone numbers, addresses, well over 150 pages' worth. The paragraph styles are fairly simple, only two per listing. The name/phone number is bold with a right hand tab with leader dots to a phone number that is flush to the right side of the column. The following lines are flush left, not bold, but indented 6pts. I've placed the text file and assigned the entire thing the NameListing paragraph style. I'd like to use GREP to find the address lines and change them to the NameListingAddress paragraph style.

       

      Here's a screen shot to give you an idea. The left column is formatted correctly with both styles, the right column is "raw", all paragraphs formatted with the NameListing paragraph style.

       

      Is this an appropriate application for GREP? If so, how do I set it up to only change the paragraphs that "don't have tabs"? It would save me a crapload of time.

       

      Screen shot 2011-11-15 at 8.10.43 AM.png

       

      THANKS again! --Dina

        • 1. Re: GREP for changing paragraph style?
          RodneyA Level 3

          The easy way would be to do the reverse of what you're trying: set all of the paragraphs to your NameListingAddress style (rather than NameListing). Then do a plain old ordinary search for Tabs, put nothing in the "Change To..." line (or put another tab in) but set Change Format to the NameListing paragraph style in the popup menu. Change all (after you've checked a few to make sure it's doing what you want).

           

          There probably is a way to do this with GREP but it would be a lot harder.

          • 2. Re: GREP for changing paragraph style?
            dunaz Level 1

            Worked like a charm, thanks Rodney! Originally I assigned the name style because it's easier to find (manually) the leader dots. But that makes total sense, and even the ones with out phone numbers have a tab (which I'll have to go in and remove, along with extra spaces and hard returns between listings).

             

            Sometimes all it takes is a different point of view to solve a problem. Thank you!

            • 3. Re: GREP for changing paragraph style?
              RodneyA Level 3

              If there are OTHER tabs that don't belong, you may be able to use a GREP to find and eliminate a lot of those. First, I'd remove all spaces following tabs (using the regular Find, search for ^t-space and replace with ^t).

               

              Then, it looks like the tabs you want to keep all have an open-parenthesis after them, which is part of the phone number. GREP can find all tabs that don't have an open parenthesis so you can replace them with a space (to avoid words separated by a space being made into one word). You'll want the "negative lookahead" option from the popup menu. Find:

               

              \t(?!\()

               

              \t is the tab, (?!x) is the negative lookahead for finding something NOT followed by x, and \( is the open parenthesis with an escape backslash so that GREP knows it's a REAL parenthesis, not part of a GREP code.

               

              Replace with a normal space. Then, I'd run a search to change all double-spaces to single spaces, in case you introduced extra spaces during that step.

              • 4. Re: GREP for changing paragraph style?
                dunaz Level 1

                Woo eee--complicated! but I think I follow. The only tabs, fortunately, that don't belong are the ones with no phone numbers following. I assume the individuals don't want their phone numbers in the book, but when they pull the list, they don't (or can't) remove that extra tab. Regardless, it's been useful for me, for a change.

                 

                My leader dot tabs all have a space before and after. I can put them back in after I delete them all, though, as find/change is how they got there in the first place.

                 

                Even with all this automation I still have to visually search for name/phone entries that are too long and don't fit on one line, and either fuss with tracking/kerning/horizontal scale or reconfigure with a logical and attractive line break. But this keeps me from getting cross-eyed, THANK YOU!

                • 5. Re: GREP for changing paragraph style?
                  Peter Spier Most Valuable Participant (Moderator)

                  If your intent here is to use the character style to trigger a variable, as I belive it is based on your other thread, you MUST apply the character style up to the first tab to pick up the text at the start of the paragraph. There are two approaches to automating the formatting after that, but it may be too late for you to be much help.

                   

                  In cases where every listing has the same number of lines it makes sense to use a unique paragraph style name (not necessarily format -- base on on another) for each lline and make it its own paragraph. Set up "next styles" to rotate through the list so each line is assigned the correct style based on the style of its predecessor. You get the rotation to sart over by making the first line style the next style for the last line. This works for manual entry and can be applied to an entire block of placed text in a single operation by selecting the text, then right-clicking the name of the first style to be applied and choose Apply <stylename>, Then Next Style.This ONLY works if you have exactly the same number of paragraphs in each listing.

                   

                  The other option is to use forced line breaks instread of paragraphs and use one style for the entire listing. Set a left indent and negative first line indent, create a character style for the part of the first line that you want to appear in your header and apply it Up To ^t^n (that's a little-known trick -- if you enter more than one character in the trigger for a nested style it will activate on the first instance of any of the characters listed that occurs, so for example if you enter the word cat, your style will end on the first, c, a or t that appears inthe paragraph. ^t is the metacharacter for tab, and ^n is for forced line break) so that the style will end at either the tab, if present, or the forced line break if there is no tab (if you use a right-indent tab instead of a regualr right aligned tab [tricky to do a leader, but that's another discussion] substitute ^y for the ^t), then add a nested Line Style for one line. That line style should use a second character style that is based on the first character style you created for the name text and has no other attributes if you want the line to be the same from end to end. Sounds more complex than it is, and will work for listings with variable lenghths. The trick is to repalce your paragraph returns with forced line breaks, and will require a little thinking.

                   

                  If using separate paragraph styles for each line, you'd use the same technique of a nested style up to a tab for the first line, but there is no need to get fancier since it will apply to the whole line if there is no tab. The paragraph style, in this case, would carry all of the bold and size formatting (and no need for any indents), and the character style would be nothing more than a name that will allow you to use it in the variable.