is now part of CreativePro.com!

Building an Index Using Character Styles or External Word List

51

Rachel wrote:

Is it possible to create a TOC or index from a character style?

We’ve heard this request so many times — along with requests for building an index based on a pre-existing list of words — it’s a wonder that Adobe hasn’t already implemented these features into InDesign. Fortunately, our friend Marc Autret has stepped up to the plate with two free scripts that seem to fill the gap perfectly.

We’ve mentioned Mr. Autret’s scripts before, including the one for swapping items on a page. Back in Episode 78, we also talked a bit about how his Index Brutal script (must be said aloud with a French accent) could create indexes that merge page numbers together. Index Brutal is an awesome script that can build an index for your documents based on a list of words in a text file. He has built in a number of very cool additional features, such as a way to search for one term, but index it under a different word. You can find more about this (including his new English-language instructions) on his Web site.

His second script — “IndexMatic,” which builds an index based on character styles — is new and seems to work well, but requires some brave people to test it and give him feedback to fine-tune it. You can download IndexMatic from this link. I believe he plans to merge the two scripts together in the future to make one über-indexing script. Currently, this is an “InDesignSecrets” exclusive! If you use it, please write comments and suggestion in the space below this blog post.

Here is a screen capture of the script’s primary dialog box, just to give you a sense of its abilities:

I hope you enjoy using it. Thank you Marc!

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Derek Berdine says:

    I see “Active Document” and “All Documents” as Targets. I assume this means All Open Documents, but I’m wondering, can this index an entire Book? Or do you have to have all the documents in a Book open at once to index the entire thing?

    Either way this sounds like a great script. I’ll see if I can’t work up some testing for it. :)

    -Derek =)D:

  • Marc says:

    Hi Derek,

    You’re right: “All documents” means exactly “all open documents”. So, to index a Book, you’ve to open *actually* the underlying docs before running IndexMatic.

    Maybe I could add an “auto-open” option (for entire Book targetting)… Maybe…

  • Derek Berdine says:

    Marc,
    It is probably better the way you have it, actually. I like to have separate documents for Table of Contents, Introduction and Conclusion sections, which I usually wouldn’t want to be indexed. So, I wouldn’t actually want a full Index for an entire book, now that I think about it a bit more. :)

    -Derek =)D:

  • JT says:

    The script does not work with nested styles, which is what I need.

    I have a large list of doctors (several thousand) that is being published by an insurance company. The doctors were sent as Excel files which I massaged into a consistent format which I could paste into InDesign. This is the format:

    SPECIALTY
    Last Name, First Name [tab] City [tab] Phone Number

    People most likely will look for docs based on specialty, but occasionally they’ll want to look for a doctor by name, so I need an index of just their names. Space is tight, so I need to exclude their cities and phone numbers. Their names are already in Lastname, Firstname format, so I needn’t worry about that. The problem is that their name, city, and phone number are all on one line, separated by tabs. Nested styles can understand tabs, so it’s easy for InDesign to grab their names. It appears that the script does not understand nested styles though, so I’m back to using a macro I developed last year to manually index all of these names.

  • JT, you are correct: It doesn’t work with nested styles. I should have mentioned that in my original post. It is a frustrating limitation of InDesign because the character styles aren’t truly applied to the text, so scripts can’t “see” them.

    It might work if there were a separate script that converted all nested styles into real styles. That might have other useful applications, too. For example, currently, if you export a file with nested styles out as an RTF document, I think you lose the nested styles, too. An “Expand Appearance” script would help in that situation, as well.

  • Eugene Tyson says:

    How about the PRESERVELOCALFORMATING.jsx script that you guys linked me up with about a year ago. I think it was Dave Saunders who wrote it. That script is the biggest and most useful script in my script arsenal.

    Even when you have a nested style, it will pick if it’s bold, bold italic etc. and then it is given a style accordingly.

    I’m sure some scripter could point you in the way of picking out a nested style and applying the character style to it.

    That kind of defeats the purpose of having a nested style though. As I found a very useful way to use the nested styles and applying a style to some text so that you can get the same text into 2 different variables. Which came in very handy for a book I was setting.

  • Marc says:

    Thanks for your feedbacks.

    About the Nested Style Problem, I wrote this short message to David during the script development:

    Nested styles are very tricky to handle because there are not really applied to the characters. Since the “nested-style-effect” depends dynamically on the context (according to the settings made from the parent paragraph style), InDesign is not able –apparently– to target nested styled text from the find/replace dialog. Also did you notice that when you select a character which is currently nested-styled, the underlying char’style is not activated in the Character Styles Panel ?

    So, thinking about the functionality that JT is looking for, I wonder if the IndexMatic missing feature is not, in fact, a InDesign missing feature (“Flat Nested Styles”)

    From my modest place, I don’t know the way to script that, but Dave Saunders is a great script developer and I’m sure that if he knows how to actually apply nested styles to the concerned characters, he will tell us soon.

    I just want to point out that it could be a problem to insert this functionnality within IndexMatic, because it would modify the document before processing…

  • Thank you for the clarification, Marc. I agree that “expand nested styles” (or “flatten nested styles” or whatever it should be called) should not be part of IndexMatic. It’s a separate script.

    I would see this as a temporary measure… You’d save the file, then “expand” the nested styles, then process with IndexMatic, then use Revert to get back to where you were.

    Eugene, the script you mention doesn’t entirely do what we need here. But I’ll ask Dave S. if he thinks such a thing can be done.

  • Robert says:

    Just a small piece of feedback:

    I tried a quite simple thing: attached a textformat to some (german) names and gave the script a try. The list I got looks like this

    aschemann 8
    beise 11
    döbele 7
    heimes 11
    höfert 4
    jipp 8
    kneitschel 5
    kollak 6
    kroner 9
    mamerow 9
    margulies 9
    mei 4, 7
    ner 4, 7
    plötz 10
    reuter 11
    schmidt 7
    schneider 11
    schwarz 11
    specht 11
    spornitz 5, 10

    As you can see, the names are uncapitalized und there is a problem with the german “sharp s” = ß
    mei 4, 7> and ner 4, 7 should be Meißner 4, 7

    Robert

  • David,

    I disagree that preserve local formatting doesn’t do it. My copy does (although, only for italic and bold, subscript and superscript). So, I’m not sure how useful that is.

    CS3 has a new text property: appliedNestedStyle which looks like the answer to a maiden’s prayer but unfortunately you’d have to look at every character to work out where ranges of appliedNestedStyle happen because nested styles are invisible when using textStyleRanges.

    On the other hand, if a nested style applies any of the four formatting attributes that my script looks for, then my script will find them because searching for formatting works even when the formatting is the result of a nested style.

    But I don’t think this is getting us closer to the goal. Presumably, you want to have an “Index Me” style that doesn’t actually apply any detectable formatting.

    I guess what you could do is to have the script change that style to apply something detectable but benign, e.g., an AltBlack swatch. Now, instead of searching for the style, search for the AltBlack formatting. When finished, delete AltBlack and replace with Black.

    Obviously this falls on its nose if the original character style applied Green, but you get the idea.

  • Robert, I can’t speak to the ß problem, but please try the “Case Formatting” pop-up menu in the script to control how the index is capitalized. The “raw strings” option might be best for you?

  • Dave, I see your point! We need to pick some formatting that Find/Change can find, but that is virtually never used in the document. I would vote for:
    * set the text to 100.01% vertical scaling
    * strikethrough with color set to None
    * or using a stylistic set in opentype features

    Perhaps if one of these is in the nested style, you can then find it and apply the “indexme” style?

  • Watch out for using 100.01% of anything. Rounding errors in floating point numbers could make that impossible to find. The other ideas are good. But whatever, they could be temporarily added by the indexing script. It could look down a list of features for one that is not already applied by the style, temporarily add that to the style, do the search based on that, then remove it from the style.

    Only possible problem is if that same attribute was locally applied to some text that also happens to have the nested style applied — I think that’s why I like my idea of creating a swatch. Given that it didn’t exist before the script was run, it can’t already be applied anywhere. Although, of course, it could wipe out other local styling — geez! These sneaky workarounds always bite you.

  • Marc says:

    Thanks Robert,

    The ß-bug is a very very strange thing.

    The bad news is that similar “holes” seem to appear with other extra-Ascii chars… on Mac OS only! I don’t know why and that’s a serious problem. A French user noticed that the LATIN SMALL LETTER OE (?, U+0153) creates the same hole than your “sharp s” (U+00DF).

    (The “case formatting” option will not change anything to this.)

    It’s not easy for me to fix this bug because it doesn’t occur on the InDesign Win version and where I am today I just can use this one.

    Please, could somebody tell me if the GREP [[:alpha:]]+ syntax catch all the characters of the word Meißner (in the Find feature)?

    And what about the alternate |w+ syntax?
    (replace | by an antislash, the IDS blog doesn’t want me to key it)

    I suspect that the Posix scheme [[:alpha:]] could be a problem on Mac OS… Just a supposition…

  • Marc says:

    Dave and David, thank you for your suggestions.

    The first method — checking the appliedNestedStyle Text property on each character — could be a solution for short documents. But that’s so frustrating!

    The second method, based on a temporary “conversion” of the nested style into something that Find could see, is a genious idea.

    Hmmm, I’ve to think about it…

  • Robert says:

    David,
    sorry, in my hurry to test the script I ignored the case formating thing.

    Marc,
    I tried the two GREP-searches you suggested on “Meißner” and in both cases it finds “Mei” and “ner” but not the sharp s.

    Robert

  • Robert says:

    Did some more testing with the names and found that there is no way to get two (or more) words into one line in the index. Especially in Germany compound names (like Leutheusser-Schnarrenberger) are very common and it is not possible to keep them together. Would it be possible to respect nonbreaking hyphens and nonbreaking spaces to solve this?

    A second thing: words containing a descretionary hyphen do not appear at all in the index.

    Robert

  • Eugene Tyson says:

    Well, I missed loads of this and I caught up this morning. Seems like the preservelocalformatting thing might work after all.

    Nested styles need a general rule to be applied don’t they? So if it was the first word of a sentence or a em space text em space that would apply the nested style. I’m guessing it’s for body text, but the nested style has to have some trigger.

    Is it not possible to GREP search the triggers and then apply a character style. You can find in between em spaces for example and you could apply a style to the text that you find. It wouldn’t affect the nested style either.

    It’s just a matter of searching your text using the criteria you set up in the nested styles.

    You could then technically use the FindChangebyList that ships with CS3 to find all the nested styles and apply the style that you want, in one big swoop.

    Does any of that sound doable?

  • Marc says:

    Robert said: I tried the two GREP-searches you suggested on ?Meißner? and in both cases it finds ?Mei? and ?ner? but not the sharp s.

    OK, here we have the culprit !! On Mac OS, it seems that InDesign DOES NOT recognize ß or other extra-Ascii latin characters AS a word letter!

    If other Mac users confirm that point, that’s a InDesign bug, because the GREP [[:alpha:]] (Posix) and antislash w are supposed to match any alphabetic/word letter.

    So, I’ve to rewrite the GREP command to get round the bug…

  • Marc says:

    Robert said: Would it be possible to respect nonbreaking hyphens and nonbreaking spaces to solve this? A second thing: words containing a descretionary hyphen do not appear at all in the index.

    Good point. I’ve to add some extra parameters in the dialog to let users extend the GREP search scope.

    That’s easy, but I need some time to analyse the different cases.

  • Robert: Also, make sure you are choosing “longest string” from the Search For pop-up menu. If you apply the character style to “silly rabbit” and use “alphabetic words,” then you will get two entries (“silly” and “rabbit”). But if you choose “longest string” then you get one entry.

  • JT says:

    I solved my problem by using a GREP search and the IndexMatic script. Here’s how, in case anyone reading this post has the same problem:

    Again, the format is:

    Doctor Name [tab] City, ST [tab] Phone Number

    For the index, I care only about the name. The names are already formatted as I need them, I just need to get them into an index.

    I do a GREP find-and-replace with the following search string:
    ^[(backslash)l(backslash)u(backslash)d, (backslash).-"'(backslash)((backslash))]+

    (Sorry, but my backslash characters get munged when I post.)

    This finds strings starting at the beginning of a paragraph, and consisting of upper- and lowercase letters, commas, spaces, periods, hyphens, single- and double quotes, parentheses, and digits (for the heck of it): characters that appear in people’s names in Roman-based languages. When InDesign encounters the tab character, it stops the match. I restrict this search to text with the paragraph style I applied to all the listings.

    I replace this string with a special character style. I include a special color with this character style so it will be easy to see what has been matched and what hasn’t. Then I run the IndexMatic script on this character style.

    It only took a few seconds for InDesign to apply this character style to 6200+ names, and about 10 minutes for IndexMatic to crank out the index. Compare that to hours doing it by hand or even with a keystroke-saving macro.

    I couldn’t have done it without stuff I learned from this site, so? thanks! :)

  • Roland says:

    I need to make an index (first ever for me) and this script seems to be just the thing I need, but I have two questions:
    Can the script search for multi-word keywords (example: radiator coupling) and create multi-word index-words without having to do a find & replace on the word list my customer will have to supply?

    And, is it preferable to have words that have multiple spellings or abbreviations mentioned once using the > operator, or to simply mention every spelling?

  • Damian says:

    Just used this most helpful script but struggled initially. The character styles I wanted to use for the index were grouped in a sub folder in my character styles palette and the script kicked out an error. Moved the styles to the root level of the palette and viola! Magnifique!

    Damian

  • Mark Finn says:

    The indexmatic is great…have used it to look for practioners in a directory and output names and page numbers. After spending a weekend indexing by hand you have saved me!!!!

    I have a way of reordering the names so that last names come first and then resort in word but it there a way in your javascript to do this?

    If not or requires javascripting skills that would take years to learn thank you again.

    Fantastic script my man!

    Regards Mark

  • David says:

    Do anyone know how to set you own default settings for this script. I am going to successful AppleScript this into a custom workflow.

    Thanks,

    David

  • Marc says:

    Do anyone know how to set you own default settings for this script.

    In the DIALOG section of the .js script (line 423), there’s a global var named DLG_PRESET, with a default affectation :


    if ( ( DLG_PRESET == undefined ) || ( DLG_PRESET == null ) )
    {
    DLG_PRESET =
    {
    target: 0,
    what: 1,
    minCars: 1,
    incFootnotes: true,
    incHiddenLayers: false,
    incMasterPages: false,
    carStyle: '',
    parStyle: '',
    caseFormat: 2,
    sortOption: 1,
    pagesReport: 0,
    outputMode:0
    }
    }

    As you see, all the IndexMatic dialog preferences are provided here.
    So, by example, if you want to default “Search for: Longest strings (styled)”, set what to 0 (in spite of what: 1).

    Regards,
    Marc

  • David says:

    Kudos to Marc on this exquisite script. I have discover that this is the only one of its kind that works with character style. Which solved a huge issue for me. I am using automation to build a product catalog. My next step is activate this script using AppleScript. Any leads as to how to do that.

    Thanks,

    David

  • Matt Milton says:

    I can’t get the IndexMatic script to work on my Mac. I’m using CS2 in OSX on an iBook.

    The error message I get is:

    Javascript Error!
    Error number: 8
    Error string: Syntax error
    Line: 24
    Source: #targetengine ‘session’
    Offending Text: #targetengine ‘session’

    Any suggestions?

    (I tried just taking the whole line out, and ran the script again: it found another error in line 50something…)

    cheers
    Matt

  • Marc says:

    I would like to run the script without the dialog boxes. How I do that? (David)

    Disclaimer: Before to operate, run once IndexMatic WITH dialog box and check that the context is OK (the DLG_PRESET var is updated by the script each time you validate the dialog). NB: If you need a persistent solution (=multi-session), you’ll have to manage yourself DLG_PRESET as explained in a previous post.

    Solution:
    1) Open the script (IndexMatic.js) in your text editor.

    2) Find the line #591 containing :

    while ( dlgOK=dlg.show() )

    3) Replace dlg.show() by true:

    while ( dlgOK=true )

    Now the script will run without the dialog box.

    Marc Autret

  • Marc says:

    I can?t get the IndexMatic script to work on my Mac. I?m using CS2 in OSX on an iBook. (Matt)

    Sorry, Matt, IndexMatic requires InDesign CS3 or later.

  • Matt Milton says:

    OK. I just tried it out on InDesign CS3. It works very well, thanks. But unfortunately, it’s not what I’m after: does anyone know of a script that will apply InDesign index tags to specific character styles?

    I used to have a great little script that would do this ? it would apply an InDesign index tag to a range of specified character styles. It was great, because it wouldn’t matter if the pagination changed ? the tags would of course move with the pagination. I *think* this is it here, but I could be wrong.

    https://olivier.berquin.free.fr/indesign/indesign_cs1.html#top_index_From_Char_Style

    (I suppose if this isn’t it, then I could dig up the script from my old CS1.)

    Sadly it only works in CS1. I would love a version of this script that worked in CS2 or higher…

  • John says:

    I love this script except for the fact that it doesn’t work in the situation I would like to use it. I have a multi-page document that contains a flowing table. When the script is activated, it reports all occurances of words throughout document on page 1, the page that the table starts on (versus the page # that it is actually on).

  • Emil Barbaric says:

    Great scripts!

    But, it seems that indexmatic script won’t pick up references in the footnotes. I tried in ID CS4 (OS X).

    Is this a bug and can be fixed or it is something wrong with my configuration?

    Thanks,

    Emil

    Same problem have Mirza
    https://forums.adobe.com/message/1318642#1318642

  • Damian says:

    Hi

    I have the same problem in CS3 re not picking up character styles in the footnotes.

    Anybody been able to fix/find a workaround for this yet?

    Tks
    Damian

  • CJ says:

    Marc-
    You have just cut my indexing time by days. I used to index a 200 pg directory by clicking and adding- thousands of names… I had them set up with character and paragraph styles, but had no idea this sort of script existed until now. I just tested it and it literally took 5 minutes to generate the type of index I needed that used to take us days! You are AWESOME!

  • Momet says:

    I really want Indexmatic! But the link does not work. Has Marc Autret pulled that page?

  • Marc moved the scripts temporarily to a new site at indiscripts… I believe you can download the scripts at this page now.

  • A new version of IndexMatic is available and it?s even more powerful than the previous one.

    https://www.indiscripts.com/post/2011/07/indexmatic-2-public-release-and-user-s-guide

  • Tina DeJarld says:

    Is there anything that will build an index based on character styles when those styles are nested styles or GREP styles within a paragraph style?

    It’s so efficient to use those and I don’t want to give it up in order to create an index.

    I have two character styles that I want to pull out of each paragraph to create the index. The project is a product catalog and each product listing is one paragraph.

  • Preston says:

    Dead link! so sad.

  • Frank Puschmann says:

    Thanks for the interesting article, this helps me.

  • MIthalogica says:

    Is there a way to get this to pick up phrases? (I’ve been asked to capture all the links included in a 300 page book. They are all formatted with a character style, but there are several words long. I saw something about selecting “longest string” in the “Search For” pop-up menu, which sounds like it would do this, but I don’t seem to have this option anywhere.

  • Having just read this thread and the one linked above, it doesn’t appear that this script adds actual Index markers into the InDesign document. (I used the Try version and didn’t see any markers inserted). What would be great is is a script that could find each instance of a paragraph or character style (using a GREP query would be great, too) . . . and insert the “Add New Index Entry (reversed)” command. My goal is to find just the people’s names in the following text:

    Jane Doe
    Address
    City, State Zip
    email
    phone

    paragraph of descriptions etc.

    Bubba Smith
    Address
    City, State Zip
    email
    phone

    paragraph of descriptions etc.

    Jim Anderson
    Address
    City, State Zip
    email
    phone

    Anderson, Jim
    Doe, Jane
    Smith, Bubba

    paragraph of descriptions etc.

    and turn it into this index:

    Anderson, Jim, page 00
    Doe, Jane, page 00
    Smith, Bubba, page 00

    The names have a unique paragraph style on them, so finding them is easy. But for now, I have to select each name, and hit the keystroke to “Add New Index Entry (reversed)” so they get added to the index as “Doe, John” etc.

    Has anyone been able to get the IndexMatic (or any other script) to accomplish this?

    • Rebecca Kurk says:

      Hi Matt, this is exactly what I’ve looking and hoping for… for a VERY long time. Your suggestion is super simple so can’t figure out why it’s been so hard to get for InDesign. Quark had a similar feature that simply made an alpha list with page numbers of everything that had a certain character style for decades now! My list is too long for the trial version of Indexmatic, I have more than 50 entries on one page, which is the limit for the trial version.

  • Alok Rawat says:

    Very helpful article thank you very much… ;-)

  • fuck69.xyz says:

    Great blog! Do you hasve anyy recomnmendations for aspiring writers?
    I’m planning to start my ownn website soon buut I’m a little lost on everything.Would you propose starting
    with a free platform like WordPress or go for a paid option? There are so many
    choices out there hat I’m completely confused ..
    Any ideas? Bless you!

  • Roy says:

    An error “None of the listed words has been found!” appears when the script is run. I tried it on a document that has the same list in a text box. Still the same error??? I would love to have this work for a project middle of next week :-)

  • Sharon Lewis says:

    Hi David. I have various sections created in InDesign and I would like to know how do I create an index page that is separate from the InDesign sections? I will be compiling my separate sections in the book feature.

    Thanks

    • David Blatner says:

      If you’re using InDesign’s index feature, you can index all the documents one at a time, then build the index in the last document in the book. InDesign can create the index from all the documents in the book if you do it right.

  • >
    Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo