4

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:

\part{A}
    \chapter{Animals}
        \custommacro{Koalas}
        \custommacro{Kangaroos}
     \chapter{Animation}
        \custommacro{Disney}
        \custommacro{Japanese}
        \custommacro{South American}
\part{B}
    \chapter{Beans}
        \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
4

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]
\stopsetups

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

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

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

%% The default list alternatives don't meet the requirements, but it's easy to
%% define a custom one
\definelistalternative
  [ListRange]
  [renderingsetup=list:ListRange]

%% 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
  \doifelse\structurelistsize1
    {\crlf\currentlistentrytitle}
    {\doif\currentlistindex1{\crlf\currentlistentrytitle\space--\space}
     \doif\currentlistindex\structurelistsize\currentlistentrytitle}
\stopsetups

The content:

\starttext

\noheaderandfooterlines
This volume covers: \placecontent [list=part]

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

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

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

\stoptext

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.