Copy link to clipboard
Copied
Hello,
I have a book formatted in InDesign. The index was created and sent to me in a .txt file. I have now had to add two pages, so all the index entries need to be advanced by two. Is there a script that can perform this task? Perhaps this could be done in the .txt file, but I could put it inDesign and work from there.
Thanks,
Tom
Copy link to clipboard
Copied
You can do it in Excel or similar.
Copy link to clipboard
Copied
Hi Tom:
For next book, it may be worth noting that InDesign can create an index for you. After you add the index markers, you can update it after edits and all the page numbers will update. https://helpx.adobe.com/indesign/using/creating-index.html
~Barb
Copy link to clipboard
Copied
All page numbers or only those greater than a certain value?
Copy link to clipboard
Copied
Hi Peter,
In my case starting at page 1 for the first volume but page 950 or so for the second volume. I was thinking of asking you to write such a script. I actually did many years ago and it worked beautifully. But change of computers and I lost it. And I have not written scripts for a long time. However, the person doing the indexing has software that will automatically do this work so I now know I no longer need a script.
I am wondering, Robert, if you can give some hints as to how to go about changing page numbers using Excel. I do not need it in this instance but perhaps others on this forum would like to know.
Thanks everyone,
Tom
Copy link to clipboard
Copied
As there is always TAB after the text - you can split it in to two columns.
Then you would need to split 2nd column further - first by separators - "," - then ranges - "-" - so you can reverse it.
When you have everything separated - you can update page numbers - either via macro - or "=if(...)".
Then join everything back.
The only downside - it will work directly only on 0-9.
With extra tinkering - Romans and letters can be handled as well.
Copy link to clipboard
Copied
Here a script to adjust numbers. You need to set the breakOff (the number from which to renumber) and by how much the numbers should be incremented (the value at diff). You can use a negative number to decrement page numbers. To do all numbers, use a break-off of 1.
Select a text frame or an insertion point to target a story.
(function () {
var breakOff = 100;
var diff = 2;
var num;
try {
var story = app.selection[0].parentStory;
} catch (_) {
alert ('Select a text frame or a text object');
exit();
}
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\d+';
var pNums = story.findGrep();
for (var i = pNums.length-1; i >= 0; i--) {
num = Number (pNums[i].contents);
if (num >= breakOff) {
pNums[i].contents = String (num + diff);
}
}
}());
Copy link to clipboard
Copied
Nice, but I think index should be converted into two column table first and then script should work only on a second column?
In case when there are some numbers in the text as well?
Copy link to clipboard
Copied
Thanks Peter, this works for me on an index using "Latin digits" (Arabic numerals of Latin script) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
However for an index using "Arabic digits" (Indian numerals of Arabic script) (٠١٢٣٤٥٦٧٨٩) there was no change.
Now, in this Arabic index, I notice that the digits were "hard coded" such that changing the language preferences in the paragraph settings did not change the style of digits (even though the preferred digits were available in the font).
Of course, there are different styles of digits in use in languages which use the Arabic script (e.g. Arabic, Farsi, Urdu) and there are many other styles of difits around the world.
I do not suppose that a simple script can account for every form of "hard coded" digits where we have the correct glyph for a digit but it is not necessarily recognised as a digit by the system (e.g. Windows, Mac) and/or the software (InDesign).
So, for these alternative-language digit adjustments, first we have to replace the digits then we have to use the adjustment script, then change the digits back again.
I just thought I would mention it here for posterity.
Copy link to clipboard
Copied
> in case when there are some numbers in the text as well?
That's true. But it's always a problem to figure out what the topic separator is. Could be an en-space, two spaces -- which are easy to find. Could also be a comma and a space, which is a problem because that's also the page-number separator. If you know the topic separator there's no need to split the index into two columns, you just take each paragraph from the separator to the end.
This particular script doesn't handle abbreviated page ranges very well. For instance, 28-9 incremented by 2 should be 30-31, but comes out as 30-11. So you'd have to unrange ranges, then do the adjustments, and re-range. But that, too, is a problem. For instance, 34-36, 37 -- it's simple enough to unrange this to 34, 35, 36, 37, then increment by 2 to 36, 37, 38, 39, but then when you're re-ranging you get 36-39. You don't know that 39 is out of the range.
So because there are that many problems with page numbers apart from deciding where they start, and because updating index numbers after the index was produced is an act of desperation, you just hope for the best and keep your fingers crossed. And checking manually later whether there are any numbers in the topic names, by the way, isn't a big deal.
What should be added to the script is also a maximum: now it has only one mode: greater than a number. It should also handle greater or smaller than a number.
Copy link to clipboard
Copied
You are right - as always.
I was thinking only about TAB as being a separator - but as you've pointed out - it may be something else.
Then there are different styles of presenting page numbers...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now