3

I would like to add leading dots before page numbers in ConTeXt registers. What is the best way to accomplish this?

Here is a minimal working example of the current behavior, and the behavior I would like it to produce:

\defineregister[cases][n=1,pagestyle=normal,indicator=no]

\setupcombinedlist[content][alternative=c]
\setuplist[chapter][headnumber=no]
\setuphead[chapter][number=no]

\starttext

\title{Table of Contents}

\placecontent

\chapter{Register Table}

\placecases

\chapter{Content}
This is a \cases{test}test. This is \cases{another test}another test.

\stoptext

The table of contents, using alternative=c, contains the leading dots: Leading Dots

I would like the cases register to appear similarly. As it stands, it appears as follows: enter image description here

3

I did not find anything to set the list alternative as for combined lists, but you can hijack the textcommand to insert the dots. The distance between text and dots and number and dots can be tuned with the distance key.

\starttexdefinition unexpanded register:text #1
  #1
  \hskip\registerparameter{distance}\relax
  \dotfill
\stoptexdefinition

\defineregister
  [cases]
  [
    n=1,
    pagestyle=normal,
    indicator=no,
    distance=1em,
    textcommand=\getvalue{register:text},
  ]

\setupcombinedlist[content][alternative=c]
\setuplist[chapter][headnumber=no]
\setuphead[chapter][number=no]

\starttext

\title{Table of Contents}

\placecontent

\chapter{Register Table}

\placecases

\chapter{Content}
This is a \cases{test}test. This is \cases{another test}another test. \dorecurse{5}{\input knuth} This is a \cases{test}test. This is \cases{another test}another test.

\stoptext

enter image description here


If you want to have exactly the same dots as in the list alternative c for the combined list, use the following textcommand in conjunction with distance=.5em.

\starttexdefinition unexpanded register:text #1
  #1
  \hskip\registerparameter{distance}\relax
  \gleaders\hbox to .5em{\hss.\hss}\hfill
\stoptexdefinition
| improve this answer | |
  • Thanks! Unfortunately, the proposed solution adds dots between multiple page numbers as well. For example, if an index entry for test appears on both page 1 and page 2, the table appears "test .... 1, .... 2". You can generate this effect by using the following code for the body text: This is a \cases{test}test. This is \cases{another test}another test. \dorecurse{5}{\input knuth} This is a \cases{test}test. This is \cases{another test}another test. – J. King Apr 20 '17 at 0:27
  • @J.King You are right. Better hijack textcommand. See updated answer. – Henri Menke Apr 20 '17 at 0:57
  • Great solution. Thank you! Hijacking textcommand rather than pagecommand makes a lot of sense, and it produces the desired result. Interestingly, the \dotfill solution doesn't work for me in my full document, but I'm not going to worry about it for now because the \gleaders version works. Thanks again! – J. King Apr 20 '17 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.