At the top of the page in many reference books or encyclopedias, there is always a range stating which topics are covered within a given area, e.g.:

  • A volume of encyclopedias will say "A-B" to indicate that topics beginning with "A or "B" will appear there.
  • The header of a dictionary will say "aardvark to animal", indicating that such topics can be found on that particular page.

I have a document formatted like this:

        \custommacro{South American}
        \custommacro{Kidney Beans}
        \custommacro{Green Beans}
        \custommacro{Jelly Beans}

From this data, how can I display this sort of information?

  • The volume covers "A-B".
  • A particular part covers "Animals-Animation".
  • A particular chapter covers "Disney-South American".
  • A particular page in the book contains parts of the articles about "Green Beans-Jelly Beans".
  • 2
    Did you read chapter 12.4 in the manual about marking? – Marco Apr 15 '12 at 12:18
  • @Marco It would really be useful if you could expand your comment into an answer: we have relatively few ConTeXt experts, so your input would be really helpful! – Joseph Wright Aug 4 '13 at 8:06

To tackle this problem I used a combination of markings and lists. The volume indicating the topics is very similar to a table of contents, so I used that mechanism. Instead of listing all the contained parts, only the first and last one should be displayed. I defined a custom list alternative which does exactly that. An additional check is included to catch the case of only one section element to prevent output like “This part covers Beans - Beans”. The same mechanism is used for the chapter summary. The sections are displayed in the footer of the page and use the markings mechanism, which works without any special modifications.

The custom list is hooked into the part and chapter macros using the insidesection key. This key only works with the MkIV sectioning style. So you have to use \startchapter … \stopchapter instead of \chapter{…}.

The setup:

%% only for the screenshot %%%%%%%%%%%%%%%%%%%%%%%%
\setuppapersize   [A6] [A4, landscape]           %%
\setuparranging   [2SIDE]                        %%
\setuplayout      [marking=on, location=middle]  %%
\setupbodyfont    [16pt]                         %%

\setuplist        [alternative=ListRange] %% a custom list alternative is used
\setupfootertexts [\setups{footer}]

%% displays the topic of the current page in the footer
\startsetups [footer]
  \getmarking [section] [top] --\space
  \getmarking [section] [bottom]

\setuphead [part]    [insidesection=\PartIntro, footer=empty]
\setuphead [chapter] [insidesection=\ChapterIntro]

\starttexdefinition PartIntro
  This part covers:
  \placecontent [list=chapter]

\starttexdefinition ChapterIntro
  This chapter covers:
  \placecontent [list=section]

%% The default list alternatives don't meet the requirements, but it's easy to
%% define a custom one

%% The default lists print a list of all structure elements, but in this case
%% only the first and last one is desired.
\startsetups [list:ListRange]
  %% catch the case of only one chapter per part

The content:


This volume covers: \placecontent [list=part]

\startpart [title=A]
  \startchapter [title=Animals]
    \startsection [title=Koalas]
    \startsection [title=Kangaroos]

  \startchapter [title=Animation]
    \startsection [title=Disney]
    \startsection [title=Japanese]
    \startsection [title=South American]

\startpart [title=B]
  \startchapter [title=Beans]
    \startsection [title=Kidney Beans]
    \startsection [title=Green Beans]
    \startsection [title=Jelly Beans]


screenshot1 screenshot2 screenshot3

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.