Table of Contents

From Wiki
Revision as of 12:25, 6 February 2012 by Mari (talk | contribs) (Force page break info added (so I can find it next time I need it...))
Jump to navigation Jump to search

Using Table of Contents

To get the default table of contents use:

\completecontent % with title
\placecontent % without title


One important quirk. If you do not start the document with \completecontent, but use it later –for example after the introduction–, you should use:

\completecontent[criterium=all]


When \completecontent is at the end of the document you can use:

\completecontent[criterium=previous]

Modifing the default Table of Contents

You can customize the appearance, number of shown levels and other attributes of predefined TOC. Please note that level parameter has recently (02/2010) no effect in Mark IV, you may use \placelist[chapter,section] (optionally adding \\title{Contents} before) instead of \setupcombinedlist[content][level=2].

\setupcolors[state=start]
% turn off numbering of some levels
\setuphead[subsection][number=no]
\setuphead[subsubsection][number=no]
% TOC
% level=4, \subsubsubsections are not listed in TOC
% alternative=c, space to the page number is filled with dots
\setupcombinedlist[content][level=4,alternative=c]
%\setuplist[chapter][width=5mm,style=bold]
\setuplist[section][width=10mm,style=bold]
\setuplist[subsection][width=20mm]
% pagestyle=normal for changing the appearance of pagenumber
\setuplist[subsubsection][width=20mm,style=slanted,pagestyle=normal]
\starttext

\startcolor[darkgreen]
\completecontent
\stopcolor

\section{First section}
\subsection{First subsection}
\subsubsection{First subsubsection}
\subsubsubsection{First subsubsubsection}
\section{Second section}
\subsection{Second subsection}
\subsubsection{Second subsubsection}
\subsubsubsection{Second subsubsubsection}
\stoptext

Page Numbering in Table of Contents

If you have a special page numbering style it won't automatically be reflected in the table of contents. You need to set the parameters of the table of contents separately. For example,

\starttext
\startfrontmatter
\placecombinedlist[MyContentsList]
\stopfrontmatter
\startbodymatter
\setuppagenumbering[way=bychapter, left=A, chapternumber=yes, numberseparator=/]
...
\stopbodymatter

will give you pagenumbering such as A1/1, A1/2 etc. on the pages in the bodymatter. In the table of contents, however, these will show up as 1-1, 1-2 etc. The ToC needs to be formatted separately.

To get a prefix to the page numbering (like "A"), use

\def\ChapterPrefix#1{A#1}
\setuplist[chapter][pagecommand=\ChapterPrefix]

To get the numberseparator working, you need to know that the ToC will use the separator that is active at the time the ToC is output. So you need to set it immediately before you call the ToC command, e.g.

\setuppagenumbering[numberseparator=/]
\placecombinedlist[MyContentsList]

The above method does not work in MkIV (not anymore at least). Hence the code below illustrates how to get it working under MkIV. It should be noted that MkIV and MkII are incompatible with respect to this feature.

As an example, consider that the frontmatter uses roman numerals and bodymatter remains unchanged. To reflect the romannumerals of the front matter in the TOC,

\definestructureconversionset[frontpart:pagenumber][][romannumerals]
\definestructureconversionset[bodypart:pagenumber] [][numbers]

\setuplist[chapter][pageconversionset=pagenumber]

\startsectionblockenvironment[frontpart]
\setupuserpagenumber[numberconversion=romannumerals]
\setuppagenumber[number=1]
\stopsectionblockenvironment

\startsectionblockenvironment[bodypart]
\setuppagenumber[number=1]
\stopsectionblockenvironment

Forced page break in a TOC

To add a manual/forced page break in a table of contents, you first have to define it. This puts the break before the given heading.

\definelistextra[page][before=\page]

Then, when you place your TOC, you have to call for the extras and define the spot for the break:

\placecontent[extras={6=page}] %puts break before Chapter 6 list item


Solution given by Hans on the mailing list on September 29, 2010, and applies to MKIV (at least).

Dots in section numbers

Last Number Dot in Table of Contents (e.g. 2.1.3.): see Dotted_number_in_caption.

If you want to avoid a dot if there's no number, try this solution (by Wolfgang Schuster as of 2008-04-29):

\setuplist
  [chapter,section,...]
  [numbercommand=\DotAfterNumber]

\def\DotAfterNumber#1{\doiftext{#1}{#1.}}

Author in ToC

see setup for author/title/subtitle titling and author in ToC in Proceedings_style.

You can write "everything" to the ToC or an other list (see below) using \writetolist.

Several ToC's in different languages

If you want to have two tables of contents in your document, one in a native language and the other, for example, in english. This is how to do it:

\mainlanguage[de]

\starttext

\completecontent

%\start\language[en]
\start\mainlanguage[en]
\completecontent
\stop

\chapter{\translate[en=Chapter One,de=Kapitel Eins]}

\chapter{\translate[en=Chapter Two,de=Kapitel Zwei]}

\stoptext


Creating other "Table of ..."

Generally all "Table (List) of ..." are defined with \definelist and \setuplist. You can "collect" several section levels in one list using \definecombinedlist, that's even explained in "ConTeXt, an excursion" (see Official_ConTeXt_Documentation).

To have some parts of your title texts not appear in the table of contents, use \nolist and have a look at mag-0001.pdf.


How the table of contents is generated by ConTeXt

(from Tobias Burnus on the mailinglist)

The mechanism is a follows:

  1. TeX is run and chapter names with pagenumbers etc. are saved into <jobname>.tui.
  2. TeXutil is run and sorts some entries in *.tui and writes *.tuo
  3. TeX is run again, reads .tuo and uses that data to produce the table of contents etc. (and produces a new .tui) As this changes the page numbers (for longer table of contents), TeXutil and TeX are re-run again.

In principle TeXExec should do this automatically.

Tables of contents (and other lists) via project structures

As of November 25, 2011, ConTeXt Mark IV supports the generation of lists via Project structure. Thus, given a product (possibly within some project), and given two or more components in that product with its own sections (chapters, sections, etc) or floats (figures, tables, etc); then each component can have its own list of contents independent of the other. This is done by setting criterium=component. For example, create three files, one product and two components (slightly modified version of a sample posted by Hans):

\startproduct example-1-product

\definecombinedlist[summary][chapter]
\setupcombinedlist[summary][criterium=component]
 
   \component example-1-component-a
   \component example-1-component-b
 
\stopproduct 
 
\startcomponent example-1-component-a
 
    \starttitle[title=Contents]
        \placesummary
    \stoptitle
    
    \startchapter[title=Ward]
        \input ward
    \stopchapter
 
\stopcomponent 
 
\startcomponent example-1-component-b
 \setupheadnumber[chapter][-1]
 
    \starttitle[title=Contents]
        \placesummary
    \stoptitle

    \startchapter[title=Zapf]
        \input zapf
    \stopchapter
 
\stopcomponent 

Processing the component file will give you a separate table of contents for each component.