17 Replies Latest reply on Dec 8, 2008 10:16 AM by (ABC_GREEN)

    PostProcessing a TOC

    Level 1
      I am this weekend taking my first foray into the world of event listening. This is a strange feeling because for the last two years, I've been almost exclusively writing scripts that respond to events. But the events I've been responding to were created by Typefi Publish not by InDesign itself.

      The thought had occurred to me that there are many requests in the forum for post processing a TOC. I can recall the following requests (although they might not all have been in these forums):

      1. Eliminate the empty paragraph that InDesign always adds to the end of a TOC it generates (could lead to false overset warnings in CS4).

      2. Automatically add pages to accommodate a TOC that takes more than one page.

      3. Delete any anchor objects that came along for the ride when a TOC is created (this is not a universal request because some people want the anchored objects to survive).

      4. For TOCs where the page numbers precede the topic, add tabs to get the numbers right-aligned.

      The actual scripts needed for this are pretty straightforward. The challenges are:

      1. Attach the scripts to the TOC-creation event.

      2. Workout which story holds the TOC that was just created.
        • 1. Re: PostProcessing a TOC
          Level 1
          There is no TOC-creation event, but there is a menu event that would tell me that a TOC has just been created/updated. So, that's where I'll be hanging my event handler, assuming I can work out how to do that.

          But here's the rub: how do you work out which story has just been updated? If a TOC has just been created for the first time, it's easy because the story is the last in the document's collection, but if it has merely been updated, then the story stays in the same place in the collection.

          And so if a document has more than one TOC, the script can't know which is which (and, for that matter, it can only deduce which are the TOC stories by looking for TOC-related paragraph styles). Perhaps that's what I'm reduced to: make sure that the scripts are benign if re-run and then run them against every TOC in the document every time any TOC is updated.

          But that has an inelegant feel to it.

          Has anyone looked into this at all? Is there something that I'm missing? Like does the event include the id of the story? I don't think so, but one surely can wish.

          Dave
          • 2. Re: PostProcessing a TOC
            Roy McCoy Level 1
            Dave Saunders wrote:

            > But here's the rub: how do you work out which story has just been
            > updated? If a TOC has just been created for the first time, it's
            > easy because the story is the last in the document's collection, but
            > if it has merely been updated, then the story stays in the same
            > place in the collection.

            Keep deleting it and generating a new one? Just guessing.

            > And so if a document has more than one TOC,

            Why haven't I ever considered the possibility of a document's having
            more than one TOC? Or have I? I'll keep it in mind for the future in
            any event, and thanks for the suggestion. Thanks also for finally
            delivering a useful characterization of the kind of things that
            practically speaking can only be scripted.


            Roy
            • 3. Re: PostProcessing a TOC
              Level 1
              Roy,

              In order to delete it, I have to know which it is. If I knew that, I wouldn't have to delete it.

              That's the issue with scripts of this sort: you can't tell the user to work with one hand tied behind his back.

              Dave
              • 4. Re: PostProcessing a TOC
                Level 1
                That's one of the reasons that I've (so far) rolled my own TOC generators.

                The only thought that's making sense to me at the moment is (since you're firing on the same event) is to, when the generation is complete write something akin to a checksum and the id of the story into a script label (probably just the length of the TOC would be enough). On future TOC generations, you can check a new calc against the old ones to find which one has changed, and use id to get to the story. Kludgy, but it would work.

                Bob
                • 5. Re: PostProcessing a TOC
                  Roy McCoy Level 1
                  Dave Saunders wrote:

                  > In order to delete it, I have to know which it is.
                  > If I knew that, I wouldn't have to delete it.
                  >
                  > That's the issue with scripts of this sort: you can't
                  > tell the user to work with one hand tied behind his back.

                  Perhaps not, but I have little doubt that one way or another
                  you could find whatever TOC you wanted - at least for yourself,
                  though perhaps not for every user. I, of course, have no idea
                  what either you or I are talking about here. :-)


                  Roy
                  • 6. Re: PostProcessing a TOC
                    Level 1
                    Bob,

                    Thanks for the thought. I wasn't thinking of this as a script for me but as a script for people to install who wanted to improve/workaround the weaknesses of the current TOC generation.

                    So, that means indeed doing something along the lines you suggest or perhaps do what I suggested -- just process all TOCs. But even identifying a story as being a TOC is a bit of a crap-shoot if you are working with an inherited document.

                    Dave
                    • 7. Re: PostProcessing a TOC
                      Harbs. Level 6
                      > But here's the rub: how do you work out which story has just been updated? If a TOC has just been created for the first time, it's easy because the story is the last in the document's collection, but if it has merely been updated, then the story stays in the same place in the collection.
                      >
                      >
                      Huh? Am I missing something? If you update a TOC, the story must be
                      selected, so just find the story of the current selection...
                      > And so if a document has more than one TOC, the script can't know which is which (and, for that matter, it can only deduce which are the TOC stories by looking for TOC-related paragraph styles).
                      There's the story.storyType property. You can check that, to see if it's
                      a TOC.

                      --
                      Harbs
                      http://www.in-tools.com
                      1 person found this helpful
                      • 8. Re: PostProcessing a TOC
                        Peter Kahrel Adobe Community Professional & MVP
                        >That's one of the reasons that I've (so far) rolled my own TOC generators.

                        I do that, too. After some experimentation I found it to be quicker and more flexible.

                        Peter
                        • 9. Re: PostProcessing a TOC
                          Level 1
                          >Huh? Am I missing something? If you update a TOC, the story must be
                          selected, so just find the story of the current selection

                          That's what you're missing. That's not true. There's an invisible (to scripts) connection between a TOC style and the story it controls.

                          >There's the story.storyType property. You can check that, to see if it's a TOC.

                          Bingo! That at least lets me find all TOCs quickly enough. So if the scripts are benign on running a second time, I could just process all TOC stories each time -- it's not like the scripts are heavy duty.

                          Thanks.

                          Dave
                          • 10. Re: PostProcessing a TOC
                            Level 1
                            Maybe we should request an associatedStory property for TOCStyle objects. Mind you, that wouldn't help in this situation unless one or other were passed along as parameters of the event.

                            Dave
                            • 11. Re: PostProcessing a TOC
                              [Jongware] Most Valuable Participant
                              >>That's one of the reasons that I've (so far) rolled my own TOC generators.

                              >I do that, too. After some experimentation I found it to be quicker and more flexible.

                              Oh, we great minds :-)
                              Yes, I
                              i do
                              use ID's TOC -- just to get the page numbers!
                              For some publications (frequently recurring journals) my script generates the entire TOC, not only copying titles but any italics and other formatting in it as well.
                              • 12. Re: PostProcessing a TOC
                                Harbs. Level 6
                                > That's what you're missing. That's not true. There's an invisible (to scripts) connection between a TOC style and the story it controls.
                                >
                                >
                                I'm still not getting it. How are you updating the TOC? You can't select
                                "Update Table of Contents" without a story selected, and when selected,
                                it only updates the currently selected story. What does this have to do
                                with TOC styles?
                                > Thanks.
                                >
                                You're welcome. :)

                                --
                                Harbs
                                http://www.in-tools.com
                                • 13. Re: PostProcessing a TOC
                                  Level 1
                                  Just go to Layout/Table of Contents. Then click OK. That updates the TOC. Ah, what do you know. I never even noticed that Update Table of Contents command. That indeed does require that a TOC story be selected/active.

                                  Dave
                                  • 14. Re: PostProcessing a TOC
                                    Harbs. Level 6
                                    > Just go to Layout/Table of Contents. Then click OK. That updates the TOC.
                                    Ah. What do you know! I never realized that that command updates
                                    existing TOCs... I guess we both learned something today! ;)

                                    --
                                    Harbs
                                    http://www.in-tools.com
                                    • 15. Re: PostProcessing a TOC
                                      How about changing page numbers to cross references?
                                      • 16. Re: PostProcessing a TOC
                                        Level 1
                                        ABC,

                                        I don't follow; in what context are you making that suggestion? It's certainly a way that a home-made TOC could be implemented. But what I'm trying to do is provide automatic post-processing for an InDesign generated TOC.

                                        Dave
                                        • 17. Re: PostProcessing a TOC
                                          Level 1
                                          I understand that it is probably difficult in post-processing. just a little frustration that a simple improvement didn't make it to cs4, and would require custom TOC.