[go: up one dir, main page]

0% found this document useful (0 votes)
165 views5 pages

Indesign

This document provides instructions for generating an index from a word list in InDesign using a JavaScript. It includes the script needed to search documents for instances of words from the list and add page references to the index, as well as explanations of how to set up and run the script. Users are instructed to save the script in the InDesign Scripts folder, create a "topic list" file with the index words, and run the script to generate the index.

Uploaded by

ramanagopal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views5 pages

Indesign

This document provides instructions for generating an index from a word list in InDesign using a JavaScript. It includes the script needed to search documents for instances of words from the list and add page references to the index, as well as explanations of how to set up and run the script. Users are instructed to save the script in the InDesign Scripts folder, create a "topic list" file with the index words, and run the script to generate the index.

Uploaded by

ramanagopal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

http://www.kahrel.plus.com/indesign/index_from_wordlist.

html - Index creting help website


Using the above website we can generate the indexes for a book

Script for creating index file

????????????????????????????????????????????????????????????????????????????????
//DESCRIPTION: Index from word list
// Peter Kahrel -- www.kahrel.plus.com

/*
16 Nov. 2011: fixed bug that chopped off word-final s
*/

// List the paragraph styles to be included, using the first three


// characters of their name (case-sensitive), and prefixed with "|".
// Use "" to ignore this and include all paragraph styles

paragraph_styles = "";
//paragraph_styles = "|def|sec";

// 'true': search documents case-sensitively,


// 'false': ignore case
case_sensitive = true;

// Replace index?
replace_index = true;

// Ignore text after comma?


comma_split = false;

// Ignore text after parenthesis?


paren_split = false;

/*--------------------------------------------------------------------------

Create word-list. To create separate indexes,


prefix items with any of the symbols £ % & @.
Open the word list and all files to be concordanced.
The word list document's name must have 'topic list' in its name.

------------------------------------------------------------------------------*/

index_from_list ();

function index_from_list ()
{
var listName = environment_check();
set_find_options();
var list = get_list (app.documents.item(listName));
//app.activeDocument.close (SaveOptions.yes);
var displ = init_progress ();
displ.show();
index_documents (list, listName, displ);
}

function index_documents (word_list, listName, displ)


{
var docs = app.documents.everyItem().getElements();
for (var i = 0; i < docs.length; i++)
{
if (docs[i].name == listName) continue; // Skip the list itself
displ.docName.text = docs[i].name;
if (replace_index == true)
try {docs[i].indexes[0].topics.everyItem().remove()} catch (_){};
if (docs[i].indexes.length == 0)
docs[i].indexes.add ();
for (var j = 0; j < word_list.length; j++)
{
displ.pbar.value = j;
// split word-list entry into item to search and item to use for index
var search_item = get_search_item (word_list[j]);
try
{
var new_topic = docs[i].indexes[0].topics.add (word_list[j]);
//delete prefixed symbol, if any
app.findGrepPreferences.findWhat = search_item;
var found = docs[i].findGrep();
for (var k = found.length-1; k > -1; k--)
{
try
{
// if the found string's parent paragraph style name begins with d,
q, or n
if (style_ok (found[k]))
new_topic.pageReferences.add (found[k],
PageReferenceType.currentPage);
} catch(_) {/* not interested in errors */}
} // for (k
} catch(_){}
} // for (j
//doc.save ();
//doc.close ();
}
}

// Take an item from the word list and create a search item:
// split word-list item on comma. If that fails,
// split on parenthesis. If that fails too, return the whole item.
// Wrap string in word-boundary markers and
// prefix the case-insensitive code, if necessary.

function get_search_item (s)


{
// delete prefixed symbol
s = s.replace(/^[£%&@]/, "");
if (comma_split) {
// delete anything from comma or parenthesis
s = s.replace (/\s?[,(].+$/, "");
}
// add word boundaries
s = "\\b" + s + "\\b";
if (case_sensitive == false)
s = "(?i)" + s;
return s;
}

function style_ok (w)


{
return ((paragraph_styles == "") ||
(paragraph_styles.search (w.appliedParagraphStyle.name.slice (0,3)) > 0))
}

function get_list (doc)


{
var story = doc.pages[0].textFrames[0].parentStory;
// Remove trailing spaces
app.findGrepPreferences.findWhat = "\\s+$";
app.changeGrepPreferences.changeTo = "";
story.changeGrep ();
// Remove serial spaces
app.findGrepPreferences.findWhat = " +";
app.changeGrepPreferences.changeTo = " "
story.changeGrep();
return story.contents.split ('\r');
}

function environment_check ()
{
if (app.documents < 2)
errorM ('Open a word list and \rthe documents to be indexed.')
var listDocName = findTopicList();
if (listDocName == null)
errorM ('Open the document with the topics to be marked (it should have "topic list" in its
name)');
// The list document is now the active document
if (app.documents.item(listDocName).pages[0].textFrames.length != 1)
errorM ('The list document should have one text frame on the first page -- not more, not fewer.');
return listDocName;
}

function findTopicList() {
var docs = app.documents.everyItem().getElements();
for (var i = docs.length-1; i >= 0; i--) {
if (docs[i].name.toUpperCase().replace(/[\x20_]/g,"").indexOf('TOPICLIST') > -1) {
return docs[i].name;
}
}
return null;
}

function set_find_options ()
{
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeHiddenLayers = true;
app.findChangeGrepOptions.includeMasterPages = false;
app.findChangeGrepOptions.includeFootnotes = true;
}

function errorM (m)


{
alert (m);
exit()
}

function init_progress ()
{
var w = new Window ('palette', 'Concordance');
w.alignChildren = ['left', 'top'];
w.docName = w.add ('statictext', undefined, '------');
w.docName.characters = 40;
w.pbar = w.add ('progressbar', undefined, 1, 50);
w.pbar.preferredSize = [270,20];
return w;
}
???????????????????????????????????????????????????????????????????????????????

1. Save the above file in .js or .jsx extension and put the file in the following folder -
C:\Program Files\Adobe\Adobe InDesign CC 2018\Scripts\Scripts Panel

2. Create a indesign file named ‘topic list’ and type all words one by one without comma(,)
and save the file

3. Open script window, goto the Window->Utilities->Scripts

4. Then right click the java script file (index_topics_list.js ) and run the file.

5. Open the Index - goto Window->Type & Table->Index - In the index panel click the generate
index.

Index_topics_list.js
The above js file is in my google drive

https://drive.google.com/file/d/14xUIDJPjk3EBn6J3sFBfEryFF0S2Dl7O/view?usp=sharing

You might also like