2 Replies Latest reply on Oct 5, 2011 1:40 PM by jsantos7

    Table of Contents


      Can anyone help me with the following problem?


      what i have now:


      Tenant Summary....27

      Tenant Summary....28

      Tenant Summary....29


      What i want


      Tenant Summary...27-29


      Is there a way to have indesign automatically do this on my table of contents?

        • 1. Re: Table of Contents
          Peter Spier Most Valuable Participant (Moderator)

          Not exactly automatically, but I do think it can be done using Find/Change.


          I wrote an article a bout two years ago that describes a method for creating an index to advertisers, and the problem is similar -- an advertiser may have multiple ads, but you want o only list them with one name followed by all of the page numbers, in the case of the advertisers, however, you want to keep all the numbers and separate them by commas. Peter Kahrel was kind enough to help me with a GREP query that would find duplicate names and remove them, leaving behind the numbers, and wrote a script, as well, to run the query until no more cases are found ( so you don't have to do that manually). I've been trying, without success, to modify the query directly to go straight to your desired range result. It may or may not be possible -- my GREP skills are still at the novice level, but I have devised a query that will work on the results of the script to transform them in a separate operation. I have presumed that you are using tabs or other white space to separate the page numbers from the text. The script will only work with white space, not typed dots.


          First the script:


          //Consolidate listings
          //By Peter kahrel with some minor additions by Peter Spier
          var myFrame = app.selection[0];     
               if (myFrame != null && (myFrame.constructor.name == "TextFrame" ||myFrame.parent.constructor.name == "Story")) {
                         app.findGrepPreferences = app.changeGrepPreferences = null;
                         app.findGrepPreferences.findWhat = "^(.+\\s)([\\d,\\s]+)\\r\\1([\\d,\\s]+)$";
                         app.changeGrepPreferences.changeTo = "$1$2, $3";
                         f = myFrame.parentStory.changeGrep ();
                         while (f.length > 0)
                              f = myFrame.parentStory.changeGrep ();
               } else { alert ("Select the Index Frame");               

          once that's run, you can use the following GREP find/change:


          Find (\d+), (\d+, )*(\d+)


          Change to $1-$3


          and only the first and last numbers, separated by a hyphen will remain.


          If one of you nice scripters would like to add the second query to the script, that would be very kind, or if you can tell us how to do it in one step, even better.

          • 2. Re: Table of Contents
            jsantos7 Level 1

            Thanks man. As you say not 100% what i was looking for but is much better than having to do it manually.