Difference between revisions of "Table of Contents"

From Wiki
Jump to navigation Jump to search
m (Official_ConTeXt_Documentation --> Manuals)
Line 1: Line 1:
== Using Table of Contents ==
+
== Placing the ToC ==
  
 
To get the default table of contents use:
 
To get the default table of contents use:
Line 19: Line 19:
 
</texcode>
 
</texcode>
  
== Modifying the default Table of Contents ==
+
== Modifying the default ToC ==
  
 
The default head that \completecontent places can be altered with
 
The default head that \completecontent places can be altered with
 
{{cmd|setupheadtext|[content=All my contents]}}.
 
{{cmd|setupheadtext|[content=All my contents]}}.
  
You can customize the appearance, number of shown levels and other attributes of predefined TOC. <span style="color:red; font-weight: bold;">Please note that the <code>level</code> parameter has recently (02/2010) no effect in [[Mark IV]], however you can set the number of levels used in the table of contents with the list option (see the next section)</span>, you may use {{cmd|placelist|[chapter,section]}} (optionally adding {{cmd|title|{Contents}}} before) instead of {{cmd|setupcombinedlist|[content][level=2]}}.
+
You can customize the appearance, number of shown levels and other attributes of predefined ToC. <span style="color:red; font-weight: bold;">Please note that the <code>level</code> parameter has recently (02/2010) no effect in [[Mark IV]], however you can set the number of levels used in the table of contents with the list option (see the next section)</span>, you may use {{cmd|placelist|[chapter,section]}} (optionally adding {{cmd|title|{Contents}}} before) instead of {{cmd|setupcombinedlist|[content][level=2]}}.
  
 
<context source="yes">
 
<context source="yes">
Line 38: Line 38:
 
\setuphead[subsubsection][number=no]
 
\setuphead[subsubsection][number=no]
  
% TOC
+
% ToC
% level=4, \subsubsubsections are not listed in TOC
+
% level=4, \subsubsubsections are not listed in ToC
 
% alternative=c, space to the page number is filled with dots
 
% alternative=c, space to the page number is filled with dots
 
\setupcombinedlist[content][level=4, alternative=c,]
 
\setupcombinedlist[content][level=4, alternative=c,]
Line 68: Line 68:
 
</context>
 
</context>
  
== Setting the Number of Sections in the Table of Contents in [[Mark IV]] ==
+
== Setting the number of sections in the ToC in [[Mark IV]] ==
  
 
To set the number of sections included in the table of contents you can explicitly set the list of items included in the 'contents' list. To include chapter, section, and subsection, in the table of contents use:
 
To set the number of sections included in the table of contents you can explicitly set the list of items included in the 'contents' list. To include chapter, section, and subsection, in the table of contents use:
Line 116: Line 116:
 
</context>
 
</context>
  
== Explicitly Excluding Headings from the Table of Content ==
+
== Including unnumbered heads in the ToC ==
 +
 
 +
ConTeXts head mechanism is designed in such a way that heads are stored in a list when they have an incrementing counter, so you must activate this for the 'unnumbered' heads (title, subject, subsubject, etc.) In addition, the {{cmd|placecontent}} command is an aggregate of only the numbered heads; to place a list that also includes unnumbered heads, you must manually specify all the heads you want.
 +
 
 +
<context mode=mkii source=yes>
 +
% mode=mkii
 +
\setuphead[subject]
 +
  [incrementnumber=yes,  % keep track of the number
 +
  number=no]            % but don't show it
 +
 
 +
% Set area in which number is placed:
 +
% distance from margin to left edge of title
 +
% NB: recent versions of MkIV may ignore `width`
 +
%    for unnumbered entries, and may require
 +
%    you to set `margin`, instead.
 +
\setuplist[section][width=2cm]
 +
\setuplist[subject][width=2cm]
 +
 
 +
\setupcombinedlist[content][list={chapter,subject,subsubject,section,subsection}]
 +
 
 +
\setuppapersize[A7][A7]
 +
\starttext
 +
 
 +
  \placecontent
 +
 
 +
  \page
 +
 
 +
  \chapter{One}
 +
  \section{Sec A}
 +
  \subject{Sub B}
 +
  \section{Sec C}
 +
\stoptext
 +
</context>
 +
 
 +
== Explicitly excluding headings from the ToC ==
  
 
To exclude headings from the table of contents, create a new heading that is a copy of the current heading. The new heading will not be in the list of heading that are printed to the table of contents. The command to create a copy of a heading is \definehead. Below is an example of excluding some subheadings from the table of contents. Note that typically this would be done for all subsections under a specific section, but as seen below this is not required:
 
To exclude headings from the table of contents, create a new heading that is a copy of the current heading. The new heading will not be in the list of heading that are printed to the table of contents. The command to create a copy of a heading is \definehead. Below is an example of excluding some subheadings from the table of contents. Note that typically this would be done for all subsections under a specific section, but as seen below this is not required:
Line 140: Line 174:
  
  
== Page Numbering in Table of Contents ==
+
== Page numbering in ToC ==
  
 
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,  
 
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,  
Line 173: Line 207:
 
<span style="color:red; font-weight: bold;">The above method does not work in MkIV (not anymore at least).</span> 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.
 
<span style="color:red; font-weight: bold;">The above method does not work in MkIV (not anymore at least).</span> 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,
+
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,
  
 
<texcode>
 
<texcode>
Line 191: Line 225:
 
</texcode>
 
</texcode>
  
== Forced page break in a TOC ==
+
== 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.
 
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.
Line 199: Line 233:
 
</texcode>
 
</texcode>
  
Then, when you place your TOC, you have to call for the extras and define the spot for the break:
+
Then, when you place your ToC, you have to call for the extras and define the spot for the break:
  
 
<texcode>
 
<texcode>
Line 224: Line 258:
 
see setup for author/title/subtitle titling and author in ToC in [[Proceedings_style]].
 
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 {{cmd|writetolist}}.
+
You can write desired items to the ToC or an other list (see below) using {{cmd|writetolist}}.
  
 
== Several ToC's in different languages ==
 
== Several ToC's in different languages ==
Line 258: Line 292:
  
  
== How the table of contents is generated by ConTeXt ==
+
== How ConTeXt generates the ToC ==
 +
 
 
(from Tobias Burnus [http://archive.contextgarden.net/message/20060809.162652.8f517267.en.html on the mailinglist])
 
(from Tobias Burnus [http://archive.contextgarden.net/message/20060809.162652.8f517267.en.html on the mailinglist])
  
Line 269: Line 304:
 
In principle TeXExec should do this automatically.
 
In principle TeXExec should do this automatically.
  
== Tables of contents (and other lists) via project structures ==
+
== ToC (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):
 
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):
Line 358: Line 393:
  
  
== Suppressing page numbering for the TOC pages ==
+
== Suppressing page numbering for the ToC pages ==
  
 
Sometimes the document needs to have pagenumbering according to realpages, but numbering shouldn't be visible until the first text page. This is Wolfgang's trick (January 2013) for suppressing the pagenumbers so that they'll still be counted:
 
Sometimes the document needs to have pagenumbering according to realpages, but numbering shouldn't be visible until the first text page. This is Wolfgang's trick (January 2013) for suppressing the pagenumbers so that they'll still be counted:

Revision as of 16:39, 24 May 2013

Placing the ToC

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]

Modifying the default ToC

The default head that \completecontent places can be altered with \setupheadtext.

You can customize the appearance, number of shown levels and other attributes of predefined ToC. Please note that the level parameter has recently (02/2010) no effect in Mark IV, however you can set the number of levels used in the table of contents with the list option (see the next section), you may use \placelist[chapter,section] (optionally adding \title{Contents} before) instead of \setupcombinedlist.

\setuppapersize[A5]

\setupcolors[state=start]

% A new ToC title
\setupheadtext[content=All my contents]

% 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
\page[yes]

\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

Setting the number of sections in the ToC in Mark IV

To set the number of sections included in the table of contents you can explicitly set the list of items included in the 'contents' list. To include chapter, section, and subsection, in the table of contents use:

\starttext

\setupcombinedlist[content][list={chapter,section,subsection}]

\startcolor[darkgreen]
\completecontent
\stopcolor
\page[yes]

\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

Or to include subsubsection in the table of contents as well use:

\starttext

\setupcombinedlist[content][list={chapter,section,subsection,subsubsection}]

\startcolor[darkgreen]
\completecontent
\stopcolor
\page[yes]

\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

Including unnumbered heads in the ToC

ConTeXts head mechanism is designed in such a way that heads are stored in a list when they have an incrementing counter, so you must activate this for the 'unnumbered' heads (title, subject, subsubject, etc.) In addition, the \placecontent command is an aggregate of only the numbered heads; to place a list that also includes unnumbered heads, you must manually specify all the heads you want.

% mode=mkii
\setuphead[subject]
  [incrementnumber=yes,  % keep track of the number
   number=no]            % but don't show it

% Set area in which number is placed: 
% distance from margin to left edge of title
% NB: recent versions of MkIV may ignore `width` 
%     for unnumbered entries, and may require 
%     you to set `margin`, instead.
\setuplist[section][width=2cm]
\setuplist[subject][width=2cm]

\setupcombinedlist[content][list={chapter,subject,subsubject,section,subsection}]

\setuppapersize[A7][A7]
\starttext

  \placecontent

  \page

  \chapter{One}
  \section{Sec A}
  \subject{Sub B}
  \section{Sec C}
\stoptext

internal error: copy error 2vAaCm/cropped.pdf

Explicitly excluding headings from the ToC

To exclude headings from the table of contents, create a new heading that is a copy of the current heading. The new heading will not be in the list of heading that are printed to the table of contents. The command to create a copy of a heading is \definehead. Below is an example of excluding some subheadings from the table of contents. Note that typically this would be done for all subsections under a specific section, but as seen below this is not required:

\starttext

% The first parameter is the new heading name, and the second is the
% name of the heading that is copied.
\definehead[mysubsection][subsection]

\startcolor[darkgreen]
\completecontent
\stopcolor
\page[yes]

\section{First section}
\subsection{First subsection}
\mysubsection{Second subsection}
\subsection{Third subsection}
\stoptext


Page numbering in ToC

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 desired items 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 Manuals).

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 ConTeXt generates the ToC

(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.

ToC (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.

Alternating filler dots

The following code was provided by Wolfgang on the mailing list (http://www.ntg.nl/pipermail/ntg-context/2013/071144.html). It produces alternating dots like in Knuths' TeXbook and MetaFont book. The \definefiller command requires ConTeXt version 2013.01.13 or newer.

\definefiller
  [pavel-0]
  [alternative=symbol,
   method=global,
   width=1em,
   leftmargin=.5em,
   rightmargin=.5em,
   symbol=\clap{.}]

\definefiller
  [pavel-1]
  [pavel-0]
  [align=left]

\definefiller
  [pavel-2]
  [pavel-0]
  [align=middle]

\newconditional\PavelState

\define\PavelFiller
  {\ifconditional\PavelState
     \global\setfalse\PavelState
     \filler[pavel-1]%%
   \else
     \global\settrue\PavelState
     \filler[pavel-2]%%
   \fi}

\setuplistalternative
  [c]
  [filler=\PavelFiller]

\starttext
  \completecontent [alternative=c]
  \dorecurse{10}{\expanded{\chapter{Chapter \recurselevel}}}
\stoptext


Suppressing page numbering for the ToC pages

Sometimes the document needs to have pagenumbering according to realpages, but numbering shouldn't be visible until the first text page. This is Wolfgang's trick (January 2013) for suppressing the pagenumbers so that they'll still be counted:

\startsectionblockenvironment[frontpart]
\setuppagenumbering[location=]
\stopsectionblockenvironment

%\startsectionblockenvironment[bodypart]
%\setcounter[userpage][1]
%\stopsectionblockenvironment

\starttext

\startfrontmatter
\completecontent
\stopfrontmatter

\startbodymatter
\dorecurse{10}{\expanded{\chapter{Chapter \recurselevel}}}
\stopbodymatter

\stoptext