Command/setregisterentry
< Command
Jump to navigation
Jump to search
Contents
\setregisterentry
Summary
The command \setregisterentry writes an entry to the register.
Settings
| \setregisterentry[...][...=...,...][...=...,...] | |
| [...] | name |
| label | name |
| keys | text processor->text |
| entries | text processor->text |
| keys:1 | text |
| keys:2 | text |
| keys:3 | text |
| entries:1 | text |
| entries:2 | text |
| entries:3 | text |
| alternative | text |
| key | value |
| Option | Explanation |
|---|---|
There’s also the processors option (plain or with :number) for formatting, see Processors. | |
Description
\setregisterentry is a more structured form of the regular \index command. With its more complex and robust structure it is suitable for automatic workflows.
When processing the command on the Lua end, one has to take care of colons in the key:1 and entry:1 parameters by enclosing them inside ["..."], which is a more robust form of putting a key in a Lua table, see example below.
Examples
Three levels, changes in the sorting, comma in the entry
\setupregister[index][balance=no] \starttext \chapter{Alfred Hitchcock} The Skin Game (1931) \setregisterentry[index] [keys:1=Hitchcock Alfred, entries:1={Hitchcock, Alfred}, keys:2=1931, entries:2=1931, keys:3=Skin Game, entries:3={Skin Game, The}] Mary (1931) \setregisterentry[index] [keys:1=Hitchcock Alfred, entries:1={Hitchcock, Alfred}, keys:2=1931, entries:2=1931, keys:3=Mary, entries:3=Mary] Rich and Strange (1931) \setregisterentry[index] [keys:1=Hitchcock Alfred, entries:1={Hitchcock, Alfred}, keys:2=1931, entries:2=1931, keys:3=Rich and Strange, entries:3=Rich and Strange] Number Seventeen (1932) \setregisterentry[index] [keys:1=Hitchcock Alfred, entries:1={Hitchcock, Alfred}, keys:2=1932, entries:2=1932, keys:3=Number Seventeen, entries:3=Number Seventeen] \blank \placeregister[index] % without title \stoptext
Using processors
You can apply a processor to the page number using keys=Processor->.
If entries overlap (e.g. with and without processor on the same page), the outcome is unsure.
The example also illustrates that entries with and without processor are handled separately (the question was if we can combine uppercase and lowercase spellings).
\defineprocessor [Upper] [command=\Word] \defineprocessor [Red] [color=red] \starttext anything\setregisterentry[index][keys=Anything, entries=Anything] something\setregisterentry[index][keys=Something, entries=Something] \page Anything\setregisterentry[index][keys=Red->,entries=Upper->anything] Something\setregisterentry[index][keys=Red->,entries=Upper->something] \page \placeindex \stoptext
How to create a “see also” entry without a page number
\defineregister[TopicIndex] \defineregister[SeeTopicIndex][TopicIndex] [pagecommand=\gobbleoneargument] \starttext \samplefile{lorem} \setregisterentry[TopicIndex][entries:1=punctuation]% \samplefile{lorem} \setregisterentry[SeeTopicIndex][entries:1=punctuation,entries:2={\emph{See also} marking}]% \samplefile{lorem} \placeregister[TopicIndex,SeeTopicIndex][n=1] \stoptext
Processing on Lua end
\startluacode context.setregisterentry({ "index" }, { ["keys:1"]="sorting key", ["entries:1"]="displayed entry"}) \stopluacode