# Background

Page numbers in an index are often formatted using hyphens for references on consecutive pages, such as:

``````1, 4-7, 10
``````

# Code

Consider the following example:

``````\defineregister[photographer][]

\setupregister[photographer][
pagestyle=normal,
indicator=no,
]

\starttext
First
\photographer{Yousuf Karsh} \page
Second
\photographer{Yousuf Karsh} \page
Third
\photographer{Yousuf Karsh} \page
Fourth
\photographer{Yousuf Karsh}

\completephotographer
\stoptext
``````

# Problem

I would like to produce the behaviour of hyphenated page numbers using ConTeXt, however the example code produces:

I thought that it would produce `1-4` instead of `1, 2, 3, 4`. The documentation describes two "tricks" to accomplish this feature:

1. Automatically collapse page ranges: `[[Command/{{{1}}}|\{{{1}}}]]`. I have no idea what that means or how to use it -- there is no complete example. Also, other documentation indicates not to use command, opting for `pagecommand` or `textcommand` instead.
2. Use `\startregister[index][mymouse]{mouse} ... \stopregister[index][mymouse]`. This does not apply in my case because I don't know when the last consecutive reference will be added to the document: the document is created dynamically.

# Question

How do you collapse page ranges in ConTeXt when you don't know where the first and last references are inserted into the document?

The option you need is `compress=yes` which compresses consecutive entries into a range with hyphen.

As a side note, generally a `\definesomething` takes the same arguments as `\setupsomething`, so you can shorten the example:

``````\defineregister
[photographer]
[compress=yes]

\starttext
\dorecurse{4}{%%
Foo
\photographer{Yousuf Karsh} \page}

\completephotographer
\stoptext
``````