Changes

Jump to navigation Jump to search
7,817 bytes added ,  11:58, 17 December 2008
added example from other pages
<table>
<tr bgcolor="#CCCCCC"> <th>numbered</th> <th>unnumbered</th> </tr> <tr> <td><cmd>part</cmd> </td><td>&#151;</td> </tr> <tr> <td><cmd>chapter</cmd></td> <td><cmd>title</cmd></td> </tr> <tr> <td><cmd>section</cmd></td> <td><cmd>subject</cmd></td> </tr> <tr> <td><cmd>subsection</cmd></td> <td><cmd>subsubject</cmd></td> </tr> <tr> <td><cmd>subsubsection</cmd></td> <td><cmd>subsubsubject</cmd></td> </tr> <tr> <td>...</td> <td>...</td> </tr>
</table>
The "''unnumbered" '' versions don't appear in a table of contents! But you can switch off the numbering of the "''numbered" '' versions with <cmd>setuphead</cmd> to get unnumbered titles ''and'' a toc (confusing?).
===Referencing Titles===
Every heading command can take an optional parameter as reference:
 
<texcode>
\title[hasselt-by-night]{Hasselt by night}
</texcode>
The bracket pair is optional and used for internal [[References]]. If you want to refer to thisheader you type for example 
<texcode>
\at{page}[hasselt-by-night].
 
(see <cmd>at</cmd>)
</texcode>
(see <cmd>at</cmd>)
==Titling Style==
A FAQ is how to get a line under the title:
 
<texcode>
\setupbackgrounds[header][text][bottomframe=on]
To make the section numbers appear as characters, do
 
<texcode>
\setupsection[section-3][bodypartconversion=Character]
</texcode>
 
The <code>section-3</code> corresponds to <code>section</code>. Similarly,
<code>section-1</code> corresponds to <code>part</code>, <code>section-2</code> corresponds to <code>chapter</code> and so on.
==Titling Alignment==
If you want you may have colors on your document's chapters or sections.
To do that you should use <codecmd>\setuphead</codecmd>.Take a look at the following example:
<texcode>
\stoptext
 
</texcode>
\definehead[myheader][section]
\setuphead [myheader] [numberstyle=bold, textstyle=cap, before=\hairline\blank, after=\nowhitespace\hairline]
\myheader[hasselt-ref]{Hasselt makes headlines}
</texcode>
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!
==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é.)
=== Truly empty pagebreak before chapters ===
 Using <cmd>setuppagenumbering[alternative=doublesided]</cmd> 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
<texcode>
\definepagebreak [mychapterpagebreak] [yes,header,right] % [yes,header,left] % [yes,header,footer,right]
\setuphead [chapter] [page=mychapterpagebreak] % [page=Mychapterpagebreak,header=empty,footer=empty]
% \setupsectionblock[frontpart][page=chapter]% \setupsectionblock[bodypart][page=chapter]% \setupsectionblock[backpart][page=chapter]% \setupsectionblock[appendix][page=chapter]
\setuppagenumbering[alternative=doublesided,location={header,margin}] \setupheadertexts[{My special headertext}] \setupfootertexts[This is a text in the footer] % \setupbackgrounds[header][text][bottomframe=on]
\starttext \chapter {testA} \dorecurse{10}{\input tufte } \chapter {testB} \dorecurse{10}{\input tufte } \chapter {testC} \dorecurse{10}{\input tufte } \stoptext
</texcode>
== Independent Section Numbering ==
 
If you want section numbering to be independent of chapter numbering, use
<texcode>
\setuphead [chapter][resetnumber=no] \setupsection[section][previousnumber=no]
</texcode>
 
==Your Own Title Styles==
Sometimes the possibilities of <cmd>setuphead</cmd> aren't enough. You can define your own styling commands, as shown in the following examples.
===Expanded chapter titles===
 
This example illustrates expanded chapter titles.
<texcode>
\def\MyChapterCommand#1#2% #1 is number, #2 is text {\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
</texcode>
 
so <tt>\chapter{My First Chapter}</tt> looks like:
 
<context>
\def\MyChapterCommand#1#2% {\framed[frame=off, bottomframe=on, topframe=on] {\vbox{\headtext{chapter} #1\blank#2}}} 
\setuphead[chapter][command=\MyChapterCommand, style={\ss\bfa}]
\setupheadtext[chapter=Chapter]
===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:
<texcode>
\exercise{Batteries}
What is the cost of energy from a 9V battery? From a wall socket (themains)?
</texcode>
<texcode>
\definehead[exercise][subsection]
 \setuphead [exercise] [style=italic, numbercommand={\determineheadnumber[subsection]\currentheadnumber\gobbleoneargument}]
</texcode>
\setuphead[chapter][command=\Myheader]
\setupheadtext [chapter=Chapitre]
\defineoverlay[HeaderDeco][\uniqueMPgraphic{HeaderDeco}]
\starttext
\chapter{Here we go!}
\stoptext
</texcode>
\stoptext
</texcode>
 
===Chapter headers===
 
Setup of headers like chapters.
 
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 ([http://archive.contextgarden.net/message/20041020.100630.d531bb1d.en.html 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.
 
<texcode>
\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]
 
\setuphead
[chapter]
[textcommand=\MyChapterText,
color=BigColorTwo,
style=\BigFontTwo]
 
\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}
 
\starttext
 
\chapter[chap:ques]{Question}
\chapter[chap:answ]{Answer}
\chapter[chap:answ]{Remarque}
\chapter[chap:answ]{Cours}
\chapter[chap:answ]{Exercice}
\chapter[chap:answ]{Travail dirigé}
\chapter[chap:answ]{Exposé}
\stoptext
</texcode>
 
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
 
<context>
\useencoding[ffr]
\mainlanguage[fr]
 
% fonts currently don't work this way,
% I'll fix that soon. Patrick
 
% \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]
 
\setuphead
[chapter]
[textcommand=\MyChapterText,
color=BigColorTwo,
style=\BigFontTwo]
 
\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}
 
\starttext
 
\chapter[chap:ques]{Question}
 
% only one page please, since this is displayed inline. Patrick
% \chapter[chap:answ]{Answer}
% \chapter[chap:answ]{Remarque}
% \chapter[chap:answ]{Cours}
% \chapter[chap:answ]{Exercice}
% \chapter[chap:answ]{Travail dirigé}
% \chapter[chap:answ]{Exposé}
\stoptext
</context>
 
===Figures in Headings===
 
This example shows how to completely replace the chapter text and number by an image:
 
<texcode>
\useexternalfigure[chapter-1][cow.pdf]
\useexternalfigure[chapter-2][hacker.jpg]
 
\setuphead
[chapter]
[command=\MyChapterCommand]
 
\def\MyChapterCommand#1#2%
{\externalfigure[chapter-\currentheadnumber][height=5cm]}
 
\starttext
 
\chapter{One}
\section{First section of Chapter One}
 
\chapter{Two}
 
\stoptext
</texcode>
 
<context>
\useexternalfigure[chapter-1][cow.pdf]
\useexternalfigure[chapter-2][hacker.jpg]
 
\setuphead
[chapter]
[command=\MyChapterCommand]
 
\def\MyChapterCommand#1#2%
{\externalfigure[chapter-\currentheadnumber][height=5cm]}
 
\starttext
 
\chapter{One}
\section{First section of Chapter One}
 
\stoptext
</context>
 
However, this "forgets" to put the chapter in the TOC. So you have to set
the <tt>textcommand</tt> and <tt>numbercommand</tt> separately instead
(thus retaining the command that puts the chapter in the TOC), rather than
setting the overall <tt>command</tt>, if you need a complete TOC.
 
<texcode>
\setuphead
[chapter]
[textcommand=\MyChapterTextCommand,
numbercommand=\MyChapterNumberCommand]
 
\def\MyChapterNumberCommand#1{} % hide chapter number
 
\def\MyChapterTextCommand#1%
{\externalfigure[chapter-\currentheadnumber][height=5cm]}
</texcode>
 
[http://archive.contextgarden.net/message/20050519.215526.df7c5cd1.html]
 
===Editing Chapter head with absolute positioning of following text===
 
<texcode>
\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]
\starttext
\chapter{test} \input tufte
\stoptext
</texcode>
 
No matter how many lines the chapter head runs to, the text will always start, e.g. 4cm below the top of the heading:
 
<context>
\setuppapersize[A6][A6]
\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]
\setupbodyfont[8pt]
\starttext
\chapter{test} \input tufte
\stoptext
</context>
 
====Bug and proposed workaround====
 
I tried this sample and <cmd>getmarking[chapter]</cmd>, used in my headers,
stopped to work properly. Proposed workaround below.
--[[User:Sebastian.rooks|SeR]] 00:52, 27 January 2006 (CET)
 
<texcode>
\def\MyChapterCommand#1#2%
{\vbox to 4cm\bgroup
{#1\hskip.75em #2}
\vss
\egroup}
 
\setuphead[chapter][header=nomarking,command=\MyChapterCommand]
\starttext
\chapter{test} \input tufte
\stoptext
</texcode>
 
<context>
\setuppapersize[A6][A6]
\setupbodyfont[8pt]
\def\MyChapterCommand#1#2%
{\vbox to 4cm\bgroup
{#1\hskip.75em #2}
\vss
\egroup}
\setuphead[chapter][header=nomarking,command=\MyChapterCommand]
\starttext
\chapter{test} \input tufte
\stoptext
</context>
 
===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:
 
<context source="yes" text="produces">
\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
 
\setuphead[section][command=\FirstSolution]
 
\starttext
 
\section{is this nice or not}
 
\section{is this nice or not nice, that's the question}
 
\setuphead[section][command=\SecondSolution,deeptextcommand=\DoSecondSolution]
 
\section{is this nice or not}
 
\section{is this nice or not nice, that's the question}
 
\stoptext
</context>
 
As if that wasn't enough, Taco pointed out that <cmd>lastlinewidth</cmd>
is the easy route to finding the width of the last line. Use something like:
 
<code>
\optimizedisplayspacingtrue\setlastlinewidth % core-mat macro
\global\advance\lastlinewidth-\hangindent\par % adjust
\blackrule[width=\lastlinewidth,height=1pt]
</code>
 
 
[[Category:Fonts]]
[[Category:Graphics]]
[[Category:Text elements]]
gardener
110

edits

Navigation menu