Index Page Ranges

Page ranges in InDesign's index are difficult to handle after document changes. A script uses a better method to manage page ranges.

This script is part of the Indexes and Concordances collection. See the full collection here.ย 

InDesign offers several ways to handle page ranges. They are listed in the New Page Reference and Page Reference Options windows:

InDesign's page-range options

Of these, the first two (Next Style Change and Next Use of Style) are useful only if you want a page reference to range over a text section delimited by paragraph styles. This works fine on the whole, but you need to keep your eye on changes in paragraph styles.

The next three (To End of Story, Document, and Section) are unproblematic, if rather heavy-handed.

The last two (For Next No of Paragraphs and Pages) can be used to set a range that’s not otherwise delimited. But they are difficult to work with in a text that is edited from time to time: to determine whether any applied paragraph and/or page counts are still correct is a nightmare.

Moreover, the ‘For the next n number of paragraphs’ function was poorly designed: it points to the beginning of the nth paragraph, which means that if the paragraph breaks across pages, the count is off and the range is a page short. The function should point to the end of the nth paragraph.

What InDesign should have implemented is something like ‘To marker’. Such a marker is some kind of destination marker that indicates the end of a range. Word processors old and new use this: Latex uses such a system, WordPerfect sported it, and Word uses it, too. It’s an efficient way to manage page ranges and it’s unfortunate that it wasn’t implemented in InDesign.

However, a system that uses end-of-range markers can be scripted. Below I outline four scripts that can be used to set up and maintain end-of-range markers in InDesign documents.

Briefly, a script is used to insert end-of-range markers; then there is a script, run immediately before generating the index, that applies ranges; and a script that can display the end-of-range markers conveniently in anchored text frames so that they are visible and easy to manage. The scripts are simple to use and very quick. They’re discussed in detail in the following sections.

Quick overview

First, download the zip package, extract the four scripts, and copy them to InDesign’s Scripts folder. The package contains these scripts:

  • index-page-range-insert-end-mark.jsxโ€ƒInsert an end-of-range marker at the appropriate place. This could be done manually, but the script makes it very easy.
  • index-page-range-apply-ranges.jsxโ€ƒImmediately before generating the index, run this script to set the ranges at the page references.
  • index-page-range-show-markers.jsxโ€ƒThe end-of-ranges markers are difficult to spot, and only in normal screen mode. This script makes the markers visible by placing a small anchored text frame, anchored at the marker and placed just outside the page. The frame contains the topic’s name.The corresponding page references are shown as well.
  • index-page-range-remove-styles.jsxโ€ƒThe script that shows the markers creates object and paragraph styles and a swatch. You can leave these styles in place but if you want to delete them, use this script.

Insert end-of-range markers

Setting up an index marker for a page range is simple. First create a page reference as usual or edit an existing page reference and set its type to For Next No of Pages. Set its scope to 1 at Number:.

A new page reference

By setting the reference type to For Next No of Pages we mark this page reference as a start-of-range marker.

To place an end-of-range marker for this page reference, select the insertion point of the range’s end and run the script index-page-range-insert-end-mark.jsx. It shows the following window:

A new page-range target

Type the name of the topic and click Create target. You must type the topic name exactly as it appears in the New Page Reference or Page Refere Options window.

If the topic is a subtopic, enter the full topic path, so to speak, using ## as a separator. For example, if the topic is footnote options, numbering style:

A subtopic

You enter the full topic name in the script’s window as follows:

A new page-range target of a subtopic

The script inserts a marker at the insertion point. This marker is a tiny graphic line (its weight is zero, it’s 6 points tall). So in Preview mode you’re not going to see it; in Normal mode (and with hidden characters shown) it’s displayed as a blue Yen symbol.

The graphic line is labelled using the name Range target: followed by the name of the topic. You can see that in the Layers panel.

A new page-range target shown with styles

The script also created an object style (Range target) and applied it to the marker. To make those markers more visible you can edit the object style and set the stroke weight to 1 point and apply some colour to it. (This may cause some text reflow, but after resetting the style everything will flow back.) But there’s another way to make end markers visible and more easily manageable; see below.

Entering a topic name

It’s important that the name that you type in the script’s window matches the topic name exactly. Be careful with spaces: you may not always see the different types of space used in a string, for instance (normal space, non-breaking space, etc).

Another thing is that it’s hard to enter a character into a script window if it’s not on the keyboard, such an accented character or some special symbol.

To make that easier, the index-page-range-insert-end-mark script can copy a topic name into the script window. It works like this. Open the Index panel and select the page reference’s page. Then click Go to selected marker (the left-most toolbutton):

The index panel

Run the script (it’s persistent so it may already be open) and click Get topic name, which copies the topic’s full path:

Copying the full topic name

Now go to the place where you want to insert the end-of-range marker and click Create target.

Display end-of-range markers

The problem with the end markers is that they’re not so easy to manage. They’re (virtually) invisible in the text, and though you can see them in the Layers panel, that doesn’t really tell you where they are and you see just the markers on the selected page.

To make end markers more easily manageable you can show them in anchored text frames. Run the script index-page-range-show-markers.jsx. The result looks as follows:

Index end-of-range markers displayed

The script places the end marker Valencia in an anchored text frame. The frame’s appearance is entirely handled by an object style (index-range-end), the appearance of the text is handled by a paragraph style (index-range-end), and the text’s fill colour is set as a swatch (index-range-end text) and applied in the paragraph style.

The position of the anchor is right next to the end marker’s position. The anchor is shown as a blue Yen symbol. To show the dotted line that connects the frame and the anchor, enable the display of text threads (View > Extras > Show Text Threads; unfortunately that can’t be scripted).

For clarity the script also shows all topics that are start-of-range markers, that is, page references whose type is For Next No of Pages:

Index start-of-range markers displayed

For these start markers, too, styles are created (index-range-end). Topic names at the start of a range are black, at the end, red.

The script creates all these styles only when they don’t yet exist. So you can change any settings (position, appearance, etc.), and when you next run the script, these modified styles are used.

Before the script adds markers it removes all existing markers. You can therefore run the script more than once, no markers will be duplicated.

Removing styles and displayed markers

To remove the markers and all the styles they use, run index-page-range-remove-styles.jsx.

Generating page ranges

The script that inserts end marks does just that: nothing else. To set the corresponding page reference’s page count so that the range is created, run index-page-range-apply.ranges.jsx, which is included in the download. It has no interface.

The script matches end-of-range markers with their associated topics and sets the range by determining the number of pages between topic and marker, and sets that number for the page reference. The Index panel is updated and shows the applied range:

Update preview in the Index panel

Topics with multiple ranges

You can create more than one page range for a topic. Simply use the method described above as often as needed. When the script creates ranges it uses the next nearest end-of-range marker in the same story.

Troubleshooting

The only script that may run into problems is index-page-range-apply.ranges.jsx. The script checks only whether the end-of-range marker is after its page reference (the start marker) and whether the start and end markers are in the same story. Other errors are for now silently ignored, a comprehensive error checker is in the works.


Version history

11 June 2026: Changed the end-of-range markers so that they can be resized without changing the text flow.

26 Aug. 2025: Added a script to display the end-of-range markers. Renamed the scripts so that their names make better sense. Rewrote most of the text on this page to reflect the changes.

11 Aug. 2024: A new approach.

1 Aug. 2023: First posted.


Peter Kahrel Script Repository
Hosted as a community service, and with deep appreciation, by CreativePro.com


Scripts by Topic | Script Index
Basic Script Installation and Use
How to Modify or Configure These Scripts
Resources for Scripting and Publishing Automation
About This Repository


Repository Home Page


Contact Peter Kahrel


Note to users: You run scripts at your own risk: CreativePro and the author accept no liability for anything that may be caused by any of these scripts. Always take the necessary precautions. We encourage you to save backups and test scripts on copies of your documents.

Bookmark
Please login to bookmark Close

This article was last modified on August 22, 2026

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading comments...