[NTG-context] How to use \setuplist for formatting a chapter entry?

Wolfgang Schuster schuster.wolfgang at gmail.com
Tue Feb 3 10:13:23 CET 2015


> Am 03.02.2015 um 09:57 schrieb Rob Heusdens <robheus at xs4all.nl>:
> 
> Hello list,
> 
> I have one little problem that I need to solve to finish my work on a
> document. I want to format a list entry for the TOC for chapters like
> this:
> 
> "Hoofdstuk #1 -- #2 . . . . . . . . #3"
> 
> Where #1 is the chapter number, #2 is the title and #3 the page number
> where the chapter begins.
> 
> Of course the ". . . " entry is just like the normal cases where the dots
> fill the rest of the line.
> 
> I have an *almost* correct solution using numbercommand and setting the
> width for the title, but this leaves a gap between the formatted chapter
> number and the title, because "chapter 9" and "chapter 10" don't take the
> same width.
> 
> So, some other solution is needed. I tried using the command option, which
> needs 3 arguments, but could not get it to work.
> 
> Here is how it looks now:
> 
> \define[1]\ChapterNumberToc%
> 	 {Hoofdstuk #1 -- }
> 
> \definecombinedlist[content][chapter]
> \setupcombinedlist[content][level=4, alternative=c]
> \setuplist[chapter][headnumber=yes,style=bold,width=8em,numbercommand=\ChapterNumberToc]
> \starttext
> \completecontent
> \dorecurse{5}{
> \chapter {Knuth} \input knuth
> \chapter {Zapf}  \input zapf}
> \stoptext
> 
> As you can see, there is a different between the 9-th and 10-th chapter,
> because title is set at a specific width, and doesn't adapt to the width
> of the formatted chapter number entry.
> 
> How to solve this, so that the title is placed directly after the
> "Hoofdstuk #1 -- " entry, thereafter the filler with dots and finally the
> page number at the location where it is now.

You have to write your own layout for the complete list entry. When you don’t
need hyperlinks for the list entries you can use “alternative=command” instead
of “alternative=interactive” for \setuplist.

\setupcombinedlist[content][list=chapter]

\definefiller[ChapterFiller]

\define[3]\ChapterListEntry
  {\vbox{Hoofdstuk #1 – #2 \filler[ChapterFiller] #3}}

\setuplist[chapter][alternative=interactive,command=\ChapterListEntry]

\starttext
\completecontent
\dorecurse{5}{
\chapter {Knuth} \input knuth
\chapter {Zapf}  \input zapf}
\stoptext

Wolfgang


More information about the ntg-context mailing list