# Titles

## Default

Titles define the structure of your document. Decide yourself, how deep you want to nest them:

numbered unnumbered
\part &#151;
\chapter \title
\section \subject
\subsection \subsubject
\subsubsection \subsubsubject
... ...

The unnumbered versions don't appear in a table of contents! But you can switch off the numbering of the numbered versions with \setuphead to get unnumbered titles and a toc (confusing?).

Also note that in the front matter of the document, all titles are unnumbered by default. In this case, the only difference between the "numbered" and "unnumbered" titles is that the latter don't show up in the table of contents.

### Referencing Titles

Every heading command can take an optional parameter as reference:

\title[hasselt-by-night]{Hasselt by night}


The bracket pair is optional and used for internal References. If you want to refer to this header you type for example

\at{page}[hasselt-by-night].

(see at)


Note that reference labels are limited to ASCII characters in traditional TeX. This limitation has been removed in ConTeXt mkiv.

## Titling Style

see \setuphead and some enhanced samples below.

A FAQ is, how to get a line under the pageheader:

\setupbackgrounds[header][text][bottomframe=on]


To make the section numbers appear as characters, do

\setupsection[section-3][bodypartconversion=Character]


The section-3 corresponds to section. Similarly, section-1 corresponds to part, section-2 corresponds to chapter and so on.

## Titling Alignment

Titles should often be left aligned without hyphenation. Try this:

\setuphead[chapter][align={flushleft, nothyphenated, verytolerant}] % "flushleft" is the same as "right"


## Using colors in chapters and sections

If you want you may have colors on your document's chapters or sections. To do that you should use \setuphead. Take a look at the following example:

\setupcolors[state=start] % Important. You won't have colors without it.

\starttext

\completecontent

\chapter{Black chapter 1}

\section{Dark cyan section 1.1}

\page
Test.

\chapter{Dark green chapter}

\page
Test.

\chapter{Red chapter}

\page
Test.

\stoptext


Of course you can define your own titling commands and probably must adapt the default settings.

\definehead[myheader][section]

[numberstyle=bold,
textstyle=cap,
before=\hairline\blank,
after=\nowhitespace\hairline]



A new header \myheader is defined and it inherits the properties of \section (title, subject, whatever). You can define several headers at once!

\setuphead accepts a number of parameters which change the style of the heading. At least the following commands are available:

text number
textstyle numberstyle
textcommand numbercommand
deeptextcommand deepnumbercommand

Quite obviously, the number-commands work on the chapter/section/etc. number, their text counterparts change the text itself. However, there are differences between style, command and deepcommand.

The style variants accept a style (bold, cap, etc.) or a font switch (\em, \tfx, etc). textstyle prepends the text with the associated style. textcommand is a command name which is given the text (with all markup) as a parameter. deeptextcommand is similar to textcommand but it acts only on the text (not on the markup).

So, if we have \title{A story}, the different parameters have the following results:

 textstyle=\em => \em A story textstyle=\em, textcommand=\uppercase => \uppercase{\em A story} => \em A STORY textstyle=\em, deeptextcommand=\uppercase => \em\uppercase{A story} => \em A STORY

What is the difference between textcommand and deeptextcommand, then? With this example there is very little difference, as uppercase knows how to handle markup. Sometimes this is not the case. For example, an almost similar command WORD is not compatible with textcommand, because it wreaks havoc with markup:

 textstyle=\em, textcommand=\WORD => \WORD{\em A story} => \EM A STORY textstyle=\em, deeptextcommand=\WORD => \em\WORD{A story} => \em A STORY

In this case using deeptextcommand is the correct solution for capitalizing headers. (Using \uppercase works in this specific case, but only if you stick to Latin 1 or Anglo-Saxon characters. Other languages will suffer from lowercase accented characters, like CAFé.)

Use \setuphead[part][conversion=Romannumerals], for example, to employ an alternative numbering scheme.

### Truly empty pagebreak before chapters

Using \setuppagenumbering[alternative=doublesided] makes the chapters start on the right page. However, the blank page is not truely empty, it contains headers and footers. To get truely empty pages, use the following

\definepagebreak
[mychapterpagebreak]

[chapter]
[page=mychapterpagebreak]

%\setupsectionblock[frontpart][page=chapter]
%\setupsectionblock[bodypart][page=chapter]
%\setupsectionblock[backpart][page=chapter]
%\setupsectionblock[appendix][page=chapter]

\setupfootertexts[This is a text in the footer]

\starttext
\chapter{testA} \dorecurse{10}{\input tufte }
\chapter{testB} \dorecurse{10}{\input tufte }
\chapter{testC} \dorecurse{10}{\input tufte }
\stoptext


Explanation (provided by Willi Egger on the mailing list)

• You define a new pagebreak rule. It has the name mychapterpagebreak. The options set read as: pagebreak=yes, placeheader, use a right page.
• You set options for the header of type chapter and use for the option page the afore defined new pagebreak.
• You might want to experiment with the commented lines and see what happens. For example, the \setupsectionblock commands will give a truly blank page (if needed) after the specified \stop*part command.

## Independent Section Numbering

If you want section numbering to be independent of chapter numbering, use

\setuphead   [chapter][resetnumber=no]
\setupsection[section][previousnumber=no]


This is handled differently in mkiv (where "resetnumber=no" is silently ignored):

\definestructureresetset[default][1,1,0][1] % reset part, chapter, but not section


Sometimes one wants an unnumbered chapter, say introduction, the following might do that trick:

\definehead     [intro] [chapter]
\definecombinedlist     [content][intro,chapter,section]

\starttext
\completecontent
\startfrontmatter
\intro{No number}
\stopfrontmatter

\startbodymatter
\chapter{Has number}
\stopbodymatter
\stoptext


Note that just putting the introduction in the frontmatter already did the trick for me (on a recent MkIV).

Sometimes the possibilities of \setuphead aren't enough. You can define your own styling commands, as shown in the following examples.

### Start the title in the margin

This very simple example shows how to start a title within the margin, rather than at the text's edge

\setuphead[chapter][alternative=margin]


This looks like

### Chapter titles in new line

To have the chapter title simply in a new line a new command needs to be defined that takes care of this. It needs to be wrapped in \framed.

\setuplabeltext [en] [chapter=Chapter~]
% Does not work, not wrapped in \framed
% \def\MyChapter#1#2{#1\blank#2}
\define[2]\MyChapter
\startchapter [title=Foo Bar]
\stopchapter


This looks like

### Expanded chapter titles

This example illustrates expanded chapter titles.

\def\MyChapterCommand#1#2% #1 is number, #2 is text
{\framed[frame=off,bottomframe=on,topframe=on]
{\vbox{\headtext{chapter} #1\blank#2}}} % \vbox is needed for \blank to work



so \chapter{My First Chapter} looks like:

### Exercise numbers

For a textbook, suppose that you collect the exercises in a section at the end of each chapter, with each exercise a subsection having a short title, and the exercises should be numbered only by the subsection (not 1.6.7 for example, just 7). The usage:

\section{Exercises}

\exercise{Batteries}
What is the cost of energy from a 9V battery?  From a wall socket (the mains)?


The setup code:

\definehead[exercise][subsection]

[exercise]
[style=italic,


### A complex graphical element under the chapter title

\setupcolors[state=start]
numeric w, h, repeats;
path p[];
w := OverlayWidth ; h := OverlayHeight ;
repeats := abs(TextWidth/BodyFontSize);
p[1] := unitsquare xscaled w yscaled h ;
draw p[1] withcolor white;
p[2] := fullcircle scaled BodyFontSize;
p[3] := fullcircle scaled .25BodyFontSize;
draw p[2] shifted (.5BodyFontSize,0);
for i = 1 upto repeats:
if odd i :
filldraw p[3] shifted (i*BodyFontSize+.5BodyFontSize,0);
else :
draw p[2] shifted (i*BodyFontSize+.5BodyFontSize,0);
fi;
endfor;
\stopuseMPgraphic

\framedtext
[width= \overlaywidth,
height=6\bodyfontsize,
offset=0pt,
strut=no,
frame=off,
align=middle]{%
\blank[small]
#2}}

\starttext
\chapter{Here we go!}
\stoptext


It looks like:

### Titles in margin

It is sometimes wanted to place the title of a section/subject etc in the margin next to the section text (instead of above it). This is achieved by the following setup:

\setuphead
[subject]



See the mailing list thread [[1]] for more on this.

If you want a heading that gets numbered without resetting at new sections or chapters (for example, for problems whose numbers increment throughout a book), here is a solution due to Hans on the mailing list:

% use a lower level head

[Problem]
[subsubsubsection]

% cleaned up

[Problem]
[style=\ss\bf,
color=red,
before=\blank]

% use a label text

\setuplabeltext
[Problem=Problem ]

[Problem]
[ownnumber=yes]

% increment and feed

\newcounter\ProblemNumber

\def\problem#1%
{\doglobal\increment\ProblemNumber
\Problem{\ProblemNumber}{#1}}

% nicer here

\setuplist
[Problem]
[alternative=c,
criterium=all,
width=2em,
interaction=all]

% the test

\starttext

List of Problems

\blank[big] \placelist[Problem] \blank[big]

\section{Tufte}

\input tufte

\problem{First problem}

The first problem description.

\section{Another Tufte}

\input tufte

\problem{Second problem}

Second problem description.

\stoptext


While reading Pixar docs about Renderman, I've found their headers nice and wanted to copy this style. I found a premise in Metafun manual, p.187 (Hello text), and Hans email me (20/10/2004 ) on the context list a more simple solution than using metapost. The minimum is to put it here, for others who are like me, wandering for source code. Feel free to adapt code below to your langage specific settings, mine is french.

\useencoding[ffr]
\mainlanguage[fr]
\enableregime[utf] %for UTF8

% \enableregime[il1]	 %for ISO 8859-1 8859-15

\usetypescript[palatino][texnansi]
\setupbodyfont[palatino,rm,12pt]

\setupcolors[state=start]

\definefont[BigFontOne][Regular sa 3] %RegularSlanted sa 3(ori)%Sans sa 3:don't work (pb accents)
\definefont[BigFontTwo][RegularBold sa 2]   %%RegularSlanted

\definecolor[BigColorOne][r=.86,g=.850,b=.54]
\definecolor[BigColorTwo][r=.43,g=.425,b=.27]

[chapter]
[deeptextcommand=\MyChapterText,
color=BigColorTwo,
style=\BigFontTwo]

\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}

\starttext

\chapter[chap:ques]{Question}
\chapter[chap:answ]{Remarque}
\chapter[chap:answ]{Cours}
\chapter[chap:answ]{Exercice}
\chapter[chap:answ]{Travail dirigé}
\chapter[chap:answ]{Exposé}
\stoptext


I've tryed to change a bit Hans code, by putting \kern15pt, for moving backgroundtext to the left of \rlap alignment, and an unsuccess one to switch same backgroundtext in Sans font (no french accents).

olivier

This example shows how to completely replace the chapter text and number by an image:

\setupexternalfigures[location=default] % needed only for the wiki to the find the figure

\useexternalfigure[chapter-1][cow.pdf]
\useexternalfigure[chapter-2][hacker.jpg]

[chapter]
[command=\MyChapterCommand]

\def\MyChapterCommand#1#2%

\starttext

\chapter{One}
\section{First section of Chapter One}
\chapter{Two}

\stoptext


There are a few snags though. MkII "forgets" to put the chapter in the TOC. So you have to set the deeptextcommand and deepnumbercommand separately instead (thus retaining the command that puts the chapter in the TOC), rather than setting the overall command, if you need a complete TOC.

\setuphead
[chapter]
[deeptextcommand=\MyChapterTextCommand,
deepnumbercommand=\gobbleoneargument]      % hide chapter number

\def\MyChapterTextCommand#1%


Users of MkIV can safely rely on command and don't have to bother with the deep...command variants. However, \currentheadnumber does not seem to return anything but 0. Thus, the following code is required to define \MyChapterCommand when using MkIV:

\def\MyChapterCommand#1#2%


### Chapter head with absolute positioning of following text

\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]
\starttext
\chapter{test} \input tufte
\stoptext


No matter how many lines the chapter head runs to, the text will always start, e.g. 4cm below the top of the heading:

#### Bug and proposed workaround

I tried this sample and \getmarking[chapter], used in my headers, stopped to work properly. Proposed workaround below. --SeR 00:52, 27 January 2006 (CET)

\def\MyChapterCommand#1#2%
{\vbox to 4cm\bgroup
{#1\hskip.75em #2}
\vss
\egroup}

\starttext
\chapter{test} \input tufte
\stoptext


### Section head with underlining to width of last line

A style called for section headings to be followed by a rule which extends only the width of the text. More tricky was the need to make sure that if the text ran onto another line, it was the length of the last line that was to be followed.

Hans came up with this cleverness, showing two alternate ways of doing it:

\def\FirstSolution#1#2%
{\vbox\bgroup
\setbox0\hbox{#1}
\hsize.4\textwidth
\beginshapebox#2\endshapebox
\gdef\SetLastLineWidth{\xdef\LastLineWidth{\the\wd\scratchbox}}%
\reshapebox
{\setbox\scratchbox\hbox{\unhbox\shapebox}%
\SetLastLineWidth
\globallet\SetLastLineWidth\relax
\box\scratchbox}%
\scratchdimen\dimexpr\wd0+.25em+\LastLineWidth\relax
% \setbox2\ruledvbox   {\innerflushshapebox}
% why is correction needed
\setbox2\vbox        {\vskip-\lineskip\innerflushshapebox}
\setbox0\vbox to \ht2{\box0}
\hbox{\box0\hskip.25em\box2}
\offinterlineskip
\vskip.25ex
\blackrule[width=\scratchdimen,height=1pt]
\egroup}

\doglobal\newcounter\NextLinePos

\def\SecondSolution#1#2%
{\vbox\bgroup
\hsize.4\textwidth
\doglobal\increment\NextLinePos
\setbox\scratchbox\hbox{#1}
\hbox{\vtop{\copy\scratchbox}\hskip.25em\vtop{#2}}%
\offinterlineskip
\scratchdimen\dimexpr\wd\scratchbox+.25em+
\MPx{e:npl:\NextLinePos}-\MPx{b:npl:\NextLinePos}\relax
\vskip.25ex
\blackrule[width=\scratchdimen,height=1pt]
\egroup}

\def\DoSecondSolution#1%
{\bpos{npl:\NextLinePos}#1\epos{npl:\NextLinePos}}

% \showstruts

\starttext

\section{is this nice or not}

\section{is this nice or not nice, that's the question}

\section{is this nice or not}

\section{is this nice or not nice, that's the question}

\stoptext


produces

As if that wasn't enough, Taco pointed out that \lastlinewidth is the easy route to finding the width of the last line. Use something like:

 \optimizedisplayspacingtrue\setlastlinewidth % core-mat macro \global\advance\lastlinewidth-\hangindent\par % adjust \blackrule[width=\lastlinewidth,height=1pt] 

### Flushing section head data without typesetting them in the text

The following is probably a very special case. Hoever suppose you need to place section information like the title e.g. in the topspace area. You want that the section is still displayed in the TOC, but you do not want that at the spot where \\startsection[title=...,list=...] resides there is any trace of it. The command to be used to hide the section title is:

Be aware that with this setting indeed the section title is not shown and no whit space is inserted. However in this way also the list entry for the TOC is gone. What you can do in such cases is to use the following command in connection with the above mentioned setting:

What happens is that the information in the \\startsection[title=...,list=...] command is passed to the texttexts, which are flushed at every page. In order to see when it is flushed you might place e.g. !!! in front of the \\placerawheaddata[section].

The result is a complete TOC without any trace of the section heading in the text.

Test: