Difference between revisions of "Titles"

From Wiki
Jump to navigation Jump to search
(→‎Titling Style: How to change section numbers to characters)
(An addition clarifying textcommand, deeptextcommand and textstyle.)
Line 66: Line 66:
 
A new header <cmd>myheader</cmd> is defined and it inherits the properties of <cmd>section</cmd> (title, subject, whatever).
 
A new header <cmd>myheader</cmd> is defined and it inherits the properties of <cmd>section</cmd> (title, subject, whatever).
 
You can "define" several headers at once!
 
You can "define" several headers at once!
 +
 +
==Formatting Titles with <cmd>setuphead</cmd>==
 +
 +
<cmd>setuphead</cmd> accepts a number of parameters which change the style of the heading. At least the following commands are available:
 +
 +
<table>
 +
<tr bgcolor="#CCCCCC"><th>text</th><th>number</th></tr>
 +
<tr><td><tt>textstyle</tt></td><td><tt>numberstyle</tt></td></tr>
 +
<tr><td><tt>textcommand</tt></td><td><tt>numbercommand</tt></td></tr>
 +
<tr><td><tt>deeptextcommand</tt></td><td><tt>deepnumbercommand</tt></td></tr>
 +
</table>
 +
 +
Quite obviously, the number-commands work on the chapter/section/etc. number, their text counterparts change the text itself. However, there are differences between <tt>style</tt>, <tt>command</tt> and <tt>deepcommand</tt>.
 +
 +
The <tt>style</tt> variants accept a style (<tt>bold</tt>, <tt>cap</tt>, etc.) or a font switch (<cmd>em</cmd>, <cmd>tfx</cmd>, etc). <tt>texstyle</tt> prepends the text with the associated style. <tt>textcommand</tt> is a command name which is given the text (with all markup) as a parameter. <tt>deeptextcommand</tt> is similar to <tt>textcommand</tt> but it acts only on the text (not on the markup).
 +
 +
So, if we have <cmd>title{A story}</cmd>, the different parameters have the following results:
 +
 +
<table>
 +
<tr><td><tt>textstyle=\em</tt></td><td><tt>=></tt></td><td><tt>\em A story</tt></td></tr>
 +
<tr><td><tt>textstyle=\em, textcommand=\uppercase</tt></td><td><tt>=></tt></td><td><tt>\uppercase{\em A story}</tt></td><td><tt>=></tt></td><td><tt>\em A STORY</tt></td></tr>
 +
<tr><td><tt>textstyle=\em, deeptextcommand=\uppercase</tt></td><td><tt>=></tt></td><td><tt>\em\uppercase{A story}</tt></td><td><tt>=></tt></td><td><tt>\em A STORY</tt></td></tr>
 +
</table>
 +
 +
What is the difference between <tt>textcommand</tt> and <tt>deeptextcommand</tt>, then? With this example there is very little difference, as <tt>uppercase</tt> knows how to handle markup. Sometimes this is not the case. For example, an almost similar command <tt>WORD</tt> is not compatible with <tt>textcommand</tt>, because it wreaks havoc with markup:
 +
 +
<table>
 +
<tr><td><tt>textstyle=\em, textcommand=\WORD</tt></td><td><tt>=></tt></td><td><tt>\WORD{\em A story}</tt></td><td><tt>=></tt></td><td><tt>\EM A STORY</tt></td></tr>
 +
<tr><td><tt>textstyle=\em, deeptextcommand=\WORD</tt></td><td><tt>=></tt></td><td><tt>\em\WORD{A story}</tt></td><td><tt>=></tt></td><td><tt>\em A STORY</tt></td></tr>
 +
</table>
 +
 +
In this case using <tt>deeptextcommand</tt> is the correct solution for capitalizing headers. (Using <cmd>uppercase</cmd> 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é.)
 +
  
 
==Table(s) of Contents==
 
==Table(s) of Contents==

Revision as of 13:13, 3 April 2006

< Structurals | Visuals >

Default

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

numberedunnumbered
\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?).

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)

Titling Style

see \setuphead and some enhanced samples below.

A FAQ is how to get a line under the title:

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

see \setupsection on modifying how the number appears. To make the section numbers appear as characters, do

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

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

Your Own Titling Levels

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

\definehead[myheader][section]

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

\myheader[hasselt-ref]{Hasselt makes headlines}

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

Formatting Titles with \setuphead

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

textnumber
textstylenumberstyle
textcommandnumbercommand
deeptextcommanddeepnumbercommand

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). texstyle 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é.)


Table(s) of Contents

Default:

\completecontent % with title
\placecontent % without title

Define your own "table of somewhat" 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 http://www.pragma-ade.com/general/magazines/mag-0001.pdf.

Page Numbering in Tables 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]

Your Own Title Styles

Sometimes the possibilities of \setuphead aren't enough. Just define your own styling command like this:

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

\setuphead[chapter][command=\MyChapterCommand, style={\ss\bfa}]

\setupheadtext[chapter=Chapter] % used by \headtext

so \chapter{My First Chapter} looks like:


A complex graphical element under the chapter title

\setupcolors[state=start]
\startuseMPgraphic{HeaderDeco}
    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

\setuphead[chapter][command=\Myheader]
\setupheadtext
      [chapter=Chapitre]
\defineoverlay[HeaderDeco][\uniqueMPgraphic{HeaderDeco}]

\def\Myheader#1#2{%
    \framedtext
        [width= \overlaywidth,
        height=6\bodyfontsize,
        background={foreground,HeaderDeco},
        offset=0pt,
        strut=no,
        frame=off,
        align=middle]{%
            \headtext{chapter} #1
            \blank[small]
            #2}}

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

It looks like: